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

349 commits

Author SHA1 Message Date
Andy Wingo
a20feea43e Continuations capture machine code address
* libguile/continuations.c (scm_i_continuation_to_frame): Adapt to vra
  field renaming.
  (scm_i_reinstate_continuation, grow_stack, copy_stack_and_call)
  (scm_dynthrow): Take mra of continuation.  Set on the vp before the
  longjmp.
* libguile/continuations.h: Update scm_i_reinstate_continuation
  prototype.
* libguile/dynstack.h:
* libguile/control.c (scm_suspendable_continuation_p):
* libguile/dynstack.c (PROMPT_WORDS, PROMPT_VRA, PROMPT_MRA):
  (PROMPT_JMPBUF, scm_dynstack_push_prompt, scm_dynstack_find_prompt)
  (scm_dynstack_wind_prompt): Store both virtual and machine return
  addresses on the dynstack, for prompts.
* libguile/eval.c (eval): Pass NULL for mra.
* libguile/intrinsics.c (push_prompt): Add mra arg, and pass it to the
  dynstack.
* libguile/intrinsics.h: Update prototypes so that continuation-related
  intrinsics can save and restore the MRA.
* libguile/jit.h:
* libguile/jit.c: Return VRA when JIT code needs to tier down.
* libguile/stacks.c (find_prompt, scm_make_stack)
* libguile/throw.c (catch): Adapt find-prompt calls.
* libguile/vm-engine.c (instrument-entry, instrument-loop): Add logic to
  continue with vcode after the mcode finishes.
  (compose-continuation, capture-continuation, abort, prompt): Add logic
  to pass NULL as captured MRA, but continue with mcode from new
  continuations, if appropriate.
* libguile/vm.c (scm_i_vm_cont_to_frame, capture_stack)
  (scm_i_capture_current_stack, reinstate_continuation_x)
  (capture_continuation, compose_continuation_inner, compose_continuation)
  (capture_delimited_continuation, abort_to_prompt): Adapt to plumb
  around machine code continuations.
  (scm_call_n): Check "mra_after_abort" field for machine code
  continuation, if any.
* libguile/vm.h (struct scm_vm): Add "mra_after_abort" field.
  (struct scm_vm_cont): Rename "ra" field to "vra" and add "mra" field.
2018-08-12 15:57:53 +02:00
Andy Wingo
939b1ae23f Rework foreign-call trampoline
* libguile/foreign.c (scm_i_foreign_call): Rename back from
  foreign_call.  Need a new trampoline that's easier to call from JIT,
  until we actually rewrite the FFI in terms of the JIT.
  (scm_register_foreign): Remove foreign_call intrinsic init.
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Foreign-call
  intrinsic sets return directly on stack.
* libguile/vm-engine.c (foreign-call): Adapt to new intrinsic behavior.
* libguile/vm.c (foreign_call, scm_bootstrap_vm): Add new intrinsic
  wrapper.
2018-08-11 14:25:07 +02:00
Andy Wingo
6027027724 Invoke VM hooks through intrinsics
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Make intrinsics for
  the VM hooks.
* libguile/vm-engine.c (RUN_HOOK): Run hooks through the intrinsics
  table.
* libguile/vm.c (invoke_apply_hook, invoke_return_hook):
  (invoke_next_hook, invoke_abort_hook): Rename, remove NOINLINE
  attribute (as we call them through the intrinsics table).
  (scm_bootstrap_vm): Init new intrinsics.
2018-08-11 11:37:03 +02:00
Andy Wingo
ef4c1a5f55 Add unpack-values-object intrinsic
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add
  unpack-values-object.
* libguile/vm-engine.c (subr-call): If the object is a values object,
  call out to unpack-values-object.  This is to avoid reifying
  allocate-frame code in each jitted subr.
* libguile/vm.c (unpack_values_object, scm_bootstrap_vm): Define new
  intrinsic.
2018-08-11 11:36:58 +02:00
Andy Wingo
c3ff72cb81 Change call/cc inst to capture-continuation
* libguile/jit.c (compile_capture_continuation): Rename from call_cc now
  that the call is elsewhere.
* libguile/vm-engine.c (call, tail-call): Remove needless SYNC_IP before
  get-callee-vcode; the intrinsic can sync the ip if needed from the
  frame.
  (capture-continuation): Rename from call/cc, and leave the call itself
  to tail-call.
* libguile/vm.c (vm_builtin_call_with_current_continuation_code): Update
  to put the continuation in a local and then tail call.
  (get_callee_vcode): Sync vp->ip if we error.
2018-08-08 16:32:18 +02:00
Andy Wingo
926b72f5ac Rework program->ip mapping in VM to always call intrinsic
* libguile/intrinsics.h:
* libguile/vm.c (get_callee_vcode): Rename from apply_non_program, and
  instead return the IP for the callee of a frame.
  (scm_call_n, scm_bootstrap_vm): Adapt to get_callee_vcode change.
* libguile/vm-engine.c (call, tail-call, call/cc): Use
  get_callee_vcode unconditionally.  JIT will do this to avoid so much
  code generation for calls.
2018-08-08 15:22:28 +02:00
Andy Wingo
b7dbc7251f Minor optimization in RESET_FRAME
* libguile/vm-engine.c (RESET_FRAME): Remove update of sp_min_since_gc.
2018-08-08 14:48:32 +02:00
Andy Wingo
41100f7786 Merge branch 'master' into lightning
This includes a manual cherry-pick of relevant stable-2.2 commits up to
4c91de3e45.
2018-08-07 12:43:25 +02:00
Ludovic Courtès
8840ee5a3c vm: Fix stack-marking bug in multi-threaded programs.
Fixes <https://bugs.gnu.org/28211>.

* libguile/vm-engine.c (call, call_label, handle_interrupts): Add
'new_fp' variable; set the dynamic link and return address of the frame
at NEW_FP before setting 'vp->fp'.  This fixes a bug whereby, in a
multi-threaded context, the stack-marking code could run after vp->fp
has been set but before its dynamic link has been set, leading the
stack-walking code in 'scm_i_vm_mark_stack' to exit early on.
2018-08-07 12:31:11 +02:00
Andy Wingo
0a01963d07 VM hooks take no values
* libguile/vm-engine.c (RUN_HOOK0, RUN_HOOK1): Remove.
  (RUN_HOOK): Take hook name.
  (APPLY_HOOK, RETURN_HOOK, NEXT_HOOK, ABORT_CONTINUATION_HOOK): Use
  RUN_HOOK.
* libguile/vm.c (vm_dispatch_hook): Remove value count arg; hooks no
  longer receive values (e.g. the return hook now uses
  frame-return-values).
  (vm_dispatch_abort_hook): Remove value count, which was bogus because
  the active frame was the continuation which might contain other
  locals, potentially unboxed, not the implicit return-values frame.  In
  the future we could push on an implicit return-values frame instead.
* module/system/vm/traps.scm (trap-in-procedure, trap-frame-finish):
  (trap-in-dynamic-extent, trap-calls-to-procedure): Adapt abort hooks
  to not take values.  They weren't being used anyway!
2018-08-07 11:05:56 +02:00
Andy Wingo
f4c50447dd Remove push continuation hook; return hook runs before FP pop
* libguile/frames.c (scm_frame_return_values): New function, for use
  when a frame is at "return-values".
  (scm_init_frames_builtins): Register frame-return-values.
* libguile/vm-engine.c (RETURN_HOOK): Rename from POP_CONTINUATION_HOOK.
  (call, call-label): Remove PUSH_CONTINUATION_HOOK; it's unneeded, as
  you can always check the FP from an apply hook.
  (return-values): Run return hook before popping frame.
* libguile/vm.c (vm_dispatch_return_hook): Rename from
  vm_dispatch_pop_continuation_hook.  Remove push continuation hook.
  (scm_vm_return_hook):
* libguile/vm.h (SCM_VM_PUSH_CONTINUATION_HOOK): Remove.
  (SCM_VM_RETURN_HOOK): Rename from SCM_VM_POP_CONTINUATION_HOOK.
* module/system/vm/frame.scm (frame-return-values): Export.
* module/system/vm/trace.scm (print-return, trace-calls-to-procedure)
  (trace-calls-in-procedure): Adapt to not receiving values as
  arguments.
* module/system/vm/traps.scm (trap-in-procedure, trap-frame-finish):
  Adapt to return hook coming from returning frame.
  (program-sources-by-line): Update to use match instead of pmatch.
* module/system/vm/traps.scm (trap-in-dynamic-extent)
  (trap-calls-to-procedure): Adapt to return hook not receiving values.
* module/system/vm/vm.scm: Remove push continuation hook and rename
  return hook.
2018-08-06 17:00:45 +02:00
Andy Wingo
dedf73d370 Consolidate apply hook to instrument-entry instruction
* libguile/vm.c (scm_call_n):
* libguile/vm-engine.c: Move apply hook to "instrument-entry"
  instruction.
2018-08-06 15:07:26 +02:00
Andy Wingo
b8a9a666f1 Rewrite subr implementation
* libguile/gsubr.c: Reimplement to store subr names and procedures in a
  side table, and to allocate fresh vcode for each subr.  This allows
  JIT of subrs, moves to a uniform all-code-starts-with-instrument-entry
  regime, and also allows statprof to distinguish between subrs based on
  IP.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_NAME): Call out to functions,
  now that these are in a side table.
  (scm_subr_function, scm_subr_name): New exports.
  (scm_i_primitive_name): New internal function, for looking up a
  primitive name based on IP.
  (scm_apply_subr): Take the subr index.
* libguile/vm-engine.c (subr-call):
* libguile/jit.c (compile_subr_call): Adapt to take index as arg.
* module/statprof.scm (sample-stack-procs, count-call):
  (stack-samples->procedure-data): Update to always record IP in stack
  samples and call counts.
* module/system/vm/frame.scm (frame-procedure-name): Simplify.
  (frame-instruction-pointer-or-primitive-procedure-name): Removed.
* libguile/programs.h:
* libguile/programs.c (scm_primitive_code_name): New function.
* module/system/vm/program.scm (primitive-code-name): New export.
2018-07-29 15:47:07 +02:00
Andy Wingo
a6b5049aa8 Emit instrument-loop in loops.
* am/bootstrap.am (SOURCES):
* module/Makefile.am (SOURCES): Handle renamve of handle-interrupts.scm
  to loop-instrumentation.scm.
* libguile/jit.h (SCM_JIT_COUNTER_ENTRY_INCREMENT): Rename from
  SCM_JIT_COUNTER_CALL_INCREMENT.
* libguile/vm-engine.c (instrument-entry): Rename from instrument-call.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  handle-interrupts code before calls and returns.  Compile the
  "instrument-loop" primcall to an "instrument-loop" instruction and a
  "handle-interrupts" instruction.
  (lower-cps): Adapt to add-loop-instrumentation name change.
* module/language/cps/loop-instrumentation.scm: Rename from
  handle-interrupts.scm and just add "instrument-loop" primcalls in
  loops.  The compiler will add handle-interrupts primcalls as
  appropriate.
* module/system/vm/assembler.scm (<jit-data>): New data type, for
  emitting embedded JIT data.
  (<meta>): Add field for current JIT data.
  (make-meta): Initialize current JIT data.
  (emit-instrument-entry*, emit-instrument-loop*): New instruction
  emitters that reference the current JIT data.
  (end-program): Now that all labels are known, arrange to serialize the
  JIT data.
  (link-data): Reserve space for JIT data, and add relocs to initialize
  the "start" / "end" fields.
2018-07-29 15:47:07 +02:00
Andy Wingo
87da1c8d20 Add instrument-call, instrument-loop VM instructions
* libguile/jit.h (struct scm_jit_function_data)
  (enum scm_jit_counter_value): New data types.
* libguile/jit.c (scm_jit_compute_mcode, scm_jit_enter_mcode): New
  function stubs.  Adapt label/offset compilers to take pointers.
* libguile/vm-engine.c (instrument-call, instrument-loop): New
  instructions.
* libguile/vm.c: Add jit.h include.
* module/system/vm/assembler.scm (emit-instrument-call)
  (emit-instrument-loop): New exports.
2018-07-29 15:47:03 +02:00
Andy Wingo
950a762dc2 Multiple-value returns now start from slot 0, not slot 1
This should reduce frame sizes.

* libguile/vm-engine.c (halt): Adapt to multiple-values change.  Also
  adapt to not having the boot closure on the stack.
  (receive, receive-values, subr-call, foreign-call): Adapt to expect
  values one slot down.
  (prompt): Capture one less word for the values return.
* libguile/vm.c (vm_dispatch_pop_continuation_hook):
  (vm_dispatch_abort_hook): Adapt for where to expect values.
  (vm_builtin_values_code): Add a call to shuffle-down before
  returning.  This is more overhead than what existed before, but the
  hope is that the savings elsewhere pay off.
  (vm_builtin_values_code): Adapt to different values location.
  (reinstate_continuation_x, compose_continuation): Adapt to place
  resume args at right position.
  (capture_delimited_continuation): Remove unused sp and ip arguments.
  (abort_to_prompt): Adapt to capture_delimited_continuation change.
  (scm_call_n): Adapt to not reserve space for the boot closure.
* module/language/cps/compile-bytecode.scm (compile-function): When
  returning values, adapt reset-frame call for return calling convention
  change.  Adapt truncating or rest returns to expect values in the
  right place.
* module/language/cps/slot-allocation.scm (compute-shuffles):
  (allocate-lazy-vars, allocate-slots): Allocate values from the "proc
  slot", not proc-slot + 1.
* module/system/vm/assembler.scm (emit-init-constants): Reset the frame
  before returning so that the return value is in the right place.
* test-suite/tests/rtl.test: Update for return convention change.
* libguile/foreign.c (get_foreign_stub_code): Update for return calling
  convention change.
2018-07-20 11:42:30 +02:00
Andy Wingo
9b70129504 Fix stale stack frame clearing for frame size change
* libguile/vm-engine.c (return-values): Clear all 3 stack slots.  Not
  sure this is necessary though!
2018-07-20 11:42:30 +02:00
Andy Wingo
c2a8224a63 Rework VM approach to shuffling unknown numbers of args
* libguile/vm-engine.c (shuffle-down, expand-apply-argument): New
  instructions.
  (tail-call, tail-call-label, return-values): Don't reset the frame.
  The compiler should reset the frame appropriately.
  (tail-call/shuffle, tail-apply): Remove unused instructions.
* libguile/vm.c (vm_builtin_apply_code): Use new shuffle-down and
  expand-apply-argument opcodes.
  (vm_builtin_call_with_values_code): Replace tail-call/shuffle with
  shuffle-down then tail-call.
* libguile/jit.c (compile_shuffle_down, compile_expand_apply_argument):
  Add compiler stubs
  (COMPILE_X8_F12_F12): New definition.
  (compile_tail_call_shuffle, compile_tail_apply): Remove unused
  compilers.
* module/language/cps/compile-bytecode.scm (compile-function): Emit
  reset-frame before tail calls and returns.
* module/system/vm/assembler.scm (system): Remove unbound "emit-return"
  export.
* module/system/vm/disassembler.scm (code-annotation)
  (instruction-has-fallthrough?, define-stack-effect-parser): Adapt for
  opcode changes.
2018-07-20 11:42:30 +02:00
Andy Wingo
043432fd57 Reserve frame word for machine return address
* libguile/frames.h: Add machine return address to diagram.
  (SCM_FRAME_MACHINE_RETURN_ADDRESS):
  (SCM_FRAME_SET_MACHINE_RETURN_ADDRESS): New macros.
  (SCM_FRAME_PREVIOUS_SP):
  (SCM_FRAME_DYNAMIC_LINK):
  (SCM_FRAME_SET_DYNAMIC_LINK): Adapt for new frame size.
* libguile/vm-engine.c (halt): Set frame size to 3.
  (call, call-label): Set mRA to 0.
* libguile/vm.c (push_interrupt_frame, reinstate_continuation_x):
  (scm_call_n): Set frame size to 3.  In push_interrupt_frame, init the
  mRA of the frame.
  (vm_builtin_call_with_values_code, vm_handle_interrupt_code): Allocate
  larger frames.
* module/language/cps/slot-allocation.scm (allocate-slots): Frame size
  is 3.
* module/system/vm/disassembler.scm (define-clobber-parser): Bump frame
  size.
2018-07-20 11:42:30 +02:00
Andy Wingo
b1705bd0f0 Prepare for frames having separate virtual and machine return addrs
* libguile/frames.c (scm_frame_return_address): Use
  SCM_FRAME_VIRTUAL_RETURN_ADDRESS.
  (scm_c_frame_previous): Likewise.
* libguile/frames.h: Update diagram for new names.
  (union scm_vm_stack_element): Rename "as_ip" to "as_vcode", and
  add "as_mcode" for machine code pointers.
  (SCM_FRAME_VIRTUAL_RETURN_ADDRESS)
  (SCM_FRAME_SET_VIRTUAL_RETURN_ADDRESS): Rename to these, from
  SCM_FRAME_RETURN_ADDRESS and SCM_FRAME_SET_RETURN_ADDRESS.
* libguile/vm-engine.c (halt, call, call-label, return-values)
  (return-from-interrupt): Adapt to renamings.  Make "halt" have frame
  size as a parameter.
* libguile/vm.c (scm_i_vm_mark_stack): Adapt to renaming.
  (push_interrupt_frame): Take mRA as additional argument.  In future we
  will set it as frame mRA.
  (capture_continuation): Adapt to renaming.
  (scm_call_n): Adapt to renaming and make frame size adjustable.
  (push_interrupt_frame, reinstate_continuation_x): Make frame size
  adjustable.
* module/language/cps/slot-allocation.scm (allocate-slots): Make frame
  size adjustable.
* libguile/intrinsics.h (scm_t_thread_mra_intrinsic): New type; use for
  push_interrupt_frame.
  (scm_t_thread_u8_scm_sp_vra_intrinsic): Rename from the same but was
  "ra" instead of "vra", and change type to uint32_t*.
* module/system/vm/disassembler.scm (define-clobber-parser):
  Parameterize clobber set for calls by frame size.
2018-07-20 11:42:30 +02:00
Andy Wingo
9fc5282ca5 Merge 'master' into 'lightning' 2018-07-20 11:41:54 +02:00
Andy Wingo
e6461cf1b2 Fix errors introduced when giving multiple-values objects a tc7
* libguile/values.c (scm_c_value_ref): Fix a case in which a request for
  the 0th value of a zero-valued object would return the object instead
  of erroring.
* libguile/vm-engine.c (halt): Fix construction of a multiple-valued
  return (off-by-one error).  Fixes a crash introduced in
  4a2d78b4d4.
2018-07-16 12:16:58 +02:00
Andy Wingo
a433620c38 Fix bad opcode in VM
* libguile/vm-engine.c (VM_NAME): Fix accidentally reused number 180.
  Both values were invalid opcodes though.
2018-07-03 13:30:32 +02:00
Andy Wingo
d6b8f6a658 Minor change to VM DSL
* libguile/instructions.c (DOP1, DOP2, DOP3, DOP4, DOP5): New parts of
  the DSL, equivalent to e.g. OP1(x) | OP_DST.  Will allow other
  definitions of OP* that use token pasting.
* libguile/vm-engine.c: Adapt to use new DOP descriptors.
2018-07-03 11:13:27 +02:00
Andy Wingo
b5dcdf2e25 Revert "Refactor hook dispatch in VM"
This reverts commit 593e2db1dd.  The goto
strategy works for hooks that run just before a "next"; it doesn't work
for ones that run at the beginning of opcodes.
2018-06-27 20:19:40 +02:00
Andy Wingo
593e2db1dd Refactor hook dispatch in VM
* libguile/vm-engine.c (GOTO_HOOK, HOOK_HANDLER): Split hooks that don't
  take args into a "goto" side and a "target" side.  The idea is to just
  reify the hook call at one place in the binary, since the VM
  continuation is fully in the registers.
  (APPLY_HOOK, PUSH_CONTINUATION_HOOK, NEXT_HOOK)
  (ABORT_CONTINUATION_HOOK): Reimplement in terms of goto hooks.
  (POP_CONTINUATION_HOOK): This one is still old-style.
  (CONTINUE): New helper definition.
  (call, call-label): Move the push-continuation hooks up a bit, so it's
  clear they don't depend on intermediate opcode state.
  (vm_engine): Reify hook handlers for apply, etc.
2018-06-27 19:56:55 +02:00
Andy Wingo
2a8d72f7e0 Microoptimizations to hook dispatch
* libguile/vm.c (vm_dispatch_hook): Add a check that we're in the debug
  engine and the trace level is positive.  Allows us to do cheaper
  checks for when to dispatch hooks.
  (scm_call_n): Just check if trace level is nonzero.
* libguile/vm-engine.c (RUN_HOOK): Likewise just check if trace level is
  nonzero.
2018-06-27 19:26:03 +02:00
Andy Wingo
19cff78bb5 Minor optimizations to debug hook dispatch
* libguile/vm.c (scm_call_n): Only call hooks if the engine supports
  it.
  (vm_dispatch_abort_hook, vm_dispatch_next_hook)
  (vm_dispatch_pop_continuation_hook, vm_dispatch_push_continuation_hook)
  (vm_dispatch_apply_hook, vm_dispatch_hook): Take a thread as arg
  instead of VM, because that will probably already be in a register in
  the VM.  Given that all values are taken relative to the SP, no
  need to pass that either.
* libguile/vm-engine.c (RUN_HOOK0, RUN_HOOK1): Update appropriately.
2018-06-27 19:16:38 +02:00
Andy Wingo
9c8c4060dd Remove "resume" arg from vm engine
* libguile/vm-engine.c (vm_engine): Remove "resume" argument; scm_call_n
  will handle the differences.
* libguile/vm.c (scm_call_n): Inline handling of what to do in normal
  and resume cases.  Remove resume argument to vm_engine.
2018-06-27 18:57:37 +02:00
Andy Wingo
64d114817a Intrinsics take registers from thread
* libguile/continuations.c (scm_i_make_continuation): Remove registers
  argument; instead get from thread.
* libguile/vm-engine.c (vm_engine): Adapt VM engine to not receive a
  registers argument, and thus to not pass it to intrinsics either.
* libguile/intrinsics.h:
* libguile/intrinsics.c (push_prompt):
* libguile/vm.c (capture_continuation, compose_continuation)
  (abort_to_prompt): Refactor these intrinsics to not take a registers
  argument; it's not necessary.
  (scm_call_n): Don't pass registers argument.
2018-06-27 18:42:21 +02:00
Andy Wingo
fd4eb14751 Use CALL_INTRINSICS helper in VM
* libguile/vm-engine.c (CALL_INTRINSIC): New helper macro.
  (ALLOC_FRAME, vm_engine): Use CALL_INTRINSIC when we need to call
  intrinsics.  GCC still doesn't allocate intrinsics to a register
  though!
2018-06-27 18:07:49 +02:00
Andy Wingo
7e11c992f3 bind-rest inst uses cons-rest intrinsic
* libguile/vm-engine.c (bind-rest): Use cons-rest intrinsic to build the
  rest list.
2018-06-27 17:40:46 +02:00
Andy Wingo
294e627c6b Intrinsic for "prompt"
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (push_prompt, scm_bootstrap_intrinsics): New
  intrinsic.
* libguile/vm-engine.c (prompt): Use push-prompt intrinsic.
2018-06-27 15:29:49 +02:00
Andy Wingo
85ab5f0299 Remove dedicated current-module instruction.
* libguile/vm-engine.c (current-module): Remove instruction.
2018-06-27 15:06:40 +02:00
Andy Wingo
0faa4144d1 allocate-words intrinsic
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (allocate_words, scm_bootstrap_intrinsics): New
  intrinsic.
* libguile/vm-engine.c (allocate-words, allocate-words/immediate): Use
  new intrinsic.
2018-06-27 14:56:39 +02:00
Andy Wingo
7883290d88 Inline handling of non-program apply
* libguile/vm.c (vm_apply_non_program_code): Remove, now unneeded.
* libguile/vm-engine.c (vm_engine, call, tail-call, tail-call/shuffle)
  (tail-apply, call/cc): Inline handling of non-programs, as will be the
  case with JIT code.
2018-06-27 13:54:45 +02:00
Andy Wingo
1735cc1fec Apply-non-program is an intrinsic
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add
  apply-non-program intrinsic.
* libguile/vm-engine.c (apply-non-program): Replace impl with call to
  intrinsic.
* libguile/vm.c (vm_error_wrong_type_apply): Inline into
  apply_non_program intrinsic.
  (apply_non_program): New intrinsic.
  (scm_bootstrap_vm): Wire it up.
2018-06-27 13:38:30 +02:00
Andy Wingo
6eb4735149 Add intrinsics for error conditions (wrong num args etc)
* libguile/intrinsics.c (error_wrong_num_args, error_no_values)
  (error_not_enough_values, error_wrong_number_of_values): New
  intrinsics.
* libguile/intrinsics.h: Add new intrinsics.
* libguile/vm-engine.c: Signal errors using the new intrinsics.
* libguile/vm.c (vm_error): Remove, now that it's unused.
  (vm_error_bad_instruction): Abort instead of throwing an exception.
  If we get a bad instruction, nothing good will ever happen!
  (compose_continuation): Use wrong-type-arg for unrewindable
  continuations.
  (scm_bootstrap_vm): No need to make "vm-run" or "vm-error" symbols.
2018-06-27 09:47:31 +02:00
Andy Wingo
0ce9a1f870 VM throw uses intrinsics
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add intrinsics for
  throw, throw/value, and throw/value+data.
* libguile/intrinsics.c (throw_, throw_with_value):
  (throw_with_value_and_data): And here they are.
* libguile/vm-engine.c (throw, throw/value, throw/value+data): Use
  intrinsics.
* libguile/vm.c: Remove vm_throw et al.
2018-06-26 20:45:26 +02:00
Andy Wingo
51e71a473f Allow abort_to_prompt to avoid a longjmp
* libguile/vm-engine.c (abort):
* libguile/vm.c (abort_to_prompt): Allow fallthrough if longjmp isn't
  needed.
2018-06-26 17:16:19 +02:00
Andy Wingo
e7778c62aa abort-to-prompt uses an intrinsic
* libguile/control.h:
* libguile/control.c (scm_i_make_composable_continuation): Rename from
  make_partial_continuation and expose internally.
  (scm_abort_to_prompt_star): Adapt to scm_i_vm_abort name change.
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Define
  abort_to_prompt intrinsic.
* libguile/throw.c (abort_to_prompt): Adapt to scm_i_vm_abort name
  change.
* libguile/vm-engine.c (abort): Use abort_to_prompt intrinsic.
* libguile/vm.c (capture_delimited_continuation): Move here from
  control.c where it was named reify_partial_continuation.
  (scm_i_vm_abort): Move from control.c where it was named
  scm_c_abort (and only exposed internally).
  (abort_to_prompt): New intrinsic, replacing vm_abort.
* libguile/vm.h: Add setjmp include and scm_i_vm_abort decl.
2018-06-26 16:23:02 +02:00
Andy Wingo
03a9b71479 Add rest-arg-length intrinsic.
* libguile/intrinsics.h:
* libguile/vm.c (rest_arg_length): New intrinsic.
  (vm_error_apply_to_non_list): Remove now-unused error proc.
* libguile/vm-engine.c (tail-apply): Use new intrinsic.
2018-06-26 15:34:40 +02:00
Andy Wingo
b4553dbb02 compose-continuation uses an intrinsic
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add
  compose-continuation intrinsic.
* libguile/vm-engine.c (compose-continuation): Call compose-continuation
  intrinsic.
* libguile/vm.c (compose_continuation_inner, compose_continuation): Move
  down and rename from vm_reinstate_partial_continuation, and make into
  a form that works as an intrinsic.
2018-06-26 15:10:58 +02:00
Andy Wingo
ba23bc12fd Add intrinsic for call/cc
* libguile/intrinsics.h: Add "capture-continuation" intrinsic.
* libguile/vm-engine.c (call/cc): Rework to use capture_continuation
  intrinsic.
* libguile/vm.c (capture_continuation): New intrinsic.
2018-06-26 12:01:01 +02:00
Andy Wingo
5804c977d7 Rename scm_i_thread to scm_thread
* libguile/scm.h (struct scm_thread, scm_thread): Rename from
  scm_i_thread.
* libguile/deprecated.h (scm_i_thread): Add deprecated typedef.
* libguile/threads.h: Adapt to renaming.
* libguile/intrinsics.h:
* libguile/scmsigs.h:
* libguile/cache-internal.h: Remove threads.h includes; unnecessary with
  the forward decl.
* libguile/continuations.h:
* libguile/gc-inline.h:
* libguile/async.h: Adapt scm_thread type name change.
* libguile/async.c:
* libguile/continuations.c:
* libguile/control.c:
* libguile/dynstack.c:
* libguile/dynwind.c:
* libguile/eval.c:
* libguile/finalizers.c:
* libguile/fluids.c:
* libguile/gc.c:
* libguile/intrinsics.c:
* libguile/load.c:
* libguile/memoize.c:
* libguile/print.c:
* libguile/read.c:
* libguile/scmsigs.c:
* libguile/script.c:
* libguile/stackchk.c:
* libguile/stacks.c:
* libguile/symbols.c:
* libguile/threads.c:
* libguile/throw.c:
* libguile/vm-engine.c:
* libguile/vm.c: Adapt to type name change, and add additional includes
  as needed.
2018-06-26 11:40:22 +02:00
Andy Wingo
51e35158ba Refactor continuation capture in VM
* libguile/continuations.h:
* libguile/continuations.c (scm_i_make_continuation): Refactor to expect
  registers to already be captured.
* libguile/scm.h (scm_i_thread): Add forward decl.
* libguile/threads.h (struct scm_i_thread): Just fill in the struct
  type.
* libguile/vm-engine.c (call/cc); Use the registers already captured
  before entering the VM.
2018-06-26 11:25:07 +02:00
Andy Wingo
185d19dfb1 Foreign-call intrinsic boxes errno
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/foreign.c (foreign_call):
* libguile/vm-engine.c (foreign-call): Change foreign-call intrinsic to
  handle boxing of errno.
2018-06-26 11:09:40 +02:00
Andy Wingo
5e8e816c61 Reinstating undelimited continuations uses intrinsic
* libguile/continuations.h (scm_t_contregs): Remove "struct vm*" member;
  unneeded.
* libguile/continuations.c (scm_i_make_continuation): No need to store
  continuation->vp.
  (scm_i_contregs): New internal function, replaces scm_i_contregs_vp
  and scm_i_contregs_vm_cont.
  (scm_i_check_continuation): Remove; moved to vm.c.
  (scm_i_reinstate_continuation): Add an abort(), to satisfy
  SCM_NORETURN.
* libguile/intrinsics.h: Add new "reinstate-continuation!" intrinsic.
* libguile/vm-engine.c (continuation-call): Use new
  reinstate-continuation! intrinsic.
* libguile/vm.c (vm_return_to_continuation_inner): Move later in the
  file.
  (reinstate_continuation_x): New intrinsic.
  (scm_bootstrap_vm): Init new intrinsic.
2018-06-26 11:09:36 +02:00
Andy Wingo
5448e5a4b0 Add intrinsic for foreign-call
* libguile/Makefile.am (noinst_HEADERS, modinclude_HEADERS): Change to
  not install intrinsics.h.
* libguile/intrinsics.h: Add an error if BUILDING_LIBGUILE isn't set, to
  catch any stray bad inclusions.  Add intrinsic for foreign-call.
* libguile/foreign.c (foreign_call): Rename from scm_i_foreign_call, and
  set as the foreign-call intrinsic.
* libguile/vm-engine.c (foreign-call): Use the intrinsic.  In the future
  we'll want to totally revamp the FFI, if we know that a JIT is
  available!
2018-06-26 09:22:07 +02:00
Andy Wingo
4a2d78b4d4 Give multiple-values objects a tc7
* libguile/scm.h (scm_tc7_values): New tc7.  Never seen by Scheme, so we
  don't need to update it anywhere else.
* libguile/values.h (scm_is_values): New public static inline function.
  (scm_i_nvalues, scm_i_value_ref): New private static inline
  functions.
  (SCM_VALUESP): Use scm_is_value.
  (scm_values_2, scm_values_3): New functions.
  (scm_values_vtable): Remove; values objects are not structs any more.
* libguile/values.c (scm_i_extract_values_2): Adapt to new values
  representation.
  (print_values): Remove now-unused function.
  (scm_c_nvalues): Use scm_i_nvalues.
  (scm_c_value_ref): Use scm_i_value_ref.
  (scm_values, scm_c_values): Make the new-style objects, which store
  their values inline.
  (scm_values_2, scm_values_3): New helpers, to avoid consing little
  useless lists.
* libguile/vm-engine.c (halt, subr-call)
* libguile/eval.c (eval): Adapt to new values representation.
* libguile/i18n.c (scm_locale_string_to_integer)
  (scm_locale_string_to_integer)
* libguile/numbers.c (scm_i_floor_divide, scm_i_ceiling_divide)
  (scm_i_truncate_divide, scm_i_centered_divide, scm_i_round_divide)
  (scm_i_exact_integer_sqrt)
* libguile/r6rs-ports.c (make_bytevector_output_port)
* libguile/srfi-1.c (scm_srfi1_partition, scm_srfi1_partition_x)
* libguile/srfi-14.c (scm_char_set_diff_plus_intersection)
  (scm_char_set_diff_plus_intersection_x)
* libguile/posix.c (scm_getrlimit, scm_open_process): Adapt to use
  scm_values_2 or scm_values_3.
* libguile/print.c (iprin1): Add printer for values objects.
2018-06-25 17:50:29 +02:00