* libguile/eval.h:
* libguile/eval.c (scm_closure_apply): New function, applies a closure.
Won't be necessary in the future, but for now here it is, with
internal linkage.
* libguile/gsubr.h:
* libguile/gsubr.c (scm_i_gsubr_apply_array): New function, applies a
gsubr to an array of values, potentially extending that array for
optional arguments and rest arguments and such.
* libguile/vm.c (apply_foreign): New function, applies a foreign
function to arguments on the stack, in place.
* libguile/vm-i-system.c (call): Add a case for procedures-with-setters
(will go away when they are applicable structs). Instead of calling
the evaluator for foreign functions, call apply_foreign.
* libguile/goops.h (SCM_MCACHE_N_SPECIALIZED)
(SCM_SET_MCACHE_N_SPECIALIZED, SCM_INITIAL_MCACHE_SIZE)
(scm_make_method_cache, scm_memoize_method, scm_mcache_lookup_cmethod)
(scm_mcache_compute_cmethod):
* libguile/goops.c: Remove these procedures which managed the method
cache. There's still a slot there but it's not initialized. The method
cache is no longer necessary.
* module/oop/goops/dispatch.scm (memoize-method!): Change to not take a
"cache" argument.
* libguile/eval.i.c:
* libguile/vm-i-system.c: Remove dispatch via the method cache.
* libguile/eval.i.c (CEVAL, SCM_APPLY): Dispatch applicable structs
before pure generics. In practice what this means is that we never hit
the mcache case, because all pure generics are applicable structs.
We're moving over to having generics dispatch themselves. Also, they
don't prepend the struct as an arg; in order to have that effect, the
user has closures.
* libguile/goops.c (scm_apply_generic, scm_call_generic_0):
(scm_call_generic_1, scm_call_generic_2, scm_call_generic_3): Dispatch
directly to the struct procedures.
(scm_var_make_extended_generic): Remove a duplicate definition for
scm_var_make_extended_generic.
(create_standard_classes): Mark all instances of
<applicable-struct-class> (themselves classes) as applicable classes.
Meaning: generics are now applicable structs.
* libguile/goops.h (SCM_CLASS_CLASS_LAYOUT): The hashsets are actually
uw slots -- or at least, making subclasses maps the int slots to be uw
slots
* libguile/vm-i-system.c (call, goto/args, mv-call): Dispatch applicable
structs in the VM.
* module/oop/goops/dispatch.scm (emit-linear-dispatch): Fix bug in the
non-rest cache miss case.
(delayed-compile): Rework to avoid fluids.
(cache-dispatch): Don't call `equal?', it causes bootstrapping
problems with the primitive-generic equal?. Using our own version is
faster anyway.
* libguile/vm-i-system.c (br-if-nargs-gt): Fix variable declaration
placement.
(bind-kwargs): Patch mostly by Ludovic: it seems that in the mode in
which we have rest args, the keywords can appear anywhere. Bummer.
Change to allow for this.
* module/ice-9/optargs.scm (parse-lambda-case): Same, add a
permissive-keys clause that handles the case in which there's a rest
argument.
* libguile/goops.h (SCM_GENERIC_METHOD_CACHE)
(SCM_SET_GENERIC_METHOD_CACHE): Two new macros; the same as
SCM_[SET_]ENTITY_PROCEDURE, but more reflecting the reality of the
generic hack.
* libguile/eval.i.c:
* libguile/goops.c:
* libguile/objects.c:
* libguile/vm-i-system.c: Use the new macros when it is appropriate to
do so.
* libguile/vm-i-system.c (call, goto/args, mv-call): Add a case for
generics, so we can avoid the evaluator in that case. Still have to
cons up a list -- the real solution comes later.
* libguile/vm-i-system.c (local-bound?, long-local-bound?)
(variable-bound?): New instructions, push #f unless the local is
bound. You can get unbound locals from optional arguments.
(bind-optionals/shuffle): A number of bugfixes.
(bind-kwargs): Bugfixes. If we enocunter an improper kwarg list but
the procedure has a rest argument, just stop kwarg processing, but
without an error.
Renumbered ops.
* libguile/_scm.h (SCM_OBJCODE_MAJOR_VERSION): Bump.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bumparoo
* libguile/vm-i-system.c (push-rest, bind-rest): Logically there are
actually two rest binders -- one that pops, conses, and pushes, and
one that pops, conses, and local-sets. The latter is used on keyword
arguments, because the keyword arguments themselves have been shuffled
up on the stack. Renumber ops again.
* module/language/tree-il/compile-glil.scm (flatten): Attempt to handle
compilation of lambda-case with keyword arguments. Might need some
help.
* module/ice-9/psyntax.scm (build-lambda-case): An attempt to handle the
interpreted case correctly. This might need a couple iterations, but
at least it looks like the compile-glil code.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/glil.scm (<glil>): Rename "rest?" to "rest" in
<glil-opt-prelude> and <glil-kw-prelude>, as it is no longer a simple
boolean, but if true is an integer: the index of the local variable to
which the rest should be bound.
* module/language/glil/compile-assembly.scm (glil->assembly): Adapt to
"rest" vs "rest?". In the keyword case, use "bind-rest" instead of
"push-rest".
* test-suite/tests/tree-il.test: Update for opt-prelude change.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (br-if-nargs-ne, br-if-args-lt)
(br-if-nargs-gt): New instructions, for use by different lambda cases.
(bind-optionals, bind-optionals/shuffle, bind-kwargs): New
instructions, for binding optional and keyword arguments. Renumber
other ops.
* module/language/ecmascript/compile-tree-il.scm (comp, comp-body):
Update for new tree-il. Use the new optional argument mechanism
instead of emulating it with rest arguments.
* module/language/glil/compile-assembly.scm (glil->assembly): Tweaks for
optional and keyword argument compilation.
* module/language/tree-il.scm (parse-tree-il, unparse-tree-il): Make the
else case optional, in the s-expression serialization of tree-il.
* module/language/tree-il/compile-glil.scm (flatten): Handle all of the
lambda-case capabilities.
* libguile/vm-i-system.c (bind-rest): Renamed from push-rest-list.
(reserve-locals): Change so that instead of reserving space for some
additional number of locals, reserve-locals takes the absolute number
of locals, including the arguments.
* module/language/glil.scm (<glil-std-prelude>, <glil-opt-prelude>)
(<glil-kw-prelude>): New GLIL constructs, to replace <glil-arity>.
* module/language/glil/compile-assembly.scm (glil->assembly): Compile
the new preludes. Some instructions are not yet implemented, though.
* module/language/tree-il/analyze.scm (analyze-lexicals): The nlocs for
a lambda will now be the total number of locals, including arguments.
* module/language/tree-il/compile-glil.scm (flatten-lambda): Update to
write the new prelude.
* module/system/vm/program.scm (program-bindings-for-ip): If a given
index doesn't have a binding at the ip given, don't cons it on the
resulting list.
* test-suite/tests/tree-il.test: Update for GLIL changes.
* gdbinit: Ignore SIGPWR and SIGXCPU, which the BDW GC seems to use.
* libguile/vm-engine.h (FETCH_WIDTH): Remove unused macro.
(INIT_ARGS, INIT_FRAME): Remove; callees now check their args and
reserve space for their locals.
* libguile/vm-engine.c:
* libguile/vm-i-system.c: Turn on callee arg checking and local
reservation. Seems to work!
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (reserve-locals): New instruction, to reserve
space for local vars. Other ops renumbered.
* module/language/tree-il/compile-glil.scm (flatten-lambda): Emit
reserve-locals instructions as necessary.
* test-suite/tests/tree-il.test: Update to expect reserve-locals as
appropriate.
* libguile/objcodes.h: Bump for metadata format change.
* libguile/frames.h: Rework so we don't frob the program's nargs, nlocs,
etc at runtime. Instead we don't really know what's a local var, an
argument, or an intermediate value. It's a little unfortunate, but
this will allow for case-lambda, and eventually for good polymorphic
generic dispatch; and the nlocs etc can be heuristically
reconstructed. Such a reconstruction would be better done at the
Scheme level, though.
(SCM_FRAME_STACK_ADDRESS): New macro, the pointer to the base of the
stack elements (not counting the program).
(SCM_FRAME_UPPER_ADDRESS): Repurpose to be the address of the last
element in the bookkeeping part of the stack -- i.e. to point to the
return address.
* libguile/vm-engine.h:
* libguile/vm-i-system.c: Adapt to removal of stack_base. Though we
still detect stack-smashing underflow, we don't do so as precisely as
we did before, because now we only detect overwriting of the frame
metadata.
* libguile/vm-engine.c (vm_engine): Remove the stack_base variable. It
is unnecessary, and difficult to keep track of in the face of
case-lambda. Also fix miscommented "ra" and "mvra" pushes. Push the
vp->ip as the first ra...
* libguile/vm-i-system.c (halt): ...because here we can restore the
vp->ip instead of setting ip to 0. Allows us to introspect ips all
down the stack, including in recursive VM invocations.
* libguile/frames.h:
* libguile/frames.c (scm_vm_frame_stack): Removed, because it's getting
more difficult to tell what's an argument and what's a temporary stack
element.
(scm_vm_frame_num_locals): New accessor.
(scm_vm_frame_instruction_pointer): New accessor.
(scm_vm_frame_arguments): Defer to an implementation in Scheme.
(scm_vm_frame_num_locals scm_vm_frame_local_ref)
(scm_vm_frame_local_set_x): Since we can get not-yet-active frames on
the stack now, with our current calling convention, we have to add a
heuristic here to jump over those frames -- because frames have
pointers in them, not Scheme values.
* libguile/programs.h:
* libguile/programs.c (scm_program_arity): Remove, in favor of..
(scm_program_arities): ...this, which a list of arities, in a new
format, occupying a slot in the metadata.
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
Fix mv-call decompilation.
* module/system/vm/frame.scm (vm-frame-bindings, vm-frame-binding-ref)
(vm-frame-binding-set!): New functions, to access bindings by name in
a frame.
(vm-frame-arguments): Function now implemented in Scheme. Commented
fairly extensively.
* module/system/vm/program.scm (program-bindings-by-index)
(program-bindings-for-ip): New accessors, parsing the program bindings
metadata into something more useful.
(program-arities, program-arguments): In a case-lambda world, we have
to assume that programs can have multiple arities. But it's tough to
detect this algorithmically; instead we're going to require that the
program metadata include information about the arities, and the parts
of the program that that metadata applies to.
(program-lambda-list): New accessor.
(write-program): Show multiple arities.
* module/language/glil/compile-assembly.scm (glil->assembly): Add
"arities" to the state of the compiler, and add arities entries as
appropriate.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (assert-nargs-ee, assert-nargs-ge)
(push-rest-list): New instructions, which for now don't actually do
anything. Renumber the rest of the ops in this file.
* module/language/glil.scm (<glil-arity>): New GLIL type, an entity that
checks the number of args for a block, optionally consing a rest list,
and either branching or erroring if the arity doesn't match.
* module/language/glil/compile-assembly.scm (glil->assembly): Compile
<glil-arity> to assembly. Some of these VM ops are not implemented --
notably the branching case.
* module/language/tree-il/compile-glil.scm (flatten-lambda): Emit
<glil-arity>.
* test-suite/tests/tree-il.test: Update.
* libguile/tags.h (scm_tc7_program):
* libguile/programs.h: Programs now have their own tc7 code. Fix up the
macros appropriately.
* libguile/programs.c: Remove smobby bits, leaving marking, printing,
and application for other parts of Guile.
* libguile/debug.c (scm_procedure_source):
* libguile/eval.c (scm_trampoline_0, scm_trampoline_1)
(scm_trampoline_2): Add cases for tc7_program.
* libguile/eval.i.c (CEVAL, SCM_APPLY):
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/gc-card.c (scm_i_sweep_card, scm_i_tag_name):
* libguile/gc-mark.c (1):
* libguile/print.c (iprin1):
* libguile/procs.c (scm_procedure_p, scm_thunk_p)
* libguile/vm-i-system.c (make-closure): Adapt to new procedure
representation.
* libguile/procprop.c (scm_i_procedure_arity): Do the right thing for
programs.
* test-suite/tests/procprop.test ("procedure-arity"): Arity test now
succeeds.
* libguile/goops.c (scm_class_of): Programs now belong to the class
<procedure>, not a smob class.
* libguile/vm.h (struct vm, struct vm_cont):
* libguile/vm-engine.c (vm_engine):
* libguile/frames.h (SCM_FRAME_BYTE_CAST, struct vm_frame):
* libguile/frames.c (scm_c_make_vm_frame): Fix usages of scm_byte_t,
changing them to scm_t_uint8.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump
* libguile/vm-engine.c (vm_engine): Push a frame corresponding to the
mv-call.
* libguile/vm-i-system.c: Renumber ops.
(new-frame): New op, pushes a frame.
(call, mv-call): No need to shuffle args, though we do need to pop the
frame in the non-vm call case.
(goto/args): Inconsequential tweaks.
(call/cc): Push a frame if needed.
* module/language/tree-il/compile-glil.scm (flatten): Emit `new-frame'
as appropriate.
* test-suite/tests/tree-il.test: Fix to expect new-frame.
* libguile/frames.h: Reorder the frame layout so the return address
comes below the arguments.working
(SCM_FRAME_SET_RETURN_ADDRESS, SCM_FRAME_SET_MV_RETURN_ADDRESS): New
macros.
* libguile/frames.c (scm_vm_frame_arguments): Use the macros to access
the arguments.
* libguile/vm-engine.c (vm_engine): Fix for new calling convention.
* libguile/vm-engine.h (INIT_FRAME): New macro. Does part of what
NEW_FRAME used to do.
* libguile/vm-i-system.c (call, mv-call): Shuffle args up to make room
for the stack, and adapt to new calling convention.
(goto/args): Shuffling down is easier now.
(return, return/args): Adapt to new frame layout.
* libguile/vm.c (vm_mark_stack): Adapt to new frame layout, and the
possibility of there being crap on the stack.
(really_make_boot_program): Remove extraneous comment.
* libguile/vm-i-system.c: Remove mark, list-mark, cons-mark,
vector-mark, and list-break, as they are no longer used.
(call, goto/args, mv-call): Remove bits about trampolines, which was
slower, and VM continuations, which are not used (we use Guile's
continuations as the applicable objects).
Renumber ops.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-engine.c (vm_error_bad_wide_string_length): New error
case.
* libguile/vm-i-loader.c (load-unsigned-integer, load-integer)
(load-keyword): Remove these instructions. The former two are
obsoleted by make-int64/make-uint64, the latter via make-keyword.
(load-string): Only handle narrow strings.
(load-symbol): Only handle narrow symbols. The wide case is handled
via make-symbol.
(load-wide-string): New instruction, for wide strings.
* libguile/vm-i-system.c (define): Move here from loaders.c, as now it
just takes a sym on the stack.
(make-keyword, make-symbol): New instructions.
* module/language/assembly.scm: Remove removed instructions. No more
width byte in load-string etc.
* module/language/assembly/compile-bytecode.scm (write-bytecode): Adapt
to change in instruction set.
* module/language/glil/compile-assembly.scm (glil->assembly): Compile
define by pushing the sym then emitting (define).
(dump-object): Dump narrow and wide strings differently. Use
make-keyword and make-symbol as appropriate.
* module/language/tree-il/compile-glil.scm (flatten): When compiling a
ref to a primitive (not a call), first see if the primitive is
actually bound in the root module. (That's not the case with e.g.
bytevector-u8-ref).
* module/system/xref.scm (program-callee-rev-vars): Don't parse out
"nexts".
* test-suite/tests/asm-to-bytecode.test ("compiler"): Adapt to bytecode
format change.
* libguile/vm-i-system.c (fix-closure): New instruction, for wiring
together fixpoint procedures.
* module/Makefile.am (TREE_IL_LANG_SOURCES): Add fix-letrec.scm.
* module/language/glil/compile-assembly.scm (glil->assembly): Reindent
the <glil-lexical> case, and handle 'fix for locally-bound vars.
* module/language/tree-il.scm (<fix>): Add the <fix> tree-il type and
accessors, for fixed-point bindings. This IL construct is taken from
the Waddell paper.
(parse-tree-il, unparse-tree-il, tree-il->scheme, tree-il-fold)
(pre-order!, post-order!): Update for <fix>.
* module/language/tree-il/analyze.scm (analyze-lexicals): Update for
<fix>. The difference here is that the bindings may not be assigned,
and are not marked as such. They are not boxed.
(report-unused-variables): Update for <fix>.
* module/language/tree-il/compile-glil.scm (flatten): Compile <fix> to
GLIL.
* module/language/tree-il/fix-letrec.scm: A stub implementation of
fixing letrec -- will flesh out in a separate commit.
* module/language/tree-il/inline.scm: Fix license, it was mistakenly
added with LGPL v2.1+.
* module/language/tree-il/optimize.scm (optimize!): Run the fix-letrec!
pass.
Since the contents of SCM_MAKE_CHAR are evaluated more than once,
don't use it in situations where this could cause side-effects.
* libguile/vm-i-system.c (make-char8): avoid side-effects with
SCM_MAKE_CHAR call
* libguile/chars.h (SCM_MAKE_CHAR): modified
This adds the 32-bit standalone characters. Strings are still
8-bit. Characters larger than 8-bit can only be entered or
displayed in octal format at this point. At this point, the
terminal's display encoding is expected to be Latin-1.
* module/language/assembly/compile-bytecode.scm (write-bytecode):
add 32-bit char
* module/language/assembly.scm (object->assembly): add 32-bit char
(assembly->object): add 32-bit char
* libguile/vm-i-system.c (make-char32): new op
* libguile/print.c (iprin1): print 32-bit char
* libguile/numbers.h: add type scm_t_wchar
* libguile/numbers.c: add type scm_t_wchar
* libguile/chars.h: new type scm_t_wchar
(SCM_CODEPOINT_MAX): new
(SCM_IS_UNICODE_CHAR): new
(SCM_MAKE_CHAR): operate on 32-bit char
* libguile/chars.c: comparison operators now use Unicode
codepoints
(scm_c_upcase): now receives and returns scm_t_wchar
(scm_c_downcase): now receives and returns scm_t_wchar
* libguile/objcodes.c (OBJCODE_COOKIE): Bump again, as our jump offsets
are now multiplied by 8.
* libguile/vm-i-system.c (BR): Interpret the 16-bit offset as a relative
jump to the nearest 8-byte-aligned block -- increasing relative jump
range from +/-32K to +/-240K.
(mvra): Do the same for the mvra jump.
* libguile/vm.c (really_make_boot_program): Align the mvra.
* module/language/assembly.scm (align-block): New export, for aligning
blocks.
* module/language/assembly/compile-bytecode.scm (write-bytecode): Emit
jumps to the nearest 8-byte-aligned block. Effectively our range is 18
bits in either direction. I would like to do this differently -- have
long-br and long-br-if, and all the other br instructions go to 8 bits
only. But the assembler doesn't have an appropriate representation to
allow me to do this yet, so for now this is what we have.
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
Decode the 19-bit jumps.
* libguile/objcodes.c (OBJCODE_COOKIE): Bump objcode cookie, as we added
to struct scm_objcode.
* libguile/objcodes.h (struct scm_objcode): Add a uint32 after metalen
and before base, so that if the structure has 8-byte alignment, base
will have 8-byte alignment too. (Before, base was 12 bytes from the
start of the structure, now it's 16 bytes.)
* libguile/vm-engine.h (ASSERT_ALIGNED_PROCEDURE): Add a check that can
be turned on with VM_ENABLE_PARANOID_ASSERTIONS.
(CACHE_PROGRAM): Call ASSERT_ALIGNED_PROCEDURE.
* libguile/vm-i-system.c (long-local-ref): Add a missing semicolon.
* libguile/vm.c (really_make_boot_program): Rework to operate directly
on a malloc'd buffer, so that the program will be 8-byte aligned.
* module/language/assembly.scm (*program-header-len*): Add another 4 for
the padding.
(object->assembly): Fix case in which we would return (make-int8 0)
instead of (make-int8:0). This would throw off compile-assembly.scm's
use of addr+.
* module/language/assembly/compile-bytecode.scm (write-bytecode): Write
out the padding int.
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
And pop off the padding int too.
* module/language/glil/compile-assembly.scm (glil->assembly): Don't pack
the assembly, assume that assembly.scm has done it for us. If a
program has a meta, pad out the program so that meta will be aligned.
* test-suite/tests/asm-to-bytecode.test: Adapt to expect programs to
have the extra 4-byte padding int.
* libguile/vm-i-system.c (long-local-ref, long-local-set)
(make-variable): New intructions, for handling nlocs >= 256.
* module/language/glil/compile-assembly.scm (glil->assembly): Compile
<glil-lexical> with support for nlocs >= 256.
* libguile/programs.h:
* libguile/programs.c: (SCM_PROGRAM_FREE_VARIABLES): Rename from
SCM_PROGRAM_FREE_VARS. Callers changed.
* libguile/programs.c (scm_make_program): Rename arg to
"free_variables".
(scm_program_free_variables): Rename from program-free-vars.
* libguile/vm-engine.h:
* libguile/vm-engine.c (VM_CHECK_FREE_VARIABLES): Rename from
VM_CHECK_CLOSURE.
(vm_engine, CACHE_PROGRAM): Rename closure and closure_count to free_vars and
free_vars_vount.
* libguile/vm-i-system.c (FREE_VARIABLE_REF): Rename from CLOSURE_REF.
(free-ref, free-boxed-ref, free-boxed-set): Rename from closure-ref,
closure-boxed-ref, closure-boxed-set.
(make-closure): Renamed from make-closure2.
* module/language/glil/compile-assembly.scm (glil->assembly): Hack to
never write out the the old "make-closure" instruction. Will fix
better later. Change to emit free-ref etc instead of closure-ref.
* module/language/tree-il/compile-glil.scm (flatten): Emit make-closure
instead of make-closure2, now that the old make-closure is gone.
* module/system/vm/program.scm (system): Rename program-free-vars to
program-free-variables.
* test-suite/tests/tree-il.test ("lambda"): Update for make-closure.
* libguile/frames.c (scm_frame_external_link): Removed.
* libguile/frames.h: No need to have the "external link" in the stack
frame -- update macros to take the new situation into account.
* libguile/objcodes.h (struct scm_objcode): Rename the nexts field to
"unused". In the future we can use it for nlocs, I think.
(SCM_OBJCODE_NEXTS): removed.
* libguile/programs.h:
* libguile/programs.c (scm_make_program): Expect the third argument to
be a vector of free variables, not a list of free variables.
SCM_BOOL_F indicates no free variables, not SCM_EOL.
(program_mark): Adapt.
(scm_program_arity): No more nexts.
(scm_program_free_vars): Replaces scm_program_externals.
* libguile/vm-engine.c (VM_CHECK_EXTERNAL)
(vm_engine): No need for the "external" var.
* libguile/vm-engine.h (CACHE_PROGRAM): Update for SCM_PROGRAM_FREE_VARS
instead of SCM_PROGRAM_EXTERNALS.
(NEW_FRAME): Update for new frame size, and no need to cons up
externals. Yay :)
* libguile/vm-i-loader.c (load-program): Update for scm_make_program.
* libguile/vm-i-system.c (external-ref, external-set): No more.
(make-closure): No more.
(goto/args): No need to re-cons externals here. Update for new stack
frame size.
(mv-call, return, return/values): Update for new frame size. No need
to reinstate externals on return.
* libguile/vm.c (really_make_boot_program, scm_load_compiled_with_vm):
Update for scm_make_program.
* module/language/objcode/spec.scm (objcode-env-externals): Treat '() as
#f, for the externals. Need to clean this up later...
* module/system/vm/program.scm (arity:nexts): Remove. Rename
program-external to program-free-vars.
* libguile/vm-i-system.c (box, empty-box): Boxing values and storing
them in local variables.
(local-boxed-ref, local-boxed-set): A combination of local-ref then
variable-ref/set.
(make-closure2, closure-ref, closure-boxed-ref, closure-boxed-set):
New ops. The idea is to migrate Guile over to using flat dispay
closures. See the paper "Three Implementation Models for Scheme" by
Kent Dybvig for more details; this is the "stack-based" model.
* libguile/vm-engine.c:
* libguile/vm-engine.h: Add the necessary infrastructure to keep track
of a "closure" variable, like our "externals" in semantics, but
minimal, flat, and O(1) in implementation.
* libguile/objcodes.c (OBJCODE_COOKIE): Bump.
* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c:
* libguile/vm-i-system.c: Renumber instructions, so I can have a bit
more space to work.
* doc/ref/vm.texi (Loading Instructions): Remove references to
load-integer and load-unsigned-integer -- they're still in the VM but
will be removed at some point.
(Data Control Instructions): Add make-int64 and make-uint64.
* libguile/vm-i-loader.c (load-unsigned-integer): Allow 8-byte values.
But this instruction is on its way out, yo.
* libguile/vm-i-system.c (make-int64, make-uint64): New instructions.
* module/language/assembly.scm (object->assembly): Write out make-int64
and make-uint64 instructions, using bytevectors to do the endianness
conversion.
(assembly->object): And pretty-print them back, for disassembly.
* module/language/glil/compile-assembly.scm: Don't generate load-integer
/ load-unsigned-integer instructions.
* libguile/vm-i-system.c (long-object-ref, long-toplevel-ref)
(long-toplevel-set): Add new instructions, for accessing the object
table with a 16-bit offset. HTMLprag defines a test program that has
more than 256 constants, necessitating this addition.
* doc/ref/vm.texi: Mention the new instructions.
* module/language/glil/compile-assembly.scm: Emit long refs for object
tables bigger than 256 entries.
* libguile/vm-i-system.c (toplevel-ref, toplevel-set)
* libguile/vm-i-loader.c (link-now):
* libguile/vm.c (resolve_variable): Factor out common code to a static
method. The compiler can still inline it, so it shouldn't have a
significant performance effect.
* libguile/vm-engine.c (vm_error_no_such_module): Remove now-unused
label.
* doc/ref/api-procedures.texi (Compiled Procedures): Fix for API changes.
* doc/ref/compiler.texi (Compiling to the Virtual Machine): Replace GHIL
docs with Tree-IL docs. Update the bits about the Scheme compiler to
talk about Tree-IL and the expander instead of GHIL. Remove
<glil-argument>. Add placeholder sections for assembly and bytecode.
* doc/ref/vm.texi: Update examples with what currently happens. Reword
some things. Fix a couple errors.
* libguile/vm-i-system.c (externals): Remove this instruction, it's not
used.
* module/ice-9/documentation.scm (object-documentation): If the object is
a macro, try to return documentation on the macro transformer.
* module/language/assembly/disassemble.scm (disassemble-load-program):
Fix problem in which we skipped the first element of the object vector,
because of changes to procedure layouts a few months ago.
* module/language/scheme/spec.scm (read-file): Remove read-file
definition.
* module/language/tree-il.scm: Reorder exports. Remove <lexical>, it was
a compat shim to something that was never released. Fix `location'.
* module/language/tree-il/primitives.scm (/): Fix expander for more than
two args to /.
* module/system/base/compile.scm (read-file-in): Remove unused
definition.
* module/system/base/language.scm (system): Remove language-read-file.
* module/language/ecmascript/spec.scm (ecmascript): Remove read-file
definition.
* libguile/vm-i-system.c:
* libguile/vm-engine.h (ASSERT_BOUND): New assertion, that a value is
bound. Used by local-ref and external-ref in paranoid mode.
* module/ice-9/boot-9.scm (and, or, cond, case, do): Since we are
switching to use psyntax as the first pass of the compiler, and perhaps
soon of the interpreter too, we need to make sure it expands out all
forms to primitive expressions. So define expanders for these derived
syntax forms, as in the R5RS report.
* module/ice-9/psyntax-pp.scm: Regenerate, with core forms fully
expanded.
* module/ice-9/psyntax.scm (build-void): New constructor, for making
undefined values.
(build-primref): Add in a hack so that primitive refs in the boot
module expand out to toplevel refs, not module refs.
(chi-void): Use build-void.
(if): Define an expander for if that calls build-conditional.
* module/language/scheme/compile-tree-il.scm (compile-tree-il): Use let*
so as not to depend on binding order for the result of
(current-module).
* module/language/scheme/spec.scm (scheme): Switch over to tree-il as the
primary intermediate language. Not yet fully tested, but at least it
can compile psyntax-pp.scm.
* module/language/tree-il/analyze.scm (analyze-lexicals): Arguments don't
count towards a function's nlocs.
* module/language/tree-il/compile-glil.scm (*comp-module*, compile-glil):
Define a "compilation module" fluid.
(flatten-lambda): Fix a call to make-glil-argument. Fix bug in
heapifying arguments.
(flatten): Fix number of arguments passed to apply instruction. Add a
special case for `(values ...)'. If inlining primitive-refs fails,
try expanding into toplevel-refs if the comp-module's variable is the
same as the root variable.
* module/language/tree-il/optimize.scm (resolve-primitives!): Add missing
src variable for <module-ref>.
* test-suite/tests/tree-il.test ("lambda"): Fix nlocs counts. Add a
closure test case.
* libguile/vm-i-system.c (toplevel-ref, toplevel-set): Correct situation
whereby we would not throw when toplevel vars were unbound, before
modules had booted.
Reported by Daniel Kraft <d@domob.eu>.
* libguile/frames.c, libguile/vm.c: Include <stdlib.h>, use `size_t'
instead of `scm_sizet'.
* libguile/objcodes.c, libguile/programs.c, libguile/vm-engine.c,
libguile/vm-i-loader.c, libguile/vm-i-system.c: Use `scm_list_X ()'
instead of the deprecated `SCM_LISTX ()'.
* 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.
* 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.
* 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.
* 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.