* 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/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/system/repl/command.scm (display-time-stat, display-mips-stat):
Always convert to float.
* module/system/vm/frame.scm (print-frame): Write the args, don't display them.
* module/system/repl/command.scm (statistics): gc-sweep-time is no more.
* module/system/repl/command.scm (module): Accept e.g. `,m ice-9 popen'
in addition to `,m (ice-9 popen)'.
* module/system/repl/repl.scm (start-repl): Call read with a backtrace
handler too.
* module/system/repl/command.scm: Coerce rationals to floats.
* module/system/vm/program.scm (program-documentation): Fix a typo, doh!
* src/vm.c (vm_reset_stack, struct vm_unwind_data): Add unwind handler to
reset vp->sp, vp->fp, and vp->this_frame when performing a nonlocal
exit from a vm_run.
(vm_heapify_frames_1): Don't repack the stack, it causes stack
corruption. I think we need spaghetti stacks to handle continuations,
not separate heap frames. I don't think call/cc is working now.
(vm-save-stack): Don't call heapify_frames, that modifies the stack
that we're copying. Instead call its helper, heapify_1.
* src/vm_engine.c (vm_run): Set up the vm_reset_stack unwind handler.
* src/vm_engine.h (IP_REG, SP_REG, FP_REG): If we got through all of the
checks without having these macros defined, define them as empty.
Happens on x86-64.
* src/vm_system.c (halt): End the dynwind before we return from the VM.
* src/vm_scheme.c (REL): Sync the regs before calling scm_lt_p et al,
cause they can do a nonlocal exit.
This reorganization kills the ugly module-export-all hacks in
bootstrap.scm and core.scm. In fact, it gets rid of core.scm entirely,
breaking out its functionality into separate files.
* module/system/vm/trace.scm:
* module/system/vm/profile.scm:
* module/system/vm/disasm.scm:
* module/system/vm/debug.scm:
* module/system/vm/conv.scm:
* module/system/vm/assemble.scm:
* module/system/repl/repl.scm:
* module/system/repl/common.scm:
* module/system/base/compile.scm:
* module/system/repl/command.scm: Update for changes, and fix a bug in
procedure-documentation.
* module/system/vm/bootstrap.scm: Just call scm_bootstrap_vm, which
handles setting load-compiled for us.
* module/system/vm/core.scm: Removed, functionality folded into other
modules.
* module/system/vm/frame.scm: Export the C frame procedures here; also
move scheme functions from core.scm here.
* module/system/vm/instruction.scm: New file, exports procedures from
instructions.c.
* module/system/vm/objcode.scm: New file, exports procedures from
objcodes.c.
* module/system/vm/program.scm: New file, exports procedures from
programs.c, and some scheme functions originally from core.scm.
* module/system/vm/vm.scm: New file, from vm.c and core.scm.
* src/Makefile.am (libguile_vm_la_SOURCES): Add bootstrap.h.
* src/bootstrap.h: New file, prototypes scm_bootstrap_vm (), which the
scm_init_* functions call.
* src/frames.h:
* src/frames.c (scm_init_frames):
* src/frames.c (scm_bootstrap_frames):
* src/vm.h:
* src/instructions.h:
* src/instructions.c (scm_init_instructions):
* src/instructions.c (scm_bootstrap_instructions):
* src/objcodes.h:
* src/objcodes.c (scm_bootstrap_objcodes):
* src/objcodes.c (scm_init_objcodes):
* src/programs.h:
* src/programs.c (scm_bootstrap_programs):
* src/programs.c (scm_init_programs):
* src/vm.c (scm_bootstrap_vm):
* src/vm.c (scm_init_vm): Call scm_bootstrap_vm() before doing anything
in an init function. Bootstrap_vm will call bootstrap_instructions(),
etc to initialize types, then set load-compiled to point to
load-compiled/vm.
* src/vm.c (scm_load_compiled_with_vm): Code to load .go files, if
they're present.
* m4/labels-as-values.m4: New file, checks for computed goto.
* configure.in: Use AC_C_LABELS_AS_VALUES.
* module/system/repl/command.scm (procedure-documentation): Extend the
core's procedure-documentation in an ad-hoc way, so that ,help works.
* module/system/vm/core.scm (program-properties): New function.
(program-documentation): New function.
* src/vm_engine.h (DROP, DROPN): Decrement sp before checking for
underflow.
* src/vm_system.c (call, tail-call): Add some optimized dispatch for some
C functions, so that we can avoid consing and the interpreter if
possible. However currently it seems that I'm always getting the
scm_call_* trampolines back.
* 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/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.
* 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 (system): Don't re-export receive or
and-let*; modules should explicitly import these if they want to. Don't
export an empty stack-catch definition!
* module/system/repl/command.scm (system): Pull in and-let*.
* module/system/vm/disasm.scm (system): Don't import and-let*.