summaryrefslogtreecommitdiff
path: root/libguile/vm.c
AgeCommit message (Collapse)AuthorFilesLines
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.
2013-07-16Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-6/+6
Conflicts: libguile/keywords.c libguile/vm.c
2013-06-04Print the faulty object upon invalid-keyword errors.Ludovic Courtès1-6/+6
* 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-05-31add new rtl vmAndy Wingo1-0/+32
* 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-27refactor to resolve_variableAndy Wingo1-16/+13
* libguile/vm.c (resolve_variable): Slight refactor.
2013-05-27pop-continuation abort-continuation hooks pass return vals directlyAndy Wingo1-4/+27
* 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-23remove some configurability in vm-engineAndy Wingo1-32/+0
* 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-03-28Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-2/+16
Conflicts: configure.ac libguile/deprecated.c libguile/deprecated.h libguile/filesys.h libguile/fluids.c libguile/fports.c libguile/gc.c libguile/guile.c libguile/numbers.c libguile/objcodes.c libguile/r6rs-ports.c libguile/smob.c libguile/socket.c libguile/threads.h module/language/scheme/decompile-tree-il.scm module/language/tree-il/peval.scm test-suite/tests/syncase.test
2013-03-07add GUILE_STACK_SIZE environment variableStefan Israelsson Tampe1-2/+16
* libguile/vm.c (initialize_default_stack_size): New helper. (scm_bootstrap_vm): Call initialize_default_stack_size. * doc/ref/guile-invoke.texi (Environment Variables): Add docs. Based on a patch by Stefan Israelsson Tampe.
2012-06-22instead of our custom .go format, use elfAndy Wingo1-4/+3
* libguile/objcodes.c: Change to expect objcode on disk to be embedded in ELF instead of having the funky cookie. (to_native_order): Use already existing SCM_BYTE_ORDER style byte order instead of chars. (bytecode_to_objcode): No need for word_size arg. (scm_bytecode_to_objcode, scm_objcode_to_bytecode): Take optional endianness arg instead of sometimes using target-endianness. (scm_load_objcode, scm_write_objcode, scm_bytecode_to_native_objcode): Remove. * libguile/objcodes.h: Adapt. * libguile/vm.c (scm_load_compiled_with_vm): Use scm_load_thunk_from_file. (make_boot_program): Adapt to use scm_bytecode_to_objcode with endianness arg. * module/Makefile.am (OBJCODE_LANG_SOURCES): Add (language objcode elf). * module/language/objcode/elf.scm: New module, embeds objcode in ELF. * module/language/bytecode/spec.scm (compile-objcode): (decompile-objcode): Use (target-endianness). * module/language/objcode/spec.scm: use (language objcode elf) for write-objcode. * module/scripts/disassemble.scm (disassemble): * module/system/repl/command.scm (disassemble-file): Use load-thunk-from-file. * module/system/vm/objcode.scm: Remove load-objcode and write-objcode. * test-suite/tests/asm-to-bytecode.test (test-target): Adapt to the new ELF world.
2012-05-23Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-9/+2
This commit removes code that was newly deprecated in stable-2.0. Conflicts: libguile/deprecated.c libguile/deprecated.h libguile/modules.c module/ice-9/boot-9.scm module/ice-9/deprecated.scm
2012-05-23deprecate scm_sym2varAndy Wingo1-9/+2
* libguile/deprecated.h: * libguile/deprecated.c (scm_sym2var): Deprecate this function. * libguile/modules.h: * libguile/modules.c (scm_module_ensure_local_variable): New public function, replacing scm_sym2var with a true definep, without going through eval closures (which are deprecated). (scm_current_module): Rework to do something sensible before modules are booted. (scm_module_lookup, scm_lookup): Refactor to use scm_module_variable. (scm_module_define, scm_define): Refactor to use scm_module_ensure_local_variable. * libguile/vm-i-system.c (define!): Use scm_define. * libguile/vm.c (resolve_variable): Use scm_module_lookup. * libguile/macros.c (scm_make_syntax_transformer): Use scm_module_variable. * libguile/gdbint.c (gdb_binding): Use scm_define. * doc/ref/api-modules.texi (Accessing Modules from C): Add docs for scm_module_ensure_local_variable.
2012-05-21Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-2/+1
Conflicts: module/language/tree-il/analyze.scm module/language/tree-il/effects.scm module/language/tree-il/fix-letrec.scm module/language/tree-il/peval.scm test-suite/tests/cse.test test-suite/tests/peval.test
2012-05-21vm.c: remove a useless checkAndy Wingo1-2/+1
* libguile/vm.c: Remove a check for modules being booted. If the module passed in is true, that is guaranteed to have been the case. Passes a fresh bootstrap.
2012-05-10Merge remote-tracking branch 'local-2.0/stable-2.0'Andy Wingo1-65/+30
Conflicts: libguile/vm-engine.c libguile/vm-i-system.c libguile/vm.c
2012-05-10refactor vm application of non-programs; boot continuation refactorAndy Wingo1-65/+30
* 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-04-30Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-0/+219
Conflicts: libguile/vm-engine.c libguile/vm-i-system.c
2012-04-30push error handlers out of line in the vmAndy Wingo1-0/+227
* 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-03-18make applicable smob calls cheaper, and fix a memory leakAndy Wingo1-0/+19
* libguile/vm.c (prepare_smob_call): New helper. Now, instead of making a per-smob trampoline, we will shuffle the smob into the args and use a gsubr. This prevents a memory leak in which the trampolines, which were values in a weak-key table, were preventing the smobs from being collected. * libguile/vm-i-system.c (call, tail-call, mv-call): Adapt to new smob application mechanism. (smob-call): Remove this instruction. * libguile/smob.h (scm_smob_descriptor): Rename apply_trampoline_objcode to apply_trampoline. * libguile/smob.c: Remove our own objcode trampolines in favor of using scm_c_make_gsubr. (scm_smob_prehistory): No more trampoline weak map. * libguile/procprop.c (scm_i_procedure_arity): Adapt to applicable smob representation change.
2012-03-18make applicable smob calls cheaper, and fix a memory leakAndy Wingo1-0/+18
* libguile/vm.c (prepare_smob_call): New helper. Now, instead of making a per-smob trampoline, we will shuffle the smob into the args and use a gsubr. This prevents a memory leak in which the trampolines, which were values in a weak-key table, were preventing the smobs from being collected. * libguile/vm-i-system.c (call, tail-call, mv-call): Adapt to new smob application mechanism. (smob-call): Remove this instruction. * libguile/smob.h (scm_smob_descriptor): Rename apply_trampoline_objcode to apply_trampoline. * libguile/smob.c: Remove our own objcode trampolines in favor of using scm_c_make_gsubr. (scm_smob_prehistory): No more trampoline weak map. * libguile/procprop.c (scm_i_procedure_arity): Adapt to applicable smob representation change.
2012-03-07dynstack: pushing a prompt no longer allocates memoryAndy Wingo1-17/+27
* 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-03the dynamic stack is really a stack now, instead of a listAndy Wingo1-31/+29
* libguile/dynstack.h: * libguile/dynstack.c: New files, implementing the dynamic stack as a true stack instead of a linked list. This lowers the cost of dynwinds: frames, winders, prompts, with-fluids, and dynamic-wind. For the most part, we allocate these items directly on the stack. * libguile/dynwinds.h: * libguile/dynwinds.c: Adapt all manipulators of the wind stack to use interfaces from dynstack.c. Remove heap-allocated winder and frame object types. (scm_dowinds, scm_i_dowinds): Remove these. The first was exported, but it was not a public interface. * libguile/continuations.c: * libguile/continuations.h (scm_t_contregs): Continuation objects reference scm_t_dynstack* values now. Adapt to the new interfaces. * libguile/control.c: * libguile/control.h: There is no longer a scm_tc7_prompt kind of object that can be allocated on the heap. Instead, the prompt flags, key, and registers are pushed on the dynwind stack. (The registers are still on the heap.) Also, since the vm_cont will reference the dynwinds, make the partial continuation stub take just one extra arg, instead of storing the intwinds separately in the object table. * libguile/fluids.c: * libguile/fluids.h: No more with-fluids objects; instead, the fluids go on the dynstack. The values still have to be on the heap, though. (scm_prepare_fluids, scm_swap_fluids): New internal functions, replacing scm_i_make_with_fluids and scm_i_swap_with_fluids. * libguile/print.c: Remove prompt and with-fluids printers. * libguile/tags.h: Revert prompt and with-fluids tc7 values to what they were before they were allocated. * libguile/vm-i-system.c (partial_cont_call): Just pop the vmcont, the intwinds will not be passed as a second arg. Rewind the dynamic stack from within the VM, so that any rewinder sees valid prompt entries. (call_cc, tail_call_cc): Adapt to pass the dynstack to scm_i_vm_capture_stack. (prompt, wind, unwind, wind_fluids, unwind_fluids): Adapt to the new interfaces. * libguile/vm.h (scm_i_capture_current_stack): Rename from scm_i_vm_capture_continuation. (scm_i_vm_capture_stack): Take a dynstack as an argument. * libguile/vm.c (vm_reinstate_partial_continuation): Don't wind here, as that could result in winders seeing invalid prompts. * libguile/eval.c: * libguile/root.c: * libguile/stacks.c: * libguile/threads.c: * libguile/threads.h: * libguile/throw.c: Adapt other users of dynwinds to use the dynstack.
2012-01-30Merge commit '3d51e57cfb0404db568a6adfde2a346d3fd9907e'Andy Wingo1-2/+3
Conflicts: libguile/foreign.c libguile/hashtab.c module/ice-9/psyntax-pp.scm module/language/tree-il/compile-glil.scm
2012-01-22Parenthesize and type `SCM_FRAME' macros; check layout of `scm_vm_frame'.Ludovic Courtès1-2/+3
* libguile/frames.c: Add compile-time assertions on the layout of `struct scm_vm_frame'. (RELOC): Parenthesize and type VAL. * libguile/frames.h (SCM_FRAME_STRUCT): Write in terms of `SCM_FRAME_DATA_ADDRESS'. (SCM_FRAME_DATA_ADDRESS): Parenthesize and type FP. (SCM_FRAME_SET_DYNAMIC_LINK): Write in terms of `SCM_FRAME_DYNAMIC_LINK'. * libguile/vm.c (RELOC): Parenthesize and type SCM_P.
2011-12-01Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-1/+1
Conflicts: configure.ac libguile/fluids.c libguile/gc.c libguile/gc.h libguile/objcodes.c libguile/procprop.c libguile/vm.c module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm
2011-11-22Complete cross-compilation support.Ludovic Courtès1-1/+1
* module/system/base/target.scm (%target-endianness, %target-word-size): New fluids. (%native-word-size): New variable. (with-target): Set these fluids. (cpu-endianness, cpu-word-size, triplet-cpu, triplet-vendor, triplet-os): New procedures. (target-cpu, target-vendor, target-os): Use them. (target-endianness, target-word-size): Refer to the corresponding fluid. * libguile/objcodes.c (target_endianness_var, target_word_size_var): New global variables. (NATIVE_ENDIANNESS): New macro. (target_endianness, target_word_size, to_native_order): New functions. (make_objcode_from_file): Use `scm_bytecode_to_native_objcode' instead of `scm_bytecode_to_objcode'. (bytecode_to_objcode): New function, based on `scm_bytecode_to_objcode', with the addition of an `endianness' and `word_size' parameters. (scm_bytecode_to_objcode): Use it. (scm_bytecode_to_native_objcode): New function. (scm_write_objcode): Use `target_word_size' and `target_endianness'. Convert OBJCODE's len and meta-len to native byte order. (scm_init_objcodes): Initialize `target_endianness_var' and `target_word_size_var'. * libguile/objcodes.h (scm_bytecode_to_native_objcode): New declaration. * libguile/vm.c (really_make_boot_program): Use `scm_bytecode_to_native_objcode' instead of `scm_bytecode_to_objcode'. * test-suite/tests/asm-to-bytecode.test (%objcode-cookie-size): New variable. (test-target): New procedure. ("cross-compilation"): Add `test-target' calls and the "unknown target" test.
2011-11-08locking for putc, putsAndy Wingo1-7/+7
* libguile/ports.c (scm_putc, scm_puts): * libguile/ports.h (scm_putc_unlocked, scm_puts_unlocked): Separate into _unlocked and locked variants. Change all callers to use the _unlocked versions.
2011-10-24add SCM_{PACK,UNPACK}_POINTERAndy Wingo1-3/+3
* libguile/tags.h (SCM_UNPACK_POINTER, SCM_PACK_POINTER): New macros. The old SCM2PTR and PTR2SCM were defined in such a way that round-tripping through a pointer could lose precision, even in the case in which you weren't interested in actually dereferencing the pointer, it was simply that you needed to plumb a SCM through APIs that take pointers. These new macros are more like SCM_PACK and SCM_UNPACK, but for pointer types. The bit representation of the pointer should be the same as the scm_t_bits representation. * libguile/gc.h (PTR2SCM, SCM2PTR): Remove support for (old) UNICOS pointers. We are going to try tagging the SCM object itself in the future, and I don't think that keeping this support is worth its cost. It probably doesn't work anyway. * libguile/backtrace.c: * libguile/bytevectors.c: * libguile/continuations.c: * libguile/fluids.c: * libguile/foreign.c: * libguile/gc.h: * libguile/guardians.c: * libguile/hashtab.c: * libguile/load.c: * libguile/numbers.c: * libguile/ports.c: * libguile/smob.c: * libguile/strings.c: * libguile/symbols.c: * libguile/vm.c: * libguile/weak-set.c: * libguile/weak-table.c: * libguile/weak-vector.c: Update many sites to use the new macros.
2011-08-31Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-4/+5
Conflicts: libguile/bytevectors.c libguile/bytevectors.h libguile/objcodes.c libguile/r6rs-ports.c libguile/strings.c libguile/vm.c
2011-08-18fix a couple of leaksAndy Wingo1-3/+4
* libguile/bytevectors.h: * libguile/bytevectors.c (scm_c_take_gc_bytevector): Rename this internal function, from scm_c_take_bytevector. This indicates that unlike the other scm_take_* functions, this one takes GC-managed memory. * libguile/objcodes.c (scm_objcode_to_bytecode): * libguile/vm.c (really_make_boot_program): Use scm_gc_malloc_pointerless, not scm_malloc. Thanks to Stefan Israelsson Tampe! * libguile/r6rs-ports.c: * libguile/strings.c: Adapt to renames.
2011-05-13merge strictness branch from 2.0Andy Wingo1-2/+2
2011-05-13vm_make_boot_program initializer fixAndy Wingo1-2/+2
* libguile/vm.c (vm_make_boot_program): Use #f as the "I don't have a program" value.
2011-05-07bytevectors have internal parent fieldAndy Wingo1-1/+2
* libguile/bytevectors.h (SCM_BYTEVECTOR_HEADER_SIZE): Bump, giving bytevectors another word: a parent pointer. Will allow for sub-bytevectors and efficient mmap bindings. * libguile/bytevectors.c (make_bytevector): (make_bytevector_from_buffer): Init parent to #f. (scm_c_take_bytevector, scm_c_take_typed_bytevector): Another argument, the parent, which gets set in the bytevector. * libguile/foreign.c (scm_pointer_to_bytevector): Use the parent field instead of registering a weak reference from bytevector to foreign pointer. * libguile/objcodes.c (scm_objcode_to_bytecode): Use the parent field to avoid copying the objcode. * libguile/srfi-4.c (DEFINE_SRFI_4_C_FUNCS): * libguile/strings.c (scm_from_stringn): * libguile/vm.c (really_make_boot_program): * libguile/r6rs-ports.c (scm_get_bytevector_some) (scm_get_bytevector_all, bytevector_output_port_procedure): Set the parent to #f.
2011-01-07use scm_from_latin1_symboln for string literals and load-symbolAndy Wingo1-6/+6
* libguile/bytevectors.c: * libguile/eval.c: * libguile/goops.c: * libguile/i18n.c: * libguile/load.c: * libguile/memoize.c: * libguile/modules.c: * libguile/ports.c: * libguile/print.c: * libguile/procs.c: * libguile/programs.c: * libguile/read.c: * libguile/script.c: * libguile/srfi-14.c: * libguile/stacks.c: * libguile/strings.c: * libguile/throw.c: * libguile/vm.c: Use scm_from_latin1_symboln to make symbols from string literals, because they aren't in the user's locale -- they are in ASCII, and we can optimize this case. * libguile/vm-i-loader.c: Also use scm_from_latin1_symboln when loading narrow symbols.
2010-11-19fix a number of assumptions that a pointer could fit into a longAndy Wingo1-3/+3
* libguile/debug.c: * libguile/eval.c: * libguile/frames.c: * libguile/objcodes.c: * libguile/print.c: * libguile/programs.c: * libguile/read.c: * libguile/struct.c: * libguile/vm.c: Fix a number of instances in which we assumed we could fit a pointer into a long.
2010-10-13Optimize `1+' and `1-' on fixnums.Ludovic Courtès1-0/+1
* libguile/vm-i-scheme.c (INUM_MAX, INUM_MIN): New macros. (add1, sub1): Add/subtract without untagging the operand. This leads to a 44% run time improvement compared to the previous implementation. * libguile/vm.c: Include <stdint.h>. * test-suite/tests/numbers.test ("1+", "1-"): Add tests for MOST-POSITIVE-FIXNUM, resp. MOST-NEGATIVE-FIXNUM, for 32-bit and 34-bit values thereof. * benchmark-suite/benchmarks/arithmetic.bm: New file. * benchmark-suite/Makefile.am (SCM_BENCHMARKS): Add it.
2010-10-01c stack overflow checked for, once moreAndy Wingo1-0/+1
* libguile/stackchk.h: Include private-options.h if we are building guile. * libguile/vm.c (scm_c_vm_run): Check for C stack overflow before entering the engine.
2010-09-28default to regular vm for noninteractive useAndy Wingo1-13/+1
* libguile/script.c (scm_compile_shell_switches): Select the debugging VM in the cases that we previously would select deval -- when running interactively without --no-debug, or otherwise with --debug. * libguile/vm.c: Default to the regular engine. (scm_c_set_vm_engine_x): Remove requirement for the VM to have no pending computations.
2010-09-27add call-with-vm; remove thread-vm bits; remove vm-apply; engines settable.Andy Wingo1-78/+177
* libguile/vm.h (scm_c_vm_run): Make internal. * libguile/vm.c (vm_default_engine): New static global variable. (make_vm): Set vp->engine based on (scm_vm_apply): Remove in favor of call-with-vm. (scm_thread_vm, scm_set_thread_vm_x): Remove these, as they did not have a well-defined meaning, and were dangerous to call on other threads. (scm_the_vm): Reinstate previous definition. (symbol_to_vm_engine, vm_engine_to_symbol) (vm_has_pending_computation): New helpers. (scm_vm_engine, scm_set_vm_engine_x, scm_c_set_vm_engine_x): New accessors for VM engines. (scm_c_set_default_vm_engine_x, scm_set_default_vm_engine_x): New setters for the default VM engine. (scm_call_with_vm): New function, applies a procedure to arguments in a context in which a given VM is current. * libguile/eval.c (eval, scm_apply): VM dispatch goes through scm_call_with_vm. * test-suite/tests/control.test ("the-vm"): * module/system/vm/coverage.scm (with-code-coverage): Use call-with-vm. * module/system/vm/vm.scm: Update exports. * test-suite/vm/run-vm-tests.scm (run-vm-program): * test-suite/tests/compiler.test ("current-reader"): Just rely on the result of make-program being an applicable. * test-suite/tests/eval.test ("stack overflow"): Add a note that this test does not test what it should.
2010-09-27Fix argument passing in VM hooks.Ludovic Courtès1-4/+9
* libguile/vm.c (vm_dispatch_hook): Take care of FRAME's alignment explicitly so that it's correct even if the current stack frame isn't 8-byte aligned (as can be the case on i686--the SysV i386 ABI just says that the stack is word-aligned.)
2010-09-25remove vm-version, vm optionsAndy Wingo1-32/+0
* libguile/vm.h (struct scm_vm): Remove "options" member. * libguile/vm.c (scm_vm_version, scm_vm_option, scm_set_vm_option_x): Remove. * module/system/vm/vm.scm (vm-version, vm-option, set-vm-option!): Remove. (vms:time, vms:clock): Remove these unused definitions. (vm-load): Remove. "Load" should be reserved for things that exist on disk, methinks.
2010-09-24Add `thread-vm' and `set-thread-vm!'.Ludovic Courtès1-7/+42
* libguile/vm.c (thread_vm, scm_thread_vm, scm_set_thread_vm_x): New functions. (scm_the_vm): Add docstring. Use `thread_vm'. * libguile/vm.h (scm_thread_vm, scm_set_thread_vm_x): New declarations. * module/system/vm/vm.scm: Export `thread-vm' and `set-thread-vm!'.
2010-09-17vm hooks run without hooksAndy Wingo1-2/+4
* libguile/vm.c (vm_dispatch_hook): Run hooks with the trace-level set to 0. We really don't want hooks running while hooks are running.
2010-09-16add vm-abort-continuation-hook, vm-restore-continuation-hookAndy Wingo1-0/+18
* libguile/vm-i-system.c (call_cc, tail_call_cc): Call the new RESTORE_CONTINUATION_HOOK when a continuation is restored. (prompt): Call the new ABORT_CONTINUATION_HOOK when entering the abort handler's continuation. * libguile/vm-engine.h (ABORT_CONTINUATION_HOOK) (RESTORE_CONTINUATION_HOOK): * libguile/vm.h (SCM_VM_ABORT_CONTINUATION_HOOK) (SCM_VM_RESTORE_CONTINUATION_HOOK): * libguile/vm.c: (scm_vm_abort_continuation_hook): New hook, called when entering an abort handler. (scm_vm_restore_continuation_hook): New hook, called after returning to a continuation. * module/system/vm/vm.scm: Add hooks to export list.
2010-09-16trim our set of vm hooksAndy Wingo1-48/+12
* libguile/vm.h (SCM_VM_PUSH_CONTINUATION_HOOK) (SCM_VM_POP_CONTINUATION_HOOK): New hooks, to replace enter/exit/return. (SCM_VM_BOOT_HOOK, SCM_VM_HALT_HOOK, SCM_VM_BREAK_HOOK): Remove these useless hooks. * libguile/vm.c (scm_vm_push_continuation_hook) (scm_vm_pop_continuation_hook): New accessors. * libguile/vm-i-system.c: Remove boot, halt, break, enter, exit, and return hooks. Also remove the break instruction. Instead now when we push a new continuation onto the stack we call PUSH_CONTINUATION_HOOK, and when we pop via a return we call POP_CONTINUATION_HOOK. APPLY_HOOK is now decoupled from continuation pushes and pops. * libguile/vm-engine.h: * libguile/vm-engine.c: Adapt for hooks. * module/system/vm/trace.scm (vm-trace): Adapt for hooks. Also revive the #:instructions? #t mode. * module/system/vm/vm.scm: Adapt exports for new set of hooks.
2010-06-01Fix unaligned accesses by the bytevector instructions.Ludovic Courtès1-0/+1
* libguile/vm-i-scheme.c (ALIGNED_P): New macro. (BV_FIXABLE_INT_REF, BV_INT_REF, BV_FLOAT_REF, BV_FIXABLE_INT_SET, BV_INT_SET, BV_FLOAT_SET): Check the alignment of the pointer instead of checking "i % size == 0". This fixes bus errors on `sparc64-linux-gnu'. * libguile/vm.c: Include <alignof.h>.
2010-05-28Add `scm_t_aligned_cell' internal type.Ludovic Courtès1-5/+1
* libguile/_scm.h (struct scm_aligned_cell)[__GNUC__]: New type. (union scm_aligned_cell)[!__GNUC__]: New type. (scm_t_aligned_cell): New type. * libguile/vm.c (vm_dispatch_hook): Use it.
2010-05-26Raise an exception upon VM stack overflows (fixes bug #29574).Ludovic Courtès1-3/+6
* libguile/vm-engine.c (VM_NAME)[vm_error_stack_overflow]: Increase `vp->stack_limit' when possible. * libguile/vm.c (VM_STACK_RESERVE_SIZE): New macro. * test-suite/lib.scm (exception:vm-error): New variable. * test-suite/tests/eval.test ("stack overflow"): New test prefix.