* module/system/base/language.scm (<language>): Rework so that instead of
hardcoding passes in the language, we define compilers that translate
from one language to another. Add `parser' to the language fields, a
bit of a hack but useful for languages with s-expression external
representations but with record internal representations.
(define-language, *compilation-cache*, invalidate-compilation-cache!)
(compute-compilation-order, lookup-compilation-order): Add an algorithm
that does a depth-first search for a translation path from a source
language to a target language, caching the result in a lookup table.
* module/language/scheme/spec.scm:
* module/language/ghil/spec.scm: Update to the new language format.
* module/language/glil/spec.scm: Add a language specification for GLIL,
with a compiler to objcode. Also there are parsers and printers, for
repl usage, but for some reason this doesn't work yet.
* module/language/objcode/spec.scm: Define a language specification for
object code. There is some sleight of hand here, in the "compiler" to
values; but there is method behind the madness, because this way we
higher levels can pass environments (a module + externals pair) to
objcode->program.
* module/language/value/spec.scm: Define a language specification for
values. There is something intellectually dishonest about this, but it
does serve its purpose as a foundation for the language hierarchy.
* configure.in:
* module/language/Makefile.am
* module/language/ghil/Makefile.am
* module/language/glil/Makefile.am
* module/language/objcode/Makefile.am
* module/language/value/Makefile.am:
Autotomfoolery for the ghil, glil, objcode, and value languages.
* module/language/scheme/translate.scm (translate): Import the bits that
understand `compile-time-environment' here, and pass on the relevant
portions of the environment to the next compiler pass.
* module/system/base/compile.scm (current-language): New procedure, refs
the current language fluid, or lazily sets it to scheme.
(call-once, call-with-output-file/atomic): Refactor these bits to use
with-throw-handler. No functional change.
(compile-file, compile-and-load, compile-passes, compile-fold)
(compile): Refactor the public interface of the compiler to be generic
and simple. Uses `lookup-compilation-order' to find a path from the
source language to the target language.
* module/system/base/syntax.scm (define-type): Adapt to changes in
define-record.
(define-record): Instead of expecting all slots in the first form,
expect them in the body, and let the first form hold the options.
* module/system/il/compile.scm (compile): Adapt to the compilation pass
API (three in and two out).
* module/system/il/ghil.scm (<ghil-var>, <ghil-env>)
(<ghil-toplevel-env>): Adapt to define-record changes.
* module/system/il/glil.scm (<glil-vars>): Adapt to define-record
changes.
(<glil>, print-glil): Add a GLIL record printer that uses unparse.
(parse-glil, unparse-glil): Update unparse (formerly known as pprint),
and write a parse function.
* module/system/repl/common.scm (<repl>): Adapt to define-record changes.
(repl-parse): New function, parses the read form using the current
language. Something of a hack.
(repl-compile): Adapt to changes in `compile'.
(repl-eval): Fix up the does-the-language-have-a-compiler check for
changes in <language>.
* module/system/repl/repl.scm (start-repl): Parse the form before eval.
* module/system/repl/command.scm (describe): Parse.
(compile): Be more generic.
(compile-file): Adapt to changes in compile-file.
(disassemble, time, profile, trace): Parse.
* module/system/vm/debug.scm:
* module/system/vm/assemble.scm: Adapt to define-record changes.
* module/language/scheme/translate.scm (receive): Fix an important bug
that gave `receive' letrec semantics instead of let semantics. Whoops!
* module/system/repl/common.scm (repl-print): Slightly refine the meaning
of "language-printer": a language printer prints an expression of a
language, not the result of evaluation. `write' prints values.
* module/language/ghil/spec.scm (ghil): Define a language printer, and a
translator for turning s-expressions (not scheme, mind you) into GHIL.
* module/language/scheme/translate.scm (quote, quasiquote): Add some
#:keyword action, so that we can (quote #:keywords).
* module/system/base/language.scm (<language>):
* module/system/base/compile.scm (read-file-in): Don't require that a
language have a read-file; instead error when read-file is called.
(compile-passes, compile-in): Refactor to call a helper method to turn
the language + set of options into a set of compiler passes.
* module/system/base/syntax.scm (define-type): Allow the type to be a
list, with the car being the name and the cdr being keyword options.
Interpret #:printer as a printer, and pass it down to...
(define-record): Here.
* module/system/il/ghil.scm (print-ghil, <ghil>): New printer for GHIL,
yay!
(parse-ghil, unparse-ghil): New lovely functions. Will document them in
the manual.
* module/language/scheme/translate.scm (*translate-table*)
(define-scheme-translator): Rework the translator to have the clauses
defined separately via the define-scheme-translator macro, so that
external modules can define their own translators. Should be no
functional change in this commit, though.
* ice-9/boot-9.scm (compile-time-environment): Remove definition from
boot-9 -- instead, autoload it and `compile' from (system base
compile).
* libguile/objcodes.h:
* libguile/objcodes.c (scm_objcode_to_program): Add an optional argument,
`external', the external list to set on the returned program.
* libguile/vm-i-system.c (externals): New instruction, returns the
external list. Only used by (compile-time-environment).
* libguile/vm.c (scm_load_compiled_with_vm): Adapt to
scm_objcode_to_program change.
* module/language/scheme/translate.scm (translate): Actually pay
attention to the environment passed as an argument.
(custom-transformer-table): Expand out (compile-time-environment) to
something that can be passed to `compile'.
* module/system/base/compile.scm (*current-language*): Instead of
hard-coding `scheme' in various places, use a current language fluid,
initialized to `scheme'.
(compile-file, load-source-file): Adapt to *current-language*.
(load-source-file): Ada
(scheme-eval): Removed, no one used this.
(compiled-file-name): Don't hard-code "scm" and "go"; instead use the
%load-extensions and %load-compiled-extensions.
(cenv-module, cenv-ghil-env, cenv-externals): Some accessors for
compile-time environments.
(compile-time-environment): Here we define (compile-time-environment)
to something that will return #f; the compiler however produces
different code as noted above.
(compile): New function, compiles an expression into a thunk, then runs
the thunk to get the value. Useful for procedures. The optional second
argument can be either a module or a compile-time-environment; in the
latter case, we can recompile even with lexical bindings.
(compile-in): If the env specifies a module, set that module for the
duration of the compilation.
* module/system/base/syntax.scm (%compute-initargs): Fix a bug where the
default value for a field would always replace a user-supplied value.
Whoops.
* module/system/il/ghil.scm (ghil-env-dereify): New function, takes the
result of ghil-env-reify and turns it back into a GHIL environment.
* scripts/compile (compile): Remove some of the tricky error handling, as
the library procedures handle this for us.
* test-suite/tests/compiler.test: Add a test for the dynamic compilation
bits.
* ice-9/boot-9.scm (compile-time-environment): New function, with
documentation. The trick is that the compiler recognizes calls to
(compile-time-environment) and replaces it with a representation of the
*available* lexicals. Note that this might not be all the lexicals;
only the heap-allocated ones are returned.
* module/language/scheme/translate.scm (custom-transformer-table):
Compile `compile-time-environment' to <ghil-reified-env>.
* module/system/il/compile.scm (codegen): Add <ghil-reified-env> clause,
which calls ghil-env-reify.
* module/system/il/ghil.scm (ghil-env-reify): New procedure, returns a
list of (NAME . EXTERNAL-INDEX).
(<ghil>): Add <ghil-reified-env> object.
* libguile/vm-engine.c (vm_error_wrong_num_args): Sync the registers
before calling scm_wrong_num_args. (The other cases are handled more
uniformly.)
* libguile/vm.c (vm_heapify_frames_1): Add a FIXME: I don't think we
should be modifying the stack.
(scm_vm_save_stack): If stack nulling is enabled, verify the stack here
before reifying it.
* module/language/scheme/spec.scm (scheme): Use primitive-eval here
instead of eval, because at the repl we do want to allow evaluations to
have side effects like setting the current module.
* libguile/vm-engine.c (vm_run): Add new error case for resolving @ or @@
references, but there is no such module. Possible if
module-public-interface returns #f.
* libguile/vm-i-loader.c (link-now): Allow the stack arg to be a sym, as
before, or a list, indicating an absolute reference. Could be two
separate instructions, but I'm lazy.
* libguile/vm-i-system.c (late-variable-ref, late-variable-set): As in
link-now, allow the lazy reference to be a list, for @ and @@.
* module/language/scheme/translate.scm (custom-transformer-table):
Compile @ and @@, and set! forms for both of them. This will ease the
non-hygienic pain for exported macros.
* module/system/il/compile.scm (make-glil-var): Translate public and
private module variable references into glil-module variables.
* module/system/il/ghil.scm (ghil-var-at-module!): New function, resolves
a variable for @ or @@.
* module/system/il/glil.scm (<glil-module>): Revival of <glil-module>,
this time with the semantics that it really links to a particular
module.
* module/system/vm/assemble.scm (<vlink-now>, <vlink-later>): Redefine as
taking a "key" as the argument, which may be a sym or a list; see the
notes on link-now for more details.
(codegen): Compile <glil-module> appropriately. Some duplication here,
probably could use some cleanup later.
* module/system/il/ghil.scm (ghil-lookup): So, it turns out this function
needed to be split into three:
(ghil-var-is-bound?, ghil-var-for-ref!, ghil-var-for-set!): The
different facets of ghil-lookup. Amply commented in the source. The
difference being that we now allocate variables that are set! on the
heap, so that other continuations see their possibly-modified values.
(force-heap-allocation!): New helper.
* testsuite/Makefile.am:
* testsuite/t-call-cc.scm: New test, that variables that are set! are
allocated on the heap, so that subsequent modifications are still
seen by the continuation. The test was distilled from test 7.3 in
r5rs_pitfall.test.
* ice-9/boot-9.scm (start-stack): Define as a defmacro instead of an acro
in C. We have a way to delay evaluation of the exp, after all: putting
it in a thunk is sufficient.
* libguile/debug.h:
* libguile/debug.c (scm_sys_start_stack): Renamed from scm_start_stack,
and exposed to the user. Takes a thunk instead of an expression +
environment.
(scm_m_start_stack): Remove this acro.
* module/language/scheme/translate.scm (custom-transformer-table): Remove
the start-stack special case.
* ice-9/boot-9.scm: Allow a compiled load of posix, networking, and
deprecated files.
* module/language/scheme/translate.scm (lookup-transformer): Lookup the
sc-macro by value, not by name. Works around the fact that compiled
macros don't have names, which is probably a bug.
* module/system/base/compile.scm (syntax-error)
(call-with-compile-error-catch): Throw and catch a key that's not used
by anyone else. Write error messages to the error port.
* module/system/repl/repl.scm (default-catch-handler): Call display-error
with the correct number of arguments.
* module/system/vm/frame.scm (frame-program-name): Guard against unbound
variables.
* ice-9/optargs.scm (let-keywords-template): Don't unquote in a helper
procedure. A bit irritating. I suppose we should fix the modules +
syncase situation at some point, and then switch to syncase.
* libguile/vm-i-system.c (call, goto/args): Add a FIXME for handling the
case in which a call to the interpreter returns a values object.
(call/cc, goto/cc): Flesh out, and handle full continuations (with the
C stack also).
* module/language/scheme/translate.scm (custom-transformer-table):
Compile call-with-current-continuation. This is necessary so that the
called procedure is called in tail position.
* module/system/il/compile.scm (codegen): Translate apply to goto/apply,
call/cc to goto/cc, etc when in tail position.
* libguile/vm-engine.c (vm_run): Add new error case,
vm_error_not_enough_values.
* libguile/vm-i-system.c (goto/nargs, call/nargs): So, in these cases, if
we get too many values, we don't truncate the values like we do in the
single-value continuation case, or in the mvbind case. What to do? I
guess we either truncate them here, or only allow the correct number of
values. Dunno. Mark the code as a fixme.
(truncate-values): New instruction, for mv-bind: checks that the number
of values on the stack is compatible with the number of bindings we
have arranged for them, truncating if necessary.
* module/language/scheme/translate.scm (custom-transformer-table):
Compile receive as a primary form -- not so much because it is a
primary form, but more to test the mv-bind machinery. Also it's more
efficient, I think.
* module/system/il/compile.scm (lift-variables!): New helper, factored
out of `optimize'.
(optimize): Add a few more cases. Adapt `lambda' optimization, which
isn't much. I'm not happy with ghil as a mungeable language.
Add a case for call-with-values with the second argument is
a lambda: lift the lambda. Untested.
(codegen): Refactor the push-bindings! code. Compile mv-bind.
* module/system/il/ghil.scm (<ghil-mv-bind>): Add mv-bind construct,
along with its procedures.
* module/system/il/glil.scm (<glil-mv-bind>): Add mv-bind construct,
different from the high-level one. It makes sense in the source, I
think.
* module/system/vm/assemble.scm (codegen): Assemble glil-mv-bind by
pushing onto the bindings list, and actually push some code to truncate
the values.
* libguile/vm-engine.c (vm_run): Add another byte onto the bootstrap
program, as the offset passed to mv-call now takes two bytes.
* module/system/vm/frame.scm (bootstrap-frame?): Update for the new
bootstrap length. Really we should just check for 'halt though.
* libguile/vm-i-system.c (FETCH_OFFSET): New helper, used in BR().
(goto/nargs, call/nargs): Versions of goto/args and call, respectively,
that take the number of arguments from a value on the top of the stack.
(mv-call): Call FETCH_OFFSET to get the offset.
* module/language/scheme/translate.scm (custom-transformer-table):
Compile call-with-values to <ghil-mv-call>. There is some trickery
because of the r4rs.scm call-with-values trampolines.
* module/system/il/ghil.scm: Add <ghil-mv-call> and accessors.
* module/system/il/compile.scm (codegen): Compile <ghil-mv-call>.
* module/system/il/glil.scm: Add <glil-mv-call>, which needs some special
assembly because of the label. Fix some typos.
* module/system/vm/assemble.scm (byte-length): New helper, factored out
and made more general.
(codegen): Assemble mv-call, including the label.
(check-length): New helper, makes sure that the addressing is
consistent within the produced object code.
(stack->bytes): Rewrite to be more generic -- now `br' instructions
aren't the only ones jumping around in the instruction stream.
* module/system/vm/conv.scm (make-byte-decoder): Return two values in the
#f case.
* module/system/vm/disasm.scm (disassemble-bytecode): Rewrite, because
the previous implementation depended on a guile interpreter quirk:
namely, that multiple values could be represented within one value, and
destructured later.
* libguile/vm-engine.c (vm_run): Move nvalues to the top level, to avoid
(spurious, it seems) gcc warnings about it being used uninitialized.
* libguile/vm-i-system.c (halt, return/values): Adapt to gcc silliness.
Deindent some of return/values.
(return/values*): New instruction, does what (apply values . args)
would do.
* module/language/scheme/translate.scm (custom-transformer-table): Move
the apply and @apply cases here from inline.scm, because we need some
more cleverness when dealing with cases like (apply values . args).
(lookup-apply-transformer): Define an eval transformer for `values',
turning it into ghil-values*.
* module/system/il/compile.scm (codegen): Compile <ghil-values*> into
return/values*.
* module/system/il/ghil.scm: Add <ghil-values*> and accessors.
(ghil-lookup): Add optional argument, define?, which if false tells us
not to actually cache the binding if it is not found in the toplevel.
* module/system/il/inline.scm: Remove apply clauses.
* module/system/vm/frame.scm (bootstrap-frame?): Update heuristic for
bootstrap-frame?, as the bootstrap frame is now 5 bytes since it
accepts multiple values.
* libguile/vm-engine.c (vm_run): The bootstrap program now uses mv_call,
so as to allow multiple values out of the VM. (It did before, because
multiple values were represented internally as single scm_values
objects, but now that values go on the stack, we need to note the boot
frame as accepting multiple values.)
(vm_error_no_values): New error, happens if you pass no values into a
single-value continuation. Passing more than one is OK though, it just
takes the first one.
* libguile/vm-i-system.c (halt): Assume that someone has pushed the
number of values onto the stack, and package up that number of values
as a scm_values() object, for communication with the interpreter.
(mv-call): New instruction, calls a procedure with a multiple-value
continuation, even handling calls out to the interpreter.
(return/values): New instruction, returns multiple values to the
continuation. If the continuation is single-valued, takes the first
value or errors if there are no values. Otherwise it returns to the
multiple-value return address, pushing the number of values on top of
the values.
* module/system/il/compile.scm (codegen): Compile <ghil-values> forms.
* module/system/il/ghil.scm (<ghil-values>) Add new GHIL data structure
and associated procedures.
* module/language/scheme/translate.scm (custom-transformer-table):
Compile (values .. ) forms into <ghil-values>.
* module/language/scheme/translate.scm (custom-transformer-table): Rename
from `primitive-syntax-table', because now it will handle procedural
values as well.
(lookup-transformer): Update for renaming. Look up custom transformers
by value, not name.
(make-pmatch-transformers): Key the transformer table by value, not
name.
* libguile/vm-i-system.c (call): Rename continuation invocation from
`vm_call_cc' to `vm_call_continuation', because that's what it really
does. Add a note that it doesn't handle multiple values at the moment.
(goto/arg): Renamed from tail-call, in deference to the progenitors, on
Dale Smith's suggestion.
(goto/apply): New instruction, for `apply' in a tail context. Not yet
used, or vetted for that matter.
(call/cc): No need to pop the program, I don't think; although this
isn't tested either.
(goto/cc): New instruction, for call/cc in a tail context.
* module/language/scheme/translate.scm (*forbidden-primitives*): Rename
from %forbidden-primitives.
* module/system/il/compile.scm (codegen): Adapt to goto/args instead of
tail-call.
* module/system/il/inline.scm: Start inlining some macros used in
r4rs.scm -- not yet fully tested.
* ice-9/boot-9.scm: Allow load of a compiled r4rs file.
* module/language/scheme/translate.scm (primitive-syntax-table): In forms
like (define x y) where y is a lambda, and the lambda has no name yet,
set the lambda's name in its metadata.
* module/language/scheme/spec.scm (scheme): Specify an evaluator, `eval'.
* module/system/repl/common.scm (repl-default-options): Add option,
`interp', specifying that, if possible, the repl should interpret its
expressions rather than compile them. Defaults to #f.
* module/system/base/syntax.scm (keywords): Don't enable :keywords, it
breaks code that may assume that ':foo is a symbol, like boot-9.
* module/*.scm: Don't use :keywords, use #:keywords. The user can decide
if she wants #:keywords in their .guile, and :keywords might make us
compile modules differently.
* module/language/scheme/translate.scm (%forbidden-primitives): Take
procedure->memoizing-macro off probation; although it's not a good
idea, there is a fair amount of existing code that uses it that can be
compiled fine. So allow it in that case.
* module/system/il/ghil.scm (<ghil-env>, <ghil-toplevel-env>): Refactor
so that all environments point (eventually) at one toplevel
environment. Instead of having potentially multiple toplevel
environments, each noting the module against which its bindings are
resolved, have each binding in the toplevel record what module it
should be resolved in. Should fix compilation units that define
multiple modules.
(ghil-lookup, ghil-define): Reworked to not be destructive. Module
variables now have the module name as their "env", and are keyed as
`(MODNAME . SYM)' in the var table.
(call-with-ghil-environment): Reindented.
* module/system/il/inline.scm (try-inline-with-env): Adapt to
env/toplevel changes.
* module/system/vm/assemble.scm (dump-object!): A vlink-later now holds
the module name, not the module itself.
* module/system/il/compile.scm (make-glil-var): The "env" of a "module"
var is now the module name, not the module.
* module/language/scheme/translate.scm (primitive-syntax-table): Update
the way we test for toplevel environments. Reindent the lambda
translator.
(lookup-transformer, trans): lookup-transformer now has 2 args, not 3.
(translate): Update the way we make toplevel environments.
* module/language/scheme/translate.scm (primitive-syntax-table): Disable
semantics of start-stack in compiled code. I think start-stack
semantics aren't bad, but they don't have vm-based implementations at
this point.
Thanks to Dale Smith.
* guilec.mk: Rework to expect the includer to define $(modpath), then
make $(moddir) from that.
* module/language/Makefile.am:
* module/language/scheme/Makefile.am:
* module/system/base/Makefile.am:
* module/system/il/Makefile.am:
* module/system/repl/Makefile.am:
* module/system/vm/Makefile.am: Define modpath instead.
* src/guilec.in: Don't import (system vm bootstrap), it is no more.
* module/language/scheme/translate.scm (translate): Adapt to lambda
having a `meta' slot now.
(primitive-syntax-table, parse-lambda-meta): Parse out a docstring from
lambda forms, putting in the <ghil-lambda>'s meta slot.
* module/system/il/compile.scm (optimize, codegen): Passthrough for the
`meta' slot to the <glil-asm> object.
* module/system/il/ghil.scm (<ghil-lambda>): Add meta slot.
* module/system/il/glil.scm (<glil-asm>): Add meta slot.
(unparse): Unparse meta.
* module/system/vm/assemble.scm (preprocess): Pass through the meta slot.
(codegen): So, set the bytespec's meta slot as a list: bindings, source
info, then the tail is the meta-info, which should be an alist.
Currently the only defined key is `documentation', but `name' could
come in the future.
* module/system/vm/core.scm (program-sources): Sources are now in the
cadr...
(program-property): And here we have access to the cddr.
* module/language/scheme/translate.scm (translate, trans)
(make-pmatch-transformers): When recursing into subexpressions, get the
appropriate source location information.
(location): Include the source filename in the location information.
* module/system/il/compile.scm (codegen): Record source locations in more
cases. (This information ends up being part of the procedure metadata,
not the actual codepath.)
* module/system/il/glil.scm (unparse): Don't destructure the source
locations (it's a vector now).
* module/system/il/inline.scm: New module, implements generic inlining of
scheme functions. It even does the right thing regarding (define
arity:nopt caddr) and such. So now there are many more inlines: the
arithmetics, `apply', the caddr family, etc. This makes the benchmarks
*much* faster.
* module/language/scheme/translate.scm (trans): Remove the
%scheme-primitives code in favor of the generic (scheme il inline)
code. Adds inlining for +, -, =, etc.
* src/vm.c (vm_puts): Fix to work.
* module/system/base/compile.scm (system): Export load/compile also.
* module/system/il/compile.scm (optimize): Further debitrotting, but I
haven't tried this function yet. It seems that <ghil-inst> was what
<ghil-inline> is.
* module/system/il/ghil.scm (*core-primitives*, *macro-module*)
(ghil-primitive-macro?, ghil-macro-expander, ghil-primitive?): Remove
these unused things.
* module/system/il/macros.scm: Removed, replaced with inline.scm.
* module/system/vm/assemble.scm (stack->bytes): Before, the final
serialization code did an (apply u8vector (apply append (map
u8vector->list ...))). Aside from the misspelling of append-map, this
ends up pushing all elements of the u8vector on the stack -- assuredly
not what you want. But besides even that, I think that pushing more
than 32k arguments on the stack brings out some other bug that I think
was hidden before, because now we actually use the `apply' VM
instruction. Further testing is needed here, I think. Fixed the code to
be more efficient, which fixes the manifestation of this particular
bug: a failure to self-compile after inlining was enabled.
* module/system/vm/bootstrap.scm: New module, serves to bootstrap
boot-9's `load-compiled'. That way when we load (system vm core), we're
loading compiled code already.
* module/system/vm/core.scm: Use (system vm bootstrap).
* src/guilec.in: Use the bootstrap code, so that we really are compiling
with an entirely compiled compiler.
* module/system/repl/repl.scm (default-catch-handler): An attempt at
making the repl print a backtrace; more work needed here.
* module/system/vm/frame.scm (make-frame-chain): Fix some misspellings --
I think, anyway.
* guilec.mk: New file, to be included when building .go files.
* module/language/scheme/Makefile.am:
* module/system/base/Makefile.am:
* module/system/il/Makefile.am:
* module/system/repl/Makefile.am:
* module/system/vm/Makefile.am: Use guilec.mk.
* module/system/base/compile.scm (compiled-file-name): Work on the
basename of a file, so that we always create files in the directory
where we run. Perhaps should add a -o option to guilec in the future.
* Makefile.am: Actually recurse into module/ in a normal build.
* module/language/scheme/translate.scm (*the-compile-toplevel-symbol*):
Reset to compile-toplevel, which requires a patch to guile.
* module/system/base/compile.scm (compile-file): Some foo so that we load
up the scheme language before call-with-output-file. Fixes compilation
of (language scheme) modules.
* module/system/base/language.scm (define-language): Don't unquote in
make-language; refer to it by name instead, and export it.
* module/system/repl/Makefile.am (vm_DATA): Don't compile describe.scm,
because we really can't deal with goops yet.
* module/system/repl/repl.scm (compile-toplevel): If we're compiling, put
in a stub definition of start-stack, which is closely tied to the
interpreter.
* src/vm_loader.c (load-program): Fix a very tricky corruption bug!
* 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.
* 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/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/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.
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.