summaryrefslogtreecommitdiff
path: root/libguile/vm.c
AgeCommit message (Collapse)AuthorFilesLines
2014-01-26More precise stack marking via .guile.frame-maps sectionAndy Wingo1-4/+31
* module/language/cps/slot-allocation.scm (lookup-dead-slot-map) (allocate-slots): For each non-tail call in a function, compute the set of slots that are dead after the function has begun the call. * module/language/cps/compile-bytecode.scm (compile-fun): Emit the `dead-slot-map' macro instruction for non-tail calls. * module/system/vm/assembler.scm (<asm>): Add `dead-slot-maps' member. (dead-slot-map): New macro-instruction. (link-frame-maps, link-dynamic-section, link-objects): Write dead slots information into .guile.frame-maps sections of ELF files. * module/system/vm/elf.scm (DT_GUILE_FRAME_MAPS): New definition. * libguile/loader.h: * libguile/loader.c (DT_GUILE_FRAME_MAPS, process_dynamic_segment): (load_thunk_from_memory, register_elf): Arrange to parse DT_GUILE_FRAME_MAPS out of the dynamic section. (find_mapped_elf_image_unlocked, find_mapped_elf_image): New helpers. (scm_find_mapped_elf_image): Refactor. (scm_find_dead_slot_map_unlocked): New interface. * libguile/vm.c (scm_i_vm_mark_stack): Mark the hottest frame conservatively, as before. Otherwise use the dead slots map, if available, to avoid marking data that isn't live.
2013-11-28Remove private-gc.hAndy Wingo1-2/+1
* libguile/simpos.c (scm_getenv_int): Move here, from gc.c. * libguile/private-gc.h: Remove, unused. * libguile/simpos.h: Move scm_getenv_int declaration here. * libguile/vm.c: * libguile/gc.c: Adapt scm_getenv_int users. * libguile/gc-malloc.c: * libguile/load.c: * libguile/script.c: Remove private-gc includes from non-users of scm_getenv_int. * libguile/Makefile.am: Adapt.
2013-11-27Remove the restore-continuation-hook.Andy Wingo1-14/+0
* 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-22Expandable stacks.Andy Wingo1-28/+122
* 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-22More precise stack marking.Andy Wingo1-5/+13
* libguile/vm.c (scm_i_vm_mark_stack): Mark the stack more precisely.
2013-11-22Allocate stacks using mmap, and mark them via the thread markerAndy Wingo1-51/+51
* 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-21Setjmp before calling into the VMAndy Wingo1-2/+13
* 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-21scm_call_n sets up boot continuation frame for VMAndy Wingo1-3/+35
* 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-21scm_call_n avoids double TLS lookupAndy Wingo1-11/+21
* 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-21Remove scm_tc7_vmAndy Wingo1-30/+0
* 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-21Remove last use of SCM vmAndy Wingo1-5/+6
* 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-21scm_the_vm now returns raw struct scm_vm pointerAndy Wingo1-17/+11
* 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-21Prefer scm_call_n to scm_c_vm_run (scm_the_vm())Andy Wingo1-7/+10
* 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-21Engine takes struct scm_vm* as argumentAndy Wingo1-2/+3
* 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-21One more SCM vm user: continuations.Andy Wingo1-4/+2
* 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-21Remove last use of SCM vm in VMAndy Wingo1-4/+6
* 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-21Remove use of SCM vm in compose-continuationAndy Wingo1-4/+3
* libguile/vm.c (vm_reinstate_partial_continuation): Take struct scm_vm argument instead of SCM. * libguile/vm-engine.c (compose-continuation): Adapt.
2013-11-21Dispatch hooks use "vp" rather than "vm"Andy Wingo1-23/+19
* 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-21Heap frame "stack holders" are raw scm_vm / scm_vm_cont pointersAndy Wingo1-1/+1
* 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-21Heap frames have a "frame kind" bitAndy Wingo1-1/+1
* 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-21No more VM objects visible to SchemeAndy Wingo1-16/+3
* 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-21VM accessors take VM as implicit argument, not explicit argumentAndy Wingo1-87/+33
* 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-21Remove unused vm:ip, vm:sp, vm:fpAndy Wingo1-30/+0
* 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-21Remove make-vm; there will be one vm per thread now.Andy Wingo1-9/+0
* 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-21Scheme frame objects hold relative stack offsetsAndy Wingo1-3/+2
* 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-20Remove unused resolve_variable helperAndy Wingo1-35/+0
* libguile/vm.c (resolve_variable): Remove unused helper.
2013-11-19Rework hook dispatch mechanismAndy Wingo1-2/+38
* 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-19Remove VM_ENABLE_STACK_NULLINGAndy Wingo1-32/+0
* 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-19Rename objcodes?.{scm,c,h} to loader.{scm,c,h}Andy Wingo1-1/+1
* 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-19Lingering RTL excision in vm.cAndy Wingo1-12/+12
* 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-19Change SCM_PACK_RTL macros to SCM_PACK_OP / SCM_PACK_OP_ARGAndy Wingo1-15/+15
* 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-19scm_rtl_op_* -> scm_op_*Andy Wingo1-15/+15
* 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-19Internal RTL excision in vm.cAndy Wingo1-5/+5
* 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-19scm_i_rtl_program_* -> scm_i_program_*Andy Wingo1-2/+2
* 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-19All instruction pointers are now scm_t_uint32*Andy Wingo1-1/+1
* 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-17Frame pointer points to local 0 instead of local 1Andy Wingo1-1/+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-15Remove MVRA from VM framesAndy Wingo1-2/+2
* 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-15Remove MVRA accessors in libguileAndy Wingo1-16/+5
* 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-08Remove stack programs, objcode, and the old VM.Andy Wingo1-41/+1
* 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-08Builtins have procedure propertiesAndy Wingo1-17/+31
* 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-01Fix call/cc with the RTL VMAndy Wingo1-19/+19
* 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-10-27Resumable partial continuations in the RTL VMAndy Wingo1-0/+3
* 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-27VM has "builtins": primitives addressable by emitted RTL codeAndy Wingo1-11/+121
* 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-27Fix toplevel-ref with named modules before boot in stack VMAndy Wingo1-1/+11
* libguile/vm.c (resolve_variable): Fix, as in e23f9e4423bbbe8521d13e1c9a223612a5e86762.
2013-10-17Better vm.c support for RTL programsAndy Wingo1-5/+16
* 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-14Refactor vm_abortAndy Wingo1-14/+13
* 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-14RTL VM: receive-values has allow-extra? flagAndy Wingo1-0/+8
* 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-08-24RTL VM: Rename 'apply' instruction to 'tail-apply'.Mark H Weaver1-1/+1
* 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-11Various RTL VM and calling convention tweaksAndy Wingo1-8/+1
* 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-07-21RTL: Local 0 is the procedureAndy Wingo1-4/+4
* 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.