* libguile/vm-engine.c (RUN_HOOK, RUN_HOOK0, RUN_HOOK1): Rework to
dispatch through specific per-hook procedures. Might reduce register
pressure in the VM.
* libguile/vm.c (vm_dispatch_apply_hook):
(vm_dispatch_push_continuation_hook):
(vm_dispatch_pop_continuation_hook):
(vm_dispatch_next_hook):
(vm_dispatch_abort_hook):
(vm_dispatch_restore_continuation_hook): New internal helpers.
* libguile/vm-engine.c:
* libguile/vm.c: Rework VM inclusion so that we don't define VM_ENGINE
and expect vm-engine.c to understand that -- since there is only
VM_USE_HOOKS, define that in vm.c directly. Rename rtl_vm_foo to
vm_foo.
* libguile/vm.h: Remove scm_t_vm_engine typedef.
* libguile/frames.h (SCM_FRAME_RTL_RETURN_ADDRESS)
(SCM_FRAME_SET_RTL_RETURN_ADDRESS): Remove. The variants without _RTL
now work fine.
(struct scm_vm_frame): Change the return address to be a
scm_t_uint32*.
(struct scm_frame): Change IP to be scm_t_uint32*.
* libguile/frames.c (scm_c_make_frame)
* libguile/control.c (reify_partial_continuation, scm_c_abort)
* libguile/dynstack.c (PROMPT_IP)
(scm_dynstack_push_prompt, scm_dynstack_find_prompt)
* libguile/dynstack.h:
* libguile/vm-engine.c (SYNC_IP, RETURN_ONE_VALUE)
(call, return-values, prompt): Adapt.
* libguile/frames.h: Change so that fp points at local 0 instead of
local 1, and clean up a bit.
(struct scm_vm_frame): Remove program, and rename stack to locals.
(SCM_FRAME_DATA_ADDRESS): Remove; it was redundant with
SCM_FRAME_LOWER_ADDRESS.
(SCM_FRAME_STACK_ADDRESS): Remove; replace with the new
SCM_FRAME_LOCALS_ADDRESS.
(SCM_FRAME_UPPER_ADDRESS): Remove; unused.
(SCM_FRAME_NUM_LOCALS, SCM_FRAME_PREVIOUS_SP): New defines.
(SCM_FRAME_BYTE_CAST, SCM_FRAME_STACK_CAST): Remove; unused;
(SCM_FRAME_LOCAL): New define, replaces SCM_FRAME_VARIABLE.
(SCM_FRAME_PROGRAM): Add cautionary commentary.
* libguile/frames.c: Adapt static asserts.
(scm_frame_num_locals, scm_frame_local_ref, scm_frame_local_set_x):
Adapt. This means that frame-local-ref 0 now returns the procedure.
* libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME)
(FRAME_LOCALS_COUNT, LOCAL_REF, LOCAL_SET, RETURN_VALUE_LIST): Adapt
to change in fp.
(LOCAL_ADDRESS): New helper.
(POP_CONTINUATION_HOOK): Reimplement, taking the previous FP as an
argument.
(ABORT_CONTINUATION_HOOK): Reimplement, taking no arguments.
(RETURN_ONE_VALUE): Reimplement.
(RETURN_VALUE_LIST): Adapt to FP change.
(halt, return-values, subr-call, foreign-call, prompt)
(continuation-call, compose-continuation, call/cc, abort): Adapt to FP
change, mostly via using LOCAL_ADDRESS, etc abstractions instead of
using the raw frame pointer.
* libguile/control.c (reify_partial_continuation): Update for fp
change.
* libguile/vm.c (vm_reinstate_partial_continuation): Adapt to removal of
SCM_FRAME_UPPER_ADDRESS.
* module/system/vm/frame.scm (frame-call-representation): Adapt to
frame-local-ref change.
* module/system/vm/trace.scm (print-return): Remove unused
frame-num-locals call.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump for frame layout
change.
* libguile/frames.c: Update some static checks.
(scm_frame_num_locals, scm_frame_local_ref, scm_frame_local_set_x):
Update to not skip over uninitialized frames, as that's not a thing
any more.
* libguile/frames.h: Update to remove MVRA. Woo!
* libguile/vm-engine.c (ALLOC_FRAME, RETURN_ONE_VALUE):
(rtl_vm_engine): Update for 3 words per frame instead of 4.
* libguile/vm.c (vm_return_to_continuation): Likewise.
* module/language/cps/slot-allocation.scm (allocate-slots): 3 words per
frame, not 4.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump. Also
remove a couple of tc7's that aren't around any more.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/objcodes.c (process_dynamic_segment): Expect the minor
version to be present and, while we are still banging on the VM,
exactly equal to SCM_OBJCODE_MINOR_VERSION.
* libguile/vm-engine.c: Renumber ops. Remove the general make-vector.
Rename constant-FOO to FOO/immediate. Remove struct-ref and
struct-set!, replace with struct-ref/immediate and
struct-set!/immediate.
* module/Makefile.am:
* module/language/cps/specialize-primcalls.scm: New pass, inlines FOO to
FOO/immediate -- e.g. vector-ref to vector-ref/immediate.
* module/language/cps/arities.scm: Remove struct-set! case, now that
there is no struct-set! opcode.
* module/language/cps/compile-rtl.scm (compile-fun): Remove dispatch to
constant-FOO versus FOO here -- that decision is made by
specialize-primcalls.
(optimize): Add specialize-primcalls pass.
* module/language/cps/dfg.scm (constant-needs-allocation?): Adapt to
name changes.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*primitive-constructors*): Add allocate-struct.
* module/system/vm/assembler.scm (*bytecode-major-version*):
(*bytecode-minor-version*, link-dynamic-section): Write minor version
into resulting image.
* libguile/Makefile.am:
* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c:
* libguile/vm-i-system.c: Remove the old VM files, and the rules to
build the .i files.
* libguile/vm-engine.c:
* libguile/vm.c: Remove the old VM. Woot!
* libguile/_scm.h (SCM_OBJCODE_COOKIE, SCM_OBJCODE_ENDIANNESS_OFFSET)
(SCM_OBJCODE_WORD_SIZE_OFFSET): Remove.
* libguile/evalext.c (scm_self_evaluating_p): Remove objcode and program
cases.
* libguile/frames.c (scm_frame_num_locals, scm_frame_previous): Remove
program cases.
* libguile/gc.c (scm_i_tag_name): Remove objcode case.
* libguile/goops.c (scm_class_of, create_standard_classes): Remove
objcode and program cases.
* libguile/instructions.h:
* libguile/instructions.c (scm_instruction_list, scm_instruction_p)
(scm_instruction_length, scm_instruction_pops, scm_instruction_pushes)
(scm_instruction_to_opcode, scm_opcode_to_instruction): Remove old VM
code.
* libguile/objcodes.h:
* libguile/objcodes.c: Remove the objcode data type, and handling for
objcode files.
* libguile/print.c: Remove objcode and program printers.
* libguile/procprop.c: Remove program cases.
* libguile/procs.c:
* libguile/programs.h:
* libguile/programs.c: Remove old program code.
* libguile/smob.c: Remove objcodes include.
* libguile/snarf.h: Remove static program defines.
* libguile/stacks.c: Remove program case.
* libguile/tags.h: Remove program and objcode tc7s.
* module/ice-9/session.scm (procedure-arguments)
* module/language/tree-il/analyze.scm (validate-arity)
* module/statprof.scm (get-call-data, procedure=?)
* module/system/vm/frame.scm (frame-bindings)
(frame-call-representation): Remove old program cases.
* module/system/repl/debug.scm (frame->module): Add a FIXME.
* module/system/vm/instruction.scm: Remove old exports.
* module/system/vm/program.scm: Remove old program code.
* libguile/vm-engine.c (br-if-npos-gt): New instruction (sigh!). For
case-lambda* dispatching on the number of positional args, as the
manual describes. Renumber other opcodes.
* libguile/vm-engine.c (define!): Rename from define.
* module/language/cps/arities.scm (fix-clause-arities): If a prim
aliases an RTL instruction with a different name and we reify a
primcall, reify the instruction name.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Update
emit-define! for new name.
* module/language/cps/primitives.scm (*rtl-instruction-aliases*): Add
bytevector native accessors.
* libguile/vm-engine.c (static-patch!): Replace link-procedure! with
this more versatile primitive.
* module/system/vm/assembler.scm (intern-constant): Emit static-patch!
for static procedures and for strings.
* module/system/vm/disassembler.scm (code-annotation): Remove annotation
for link-procedure!. There can be no annotation for static-patch!, as
neither operand is guaranteed to be a SCM value.
* libguile/vm-engine.c (receive-values): Bugfix for the case where we
want an exact number of values.
(abort): Advance the IP before capturing. The captured SP is fp - 1,
not fp.
* libguile/vm.c (vm_reinstate_partial_continuation): Don't push on a
number-of-values marker.
* libguile/Makefile.am:
* libguile/vm-builtins.h: New header, declaring stubs needed by the
compiler like values, apply, and abort-to-prompt.
* libguile/vm.c: Adapt the apply and values stubs to conform to a
standard interface. Add an abort-to-prompt stub. Add call/cc and
call-with-values stubs.
(scm_vm_builtin_ref): New helper, for the builtin-ref opcode.
(scm_vm_builtin_name_to_index)
(scm_vm_builtin_index_to_name): New helpers, for the compiler and
disassembler, respectively.
(scm_init_vm_builtins, scm_bootstrap_vm): Allow the compiler helpers
to be loaded later into a module.
* module/language/rtl.scm: Export builtin-index->name and
builtin-name->index.
* libguile/vm-engine.c (RETURN_VALUE_LIST): Update to use new names of
"apply" and "values".
(tail-call/shuffle): New opcode.
(abort): Update to be a tail VM op, and reorder and renumber other
ops.
(builtin-ref): New opcode.
* libguile/continuations.h:
* libguile/continuations.c (scm_i_call_with_current_continuation):
Move this to vm.[ch], implemented as a builtin.
* module/language/tree-il/compile-cps.scm (convert): Convert to
'abort-to-prompt calls, possibly with 'apply, effectively undoing the
tree-il transformation.
* module/language/cps/reify-primitives.scm (builtin-ref): New helper.
(reify-primitives): Convert builtin primitives to builtin-ref.
* module/language/cps/dfg.scm (constant-needs-allocation?):
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add support
for compiling builtin-ref.
* module/system/vm/disassembler.scm (code-annotation): Add annotation
for builtin-ref.
* libguile/control.c: Implement partial continuations as RTL programs.
* libguile/programs.c (scm_i_rtl_program_minimum_arity): Add partial
continuation case.
* libguile/vm-engine.c (compose-continuation): Fix to look for vm_cont
from the free variables.
* libguile/vm-i-system.c (abort): Poison continuations captured in the
stack VM, as the can't be rewound by the RTL stubs.
* libguile/vm-engine.c (rtl_vm_engine): Add make-vector and
constant-make-vector instructions and renumber.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Emit
constant-make-vector and make-vector as appropriate.
* module/language/cps/dfg.scm (constant-needs-allocation?): In some
cases, make-vector doesn't need to allocate its index.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*, *primitive-constructors*): Add
make-vector.
* libguile/vm-engine.c (rtl_vm_engine): Add constant-vector-set!
instruction and renumber.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Emit
constant-vector-ref and constant-vector-set! as appropriate.
* module/language/cps/dfg.scm (constant-needs-allocation?): In some
cases, vector-ref and vector-set! don't need to allocate their index.
* libguile/vm-engine (box-ref, box-set!): Instead of aborting if a box
isn't a var, call out to vm_error_not_a_variable. This makes these
instructions equivalent to variable-ref/variable-set!.
(vector-set!): Rename from vector-set.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add
variable-set! case, and adapt vector-set!.
* module/language/cps/primitives.scm (*rtl-instruction-aliases*): Add
variable-ref / variable-set! aliases to box-ref / box-set!.
* libguile/continuations.h:
* libguile/continuations.c: Reimplement continuations and the call_cc
stub as RTL programs.
* libguile/programs.c (scm_i_rtl_program_minimum_arity): Add a case for
continuations.
* libguile/vm-engine.c (rtl_vm_debug_engine): Always call the abort
continuation hook with the number of non-procedure locals. Fix
compose-continuation argument count. Enable call/cc.
* libguile/vm-engine.c (bind-rest): If the sp is below the dst reg,
alloc the frame to ensure there is enough space, and to fill in
intermediate values with SCM_UNDEFINED.
* libguile/vm-engine.c (prompt): Adapt to explicitly set the saved SP so
we know how many incoming values the handler will receive, and to make
escape-only? a flag.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): $prompt
should only be found in a "seq" context, as it just pushes on a prompt
and doesn't bind any values. On the other hand it should emit
appropriate code for the handler to bind its values, so do that.
* module/language/cps/slot-allocation.scm ($cont-allocation): Add a note
that proc-slot is used by prompts as well.
(allocate-slots): Compute the allocation of a prompt handler's args.
* module/language/tree-il/compile-cps.scm (convert): Use "unwind"
instead of the nonexistent "pop-prompt".
* module/system/vm/disassembler.scm (code-annotation): Adapt to change
in prompt VM op.
* libguile/vm-engine.c (receive-values): Add an ALLOW-EXTRA? flag in
unused bits of the third word. Without it, receive-values will check
for the exact number of incoming values.
* libguile/vm.c (vm_error_wrong_number_of_values): New error case.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Adapt to add
the ALLOW-EXTRA? flag.
* libguile/vm-engine.c (return-values): Remove NVALUES operand.
Don't reset the frame.
* test-suite/tests/rtl.test ("cached-toplevel-set!"): Adapt to the fact
that 'return-values' has no operand now, and that 'reset-frame' must
be done first.
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Allow for
five-word instructions, and for new instruction word types.
* libguile/vm-engine.c (RETURN_ONE_VALUE): Instead of returning the
value in the fixed part of the call frame, return it in the same place
multiple-value returns go: from slot 1.
(BR_ARITHMETIC): Allow arithmetic tests to be negated.
(rtl_vm_engine): Change calling convention to use the same location
for single and multiple-value returns. Renumber all instructions.
(halt, halt/values): Fold into a single instruction (halt).
(call): Take the location of the procedure instead of the location of
the call frame. Also take the number of args, and reset the sp before
jumping to the procedure, so as to indicate the number of arguments.
(call/values): Remove, as the new calling convention has RA == MVRA.
(tail-call): Require the procedure to be shuffled down already, and
take "nlocals" as an arg instead of "nargs".
(receive, receive-values): New instructions, for receiving returned
values from calls.
(return-values): Rename from return/values. Remove "values".
(alloc-frame): Rename from reserve-locals.
(reset-frame): New instruction.
(drop-locals): Remove.
(br-if-=, br-if-<, br-if-<=): Allow these instructions to be
negatable.
(br-if->, br-if->=): Remove. Probably a bad idea, given NaN.
(box-ref): Don't bother trying to do a reverse lookup -- the
toplevel-box, module-box, and resolve instructions should handle
that.
(resolve): Add arg to check that the variable is bound.
(toplevel-box, module-box): New instructions, replacing toplevel-ref,
toplevel-set, module-ref, and module-set.
* libguile/vm.c (rtl_boot_continuation_code, rtl_values_code): Adapt to
instruction set changes.
* module/Makefile.am: Make the assembler and disassembler dependent on
vm-operations.h.
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm: Adapt to instruction changes and
new instruction word kinds.
* test-suite/tests/rtl.test: Adapt to instruction set changes.
* libguile/vm-engine.c (INUM_MIN, INUM_MAX): Redefine without making
assumptions about the representation.
(INUM_STEP): New macro.
(add1, sub1): Avoid signed overflows, and use INUM_STEP.
* libguile/struct.h:
* libguile/struct.c (scm_allocate_struct): New interface: allocates a
struct.
* libguile/vm-engine.c (allocate_struct): Instead of make-struct with a
rest arg, separate allocation from initialization.
* libguile/vm-engine.c (push_frame, call): Separate out push_frame from
call, and expect the caller to arrange the proc and arguments.
* test-suite/tests/rtl.test ("call"): Update tests.
* libguile/vm-engine.c: Change the RTL VM to number the procedure as
local 0, and other locals from 1. In the future we will want the FP
to point to local 0 instead of local 1. In the future also we can
elide the procedure for well-known closures (closures in which all
references are known call sites).
(make_closure, free_set): Instead of taking rest arguments, we add a
new free-set! op that initializes closures.
(free_ref): Take the closure as an argument.
* libguile/vm.c (rtl_boot_continuation_code): Remove comments, which
were out of date.
(rtl_apply_code, rtl_values_code): Update comments.
* module/system/vm/assembler.scm (intern-constant, emit-init-constants):
Adapt to locals numbering change.
(begin-kw-arity): For assert-nargs-ee purposes, nreq includes the
procedure.
* module/system/vm/disassembler.scm (code-annotation): Adapt annotation
for assert-nargs-ee/locals.
* test-suite/tests/rtl.test: Adapt tests.
* libguile/dynstack.h (SCM_DYNSTACK_TYPE_WITH_FLUID): Rename from
with-fluids.
* libguile/dynstack.c (scm_dynstack_push_fluid):
(scm_dynstack_unwind_fluid): Change API to only wind/unwind one
fluid binding.
(WITH_FLUID_WORDS): New define, always 2 words (fluid and value box).
(WITH_FLUID_FLUID, WITH_FLUID_VALUE_BOX): New macros to get offsets of
fluid and value box.
(scm_dynstack_push_rewinder, scm_dynstack_push_unwinder): Use
WINDER_WORDS.
(scm_dynstack_push_dynwind): Use DYNWIND_WORDS.
(scm_dynstack_wind_1): Update for scm_swap_fluid API change.
* libguile/fluids.h:
* libguile/fluids.c (scm_prepare_fluids): Remove; no longer needed.
(scm_swap_fluid): Update to just swap one fluid binding.
(scm_c_with_fluids, scm_c_with_fluid): Update to use
scm_dynstack_push_fluid.
* libguile/memoize.c (do_push_fluid, do_pop_fluid): Adapt to API
change.
* libguile/vm-engine.c (rtl_vm_engine): Change wind-fluids / unwind-fluids
to push-fluid / pop-fluid, and actually enable. Woo!
* libguile/vm-i-system.c (push-fluid, pop-fluid): Update to new API.