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

364 commits

Author SHA1 Message Date
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
Andy Wingo
e23f9e4423 RTL VM: Fix variable lookup before modules boot
* libguile/vm-engine.c (toplevel-box, module-box): Handle the case where
  the module system isn't booted yet.
2013-10-26 14:38:11 +02:00
Andy Wingo
8cff7f54dc RTL VM: Fix LOCAL_REF, LOCAL_SET for unsigned indices
* libguile/vm-engine.c (LOCAL_REF, LOCAL_SET): Fix so to work with
  unsigned 0.  Previously subtracting 1 was making the index wrap
  around.
2013-10-23 19:28:26 +02:00
Andy Wingo
d691ac2069 Continuations are RTL stubs
* 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.
2013-10-18 18:47:49 +02:00
Andy Wingo
9d87158fdb RTL engine can apply smobs and applicable structs w/o stack VM
* libguile/vm-engine.c (rtl_vm_engine): Allow the RTL VM to handle the
  dispatch for SMOBs and applicable structs.
2013-10-17 23:24:16 +02:00
Andy Wingo
8d23c43641 Fix subr-call
* libguile/vm-engine.c (subr-call): Fix for locals count including the
  procedure.
2013-10-17 23:21:29 +02:00
Andy Wingo
e93c0430fa Fix tail-apply bugs
* libguile/vm-engine.c (tail-apply): Fix for old change that made
  the procedure indexed 0 instead of -1.
2013-10-17 23:20:32 +02:00
Andy Wingo
234155e336 bind-rest works in the optional-and-rest-arg case.
* 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.
2013-10-17 23:20:26 +02:00
Andy Wingo
8d59d55e86 RTL: Compile prompts
* 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.
2013-10-14 16:13:57 +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
Andy Wingo
e063995db8 rtl vm: box-set! binds no values
* libguile/vm-engine.c (box-set!): Remove the OP_DST flag.
2013-08-24 15:40:29 +02:00
Mark H Weaver
84cc4127bd RTL: 'return-values' instruction assumes 'reset-frame' has been called.
* 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.
2013-08-24 15:27:50 +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
Mark H Weaver
e79ed6b1d7 RTL VM: fix multiple value returns.
* libguile/vm-engine.c (halt): Fix off-by-one error in retrieving
  multiple values from the frame.
2013-08-24 15:20:56 +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
Mark H Weaver
e7f64971ed RTL VM: Avoid untagging inums in 'logand' and 'logior'.
* libguile/vm-engine.c (logand, logior): Avoid untagging.
2013-08-06 17:03:56 -04:00
Mark H Weaver
d2295ba571 RTL VM: Avoid signed overflows in 'add1' and 'sub1'.
* 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.
2013-08-06 17:00:23 -04:00
Mark H Weaver
0bd659658b RTL VM: ash: Use SCM_SRS and fix large right shifts in fast path.
* libguile/vm-engine.c (ash): Use SCM_SRS, and handle large right
  shifts properly.
2013-08-06 16:51:41 -04:00
Andy Wingo
14d102920f add allocate-struct primitive and rtl opcode
* 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.
2013-07-21 17:12:22 +02:00
Andy Wingo
b21713128e abort is no longer an op with rest args
* libguile/vm-engine.c (abort): No longer an op with rest args.
2013-07-21 17:12:22 +02:00
Andy Wingo
286a0fb3ae call is no longer a vararg instruction
* 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.
2013-07-21 17:12:22 +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
Andy Wingo
98eaef1b50 Simplify dynstack API to only wind one fluid at a time
* 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.
2013-06-28 20:01:35 +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
Andy Wingo
a0ec1ca116 cpp hygiene in the vm
* libguile/vm-engine.c:
* libguile/vm-i-scheme.c:
* libguile/vm-i-system.c: CPP hygiene: the code that #defines, #undefs.
  Makes things cleaner given the multiple inclusion dance we do.
2013-05-27 07:14:26 +02:00
Andy Wingo
c850a0ff4d pop-continuation abort-continuation hooks pass return vals directly
* doc/ref/api-debug.texi (VM Hooks): Update documentation.

* libguile/vm.c (vm_dispatch_hook):
* libguile/vm-engine.c:  Rework the hook machinery so that they can
  receive an arbitrary number of arguments.  The return and abort
  hooks will pass the values that they return to their continuations.
  (vm_engine): Adapt to ABORT_CONTINUATION_HOOK change.

* libguile/vm-i-system.c (return, return/values): Adapt to
  POP_CONTINUATION_HOOK change.

* module/system/vm/frame.scm (frame-return-values): Remove.  The
  pop-continuation-hook will pass the values directly.

* module/system/vm/trace.scm (print-return):
  (trace-calls-to-procedure):
  (trace-calls-in-procedure): Update to receive return values
  directly.

* module/system/vm/traps.scm (trap-in-procedure)
  (trap-in-dynamic-extent): Ignore return values.
  (trap-frame-finish, trap-calls-in-dynamic-extent)
  (trap-calls-to-procedure): Pass return values to the handlers.
2013-05-27 07:13:13 +02:00
Andy Wingo
27319ffaa9 Allow vm_engine caller to pass arguments on the stack.
* libguile/vm-engine.c (vm_engine): Allow the caller to pass arguments
  on the stack.
2013-05-27 07:12:22 +02:00
Andy Wingo
8dd6bfa7bb vm-engine: remove register assignments
* libguile/vm-engine.c: Remove the register assignments inherited from
  the 1990s.  GCC does seem to allocate reasonably on systems with
  enough registers (e.g. x86-64), and on system with too few (ia32) we
  disabled manual allocation.  Anyway this code was never tested, so
  it's better to leave the compiler to do its own thing, until proven
  otherwise.  Also in the RTL VM we don't need to allocate a register to
  the SP, because it isn't accessed as much.
2013-05-27 07:06:39 +02:00
Andy Wingo
ff3968c22d remove some configurability in vm-engine
* libguile/vm-engine.c: Remove the ability for the VM to check object
  access, free variable access, and the ip.  They were off by default.
  Since they will be different in the RTL VM, their presence is just
  making things confusing.

* libguile/vm.c: Remove corresponding error helpers.
2013-05-23 14:42:25 +02:00
Andy Wingo
27c7c630a1 minor vm-engine cleanups
* libguile/vm-engine.c: Some very minor cleanups: indenting, use of
  VM_ASSERT, commenting.
2013-05-23 14:38:10 +02:00
Andy Wingo
52182d5280 remove CONS macro in VM; use scm_cons instead
* libguile/vm-engine.c (CONS): Remove.  Callers should use scm_cons
  instead, syncing registers beforehand.
  (POP_LIST): Adapt, only synchronizing once.
  (POP_LIST_MARK, POP_CONS_MARK): Remove unused macros.

* libguile/vm-i-scheme.c (cons):
* libguile/vm-i-system.c (push-rest, bind-rest): Adapt.
2013-05-23 14:27:17 +02:00
Andy Wingo
eac1202483 inline vm-engine.h into vm-engine.c
* libguile/vm-engine.h:
* libguile/vm-engine.c: Fold vm-engine.h into vm-engine.c.

* libguile/Makefile.am: Adapt.
2013-05-23 14:27:17 +02:00
Andy Wingo
968a9add65 Merge remote-tracking branch 'local-2.0/stable-2.0'
Conflicts:
	libguile/vm-engine.c
	libguile/vm-i-system.c
	libguile/vm.c
2012-05-10 13:02:11 +02:00
Andy Wingo
67b699cc77 refactor vm application of non-programs; boot continuation refactor
* libguile/frames.c (scm_frame_instruction_pointer):
* module/system/vm/frame.scm (frame-bindings):
  (frame-next-source, frame-call-representation): Fix a few locations
  that thought that the frame-procedure will always be a VM
  procedure.  This will not not be the case when traversing the stack of
  an application of a non-procedure.

* libguile/vm-i-system.c (call, tail-call, mv-call): Instead of
  special-casing structs and smobs at these call sites, just set up the
  stack, and jump to a generic apply loop if the proc is not a program.

* libguile/vm-engine.c: The generic apply loop is here.  Also, the boot
  program is now simply a boot continuation, and can handle any number
  of arguments.

* libguile/vm.c (make_boot_program): Update the code that makes the boot
  continuation.
2012-05-10 12:59:45 +02:00
Andy Wingo
4d497b629b Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/vm-engine.c
	libguile/vm-i-system.c
2012-04-30 21:34:58 +02:00
Andy Wingo
53bdfcf034 push error handlers out of line in the vm
* libguile/vm.c:
  (vm_error):
  (vm_error_bad_instruction):
  (vm_error_unbound):
  (vm_error_unbound_fluid):
  (vm_error_not_a_variable):
  (vm_error_not_a_thunk):
  (vm_error_apply_to_non_list):
  (vm_error_kwargs_length_not_even):
  (vm_error_kwargs_invalid_keyword):
  (vm_error_kwargs_unrecognized_keyword):
  (vm_error_too_many_args):
  (vm_error_wrong_num_args):
  (vm_error_wrong_type_apply):
  (vm_error_stack_overflow):
  (vm_error_stack_underflow):
  (vm_error_improper_list):
  (vm_error_not_a_pair):
  (vm_error_not_a_bytevector):
  (vm_error_not_a_struct):
  (vm_error_no_values):
  (vm_error_not_enough_values):
  (vm_error_continuation_not_rewindable):
  (vm_error_bad_wide_string_length):
  (vm_error_invalid_address):
  (vm_error_object):
  (vm_error_free_variable): New internal helpers, implementing VM error
  handling.

* libguile/vm-engine.h (VM_ASSERT): New helper macro.
  (ASSERT, CHECK_OBJECT, CHECK_FREE_VARIABLE):
  (PRE_CHECK_UNDERFLOW, PUSH_LIST): Use the new helper.

* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c:
* libguile/vm-i-system.c: Use VM_ASSERT and the out-of-line error
  handlers.

* libguile/vm-engine.c (vm_engine): Remove inline error handlers, and
  remove a couple of local vars.  Use VM_ASSERT.  Have halt handle the
  return itself.
2012-04-30 21:29:11 +02:00
Andy Wingo
9d381ba478 dynstack: pushing a prompt no longer allocates memory
* libguile/control.h: Remove scm_t_prompt_registers and
  scm_c_make_prompt_registers.
  (scm_c_abort): Take a pointer to a jmpbuf instead of a cookie.  It
  will serve the same purpose.
* libguile/control.c (reify_partial_continuation, scm_at_abort): Adapt
  to new prompt representation.

* libguile/dynstack.h:
* libguile/dynstack.c (scm_dynstack_push_prompt): Prompts now have 5
  words instead of 2, as they now push the fp, sp, ip, and jmpbuf on the
  stack separately.  This avoids allocation.
  (scm_dynstack_find_prompt): Likewise, add return values for fp, sp,
  etc.
  (scm_dynstack_wind_prompt): Replaces scm_dynstack_relocate_prompt.

* libguile/eval.c (eval):
* libguile/stacks.c (find_prompt):
* libguile/throw.c (pre_init_catch): Adapt to the new prompt mechanism.

* libguile/vm-engine.c (vm_engine): Setjmp an on-stack jmpbuf every time
  the VM enters.  We can then re-use that jmpbuf for all prompts in that
  invocation.

* libguile/vm-i-system.c (partial_cont_call): Adapt to change in prompt
  representation.  We don't need to wind here any more, since we pass in
  the prompt's jmpbuf.
  (prompt): Adapt to scm_dynstack_push_prompt change.
  (abort): Adapt to vm_abort change.

* libguile/vm.h (struct scm_vm): No more cookie.

* libguile/vm.c (vm_abort): Adapt to scm_c_abort change.
  (vm_reinstate_partial_continuation): Rewind the dynamic stack here,
  now that we do have a valid jmpbuf.
  (make_vm): No need to initialize a cookie.
2012-03-07 10:27:16 +01:00