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

342 commits

Author SHA1 Message Date
Andy Wingo
22d425ec55 Expandable stacks.
* libguile/vm-engine.c (CHECK_OVERFLOW): Call vm_expand_stack, not
  vm_error_stack_overflow.
* libguile/vm.c (hard_max_stack_size, default_max_stack_size): Recast
  #defines as locals.  Have both hard and soft stack limits.
  (initialize_default_stack_size): Set soft stack limit from
  GUILE_STACK_SIZE.
  (expand_stack, vm_expand_stack): Support for expanding stacks as
  needed.  Whee!
  (make_vm): Adapt limits.
  (scm_call_n): Expand stack if needed.

* libguile/vm.h (struct scm_vm): Add max_stack_size member.
2013-11-22 18:45:01 +01:00
Andy Wingo
1cdf9b788e More precise stack marking.
* libguile/vm.c (scm_i_vm_mark_stack): Mark the stack more precisely.
2013-11-22 15:02:17 +01:00
Andy Wingo
5f18bc8450 Allocate stacks using mmap, and mark them via the thread marker
* libguile/threads.c (thread_mark): Mark the VM stack, if we have one.
  (on_thread_exit): Free the VM stack here.

* libguile/vm.c (make_vm): Allocate the VM stack using mmap, and arrange
  for it to be marked by the thread marker.
  (scm_i_vm_mark_stack, scm_i_vm_free_stack): New internal interfaces.
  (allocate_stack, free_stack): New helpers.
2013-11-22 14:41:19 +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
350930756c Remove scm_tc7_vm
* libguile/tags.h (scm_tc7_vm): Return to pool.

* libguile/goops.c:
* libguile/gc.c (scm_i_tag_name):
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/print.c (iprin1): Remove tc7_vm things.

* libguile/vm.h (scm_the_vm_fluid): Remove stray declaration.  Remove
  SCM_VM_P.  Remove SCM_VM_DATA.  Remove SCM_VALIDATE_VM.
* libguile/vm.c (scm_i_vm_print): Remove.
2013-11-21 18:39:21 +01:00
Andy Wingo
3506b1521e Remove last use of SCM vm
* libguile/threads.h (scm_i_thread): Hold a struct scm_vm*, not a SCM
  vm.
* libguile/threads.c (guilify_self_2):
* libguile/vm.c (make_vm): Adapt.
2013-11-21 18:33:06 +01:00
Andy Wingo
e7f9ababe0 scm_the_vm now returns raw struct scm_vm pointer
* libguile/vm.h (scm_the_vm): Return struct scm_vm*.
  (scm_c_vm_run): Remove.

* libguile/control.c:
* libguile/eval.c:
* libguile/throw.c:
* libguile/vm.c: Adapt.
2013-11-21 18:28:06 +01:00
Andy Wingo
55ee360700 Prefer scm_call_n to scm_c_vm_run (scm_the_vm())
* libguile/vm.c (scm_i_capture_current_stack): Cosmetic tweak.
  (scm_call_n): Define here instead of in eval.c.  All callers of
  scm_c_vm_run were passing scm_the_vm() as the VM.  Eventually
  scm_call_n will replace scm_c_vm_run.

* libguile/eval.c: Adapt all callers.
2013-11-21 18:23:08 +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
5515edc5f2 Heap frame "stack holders" are raw scm_vm / scm_vm_cont pointers
* libguile/frames.h (struct scm_frame): stack_holder is a void*.
* libguile/frames.c (scm_i_frame_stack_base, scm_i_frame_offset): Expect
  stack_holder to be the raw struct scm_vm or scm_vm_cont.

* libguile/continuations.c (scm_i_continuation_to_frame):
* libguile/stacks.c (scm_make_stack)
* libguile/vm.c (vm_dispatch_hook): Adapt creators.
2013-11-21 17:21:37 +01:00
Andy Wingo
050a40db5b Heap frames have a "frame kind" bit
* libguile/frames.h (enum scm_vm_frame_kind, SCM_VM_FRAME_KIND)
  (scm_c_make_frame): Add a "frame kind" bit to the first word.  This
  will allow the "stack holder" to be a non-SCM object.

* libguile/continuations.c (scm_i_continuation_to_frame):
* libguile/frames.c (scm_c_make_frame, scm_frame_previous)
* libguile/stacks.c (scm_make_stack):
* libguile/vm.c (vm_dispatch_hook): Adapt frame creators to set the
  frame kind bit.
2013-11-21 17:13:18 +01:00
Andy Wingo
a222cbc9d1 No more VM objects visible to Scheme
* libguile/vm.h:
* libguile/vm.c (scm_the_vm): Don't expose to Scheme.
  (scm_vm_p): Remove, as it is not needed.

* module/system/vm/vm.scm: Remove the-vm and vm? exports.

* doc/ref/api-coverage.texi (Code Coverage):
* test-suite/tests/coverage.test:
* module/system/vm/coverage.scm (with-code-coverage): Don't take a VM
  argument.  Adapt documentation and tests.

* module/ice-9/command-line.scm: Remove the-vm autoload.

* module/system/vm/trace.scm (trace-calls-to-procedure):
  (trace-calls-in-procedure):
  (trace-instructions-in-procedure):
  (call-with-trace): Remove #:vm kwarg, and adapt to trap changes.

* module/system/vm/trap-state.scm (the-trap-state): Rework to use a
  parameter underneath instead of a weak key on (the-vm).

* module/system/vm/traps.scm (new-disabled-trap):
  (new-enabled-trap): Remove vm argument.
  (trap-at-procedure-call):
  (trap-in-procedure):
  (trap-instructions-in-procedure):
  (trap-at-procedure-ip-in-range):
  (trap-at-source-location):
  (trap-frame-finish):
  (trap-in-dynamic-extent):
  (trap-calls-in-dynamic-extent):
  (trap-instructions-in-dynamic-extent):
  (trap-calls-to-procedure):
  (trap-matching-instructions): Remove vm keyword arguments.

* test-suite/tests/control.test ("unwind"): Adapt test.

* test-suite/tests/eval.test (test-suite): Remove the-vm import.
2013-11-21 16:45:03 +01:00
Andy Wingo
972275eee5 VM accessors take VM as implicit argument, not explicit argument
* libguile/vm.h:
* libguile/vm.c:
  (scm_vm_apply_hook, scm_vm_push_continuation_hook,
  scm_vm_pop_continuation_hook, scm_vm_abort_continuation_hook,
  scm_vm_restore_continuation_hook, scm_vm_next_hook,
  scm_vm_trace_level, scm_set_vm_trace_level_x, scm_vm_engine,
  scm_set_vm_engine_x, scm_c_set_vm_engine_x): The VM argument is now
  implicit: the VM for the current thread.

* doc/ref/api-debug.texi (VM Hooks): Try to adapt.

* module/ice-9/command-line.scm:
* module/statprof.scm:
* module/system/vm/coverage.scm:
* module/system/vm/trace.scm:
* module/system/vm/trap-state.scm:
* module/system/vm/traps.scm:
* test-suite/tests/control.test:
* test-suite/tests/eval.test: Adapt users that set hooks or ensure that
  we have a debug engine.
2013-11-21 16:10:41 +01:00
Andy Wingo
3583665aa0 Remove unused vm:ip, vm:sp, vm:fp
* libguile/vm.h:
* libguile/vm.c (scm_vm_ip, scm_vm_fp, scm_vm_sp): Remove unused
  functions.

* module/system/vm/vm.scm: Remove exports.
2013-11-21 15:02:36 +01:00
Andy Wingo
e08caa5620 Remove make-vm; there will be one vm per thread now.
* libguile/vm.h:
* libguile/vm.c (scm_make_vm): Remove.

* module/system/vm/vm.scm: Remove make-vm export.

* test-suite/tests/control.test ("the-vm"):
* test-suite/tests/coverage.test (%test-vm):
* test-suite/tests/eval.test ("stack overflow"): Adapt tests.
2013-11-21 15:00:03 +01:00
Andy Wingo
89b235afd3 Scheme frame objects hold relative stack offsets
* libguile/frames.h: Wrap the C interface to VM frames in
  BUILDING_LIBGUILE.  Change VM frames to record relative offsets into a
  stack held by some other object, so that if the stack moves they will
  remain valid.
* libguile/frames.c (scm_c_make_frame): Remove offset argument.
  (scm_i_frame_offset): Instead, compute the offset from the stack
  holder.
  (scm_i_frame_stack_base): New helper.
  (scm_frame_previous): Adapt.

* libguile/stacks.c (scm_make_stack)
* libguile/vm.c (vm_dispatch_hook):
* libguile/continuations.c (scm_i_continuation_to_frame): Adapt.
2013-11-21 11:20:19 +01:00
Andy Wingo
62e1660695 Remove unused resolve_variable helper
* libguile/vm.c (resolve_variable): Remove unused helper.
2013-11-20 19:38:06 +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
c4f7923fa9 Remove VM_ENABLE_STACK_NULLING
* libguile/vm.c: Remove code dependent on VM_ENABLE_STACK_NULLING.  This
  defined didn't work and doesn't apply to the RTL model.
2013-11-19 21:47:55 +01:00
Andy Wingo
4cbc95f150 Rename objcodes?.{scm,c,h} to loader.{scm,c,h}
* libguile/loader.c:
* libguile/loader.h: Rename from objcodes.[ch].
* module/system/vm/loader.scm: Rename from objcode.scm.

* libguile/Makefile.am:
* libguile/gsubr.c:
* libguile/init.c:
* libguile/procs.c:
* libguile/vm.c:
* module/Makefile.am:
* module/ice-9/eval-string.scm:
* module/language/rtl/spec.scm:
* module/system/base/target.scm:
* module/system/repl/command.scm:
* module/system/repl/common.scm:
* module/system/vm/debug.scm:
* module/system/vm/disassembler.scm:
* module/system/vm/objcode.scm:
* test-suite/tests/compiler.test:
* test-suite/tests/dwarf.test:
* test-suite/tests/rtl-compilation.test:
* test-suite/tests/rtl.test: Adapt.
2013-11-19 21:45:07 +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
095100bbdb Change SCM_PACK_RTL macros to SCM_PACK_OP / SCM_PACK_OP_ARG
* libguile/instructions.h: Guard in BUILDING_LIBGUILE.
  (SCM_PACK_OP_24):
  (SCM_PACK_OP_8_8_8):
  (SCM_PACK_OP_8_16):
  (SCM_PACK_OP_16_8):
  (SCM_PACK_OP_12_12): Rename from SCM_PACK_RTL_*, and splice in the
  opcode.
  (SCM_PACK_OP_ARG_8_24): New helper.

* libguile/vm.c:
* libguile/gsubr.c:
* libguile/foreign.c:
* libguile/control.c:
* libguile/continuations.c: Adapt.
2013-11-19 21:04:24 +01:00
Andy Wingo
3fe96dd808 scm_rtl_op_* -> scm_op_*
* libguile/instructions.h (scm_opcode): Rename from scm_rtl_opcode.
  Rename opcodes from scm_rtl_op_* to scm_op_*.

* libguile/continuations.c:
* libguile/control.c:
* libguile/foreign.c:
* libguile/gsubr.c:
* libguile/instructions.c:
* libguile/vm.c: Adapt.
2013-11-19 20:46:10 +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
8079714576 scm_i_rtl_program_* -> scm_i_program_*
* libguile/programs.h (scm_i_make_program):
* libguile/programs.c (scm_i_program_name):
  (scm_i_program_documentation):
  (scm_i_program_properties): Remove "rtl_" infix.

* libguile/objcodes.c:
* libguile/procprop.c:
* libguile/vm.c: Adapt callers.
2013-11-19 18:57:31 +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
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
9f309e2cd9 Builtins have procedure properties
* libguile/vm-builtins.h (FOR_EACH_VM_BUILTIN): Add arity information.
  (enum scm_vm_builtins):
* libguile/vm.c (scm_vm_builtin_ref):
  (scm_vm_builtin_name_to_index):
  (scm_vm_builtin_index_to_name): Adapt to macro interface change.
  (scm_init_vm_builtin_properties): New helper, sets procedure
  properties on builtins.
  (scm_bootstrap_vm): Just define the builtins here.  Later in the
  bootstrap we set their properties.
  (scm_sym_apply): Move definition here from expand.c.

* libguile/procprop.c (scm_init_procprop): Call
  scm_init_vm_builtin_properties.
2013-11-08 14:08:42 +01:00
Andy Wingo
03f16599e3 Fix call/cc with the RTL VM
* libguile/vm.c (vm_return_to_continuation): The RTL VM saves the
  registers for the caller of call/cc, but the caller will expect values
  in the normal MV return location: above the frame.  Make it so, number
  four!
2013-11-01 19:28:36 +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
d6fbf0c00e Fix toplevel-ref with named modules before boot in stack VM
* libguile/vm.c (resolve_variable): Fix, as in
  e23f9e4423.
2013-10-27 11:25:31 +01:00
Andy Wingo
73c3db6669 Better vm.c support for RTL programs
* libguile/vm.c (scm_c_vm_run): Directly dispatch to the RTL VM for RTL
  programs.
  (scm_bootstrap_vm): Initialize the RTL program stubs early, and mark
  the RTL boot program with the boot flag.
2013-10-17 23:20:32 +02:00
Andy Wingo
99511cd0ab Refactor vm_abort
* libguile/vm.c (vm_abort):
* libguile/vm-i-system.c (abort): Refactor abort interface so that it is
  more amenable to the RTL VM.
2013-10-14 17:32:16 +02:00
Andy Wingo
82f4bac420 RTL VM: receive-values has allow-extra? flag
* 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.
2013-10-14 16:09:43 +02:00
Mark H Weaver
adb8d905df RTL VM: Rename 'apply' instruction to 'tail-apply'.
* libguile/vm-engine.c (apply, tail-apply): apply -> tail-apply.
  (RETURN_VALUE_LIST): goto op_apply -> goto op_tail_apply.

* libguile/vm.c (rtl_apply_code): scm_rtl_op_apply ->
  scm_rtl_op_tail_apply.
2013-08-24 15:22:17 +02:00
Andy Wingo
af95414f1d Various RTL VM and calling convention tweaks
* 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.
2013-08-11 16:45:31 +02:00
Andy Wingo
7396d21670 RTL: Local 0 is the procedure
* 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.
2013-07-21 17:12:22 +02:00
Mark H Weaver
28d5d2537c Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/keywords.c
	libguile/vm.c
2013-07-16 01:33:27 -04:00
Ludovic Courtès
4af0d97ee6 Print the faulty object upon invalid-keyword errors.
* libguile/vm.c (vm_error_kwargs_invalid_keyword,
  vm_error_kwargs_unrecognized_keyword): Add parameter.  Pass it
  enclosed in a list as the last argument to `scm_error_scm'.
* libguile/vm-i-system.c (bind_kwargs): Adjust accordingly.
* libguile/eval.c (error_invalid_keyword, error_unrecognized_keyword):
  Add parameter.
  (prepare_boot_closure_env_for_apply): Adjust accordingly.
* module/ice-9/eval.scm (primitive-eval): Likewise.
* libguile/error.c (scm_error_scm): Mention `keyword-argument-error' in
  docstring.
* module/ice-9/boot-9.scm (keyword-error-printer): New procedure; use it.
* test-suite/tests/optargs.test (c&e, with-test-prefix/c&e): Remove.
  ("define*")["unrecognized keyword"]: Test the value passed along the
  `keyword-argument-error' exception.
  ["invalid keyword"]: New test.
* doc/ref/api-control.texi (Error Reporting): Update `scm-error'
  description.
2013-06-04 12:08:02 +02:00
Andy Wingo
510ca12687 add new rtl vm
* libguile/vm-engine.c (rtl_vm_engine): Add new VM.
  (vm_engine): Add support for calling RTL programs.

* libguile/tags.h (scm_tc7_rtl_program): New type for procedures that
  run on the new VM.
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (scm_class_of):
* libguile/print.c (iprin1):
* libguile/procprop.c (scm_i_procedure_arity):
* libguile/procs.c (scm_procedure_p): Add hooks for the new tc7.

* libguile/programs.h:
* libguile/programs.c (scm_make_rtl_program, scm_i_rtl_program_print)
  (scm_rtl_program_p, scm_rtl_program_code):
* module/system/vm/program.scm: Add constructors and accessors for the
  new "RTL programs".

* libguile/vm.c (rtl_boot_continuation): Define a boot program.
  (rtl_apply, rtl_values): New static RTL programs.

* libguile/frames.c (scm_frame_num_locals): Adapt for frames of RTL
  programs.

* libguile/frames.h: Add description of RTL frames.

* libguile/Makefile.am: Add rules to generate vm-operations.h.
* .gitignore: Ignore vm-operations.h.
* module/system/vm/instruction.scm:
* libguile/instructions.c:
* libguile/instructions.h: Use vm-operations.h to define enumerated
  values for the new RTL opcodes.  Define some helper macros to pack and
  unpack 32-bit instruction words.
  (rtl-instruction-list): New function, exported by (system vm
  instruction).

* libguile/objcodes.c: Wire up the bits needed to detect the new RTL
  bytecode and load it, as appropriate.
2013-05-31 09:48:16 -04:00