Andy Wingo [Tue, 17 Mar 2009 15:01:18 +0000 (16:01 +0100)]
Andy Wingo [Tue, 17 Mar 2009 14:59:40 +0000 (15:59 +0100)]
Merge commit '
53d81399bef1d9396665e79fb6b9c25eb8e2a6ad' into vm-check
Also cherry-picks the changes from
1405f1b60fa178303484cd428068ecd01ff6d322
Conflicts:
module/ice-9/session.scm
Andy Wingo [Tue, 17 Mar 2009 14:57:07 +0000 (15:57 +0100)]
Andy Wingo [Tue, 17 Mar 2009 14:56:31 +0000 (15:56 +0100)]
Andy Wingo [Tue, 17 Mar 2009 14:56:22 +0000 (15:56 +0100)]
Andy Wingo [Tue, 17 Mar 2009 14:54:42 +0000 (15:54 +0100)]
Andy Wingo [Tue, 17 Mar 2009 14:54:34 +0000 (15:54 +0100)]
Merge commit '
752be95a475132506c35922d284884cf776149d0' into vm-check
Conflicts:
INSTALL
Andy Wingo [Tue, 17 Mar 2009 14:52:41 +0000 (15:52 +0100)]
Andy Wingo [Fri, 13 Mar 2009 22:45:24 +0000 (23:45 +0100)]
revert annotation support in syncase. another day perhaps.
* module/ice-9/syncase.scm: Revert support for annotations, as I'm seeing
wierd problems whereby syntax-object->datum does not fully strip its
input.
Andy Wingo [Sun, 8 Mar 2009 22:51:12 +0000 (23:51 +0100)]
Fix errors when stripping annotations
* module/ice-9/annotate.scm (set-annotation-stripped!): Fix prototype to
correspond to what syncase needs.
* module/ice-9/psyntax.scm (strip-annotation): Use `if', not `when', for
portability.
* module/ice-9/psyntax-pp.scm: Regenerate.
Andy Wingo [Fri, 6 Mar 2009 18:50:11 +0000 (19:50 +0100)]
actually use syncase's source information tracking. rock!
* module/ice-9/annotate.scm (deannotate/source-properties): Version of
deannotate that sets source properties on the resulting expressions.
* module/ice-9/syncase.scm (sc-macro, syncase): Annotate expressions
before they go into syncase, and deannotate/source-properties when they
come out. The upshot is that syncase now understands source
information, yay!
Andy Wingo [Fri, 6 Mar 2009 18:37:44 +0000 (19:37 +0100)]
modify psyntax so it produced annotated source if given annotated source
* module/ice-9/psyntax.scm (build-annotated): New helper, used by the
output constructors.
(build-application, build-conditional, build-lexical-reference)
(build-lexical-assignment, build-global-reference)
(build-global-assignment, build-global-definition, build-lambda)
(build-primref, build-data, build-sequence, build-let)
(build-named-let, build-letrec, build-lexical-var): Use
build-annotated, so we produce annotated source if we have source
information.
* module/ice-9/psyntax-pp.scm: Regenerated.
Andy Wingo [Fri, 6 Mar 2009 16:01:47 +0000 (17:01 +0100)]
support source-level annotations in syncase
* module/ice-9/annotate.scm (<annotation>): Slightly more concise
printing.
(annotate): Don't create annotations if we have no source info.
* module/ice-9/psyntax.scm (annotation?): Remove this definition, as we
now provide annotation support.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/syncase.scm: Use (ice-9 annotate).
* module/language/scheme/expand.scm (eval-when): Define the eval-when
transformer.
Andy Wingo [Fri, 6 Mar 2009 15:57:17 +0000 (16:57 +0100)]
fix eval-when statements in boot-9
* module/ice-9/boot-9.scm: Fix a couple eval-when statements.
Andy Wingo [Fri, 6 Mar 2009 12:29:13 +0000 (13:29 +0100)]
Replace eval-case with eval-when
* module/ice-9/boot-9.scm (eval-when): Replace eval-case with eval-when.
Eval-when is *much* simpler, and more expressive to boot. Perhaps in
the future we'll get 'visit and 'revisit too.
* module/ice-9/deprecated.scm (eval-case): Provide mostly-working
deprecated version of eval-case.
* module/ice-9/boot-9.scm (defmacro, define-macro): Relax condition: we
can make defmacros that are not at the toplevel now. But in the future
we should replace this implementation of defmacros with one written in
syntax-case.
(define-module, use-modules, use-syntax): Allow at non-toplevel.
(define-public, defmacro-public, export, re-export): Don't evaluate at
compile-time, I can't see how that helps things. Allow `export' and
`re-export' at non-toplevel.
* module/ice-9/getopt-long.scm:
* module/ice-9/i18n.scm:
* module/oop/goops.scm:
* module/oop/goops/compile.scm:
* module/oop/goops/dispatch.scm: Switch to use eval-when, not
eval-case.
* module/language/scheme/compile-ghil.scm (eval-when): Replace eval-case
transformer with eval-when transformer. Sooooo much simpler, and it
will get better once we separate expansion from compilation.
* module/language/scheme/expand.scm (quasiquote): Hm, expand quasiquote
properly. Not hygienic. Syncase needed.
(lambda): Handle internal defines with docstrings propertly.
Andy Wingo [Mon, 2 Mar 2009 21:15:27 +0000 (22:15 +0100)]
fixups to expand.scm
* module/language/scheme/expand.scm: Some changes to avoid unnecessary
begins or empty lets, and properly handle internal defines (finally).
Andy Wingo [Mon, 2 Mar 2009 16:27:45 +0000 (17:27 +0100)]
add separate expansion phase, to detwingle things a bit
* module/language/scheme/expand.scm: New module, implements a separate
expansion phase, not interleaved with compilation.
* module/language/scheme/amatch.scm: Helper for expand.scm, it's pmatch
with support for annotated source.
* module/ice-9/Makefile.am (SOURCES): Add annotate.scm to build list --
early on because it will be used in the compiler.
* module/ice-9/annotate.scm: Fix the printer, default to unstripped
(whatever that is), and add a deannotator.
* module/system/base/compile.scm (call-with-compile-error-catch): Fix for
new representation of source locations.
* module/Makefile.am (SCHEME_LANG_SOURCES): Add amatch and expand.
Andy Wingo [Mon, 2 Mar 2009 14:46:17 +0000 (15:46 +0100)]
fix printer in struct docs
* doc/ref/api-compound.texi (Vtables): Fix example printer.
Andy Wingo [Mon, 2 Mar 2009 10:23:03 +0000 (11:23 +0100)]
add annotation module
* module/ice-9/annotate.scm: Add annotation module, for source location
tracking with syncase, and for internal use in the compiler.
Andy Wingo [Fri, 27 Feb 2009 15:25:32 +0000 (16:25 +0100)]
make the ES compiler more readable via use of ->
* module/language/ecmascript/compile-ghil.scm: Use -> to make the ES
compiler more readable. Fix bugs in do, while, and for, whereby we were
missing ->boolean calls.
Andy Wingo [Fri, 27 Feb 2009 14:17:01 +0000 (15:17 +0100)]
use -> macro in scheme->ghil compiler
* module/language/scheme/compile-ghil.scm (->): New macro, makes GHIL
generation a bit more palatable. Use it in all the transformers.
Andy Wingo [Fri, 27 Feb 2009 12:37:35 +0000 (13:37 +0100)]
slight optimization in transform-record, note in optimize*
* module/language/ghil/compile-glil.scm (optimize*): Add a note.
* module/system/base/syntax.scm (transform-record): Access the common
slots once at the beginning. Cuts down on the number of toplevel refs
needed by the generated code.
Andy Wingo [Fri, 27 Feb 2009 12:24:38 +0000 (13:24 +0100)]
introduce -> binding inside transform-record body expressions
* module/system/base/syntax.scm (transform-record): Introduce a ->
binding inside the body, that produces records of the same type.
* module/language/ghil/compile-glil.scm (optimize*): Remove our ->ghil
definition, as transform-record introduces a -> binding for us. Nice.
Andy Wingo [Fri, 27 Feb 2009 11:36:58 +0000 (12:36 +0100)]
first stabs as s-expression-driven transformation of GHIL
* module/language/ghil/compile-glil.scm (optimize*): Rewritten optimizer
-- not yet in use, but it's closer to the code that I'd like to write.
* module/system/base/syntax.scm (transform-record): New crazy macro,
makes GHIL a little less painful to work with.
Andy Wingo [Fri, 27 Feb 2009 09:56:15 +0000 (10:56 +0100)]
common slot accessors are procedures-with-setters
* module/system/base/syntax.scm (define-type): Common slot accessors are
also procedures-with-setters.
Andy Wingo [Fri, 27 Feb 2009 09:53:00 +0000 (10:53 +0100)]
use common slots mechanism in ghil
* module/system/base/syntax.scm (define-type): Fix getter for common
slot.
* module/language/ghil.scm (<ghil>): Use the common slots mechanism.
Andy Wingo [Fri, 27 Feb 2009 09:44:47 +0000 (10:44 +0100)]
define-type has #:common-slots
* module/system/base/syntax.scm (define-type): Accept a #:common-slots
argument, defining slots that are in all instances of this type.
Andy Wingo [Tue, 24 Feb 2009 23:21:03 +0000 (00:21 +0100)]
fix variable not initialized spurious warnings
* libguile/vm-i-system.c: Work around some spurious "variable not
initialized" messages on Etch's gcc.
Andy Wingo [Tue, 24 Feb 2009 23:16:26 +0000 (00:16 +0100)]
don't crash etch's gcc
* libguile/vm-engine.h: Don't allocate registers in registers if we're on
Etch's GCC.
Andy Wingo [Tue, 24 Feb 2009 23:06:58 +0000 (00:06 +0100)]
export procedure-arguments from ice-9 session
* module/system/vm/program.scm (program-arguments): New function, used by
procedure-arguments.
* module/ice-9/session.scm (procedure-arguments): New exported function,
returns an alist describing the given procedure.
Ludovic Courtès [Tue, 24 Feb 2009 22:52:57 +0000 (23:52 +0100)]
Aggregate makefiles for `module/system' and `module/language'.
* am/guilec (.scm.go): Create the target's directory, in case
$(builddir) != $(srcdir).
* configure.in: Don't output any makefile under `module/system' or
`module/language'.
* module/Makefile.am (SUBDIRS): Remove `language' and `system'. Add `.'
to the front.
(modpath, SOURCES, SCHEME_LANG_SOURCES, ECMASCRIPT_LANG_SOURCES,
GHIL_LANG_SOURCES, GLIL_LANG_SOURCES, ASSEMBLY_LANG_SOURCES,
BYTECODE_LANG_SOURCES, OBJCODE_LANG_SOURCES, VALUE_LANG_SOURCES): New
variables, taken from former `Makefile.am' files in sub-directories.
Andy Wingo [Tue, 24 Feb 2009 22:34:26 +0000 (23:34 +0100)]
unbork the repl
* module/system/repl/repl.scm (meta-reader): Whoops, unbork the repl.
Andy Wingo [Tue, 24 Feb 2009 22:16:58 +0000 (23:16 +0100)]
in meta-reader, return directly if the peeked char is EOF
* module/system/repl/repl.scm (meta-reader): If the (next-char #t)
returns EOF, return that EOF directly, as it seems that with guile -q,
the subsequent `read' actually waits for another C-d. Dunno why.
Andy Wingo [Tue, 24 Feb 2009 22:02:33 +0000 (23:02 +0100)]
use umask when making permissions on .go files
* module/system/base/compile.scm (call-with-output-file/atomic): Temp
files get created 0600. After we're done writing, chmod them to
something in line with the user's umask.
Andy Wingo [Tue, 24 Feb 2009 21:32:50 +0000 (22:32 +0100)]
use nobase in am/guilec
* am/guilec (nobase_mod_DATA): Use nobase_mod_DATA so we install to the
correct dir for foo/bar.scm.
Andy Wingo [Sun, 22 Feb 2009 16:37:59 +0000 (17:37 +0100)]
parse division vs regexps properly
* module/language/ecmascript/tokenize.scm (make-tokenizer/1): Whoops, fix
the cases in which we detect that division is valid.
Andy Wingo [Sun, 22 Feb 2009 15:01:11 +0000 (16:01 +0100)]
compile for-in
* module/language/ecmascript/base.scm (prop-keys): New method, returns
the list of keys of props of this instance.
* module/language/ecmascript/impl.scm: Refactor the global object into a
special kind of module object. Provide a prop-keys implementation for
module objects.
* module/language/ecmascript/compile-ghil.scm (comp): Compile for-in.
* module/language/ecmascript/impl.scm: Reshuffly things, and implement
make-enumerator, a helper for use in for-in statements.
* module/language/ecmascript/parse.scm (parse-ecmascript): Fix parsing of
for (var foo in bar) {}...
Andy Wingo [Sun, 22 Feb 2009 11:07:09 +0000 (12:07 +0100)]
fix "for" compilation
* module/language/ecmascript/compile-ghil.scm (comp): Whoops, fix `for'
compilation.
Andy Wingo [Sun, 22 Feb 2009 10:55:20 +0000 (11:55 +0100)]
add scheme integration to js via `require'
* module/language/ecmascript/impl.scm: Add <js-module-object>, that wraps
a module. Add js-require, a javascript-happy function that returns an
object that wraps a Guile module. Bind it to `require' in the default
environment.
Andy Wingo [Sun, 22 Feb 2009 10:37:55 +0000 (11:37 +0100)]
ecmascript tokens have source info
* module/language/ecmascript/tokenize.scm: Attach source information to
tokens. We have to enhance the lalr parser to actually let this
information propagate through, though...
Andy Wingo [Sun, 22 Feb 2009 10:20:15 +0000 (11:20 +0100)]
throw SyntaxError on bad syntax
* module/language/ecmascript/parse.scm (syntax-error):
* module/language/ecmascript/tokenize.scm (syntax-error): Throw an error
on bad syntax.
Andy Wingo [Sun, 22 Feb 2009 10:06:13 +0000 (11:06 +0100)]
more arithmetic on non-numbers
* module/language/ecmascript/compile-ghil.scm (comp): Convert to number
on unary +.
* module/language/ecmascript/impl.scm: Define -, *, /, <, <=, >=, >
operations on non-numbers.
Andy Wingo [Sun, 22 Feb 2009 09:51:49 +0000 (10:51 +0100)]
+ for strings, global js object, new Foo() works
* module/language/ecmascript/array.scm (*array-prototype*): Declare the
constructor.
* module/language/ecmascript/base.scm (pput, pdel): Remove some needless
checks.
(new): Move definition of new here, and use the constructor.
* module/language/ecmascript/compile-ghil.scm (compile-ghil): Add a stub
so that when we load a compiled JS program, we make sure the runtime
has been booted.
* module/language/ecmascript/function.scm (js-constructor): Export a
js-constructor method instead of a new method.
* module/language/ecmascript/impl.scm (<js-global-object>): Define a new
class for the global "this" object, wrapping bindings from the current
module.
(init-js-bindings!): Define the dozen or so global properties, in the
current module.
(+): Define addition operations for non-numbers. This is efficient
because the generics are only dispatched if the fast-path fails.
Andy Wingo [Sat, 21 Feb 2009 19:07:57 +0000 (20:07 +0100)]
compile ecmascript's parser. yay! instant load-time!
* module/language/ghil/compile-glil.scm (codegen): If there are more than
255 arguments, make a list and use apply instead of calling directly.
* module/language/Makefile.am: Now we can compile parse.scm. Yay!
* module/language/scheme/compile-ghil.scm: Add a note.
* module/language/ecmascript/compile-ghil.scm: Add a note.
Andy Wingo [Sat, 21 Feb 2009 18:25:35 +0000 (19:25 +0100)]
be smarter about allocating local variables, reusing slots if possible
* module/language/Makefile.am: OK, we can compile compile-ghil.scm now,
thankfully.
* module/language/ecmascript/compile-ghil.scm (ormatch): New macro, a
wrapper around pmatch to avoid some of the more egregious
non-tail recursiveness.
(comp): Use ormatch.
* module/language/ghil.scm (unparse-ghil): The body of bind and mv-bind
is a single expression, not a list of expressions.
* module/language/ghil/compile-glil.scm (codegen): Be more clever when
allocating "local" variables -- if a variable goes out of scope, its
index can be re-used later.
* module/language/glil.scm (parse-glil, unparse-ghil): The "rest" of a
mv-bind is a flag, not a list. The "ra" of an mv-call is a label, not a
GLIL expression.
* module/language/objcode/spec.scm (collapse-locals, decompile-value):
When decompiling a value, process the bindings list differently.
Comments in the code.
* module/language/scheme/compile-ghil.scm (define-scheme-translator): Fix
the generated error procedure.
(let): Re-indent.
(letrec): Re-indent.
* module/system/base/syntax.scm (record-case): If the body of a clause is
null, fill it with the unspecified value.
Andy Wingo [Sat, 21 Feb 2009 13:04:53 +0000 (14:04 +0100)]
implement break and continue, work around overly recursive pmatch expansion
* libguile/vm-i-system.c (goto/args): On a tail call to a different
procedure, init the locals to valid scheme values. Shouldn't matter for
well-compiled scheme, but inspecting uninitialized locals could give
garbage, or badly-compiled code could cause a crash.
* module/language/Makefile.am (NOCOMP_SOURCES): For the moment, don't
compile compile-ghil.scm. I need to fix this.
* module/language/ecmascript/compile-ghil.scm (load-toplevel): Sigh, and
disable stack checking in the evaluator too. Grr.
(comp): Implement (unnamed) break and continue.
* module/language/ecmascript/parse.scm (parse-ecmascript): Fix var
statements in `for' -- though it still doesn't work.
Ludovic Courtès [Fri, 20 Feb 2009 23:47:59 +0000 (00:47 +0100)]
Fix `.go' compilation for $(builddir) != $(srcdir).
* am/guilec (.scm.go): Use "-o $@" to make sure the output file ends up
in $(builddir).
Ludovic Courtès [Fri, 20 Feb 2009 23:36:29 +0000 (00:36 +0100)]
Add `-o'/`--output' option to "guile-tools compile".
* module/system/base/compile.scm (compile-file): Add optional
OUTPUT-FILE argument.
* scripts/compile (fail): New procedure.
(%options): Add `-o'/`--output' option.
(compile): Handle `-o'.
Andy Wingo [Fri, 20 Feb 2009 23:31:43 +0000 (00:31 +0100)]
implement do, while, for
* module/language/ecmascript/compile-ghil.scm (comp): Use ghil-bind when
making temp vars, so that disassembly understands things. Implement do,
while, and for.
* module/language/ecmascript/parse.scm (parse-ecmascript): Some tweaks.
* module/language/ecmascript/impl.scm (language): Export ->boolean.
Andy Wingo [Fri, 20 Feb 2009 17:16:34 +0000 (18:16 +0100)]
implement more operations
* module/language/ecmascript/base.scm: Implement some more robust
property getters that convert strings to symbols. Implement
has-property?.
* module/language/ecmascript/compile-ghil.scm (comp): Implement lots more
mathematical operators. We now do all expressions; on to statements.
* module/language/ecmascript/impl.scm: Define some math helpers. They
probably need to call ->number on some things.
* module/language/ecmascript/parse.scm (parse-ecmascript): Fix a typo.
Andy Wingo [Fri, 20 Feb 2009 16:08:20 +0000 (17:08 +0100)]
clean up ++ and -- a little bit
* module/language/ecmascript/compile-ghil.scm (comp): Define let1 and
begin1 helpers. Use them in pre- and post- increment and decrement.
Andy Wingo [Fri, 20 Feb 2009 15:15:50 +0000 (16:15 +0100)]
implement ++, --, new, delete, void, typeof
* module/language/ecmascript/compile-ghil.scm (@impl): Implement with
@implv.
(comp): Implement ++ and -- (pre- and post-). Quite a pain. I'll be
looking for ways to simplify this notation. Also implement new, delete,
and void.
* module/language/ecmascript/impl.scm: Implement typeof.
Andy Wingo [Fri, 20 Feb 2009 12:21:09 +0000 (13:21 +0100)]
handle "this" in ecmascript
* module/language/ecmascript/base.scm:
* module/language/ecmascript/compile-ghil.scm:
* module/language/ecmascript/impl.scm:
* module/language/ecmascript/parse.scm: Compile "method calls" in such a
way that "this" gets propagated correctly.
Andy Wingo [Fri, 20 Feb 2009 11:50:15 +0000 (12:50 +0100)]
implement more of the standard runtime
* module/language/Makefile.am:
* module/language/ecmascript/impl.scm:
* module/language/ecmascript/array.scm:
* module/language/ecmascript/base.scm:
* module/language/ecmascript/function.scm: Split out the runtime into
different files. Implement more of the spec's runtime.
Ludovic Courtès [Fri, 20 Feb 2009 16:38:32 +0000 (17:38 +0100)]
Fix interpretation of `(ice-9 getopt-long)'.
* module/ice-9/getopt-long.scm (define-one-option-spec-field-accessor,
define-one-option-spec-field-modifier): Eval-case for `load-toplevel'
as well so that the interpreter can load this module.
Ludovic Courtès [Fri, 20 Feb 2009 16:12:47 +0000 (17:12 +0100)]
Fix compilation of `(ice-9 getopt-long)'.
* module/ice-9/getopt-long.scm (option-spec-fields): Enclose in a
`(load-toplevel compile-toplevel)' `eval-case'.
(define-one-option-spec-field-accessor,
define-one-option-spec-field-modifier): Enclose in a
`compile-toplevel'-only `eval-case'.
Ludovic Courtès [Fri, 20 Feb 2009 15:19:12 +0000 (16:19 +0100)]
Add `-L'/`--load-path' option to "guile-tools compile".
* scripts/compile (%options): Add `-L'/`--load-path'.
(parse-args): Have `load-path' default to '().
(compile): Handle `--load-path' option.
Ludovic Courtès [Fri, 20 Feb 2009 15:11:49 +0000 (16:11 +0100)]
Change "guile-tools compile" to use SRFI-37 to process options.
* scripts/compile (%options): Rewrite in SRFI-37 style.
(parse-args): New procedure.
(compile): Update to SRFI-37.
Ludovic Courtès [Fri, 20 Feb 2009 13:23:55 +0000 (14:23 +0100)]
Make the `module-defer-observers-mutex' recursive.
* module/ice-9/boot-9.scm (module-defer-observers-mutex): Made
recursive. See
http://lists.gnu.org/archive/html/guile-devel/2009-02/msg00068.html
for an example where it matters.
Andy Wingo [Thu, 19 Feb 2009 16:25:52 +0000 (17:25 +0100)]
support foo["bar"] in addition to foo.bar
* module/language/ecmascript/parse.scm (parse-ecmascript): And update the
function declaration forms for the new var syntax.
* module/language/ecmascript/compile-ghil.scm (comp): Support foo["bar"]
in addition to foo.bar.
* module/language/ecmascript/impl.scm (pget, pput): Some fixes for when
we get non-symbols -- it can happen, yo. I suppose we should allow for
non-string keys too..
Andy Wingo [Thu, 19 Feb 2009 16:14:16 +0000 (17:14 +0100)]
implement object literals
* module/language/ecmascript/impl.scm:
* module/language/ecmascript/compile-ghil.scm (comp): Object literals.
* module/language/ecmascript/parse.scm (parse-ecmascript): Fix some
object literal parsing.
Andy Wingo [Thu, 19 Feb 2009 15:59:21 +0000 (16:59 +0100)]
var at toplevel works too
* module/language/ecmascript/compile-ghil.scm (comp): Fix the var form at
toplevel.
Andy Wingo [Thu, 19 Feb 2009 15:40:22 +0000 (16:40 +0100)]
property gets and puts implemented, yays
* module/language/ecmascript/compile-ghil.scm (@impl): Ok, don't recurse
on args here.
(comp): Implement property gets and puts and lexical assignment.
(comp-body): Fix scanning of var forms.
* module/language/ecmascript/impl.scm (prop-attrs): Allow for the prop
attr array to be #f.
* module/language/ecmascript/parse.scm (parse-ecmascript): Fix assignment
parsing.
Andy Wingo [Thu, 19 Feb 2009 15:09:00 +0000 (16:09 +0100)]
add array support
* module/language/ecmascript/compile-ghil.scm (@impl): Whoops, fix this
macro.
(comp): Handle array literals.
* module/language/ecmascript/impl.scm: Add support for arrays.
Andy Wingo [Thu, 19 Feb 2009 12:55:55 +0000 (13:55 +0100)]
further ecmascript work
* libguile/vm-i-system.c (drop, return): Declare drop and return as
popping one arg from the stack.
* module/language/ghil/compile-glil.scm:
* module/language/glil/compile-assembly.scm (make-meta): Adjust so that
we declare 'drop and 'return calls as popping one arg from the stack.
* module/language/ecmascript/compile-ghil.scm (comp, comp-body): Flesh
out a bit more. Most significantly, scoping within functions obeys
javascript semantics better, modulo bits about with() forms.
* module/language/ecmascript/impl.scm: Define some runtime helper
routines.
* module/language/Makefile.am (SOURCES): Add impl.scm.
* module/language/ecmascript/parse.scm (parse-ecmascript): Minor tweaks.
* module/language/ecmascript/tokenize.scm (read-identifier): Identifiers
now read as symbols, not strings.
Andy Wingo [Wed, 18 Feb 2009 00:17:14 +0000 (01:17 +0100)]
add more ecmascript compilation -- functions work now
* module/language/ecmascript/parse.scm (parse-ecmascript): Lambdas always
just have one member in their bodies.
* module/language/ecmascript/compile-ghil.scm (comp): Add some more silly
compilers.
Ludovic Courtès [Tue, 17 Feb 2009 23:54:05 +0000 (00:54 +0100)]
Add `load-unsigned-integer' instruction.
* libguile/vm-i-loader.c (load_unsigned_integer): New loader.
* module/language/assembly.scm (byte-length): Handle
`load-unsigned-integer'.
* module/language/assembly/compile-bytecode.scm (write-bytecode):
Likewise.
* module/language/glil/compile-assembly.scm (dump-object): Emit a
`load-unsigned-integer' instruction for positive integers. This fixes
loading of integers greater than 2^31 - 1.
* testsuite/Makefile.am (vm_test_files): Add `t-literal-integers.scm'.
* doc/ref/vm.texi (Loading Instructions): Add `load-unsigned-integer'.
Andy Wingo [Tue, 17 Feb 2009 23:49:21 +0000 (00:49 +0100)]
world's stupidest ecmascript compiler
* module/language/ecmascript/spec.scm: Add language spec for ecmascript.
* module/language/ecmascript/compile-ghil.scm: Add a stupid compiler.
* module/language/Makefile.am: Buildage.
Andy Wingo [Tue, 17 Feb 2009 23:07:51 +0000 (00:07 +0100)]
add ecmascript parser
* module/language/ecmascript/parse-lalr.scm: Add the Boucher/Bison lalr
parser. This is from guile-lib, but with : changed to -> so as not to
molest `prefix' keywords. Should probably be elsewhere.
* module/language/ecmascript/parse.scm: Add parser for ECMAScript. Rules
from the spec, 3rd edition.
* module/language/ecmascript/tokenize.scm: Add ECMAScript tokenizer,
hand-written. Neat stuff.
* module/language/Makefile.am: Autofoo.
Andy Wingo [Sat, 14 Feb 2009 22:09:10 +0000 (23:09 +0100)]
lengths written out in native endianness
* module/language/assembly/compile-bytecode.scm (write-bytecode): Write
out the lengths that are mapped to struct scm_objcode using native
endianness.
Andy Wingo [Tue, 17 Feb 2009 14:57:51 +0000 (15:57 +0100)]
avoid deprecated functions in SCM_VALIDATE_VECTOR_LEN
* libguile/validate.h (SCM_VALIDATE_VECTOR_LEN): Don't use deprecated
functions.
Andy Wingo [Sat, 14 Feb 2009 21:54:19 +0000 (22:54 +0100)]
better alignment
* module/language/assembly.scm (align-program): Whoops, align programs
properly.
* module/language/glil/compile-assembly.scm (compile-assembly): Start
with addr=-1, for the unserialized load-program byte.
(glil->assembly): Align programs in all cases.
Ludovic Courtès [Sat, 14 Feb 2009 21:17:47 +0000 (22:17 +0100)]
Change `compiled-file-name' to preserve the input file's directory.
* module/system/base/compile.scm (compiled-file-name): Prepend "(dirname
file)" so that "guile-tools compile foo/bar.scm" produces
"foo/bar.go", not "bar.go".
Andy Wingo [Sat, 14 Feb 2009 18:50:44 +0000 (19:50 +0100)]
align programs on 8-byte boundaries
* module/language/assembly.scm (addr+): New helper.
(align-program): New function, aligns a (load-program) form, currently
to 8-byte boundaries.
* module/language/glil/compile-assembly.scm (<subprogram>): Record the
object table and the program code separately, so that we can align the
program after the object table has been written.
(glil->assembly): Use addr+.
(dump-object): Rework to fold `addr' through dumping of compound
objects, so that procedures can be aligned properly.
Andy Wingo [Sat, 14 Feb 2009 17:57:30 +0000 (18:57 +0100)]
re-enable assembly packing
* module/language/glil/compile-assembly.scm (glil->assembly): Enable
assembly packing, for e.g. (make-int8:0).
Andy Wingo [Fri, 13 Feb 2009 23:47:56 +0000 (00:47 +0100)]
a slight add-method speedup
* module/oop/goops.scm (add-method-in-classes!): Use memq instead of
memv.
Andy Wingo [Fri, 13 Feb 2009 23:24:32 +0000 (00:24 +0100)]
generate the fixed-offset accessors at compile-time
* module/language/scheme/compile-ghil.scm (define-scheme-translator):
Only add an else clause if the transformer didn't have one.
* module/oop/goops.scm (min-fixnum, max-fixnum): Define at compile-time
as well.
(@slot-ref, @slot-set!): Only define transformers for these at
compile-time. Avoids loading up the compiler unnecessarily. Also, allow
for the `n' to be determined lexically, in which case we dispatch to
the primitive.
(num-standard-pre-cache, define-standard-accessor-method)
(bound-check-get, standard-get, standard-set): Rework the fixed-offset
getters and setters so that they can be computed at compile-time.
Accessors to fields with n > num-standard-pre-cache will be dispatched
to the primitive instead of within the VM.
Andy Wingo [Fri, 13 Feb 2009 22:30:20 +0000 (23:30 +0100)]
don't re-enter the compiler during method dispatch
* libguile/goops.c (scm_make): In the pre-inst `make', default
`procedure' to #f, and read a `make-procedure' instead of
`compile-env'.
* libguile/goops.h (scm_si_make_procedure): This instead of
scm_si_compile_env.
* module/oop/goops.scm (make-method): Remove this unused function. Users
should use (make <method> ...) directly.
(method): Capture `make-procedure' instead of `procedure' in the case
that the body calls a next-method. Allows for the kind of
"recompilation" that we were using before, but with closures instead of
re-entering the compiler. Type-specific compilation is still
interesting, but probably should be implemented in another way.
(initialize): Default #:procedure to #f, and
s/compile-env/make-procedure/.
* module/oop/goops/compile.scm (code-table-lookup): Just return the
cmethod, not the entry -- since the entry is now just (append types
cmethod).
(compile-make-procedure): New procedure, returns a form that, when
evaluated/compiled, will yield a procedure of one argument, the
next-method. When called with a next-method, the procedure returns an
actual method implementation. compile-make-procedure returns #f if the
body doesn't call next-method.
(compile-method): Unify to always return procedures. Much cleaner and
*much* faster in the compiled case. In the interpreted case, there
might be a slight slowdown, but if there is one it should be slight.
* module/oop/goops/dispatch.scm (method-cache-install!): Adapt to removal
of compute-entry-with-cmethod.
Andy Wingo [Fri, 13 Feb 2009 20:48:56 +0000 (21:48 +0100)]
flush output when writing .go files
* module/system/base/compile.scm (call-with-output-file/atomic): Close
the port we are writing to before renaming it, so that we flush output.
Might fix some 0-length write errors that Jao was seeing.
Andy Wingo [Thu, 12 Feb 2009 23:16:44 +0000 (00:16 +0100)]
inline record predicates into record-case
* module/system/base/syntax.scm (record-case): Inline record predicates
into the record-case. Shaves off a few more milliseconds from a GOOPS
load.
Andy Wingo [Thu, 12 Feb 2009 23:01:47 +0000 (00:01 +0100)]
no keyword arguments in GHIL / GLIL, just optional args -- faster compiles
* module/system/base/syntax.scm (define-record): So, in the generated
constructors, allow optional arguments, but not keyword arguments.
Conses much less in the constructors.
(define-record/keywords): And the old define-record is here.
* module/language/ghil.scm (parse-ghil):
* module/language/ghil/compile-glil.scm (codegen):
* module/language/scheme/compile-ghil.scm (translate-1, quote)
(quasiquote): Don't use keywords in this compiler hotpath.
* module/system/base/language.scm (<language>):
* module/system/repl/common.scm (<repl>):
* module/system/vm/debug.scm (<debugger>): Use define-record/keywords.
Andy Wingo [Wed, 11 Feb 2009 22:04:37 +0000 (23:04 +0100)]
provide program apply_0, apply_1, apply_2 implementations
* libguile/programs.c (program_apply_0, program_apply_1)
(program_apply_2, scm_bootstrap_programs): Provides some cons-less
smob application procedures. This molests some internal interfaces, but
hey, we're internal.
Andy Wingo [Wed, 11 Feb 2009 21:08:04 +0000 (22:08 +0100)]
speed up record-case
* module/language/ghil.scm: Whoops, export some unquote-splicing
accessors that we didn't have exported before.
* module/system/base/syntax.scm: Speed up record-case, by syntactically
determining the predicates and accessors. Nasty, in a way; but also
much faster.
Andy Wingo [Tue, 10 Feb 2009 12:18:36 +0000 (13:18 +0100)]
match bare literals with eq? in pmatch, not equal?
* module/system/base/pmatch.scm (ppat): Match atoms with eq?, not equal?.
This speeds up compilation considerably, as we never match against
numbers or strings or what-have-you. Note, you can match against
literals with equal? via quoting the literal in the pattern.
Andy Wingo [Tue, 10 Feb 2009 10:53:23 +0000 (11:53 +0100)]
propagate much more source info through compilation
* module/language/ghil/compile-glil.scm (codegen): Record source location
for offset 0 into a lambda, if we can.
* module/language/scheme/compile-ghil.scm (translate-1)
(define-scheme-translator): In the retrans procedures, propagate the
location information from the enclosing expression if the subexpression
has no location information. Gives source information to many more
expressions.
(location): Just propagate the source properties as they are, the
glil->assembly compiler will interpret them.
* module/language/glil.scm (<glil>): Change glil-source to take "props"
and not "loc", as it's the source properties that we're interested in.
* module/language/glil/compile-assembly.scm (limn-sources): New function,
takes a list of addr-source property pairs and "compresses" them for
serialization to disk.
(glil->assembly): Limn the sources before writing them to disk. Avoid
non-tail recursion when determining total byte length of code.
* module/system/vm/program.scm (source:file, source:line, source:column):
Update for new source representation.
(program-source): Export.
(write-program): Nicer pretty-printing of anonymous procedures.
* libguile/backtrace.c (display_backtrace_get_file_line): Update for the
new VM source representation.
* libguile/programs.h:
* libguile/programs.c (scm_program_sources): Update for the new
serialized source representation, where the filename is not in the
stream unless it changes.
(scm_program_source): New exported function, looks up the source for a
given ip offset.
(scm_c_program_source): Update to return the last source information
that was <= the given IP, because we only serialize source info when it
changes.
Andy Wingo [Mon, 9 Feb 2009 11:02:04 +0000 (12:02 +0100)]
nicety in the compiler
* module/language/scheme/compile-ghil.scm (lookup-transformer): Use @@.
Delightfully metacircular.
Andy Wingo [Mon, 9 Feb 2009 10:50:58 +0000 (11:50 +0100)]
allow defmacros to unquote in macros into expanded expressions
* module/language/scheme/compile-ghil.scm (lookup-transformer): Allow
macros to be unquoted into the car of any form that results from macro
expansion. This lets modules export defmacros built on other defmacros
that are not exported.
Andy Wingo [Mon, 9 Feb 2009 10:42:27 +0000 (11:42 +0100)]
minor cleanups
* libguile/stacks.c (scm_make_stack): Instead of aborting when we misread
the number of stack frames, just print a warning. I'd like to figure
out what these cases are, exactly.
* module/language/scheme/compile-ghil.scm (lambda): Reindent the lambda
transformer.
* module/system/base/compile.scm (call-with-compile-error-catch): Write
the expression instead of displaying it.
(call-with-output-file/atomic): Don't actually redirect output to this
port, as it's not necessary -- the language-printer should respect the
port that we pass.
Andy Wingo [Thu, 5 Feb 2009 17:13:27 +0000 (18:13 +0100)]
fix the ping-pong between evaluator and vm stacks in make-stack
* libguile/frames.c (vm_frame_print): Add a frame printer.
* libguile/stacks.c (stack_depth, read_frames): Only switch the VM stack
for boot program dframes.
* libguile/vm-engine.c (VM_NAME): Push one debug frame per invocation,
unconditionally. (If we push them at all, of course.)
Andy Wingo [Thu, 5 Feb 2009 12:44:06 +0000 (13:44 +0100)]
fix boot program detection, which in turn makes `make-stack' actually work
* libguile/programs.h (SCM_F_PROGRAM_IS_BOOT, SCM_PROGRAM_IS_BOOT): Flags
for determining if a program is a boot program. It turns out that our
heuristics e.g. in stacks.c would catch non-boot programs, like
programs that end with (goto/args 1), because the 1 is the same byte as
`halt'. That took a while to find...
* libguile/stacks.c (stack_depth, read_frames): Use the new boot prog
macros.
(scm_make_stack): Assert that we read the number of frames that we said
we would.
* libguile/vm.c (really_make_boot_program): Mark boot programs
appropriately.
Andy Wingo [Thu, 5 Feb 2009 11:28:19 +0000 (12:28 +0100)]
in debug mode, make sure that calls to the vm can be captured via make-stack
* libguile/vm-engine.c (VM_PUSH_DEBUG_FRAMES): New knob, if true we much
with the scm_i_last_debug_frame when entering the VM, because sometimes
the evaluator doesn't do it for us.
(VM_ENGINE): Plug through debug frame fondling. Now, program exit comes
back to the main text. Rename err_args to finish_args, and reuse for
the return value.
* libguile/vm-engine.h (PUSH_LIST):
* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c:
* libguile/vm-i-system.c: Update for finish_args.
(halt): goto vm_done, now, instead of returning directly.
Andy Wingo [Wed, 4 Feb 2009 23:51:34 +0000 (00:51 +0100)]
scm_call_N doesn't cons for calling programs
* libguile/eval.c (scm_call_0, scm_call_1, scm_call_2, scm_call_3)
(scm_call_4): Special-case compiled procedures here, to avoid consing.
* libguile/vm.h:
* libguile/vm.c (scm_c_vm_run): Take a SCM after all.
(scm_vm_apply, scm_load_compiled_with_vm): Adapt to vm_run change.
Andy Wingo [Wed, 4 Feb 2009 23:31:38 +0000 (00:31 +0100)]
use append-map in goops
* module/oop/goops.scm (ensure-metaclass, make-extended-generic): Some
minor optimizations to use append-map.
Andy Wingo [Wed, 4 Feb 2009 23:20:51 +0000 (00:20 +0100)]
inline call to scm_make_program when making closures
* libguile/programs.c (scm_make_program): Add a comment.
* libguile/vm-engine.h (INIT_ARGS): Add a couple of UNLIKELY notes.
* libguile/vm-i-system.c (make-closure): Inline the call to
scm_make_program, which avoids some redundant checks.
Andy Wingo [Wed, 4 Feb 2009 22:47:56 +0000 (23:47 +0100)]
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
Andy Wingo [Tue, 3 Feb 2009 23:49:55 +0000 (00:49 +0100)]
"optimize" dispatch to specific GF's in goops
* libguile/goops.c: Some micro-optimizations so that calling generic
functions as part of the protocol doesn't cons.
Andy Wingo [Tue, 3 Feb 2009 23:09:38 +0000 (00:09 +0100)]
make catch cache and restore vm regs, not the vm itself -- speedy speedy
* libguile/throw.c (scm_c_catch): Stash away the current vm's regs, and
restore them if there's a nonlocal exit. There is a terrible case we
have to handle if we catch from when the vm smob type isn't registered
but the throw has the vm registered, but I think we handle this fine.
* libguile/vm-engine.c (vm_run):
* libguile/vm-i-system.c (halt): Don't make a dynwind context, so that
entering the VM doesn't cons at all, except for the arg list. Maybe we
can fix that bit too.
* libguile/vm.c (vm_reset_stack): Remove, as there is no more dynwind.
(make_vm): Return #f if the tc16 hasn't yet been registered.
Andy Wingo [Tue, 3 Feb 2009 21:36:02 +0000 (22:36 +0100)]
make symbol -> opcode lookup faster
* libguile/instructions.c (fetch_instruction_table)
(scm_lookup_instruction_by_name): Rework so we lazily load instructions
into an array keyed by opcode, and a hash table keyed by symbolic name.
Much faster, in this hot spot of compilation.
* libguile/vm-engine.c (vm_run): Use malloc instead of scm_gc_malloc,
given that we aren't ever going to free this thing.
* libguile/vm-expand.h (VM_DEFINE_FUNCTION, VM_DEFINE_LOADER): Rework to
always be aliases to VM_DEFINE_INSTRUCTION.
(VM_DEFINE_INSTRUCTION): In the table case, update to work with
fetch_instruction_table().
Andy Wingo [Tue, 3 Feb 2009 20:13:01 +0000 (21:13 +0100)]
inline dispatch to program cmethods, tick in return, remove old goops methods
* libguile/objects.c (scm_apply_generic): Inline the case when the
generic is a program.
* libguile/vm-i-system.c (return): Tick when functions return.
* module/oop/goops.scm (object-eqv?, object-equal?): Remove these
historical methods.
Andy Wingo [Mon, 2 Feb 2009 22:36:14 +0000 (23:36 +0100)]
Name anonymous let- or letrec-bound procedures
* module/language/scheme/compile-ghil.scm (let, letrec): Give names to
procedures of the form (let ((foo (lambda ....)))).