* module/language/scheme/translate.scm (lookup-transformer): Allow for
undefined variables when doing the transformation -- it's possible that
they come from a module definition's forward declaration.
* module/system/repl/command.scm (import): Make into legal Scheme, caught
by the compiler :-)
* module/system/vm/assemble.scm (<vlink-now>): Remove the module field.
Immediate bindings will now always be relative to the current module.
Fixes some mess about process-define-module not being defined when
loading modules, probably because we destructively modified the
ghil-env.
(codegen, dump-object!): Don't dump a module name.
* src/vm_loader.c (link-now): Just use scm_lookup.
comments in ghil-lookup are pertinent.
* module/system/il/compile.scm (make-glil-var): Require that ghil vars
have environments. Remove the 'unresolved case -- we'll treat all
module-level variables as late bound.
* module/system/il/ghil.scm (ghil-lookup): Treat all module level vars as
late bound.
* module/system/vm/assemble.scm: Instead of vlink and vlate-bound, have
vlink-now and vlink-later.
(codegen): Add a bunch of crap to get the various cases right.
(object-assoc, dump-object!): Handle the new cases, remove the old
cases.
* src/vm_loader.c (link-now, link-later): Change from link and lazy-bind.
Include the module in which the link is to be done, so that callers
from other modules get the right behavior.
* src/vm_system.c (late-variable-ref, late-variable-set): Instead of a
sym, the unbound representation is a module name / symbol pair.
* testsuite/run-vm-tests.scm (run-vm-tests): Remove some debugging.
Fixes the mutually-recursive toplevel definitions case. This could be
fixed by rewriting bodies as letrecs, as r6 does, but that's not really
repl-compatible.
* module/system/il/ghil.scm (ghil-lookup): Ok, if we can't locate a
variable, mark it as unresolved.
* module/system/il/compile.scm (make-glil-var): Compile unresolved
variables as <glil-late-bound> objects.
* module/system/il/glil.scm: Add <glil-late-bound> definition.
* module/system/vm/assemble.scm (codegen): And, finally, when we see a
<vlate-bound> object, allocate a slot for it in the object vector,
setting it to a symbol. Add a new pair of instructions to resolve that
symbol to a variable at the last minute.
* src/vm_loader.c (load-number): Bugfix: the radix argument should be
SCM_UNDEFINED in order to default to 10.
(late-bind): Add an unresolved symbol to the object vector. Could be
replaced with load-symbol I guess.
* src/vm_system.c (late-variable-ref, late-variable-set): New
instructions to do late symbol binding.
* testsuite/Makefile.am (vm_test_files):
* testsuite/t-mutual-toplevel-defines.scm: New test, failing for some
reason involving the core even? and odd? definitions.
* module/language/scheme/translate.scm (lookup-transformer): When
expanding syncase macros, use the eval closure from the ghil-env.
Probably doesn't make any difference whatsoever.
* module/system/base/Makefile.am (SOURCES): Compile pmatch.scm, now that
it works :-))
* module/system/base/compile.scm (compile-in): Compile inside a
save-module-excursion, so that side effects of evaluation don't leak
out.
* module/system/base/pmatch.scm: Change from :use-syntax/:export-syntax
to simply :use-modules/:export. Also probably has no effect.
* module/system/il/ghil.scm (fix-ghil-mod!): Suppress warnings resulting
from compilation of define-module.
* src/vm_loader.c (link): So, referencing variables defined but not
exported from the current module didn't work. Fixed that, but it's
hacky. There are still some uncaught cases.
* module/system/base/compile.scm: Also import load-objcode from (system
vm core).
* module/language/scheme/translate.scm (lookup-transformer): Use
sc-expand3 in compilation mode when compiling macros. Yay, syncase
macros compile!
* module/system/vm/assemble.scm (dump-object!):
* src/vm_loader.c (VM_DEFINE_LOADER): Use scm_from_locale_keywordn, not
the krazy dash symbol stuff.
* module/language/scheme/translate.scm (lookup-transformer): Add a
special case for syncase macros.
* module/system/base/syntax.scm (define-record): Again, don't unquote in
actual objects, because this is uncompilable. Ah well. At least now all
of base/ is compiling.
* module/system/vm/assemble.scm (dump-object!): More debug info.
* module/language/scheme/translate.scm (primitive-syntax-table):
Translate the `else' clause of a cond as (begin ...). We used to use
trans-body, which processes internal defines, which are not legal
syntax here.
* module/system/base/syntax.scm (define-record): Unfortunately, we can't
unquote in the actual procedure for `%compute-initargs', because that
doesn't work with compilation. So reference %compute-initargs by name,
and export it.
* module/system/il/ghil.scm (apopq!): Gaaaaar. The order of the arguments
to assq-remove! was reversed, which was the badness, causing corruption
to the env after calling call-with-ghil-bindings. Grrrrrr.
(fix-ghil-mod!, ghil-lookup, ghil-define): As amply commented in the
code, deal with compile-time side effects to the current module by
lazily noticing and patching up the compile-time environment. A hacky
solution until such a time as we special-case something for
`define-module'.
* module/system/il/compile.scm (make-glil-var): Only dump the module if
we actually have one.
* module/system/il/ghil.scm (ghil-define): Make sure that ghil-var-env is
a ghil-env.
* src/vm_loader.c (link):
* module/system/vm/assemble.scm (dump-object!): Rewrite `link' to take
two Scheme arguments on the stack: the symbol, as before, and the
module in which the symbol was found at compile time. This introduces
some undesireable early binding, but it does let the vm load up
modules, and (potentially) have multiple modules in one .go file. On a
practical level, I can now compile modules and have their .go files
load up the modules' dependencies as necessary.
* module/system/il/compile.scm (make-glil-var): Make the :mod of the
glil-var actually a guile module, not a ghil-env.
* module/system/il/ghil.scm (module-lookup, ghil-lookup): For module
variables, encode the location where we found the variable in the
ghil-var.
* module/language/scheme/translate.scm (trans):
* module/system/il/compile.scm (codegen): When making records where a
value can be a keyword, make sure to use the keyword initialization
form, so that the record initializer doesn't interpret the keyword as a
slot name.
* module/system/base/Makefile.am (vm_DATA): For now, don't compile
pmatch.
* module/language/scheme/translate.scm (*the-compile-toplevel-symbol*)
(primitive-syntax-table): Existing eval-case invocations in boot-9.scm
only have `load-toplevel', not `load-toplevel' and `compile-toplevel'
as they should. Allow for interpreting `load-toplevel' as
`compile-toplevel'.
* module/language/scheme/translate.scm (trans): Remove the hacky case for
the unspecified value, not needed any more.
(primitive-syntax-table): Rework eval-case to understand
compile-toplevel and evaluate contexts, as in common lisp's eval-when:
http://www.lisp.org/HyperSpec/Body/speope_eval-when.html
This is the Right Thing.
* module/language/scheme/translate.scm (eval-at-compile-time)
(&compile-time-module, expand-macro): Remove this attempt at dealing
with macros. Instead, we're going to rely on macros being first-class,
and just catch eval-case at the bottom.
(lookup-transformer): Lookup all syntax transformers in the module's
eval closure. We catch the primitive-macros, compiling them to ghil,
and expand the rest.
(lookup-transformer): Fold in trans-pair here. Add a hacky case for the
unspecified value; the problem shows up when compiling e.g.
(define-macro (plus! x) `(set! ,x (1+ x))), as a fallout from
eval-case.
(make-pmatch-transformers, primitive-syntax-table): Define the
primitive syntax transformers as a data-driven table instead of a
function. There's a bit of syntax, too. Eval-case was rewritten to use
pmatch.
* module/system/base/compile.scm (scheme): Define as a thunk instead
of a value, so as to allow (language scheme translate) to be imported
in the repl. Still, a hack.
* module/language/scheme/translate.scm (expand-macro, trans-pair): Remove
support for the scheme form, '(void). Replace it by (begin). What was
Keisuke thinking? :)
* Makefile.am:
* module/Makefile.am:
* module/language/scheme/Makefile.am:
* module/system/Makefile.am:
* module/system/base/Makefile.am:
* module/system/il/Makefile.am:
* module/system/repl/Makefile.am:
* module/system/vm/Makefile.am: Cleaned up to be more complete, if not
completely working.
* module/guile/slib.scm:
* module/slib/: Removed the slib import; it's a bit out of place here,
and bitrotten at that.
* module/system/repl/repl.scm (default-pre-unwind-handler)
(default-catch-handler): New procedures, to do some error handling in
the repl.
(start-repl): Catch errors in the repl loop.
* module/system/base/compile.scm (<cenv>): No more cenv, it was a useless
data structure.
* module/system/repl/command.scm (*command-table*): Remove `use', it's
the same as `import'. Otherwise in this file, adapt to the repl having
direct pointers to the vm and the language, and to the module being in
the current-module fluid.
* module/system/repl/repl.scm (prompting-meta-read):
* module/system/repl/common.scm (<repl>): The repl now has a direct
pointer to the vm and language. Adapt accordingly.
Before:
> ,c (set! x 3)
0 (make-int8 3) ;; 3
2 (link "x")
5 (variable-set)
> ,c (define x 3)
0 (make-int8 3) ;; 3
2 (link "x")
5 (variable-set)
After:
> ,c (define x 3)
0 (make-int8 3) ;; 3
2 (define "x")
5 (variable-set)
* src/vm_loader.c (link): `link' now errors if the variable is undefined.
This corresponds with desired behavior, for both `ref' and `set'
operations, for scheme. It's not what elisp wants, though. Perhaps
elisp linking needs another instruction.
(define): New instruction, the same as calling scm_define(), basically.
* module/language/scheme/translate.scm (trans-pair): Don't try to look up
an existing variable definition when translating `define'; instead use
the special-purpose lookup from ghil.scm's `ghil-define'.
* module/system/il/compile.scm (codegen): Compile to a different kind of
variable access from `set!', specifically via passing 'define as the op
to `make-glil-var'.
* module/system/il/ghil.scm (ghil-lookup): Don't add to the module table
when compiling variable sets via `set!'.
(ghil-define): New procedure, for looking up variables for `define'.
* module/system/vm/assemble.scm (<vdefine>): New record: a new
instruction type.
(codegen): Compile `define' module vars into <vdefine>.
(dump-object!): <vdefine> == `define'.
* module/language/scheme/translate.scm (trans-pair): Add a guard to only
allow `define' at the top level; other defines are already filtered out
via trans-body.
* module/system/il/ghil.scm (ghil-env-toplevel?): Export, and fix.
* module/system/base/compile.scm:
* module/system/il/ghil.scm:
* module/system/repl/describe.scm:
* module/system/vm/core.scm:
* module/system/vm/frame.scm:
* module/system/vm/trace.scm: Explicitly list exports in the module
declaration instead of using define-public.
* module/system/base/compile.scm: Export cenv? also.
* module/system/base/syntax.scm: Clean up vestiges of the old structure
code. Make accessors defined as foo? instead of <foo>?.
* module/system/il/glil.scm:
* module/system/il/ghil.scm: Remove <foo>-1 accessors, since we have
named accessors.
* module/system/repl/common.scm (repl-prompt): Return a string instead of
outputting to the port, for better readline integration.
* module/system/repl/repl.scm (meta-reader, prompting-meta-read)
(start-repl): Integrate with (ice-9 readline) via the current-reader
fluid and the repl-reader function, both from boot-9.scm.
* module/system/repl/command.scm (system): Declare exports in the module
declaration.
* module/system/repl/repl.scm (start-repl): If the evaluation returns
multiple values, print them separately.
* module/system/base/syntax.scm (define-record): Rebase to implement on
top of Guile's records, which are the substrate of srfi-9's records.
(%compute-initargs): Rename from %make-struct, just return the list of
values.
(get-slot, set-slot!, slot): Removed, no longer used.
(record-case): Allow slots of the form (MYNAME SLOTNAME), which binds
SLOTNAME to MYNAME (instead of SLOTNAME to SLOTNAME).
(record-case, record?): No more ice-9 match!
* module/system/il/compile.scm (codegen): Tweaks so that the new record
code works.
* module/system/il/ghil.scm: Fix some slot references.
* module/system/vm/assemble.scm (preprocess, codegen): Remove calls to
`slot'.
(codegen): Fix some slot references.
* module/system/base/syntax.scm (define-record): Define the accessors as
procedures-with-setters, not just as getters.
* module/system/il/compile.scm (optimize): This function was bitrotten
since the addition of source locations in
cb4cca12e7. Untested attempts to
de-bitrot it. Dedottify as well.
* module/system/il/ghil.scm:
* module/system/il/glil.scm (unparse):
* module/system/vm/debug.scm (debugger-repl): Ongoing dedottification.
* module/system/base/syntax.scm (define-record): Define named accessors,
to prepare the code for srfi-9 records switchover.
* module/system/il/ghil.scm:
* module/system/il/glil.scm: Export a bunch of named accessors.
* module/language/scheme/translate.scm: Refactor use of `match' to use
`pmatch'. Relatively straightforward.
* module/system/base/pmatch.scm (ppat): Fix some copy-n-paste bugs: the _
rule, the quote rule.
* module/system/base/Makefile.am: Add pmatch.scm.
* module/system/base/pmatch.scm: New file, taken from Dan Friedman's
alpha-kanren paper. Implements a less magical match syntax, pmatch.
* module/system/vm/assemble.scm: No more need for (ice-9 match).
* module/system/vm/conv.scm (code-pack, code->object): Change to use
pmatch.
* module/system/base/syntax.scm (record-case): Capture the match macro.
* module/system/il/glil.scm:
* module/system/il/compile.scm: Convert to record-case.
* module/system/base/syntax.scm (define-record): Rework to separate the
type and its constructor. Now (define-record (<foo> bar)) will create
`make-foo' as the constructor, not `<foo>'. Also the constructor now
takes either keyword or positional arguments, so that it can be used as
the implementation of variant types as well.
(|): Map directly to define-record instead of rolling our own thing.
* module/language/scheme/translate.scm:
* module/system/base/language.scm:
* module/system/il/compile.scm:
* module/system/il/ghil.scm:
* module/system/il/glil.scm:
* module/system/repl/common.scm:
* module/system/vm/assemble.scm:
* module/system/vm/debug.scm: Change instances of record creation to use
the make-foo procedures instead of <foo>. Adjust module exports as
necessary.
* module/system/base/syntax.scm (record?): Temporarily export this thing,
so that code will remain correct when I change to srfi-9 records.
* module/system/vm/assemble.scm: Convert to use record-case.