1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

201 commits

Author SHA1 Message Date
Andy Wingo
a32488ba13 SCM_I_IS_VECTOR only true for tc7_vector, not weak vectors
* libguile/tags.h (SCM_TYP7S, SCM_HAS_TYP7S): Remove these, as we no
  longer do the differs-by-one-bit thing for vectors and weak vectors.
* libguile/vectors.h (SCM_I_IS_VECTOR): Use SCM_HAS_TYP7.
  (SCM_I_IS_NONWEAK_VECTOR): Remove.
* libguile/vm-engine.c (vector-length, vector-ref, vector-set!)
  (vector-ref/immediate, vector-set!/immediate): We can inline these
  instructions completely now.

* libguile/vm.c (vm_error_not_a_vector, vm_error_out_of_range): New
  error conditions.
2014-02-08 17:19:52 +01:00
Andy Wingo
b914b236c3 Various VM stack management fixes
* libguile/vm.c (vm_increase_sp): New interface, to increase the SP to
  some new level, possibly expanding the stack.
  (vm_push_sp, vm_restore_sp): Intefaces to vm_increase_sp.
  (vm_return_to_continuation): Don't throw an error if there's not
  enough space; instead, expand.
  (vm_reinstate_partial_continuation): Use the new helper.
  (return_unused_stack_to_os): Avoid off-by-one error (sp points to
  valid memory.)
  (scm_call_n): Never write beyond the sp.
2014-02-05 22:52:00 +01:00
Andy Wingo
b3ae2b5068 Add VM and compiler support for calls to known procedures
* module/language/cps.scm ($callk): New expression type, for calls to
  known labels.  Part of "low CPS".
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm: Adapt call sites.

* libguile/vm-engine.c (call-label, tail-call-label): New instructions.
  Renumber the rest; this is an ABI change.

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.

* doc/ref/compiler.texi (CPS in Guile): Document $callk.
2014-02-02 23:19:22 +01:00
Andy Wingo
aef1fcf94e Add thread-local lock-free, TLS-free freelists.
* libguile/bdw-gc.h: Remove a needless compatibility hack.

* libguile/gc-inline.h: New file, implementing thread-local freelists
  providing faster allocation if we already have a scm_i_thread*
  pointer.  Based on gc_inline.h from libgc.

* libguile/threads.h (scm_i_thread): Add freelists here.
* libguile/threads.c (guilify_self_1, guilify_self_2): Initialize
  freelists.

* libguile/vm.c: Include gc-inline.h.
* libguile/vm-engine.c: Rename current_thread to thread.  Use
  scm_inline_cons instead of scm_cons, scm_inline_cell instead of
  scm_cell, and scm_inline_words instead of words.
2014-02-02 16:17:54 +01:00
Andy Wingo
7dba1c2ff1 Return unused parts of the stack to the OS
* libguile/vm.h (struct scm_vm): Reorder fields.  Add "sp_max_since_gc"
  field.
* libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME):
* libguile/vm.c (vm_return_to_continuation)
  (vm_reinstate_partial_continuation, scm_call_n): In places where we
  could increase the stack height, update sp_max_since_gc.
  (vm_expand_stack): Relocate sp_max_since_gc on expansion.
  (scm_bootstrap_vm): Record the page size using gnulib's getpagesize.
  (return_unused_stack_to_os): New routine, run when marking stacks.
2014-01-31 21:41:36 +01:00
Andy Wingo
024a60e374 Unnecessary VM_HANDLE_INTERRUPTS elision
* libguile/vm-engine.c: Remove VM_HANDLE_INTERRUPTS before entering a
  subr or foreign call.  The bytecode stub will have already done so
  when entering the stub, and the return sequence handles doing so
  before returning.
2014-01-28 21:56:54 +01:00
Andy Wingo
ddf0d7bb2e Fix more vm-engine comments
* libguile/vm-engine.c: Fix more comments.
2013-11-30 18:46:14 +01:00
Andy Wingo
2b6659e438 Remove slot-ref and slot-set! ops
* libguile/vm-engine.c: Remove slot-ref and slot-set! ops.
2013-11-30 18:46:14 +01:00
Andy Wingo
02f9d49614 Fix vm-engine.c comments
* libguile/vm-engine.c: Fix some comments.
2013-11-30 18:46:14 +01:00
Andy Wingo
f689dd6982 Remove the restore-continuation-hook.
* libguile/vm.h:
* libguile/vm.c:
* libguile/vm-engine.c:
* module/system/vm/traps.scm:
* module/system/vm/vm.scm: Remove the unused and redundant
  restore-continuation-hook.
2013-11-27 22:03:58 +01:00
Andy Wingo
4a1ce0169d VM copes with moving FP
* libguile/_scm.h (SCM_ASYNC_TICK_WITH_GUARD_CODE): New macro.
* libguile/vm-engine.c (VM_HANDLE_INTERRUPTS): Restore FP after
  ticking.
  (CACHE_FP): New macro.
  (CHECK_OVERFLOW): Use CACHE_FP.
  (BR_ARITHMETIC, RETURN_EXP, RETURN_ONE_VALUE, BINARY_INTEGER_OP):
  (call, return-values, subr-call, foreign-call)
  (resolve, define!, toplevel-box, module-box): Restore the FP from the
  vp where needed.
2013-11-22 18:44:33 +01:00
Andy Wingo
56280be983 Simplify state sync in VM before potential bailout.
* libguile/vm-engine.c (SYNC_IP): Remove calls to SYNC_BEFORE_GC, a
  no-op.  Replace SYNC_REGISTER / SYNC_ALL calls with just SYNC_IP.
2013-11-22 18:44:31 +01:00
Andy Wingo
d86682ba2c Add explicit nopcodes
* libguile/vm-engine.c (VM_NAME): Add explicit nopcodes, later to be
  interspersed with others.  This will allow us some extensibility
  without always shuffling around opcodes.  Also avoid lazy
  initialization; have the linker do it for us.

* libguile/instructions.c (parse_instruction):
  (scm_instruction_list): Rework instruction parsing to avoid using
  malloc.  It would seem that this would fix some GC issue -- but who
  knows!
2013-11-21 22:51:38 +01:00
Andy Wingo
dd1c7deccc Setjmp before calling into the VM
* libguile/vm-engine.c (CACHE_REGISTER): Remove an unneeded cast.
  (VM_NAME):
* libguile/vm.c (scm_call_n): Setjmp out here.  This leaves the VM
  without any initialization work to do.  It also makes it possible to
  restart the VM in another mode (with hooks, for example).
2013-11-21 21:15:58 +01:00
Andy Wingo
bd63e5b2c3 scm_call_n sets up boot continuation frame for VM
* libguile/vm-engine.c:
* libguile/vm.c (scm_call_n): Move boot continuation setup to
  scm_call_n, so that vm-engine takes all of its state from the vp.
2013-11-21 19:05:43 +01:00
Andy Wingo
b85cd20f80 scm_call_n avoids double TLS lookup
* libguile/vm-engine.c (VM_NAME): Take the current thread as an
  argument.
* libguile/vm.c (scm_i_capture_current_stack): Call thread_vm.
  (thread_vm): New helper.
  (scm_the_vm): Call thread_vm.
  (scm_call_n): Call thread_vm.  Avoids a double TLS lookup.
2013-11-21 18:50:12 +01:00
Andy Wingo
9b4c3ab5fa Engine takes struct scm_vm* as argument
* libguile/vm-engine.c:
* libguile/vm.c (scm_c_vm_run): VM engine now takes struct scm_vm* as
  argument, not SCM vm.
2013-11-21 17:52:00 +01:00
Andy Wingo
796e54a74c One more SCM vm user: continuations.
* libguile/continuations.c:
* libguile/continuations.h (struct scm_t_contregs): Rename SCM vm member
  to struct scm_vm *vp.
  (scm_i_make_continuation): Take vp instead of vm.
  (scm_i_contregs_vp): Rename from scm_i_contregs_vm, return vp.

* libguile/vm-engine.c (continuation-call, call/cc): Fix remaining SCM
  vm user.

* libguile/vm.c (vm_return_to_continuation): Adapt prototype.
2013-11-21 17:50:33 +01:00
Andy Wingo
b44f5451f8 Remove last use of SCM vm in VM
* libguile/control.h:
* libguile/control.c (reify_partial_continuation, scm_c_abort): Take
  struct scm_vm *vp as an arg.

* libguile/dynstack.h: Remove control.h include.

* libguile/vm.c (vm_abort): Take struct scm_vm *vp as an arg.

* libguile/vm-engine.c (abort): Adapt to vm_abort change.
2013-11-21 17:36:22 +01:00
Andy Wingo
44ece39907 Remove use of SCM vm in compose-continuation
* libguile/vm.c (vm_reinstate_partial_continuation): Take struct scm_vm
  argument instead of SCM.
* libguile/vm-engine.c (compose-continuation): Adapt.
2013-11-21 17:28:34 +01:00
Andy Wingo
59f85eedc2 Dispatch hooks use "vp" rather than "vm"
* libguile/vm.c (vm_dispatch_hook):
  (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): Use scm_vm pointer instead of
  Scheme vm object.
2013-11-21 17:24:48 +01:00
Andy Wingo
0bca90aac9 The dynamic stack records SP and FP values as offsets
* libguile/dynstack.h:
* libguile/dynstack.c (PROMPT_FP, PROMPT_SP):
  (scm_dynstack_push_prompt, scm_dynstack_find_prompt): Prompts on the
  dynstack are recorded as offsets from the base stack address in this
  thread.

* libguile/control.c (scm_c_abort):
* libguile/eval.c (eval):
* libguile/stacks.c (find_prompt, narrow_stack):
* libguile/throw.c (pre_init_catch):
* libguile/vm-engine.c (prompt): Adapt.
2013-11-21 16:51:15 +01:00
Andy Wingo
eadd9eb4c9 Prepare for moveable stacks in the VM.
* libguile/vm-engine.c (CHECK_OVERFLOW, ALLOC_FRAME, vm_engine): Prepare
  for moveable stacks.
2013-11-21 10:23:35 +01:00
Andy Wingo
f593117165 CHECK_OVERFLOW tweak
* libguile/vm-engine.c (CHECK_OVERFLOW): Now that we aren't checking for
  overflow on every push, fetch the stack limit from the vm instead of a
  local.
2013-11-21 10:07:58 +01:00
Andy Wingo
6ed55e9143 vm-engine cosmetic cleanup
* libguile/vm-engine.c: Reindent UNPACK macros.
2013-11-20 19:39:40 +01:00
Andy Wingo
ea0cd17d11 Rework hook dispatch mechanism
* 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.
2013-11-19 22:14:20 +01:00
Andy Wingo
f42cfbf0b7 Lingering RTL excision in vm.c
* 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.
2013-11-19 21:26:26 +01:00
Andy Wingo
20b1b91394 Move RTL unpack macros to vm-engine.c
* libguile/instructions.h: Remove SCM_UNPACK macros from here.
* libguile/vm-engine.c: Add them here, without the RTL_, and without the
  SCM_ prefix.
2013-11-19 21:12:21 +01:00
Andy Wingo
ef6b7f718a Internal RTL excision in vm.c
* libguile/vm.c (vm_boot_continuation, vm_boot_continuation_code):
  Rename from rtl_boot_continuation[_code].
  (scm_bootstrap_vm):
* libguile/vm-engine.c (rtl_vm_engine): Adapt.
2013-11-19 20:05:45 +01:00
Andy Wingo
d798a895cc Remove RTL_ infix from macros
* libguile/programs.h (SCM_PROGRAM_P):
  (SCM_PROGRAM_CODE):
  (SCM_PROGRAM_FREE_VARIABLES):
  (SCM_PROGRAM_FREE_VARIABLE_REF):
  (SCM_PROGRAM_FREE_VARIABLE_SET):
  (SCM_PROGRAM_NUM_FREE_VARIABLES):
  (SCM_VALIDATE_PROGRAM): Remove RTL_ infix.

* libguile/continuations.c:
* libguile/continuations.h:
* libguile/control.c:
* libguile/foreign.c:
* libguile/frames.c:
* libguile/gsubr.c:
* libguile/gsubr.h:
* libguile/procprop.c:
* libguile/procs.c:
* libguile/programs.c:
* libguile/stacks.c:
* libguile/vm-engine.c: Adapt.
2013-11-19 18:28:19 +01:00
Andy Wingo
e0755cd12a Rename scm_tc7_rtl_program to scm_tc7_program
* libguile/tags.h (scm_tc7_program): Rename from scm_tc7_rtl_program.
* libguile/continuations.c:
* libguile/control.c:
* libguile/evalext.c:
* libguile/foreign.c:
* libguile/goops.c:
* libguile/gsubr.c:
* libguile/print.c:
* libguile/programs.c:
* libguile/programs.h:
* libguile/vm-engine.c: Adapt users.

* module/system/vm/assembler.scm: Rename a tc7-rtl-program local to
  tc7-program.
* libguile/tags.h (scm_tc7_program): Rename from scm_tc7_rtl_program. * libguile/continuations.c: * libguile/control.c: * libguile/evalext.c: * libguile/foreign.c: * libguile/goops.c: * libguile/gsubr.c: * libguile/print.c: * libguile/programs.c: * libguile/programs.h: * libguile/vm-engine.c: Adapt users.

* module/system/vm/assembler.scm: Rename a tc7-rtl-program local to
  tc7-program.
2013-11-19 18:24:54 +01:00
Andy Wingo
9121d9f1ac All instruction pointers are now scm_t_uint32*
* 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.
2013-11-19 18:09:34 +01:00
Andy Wingo
b636cdb0f3 Frame pointer points to local 0 instead of local 1
* 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.
2013-11-17 22:07:44 +01:00
Andy Wingo
f8085163d6 Remove MVRA from VM frames
* 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.
2013-11-15 17:13:27 +01:00
Andy Wingo
840ec33422 Remove MVRA accessors in libguile
* libguile/vm.c (scm_i_vm_capture_stack): Remove MVRA argument, in
  preparation for removing MVRA from frames.
  (scm_i_capture_current_stack): Adapt to scm_i_vm_capture_stack
  change.
  (vm_reinstate_partial_continuation): Remove references to MVRA.

* libguile/vm.h (struct scm_vm_cont): Remove mvra member.

* libguile/vm-engine.c (call): Set MVRA to 0.  Will remove later.
  (return-values): Return to RA.
  (call/cc): Remove MVRA from capture call.

* libguile/frames.c:
* libguile/frames.h (SCM_FRAME_MV_RETURN_ADDRESS)
  (SCM_FRAME_RTL_MV_RETURN_ADDRESS, scm_frame_mv_return_address): Remove
  accessors.

* libguile/control.c (reify_partial_continuation): Adapt to
  scm_i_vm_capture_stack change.
2013-11-15 15:39:38 +01:00
Andy Wingo
4c906ad5a5 Add specialize-primcalls pass; bump objcode version.
* 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.
2013-11-10 19:27:19 +01:00
Andy Wingo
1c33be992e Remove stack programs, objcode, and the old VM.
* 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.
2013-11-08 18:28:24 +01:00
Andy Wingo
f90c055464 Add br-if-npos-gt
* 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.
2013-11-08 11:38:34 +01:00
Andy Wingo
d2bd8fa810 Fix BR_NARGS data type width
* libguile/vm-engine.c (BR_NARGS): Fix width of "expected".  Fixes bug
  with > 65536 arguments in case-lambda clauses.
2013-11-08 11:36:53 +01:00
Andy Wingo
da60ba8062 fix make-long-immediate, make-long-long-immediate for dst >= 256
* libguile/vm-engine.c (make-long-immediate, make-long-long-immediate):
  Fix declaration of "dst" variable.
2013-11-05 19:22:26 +01:00
Andy Wingo
6165d8120d Better aliased primcall compilation
* 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.
2013-10-31 12:55:24 +01:00
Andy Wingo
ecbef96687 Fix bytevector error messages.
* libguile/vm-engine.c (BV_FIXABLE_INT_SET, BV_INT_SET):
  (BV_FLOAT_SET): Fix instruction names in error messages.
2013-10-31 12:55:24 +01:00
Andy Wingo
2ab2a10d50 static-patch! replaces link-procedure!
* 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.
2013-10-31 09:47:48 +01:00
Andy Wingo
186b56c4dc Resumable partial continuations in the RTL VM
* 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.
2013-10-27 20:09:09 +01:00
Andy Wingo
486013d67c VM has "builtins": primitives addressable by emitted RTL code
* 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.
2013-10-27 20:09:01 +01:00
Andy Wingo
d76de8716d Partial continuations are RTL stubs
* 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.
2013-10-27 11:30:22 +01:00
Andy Wingo
607fe5a604 Add make-vector, constant-make-vector instructions
* 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.
2013-10-26 22:06:01 +02:00
Andy Wingo
8ba3f20c47 Emit constant-vector-ref, constant-vector-set! for known small indices
* 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.
2013-10-26 21:30:37 +02:00
Andy Wingo
4f406fea7e Compile variable-ref, variable-set!
* 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!.
2013-10-26 15:40:49 +02:00
Andy Wingo
2a4ee2ac8c RTL VM: Fix fluid-ref local addressing.
* libguile/vm-engine.c (push-fluid): Fix variable addressing.
2013-10-26 14:38:11 +02:00