summaryrefslogtreecommitdiff
path: root/libguile/vm-i-system.c
AgeCommit message (Collapse)AuthorFilesLines
2010-09-16add vm-abort-continuation-hook, vm-restore-continuation-hookAndy Wingo1-4/+19
* 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-16/+4
* 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-07-28Use "pointer" instead of "foreign" when dealing with wrapped pointers.Ludovic Courtès1-3/+4
* libguile/foreign.h (scm_t_foreign_finalizer): Rename to... (scm_t_pointer_finalizer): ... this. (SCM_FOREIGN_P): Rename to... (SCM_POINTER_P): this. (SCM_VALIDATE_FOREIGN): Rename to... (SCM_VALIDATE_POINTER): ... this. (SCM_FOREIGN_HAS_FINALIZER): Rename to... (SCM_POINTER_HAS_FINALIZER): ... this. (scm_take_foreign_pointer): Rename to... (scm_from_pointer): ... this. (scm_foreign_address): Rename to... (scm_pointer_address): ... this. (scm_foreign_to_bytevector): Rename to... (scm_pointer_to_bytevector): ... this. (scm_foreign_set_finalizer_x): Rename to... (scm_set_pointer_finalizer_x): ... this. (scm_bytevector_to_foreign): Rename to... (scm_bytevector_to_pointer): ... this. (scm_i_foreign_print): Rename to... (scm_i_pointer_print): ... this. * libguile/foreign.c: Update accordingly. * libguile/tags.h (scm_tc7_foreign): Rename to... (scm_tc7_pointer): ... this. * libguile/foreign.c, libguile/deprecated.c, libguile/dynl.c, libguile/evalext.c, libguile/gc.c, libguile/goops.c, libguile/gsubr.c, libguile/gsubr.h, libguile/print.c, libguile/snarf.h, libguile/vm-i-system.c, module/system/foreign.scm, test-suite/standalone/test-ffi, test-suite/tests/foreign.test: Update accordingly.
2010-07-26Simplify the (system foreign) API.Ludovic Courtès1-1/+1
Suggested by Neil Jerram. * libguile/foreign.h (SCM_FOREIGN_TYPE, SCM_FOREIGN_VALUE_REF, SCM_FOREIGN_VALUE_SET, SCM_FOREIGN_LEN, SCM_FOREIGN_TYPED_P, SCM_FOREIGN_VALUE_P, SCM_VALIDATE_FOREIGN_VALUE, scm_foreign_set_x, scm_foreign_type): Remove. (scm_foreign_ref): Rename to... (scm_foreign_address): ... this. (scm_take_foreign_pointer): Update. (SCM_FOREIGN_POINTER): Remove CTYPE argument. Update callers. (scm_make_pointer): New declaration. * libguile/foreign.c (scm_to_uintptr, scm_from_uintptr): New macros. (scm_make_pointer): New function. (scm_take_foreign_pointer): Remove TYPE and LEN arguments. Update callers. (scm_foreign_ref): Remove to... (scm_foreign_address): ... this. Remove type-related code. (scm_foreign_set_x): Remove. (scm_foreign_to_bytevector): Change argument order; make LEN argument compulsory. (scm_i_foreign_print): Remove type printing. (unpack): Remove foreign-type checking. * libguile/deprecated.c (scm_dynamic_args_call): Update accordingly. * libguile/dynl.c (scm_dynamic_pointer): Remove the TYPE and LEN arguments; update callers. Update to the new foreign API. * libguile/dynl.h (scm_dynamic_pointer): Update. * libguile/gsubr.c (create_gsubr): Update to the new foreign API. * libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Ditto. * libguile/snarf.h (SCM_IMMUTABLE_FOREIGN): Ditto. * libguile/vm-i-system.c (subr_call): Ditto. * module/system/foreign.scm (null-pointer?): New procedure. * test-suite/standalone/test-ffi: Update to the new `bytevector->foreign' signature. * test-suite/tests/foreign.test ("null pointer")["null pointer identity", "null-pointer? %null-pointer"]: New tests. ["foreign-set! other-null-pointer", "foreign->bytevector other-null-pointer"]: Remove. ("make-pointer", "foreign<->bytevector"): New test prefixes.
2010-07-26Import unbound variable reports in the VM.Ludovic Courtès1-3/+6
* libguile/vm-engine.c (VM_NAME)[vm_error_unbound]: Add comment. * libguile/vm-i-system.c (variable_ref): Attempt provide the name of X in FINISH_ARGS.
2010-07-17SCM_I_FLUID_P -> SCM_FLUID_PAndy Wingo1-2/+2
* libguile/fluids.h (SCM_FLUID_P): Change from SCM_I_FLUID_P. (SCM_I_FLUID_NUM, SCM_I_DYNAMIC_STATE_P, SCM_I_DYNAMIC_STATE_FLUIDS): Wrap in BUILDING_LIBGUILE ifdef.
2010-07-15better error reporting from the vmAndy Wingo1-4/+10
* libguile/vm-engine.c: Add func_name local, for error reporting. (vm_error_apply_to_non_list): New error case. (vm_error_wrong_type_arg): Remove this generic error case. (vm_error_wrong_type_apply): Remove FUNC_NAME -- no sense in seeing "vm-debug-engine" in the error report. (vm_error_not_a_pair, vm_error_not_a_bytevector) (vm_error_not_a_struct, vm_error_not_a_thunk): Use func_name instead of FUNC_NAME, so we can indicate what caused the error. * libguile/vm-i-scheme.c (VM_VALIDATE_CONS, car, cdr, set-car!) (set-cdr!): Indicate provenance of errors. (VM_VALIDATE_STRUCT, struct-vtable): (VM_VALIDATE_BYTEVECTOR, BV_FIXABLE_INT_REF, BV_INT_REF) (BV_FLOAT_REF, BV_FIXABLE_INT_SET, BV_INT_SET, BV_FLOAT_SET): Same. * libguile/vm-i-system.c (apply, tail-apply): Use vm_error_apply_to_non_list.
2010-05-02add assert-nargs-ee/locals instructionAndy Wingo1-0/+20
* libguile/vm-i-system.c (assert-nargs-ee/locals): New instruction, a combination of assert-nargs-ee and reserve-locals in the case in which nreq and nlocs can both be represented in 8 bits. * module/language/glil/compile-assembly.scm (glil->assembly): Add compiler case. * doc/ref/vm.texi (Function Prologue Instructions): Update docs.
2010-03-30nil is null, wheeAndy Wingo1-2/+2
* libguile/pairs.h (scm_is_null): Nil is also null. * libguile/vm-i-scheme.c (not, not-not, null?, not-null?): * libguile/vm-i-system.c (br-if-null, br-if-not-null): Remove some more nil special cases.
2010-03-30nil is false, wheeAndy Wingo1-2/+2
* libguile/boolean.h (scm_is_false): Recognize nil as false, by default. (scm_is_bool): Recognize nil as a boolean. * libguile/boolean.c (scm_not, scm_boolean, scm_to_bool, scm_is_bool): Adapt to treat nil as false. * libguile/vm-i-system.c (br-if, br-if-not): Just use scm_is_false instead of specifically mentioning nil.
2010-03-16more vm gc fixenAndy Wingo1-0/+2
* libguile/vm-i-system.c (continuation_call): Sync before calling a continuation. Shouldn't much matter, but it seems like a good idea. (wind-fluids): More importantly, sync before allocating a with-fluids object.
2010-02-26rewinding prompts worksAndy Wingo1-4/+16
* libguile/control.h (SCM_PROMPT_HANDLER): Remove, it was unused. (SCM_PROMPT_DYNWINDS): Rename from SCM_PROMPT_DYNENV. * libguile/control.c: (scm_c_make_prompt): Take another arg, the winds that are to be in place for the prompt. Fix allocation to be 4 words instead of 5 (the handler was never used). * libguile/eval.c (eval): * libguile/throw.c (pre_init_catch): Adapt to scm_c_make_prompt change. * libguile/vm-i-system.c (partial-cont-call): Grovel the new elements of the wind list in order to call setjmp() on the new prompts. Pass cookie to vm_reinstate_partial_continuation. (prompt): Adapt to scm_c_make_prompt change. * libguile/vm.c (vm_reinstate_partial_continuation): Take a cookie arg, used when winding captured prompts onto the stack. Winding a prompt implies making a new prompt, actually -- with new registers, a new jump buffer, new winds, etc. * test-suite/tests/control.test ("rewinding prompts"): Add a test for rewinding prompts.
2010-02-26fix a prompt bugAndy Wingo1-7/+9
* libguile/control.h: * libguile/control.c (scm_c_make_prompt): Instead of taking a VM arg, take the registers directly. (scm_c_abort): Declare as returning void. In fact it will never return. * libguile/eval.c (eval): * libguile/throw.c (pre_init_catch): Adapt to prompt API change. * libguile/vm-i-system.c (prompt): Pass the abort ip as the ip to scm_c_make_prompt. This fixes a bug in which we used the "offset" local var, but it wasn't guaranteed to be around after a longjmp.
2010-02-25error if given an unrewindable partial continuationAndy Wingo1-0/+4
* libguile/vm-engine.c (vm_error_continuation_not_rewindable): * libguile/vm-i-system.c (partial-cont-call): * libguile/vm.h (SCM_VM_CONT_PARTIAL_P): (SCM_VM_CONT_REWINDABLE_P): Fix a bug in which we weren't checking if a partial continuation was actually rewindable.
2010-02-24rewind the dynamic state when entering a partial continuationAndy Wingo1-4/+2
* libguile/control.c (cont_objcode): * libguile/vm-i-system.c (partial-cont-call): * libguile/vm.c (vm_reinstate_partial_continuation): Don't keep the "external winds" in a partial continuation, as they aren't logically part of the continuation. Reinstate the "internal winds" when entering a partial continuation. Things seem to work!
2010-02-24partial-cont-call worksAndy Wingo1-2/+6
* libguile/vm-i-system.c (partial-cont-call): Sync registers before splatting a partial continuation, and cache them back afterwards. * libguile/vm.c (vm_reinstate_partial_continuation): Actually implement, except dynamic-wind.
2010-02-22actually capture partial continuationsAndy Wingo1-7/+19
* libguile/control.c (cont_objcode): Along with a bunch of boilerplate that certainly needs to go in some central place, define this continuation-calling trampoline. (reify_partial_continuation): New function, returns a procedure that when called will reinstate a partial continuation. (scm_c_abort): Take an extra arg, the cookie. Actually reify a continuation. (scm_at_abort): Adapt to scm_c_abort change. * libguile/control.h: Declare scm_c_abort change. * libguile/vm-i-system.c (partial_cont_call): New instruction. (call/cc, tail-call/cc): Adapt to scm_i_vm_capture_stack change. (abort): Pass vm_cookie to abort. * libguile/vm.h (SCM_F_VM_CONT_PARTIAL, SCM_F_VM_CONT_REWINDABLE): New flags. (struct scm_vm_cont): Add flags field. (SCM_VM_CONT_PARTIAL_P, SCM_VM_CONT_REWINDABLE_P): New predicates. * libguile/vm.c (scm_i_vm_capture_stack): Rename from vm_capture_continuation, and make internal instead of static. Take a flags argument. (scm_i_vm_capture_continuation): Adapt to scm_i_vm_capture_stack change. (vm_abort): Plumb cookie to scm_c_abort. (vm_reinstate_partial_continuation): New stub.
2010-02-22abort always dispatches to VM bytecode, to detect same-invocation abortsAndy Wingo1-2/+2
* libguile/control.h: * libguile/control.c (scm_c_make_prompt): Take an extra arg, a cookie. Continuations will be rewindable only if the abort has the same cookie as the prompt. (scm_at_abort): Redefine from scm_abort, and instead of taking rest args, take the abort values as a list directly. Also, don't allow rewinding, because we won't support rewinding the C stack with delimited continuations. * libguile/eval.c (eval): Adapt to scm_c_make_prompt change. * libguile/vm-engine.c (vm_engine): Use vp->cookie to get a unique value corresponding to this VM invocation. * libguile/vm-i-system.c (prompt): Pass the cookie to scm_c_make_prompt. (abort): Take an additional tail arg. * libguile/vm.c (vm_abort): Parse out the abort tail arg. This is for the @abort case, or the (apply abort ...) case. (make_vm): Initialize the cookie to 0. * libguile/vm.h (struct scm_vm): Add cookie. * module/ice-9/boot-9.scm (abort): Define here as a trampoline to @abort. Needed to make sure that a call to abort dispatches to a VM opcode, so the cookie will be the same. * module/language/tree-il.scm (<tree-il>): Add a "tail" field to <abort>, for the (apply abort ...) case, or (@abort tag args). Should be #<const ()> in the normal case. Add support throughout. * module/language/tree-il/analyze.scm (analyze-lexicals): Add abort-tail support here too. * module/language/tree-il/compile-glil.scm (flatten): Compile the tail argument appropriately. * module/language/tree-il/primitives.scm (*primitive-expand-table*): Fix @abort and abort cases to pass the tail arg to make-abort.
2010-02-19prompt as part of guile's primitive languageAndy Wingo1-3/+2
* libguile/control.h: * libguile/control.c: Remove scm_atcontrol and scm_atprompt. (scm_c_make_prompt): Remove handler arg, as the handler is inline. (scm_abort): New primitive, exported to Scheme as `abort'. The compiler will also recognize calls to `abort', but this is the base case. (scm_init_control): Remove scm_register_control, just have this function, which adds `abort' to the `(guile)' module. * libguile/eval.c (eval): Add SCM_M_PROMPT case. * libguile/init.c (scm_i_init_guile): Change scm_register_control call into a nice orderly scm_init_control call. * libguile/memoize.h: (scm_sym_at_prompt, SCM_M_PROMPT): * libguile/memoize.c (MAKMEMO_PROMPT, scm_m_at_prompt, unmemoize): Add prompt support to the memoizer. * libguile/vm-i-system.c (prompt): Fix to not expect a handler on the stack. * module/ice-9/boot-9.scm (prompt): Add definition in terms of @prompt. * module/ice-9/control.scm: Simplify, and don't play with the compiler here, now that prompt and abort are primitive. * module/ice-9/eval.scm (primitive-eval): Add a prompt case. * module/language/tree-il/primitives.scm (*interesting-primitive-names*): Add @prompt and prompt.
2010-02-19add scm_c_abort, wire it up to the abort opcodeAndy Wingo1-6/+3
* libguile/control.h: * libguile/control.c (scm_c_abort): Add an implementation of `abort', but it doesn't reify the continuation yet. * libguile/vm-i-system.c (abort): * libguile/vm.c (vm_abort): Wire up the call to `abort', avoiding consing the args into a list. * module/language/tree-il/compile-glil.scm (flatten): Add some compily bits that can allow the abort to be resumed.
2010-02-19prompt handlers are always inlineAndy Wingo1-7/+5
* libguile/control.h (SCM_F_PROMPT_INLINE, SCM_PROMPT_INLINE_P): Remove; prompts always have "inline" handlers now. * libguile/control.c (scm_c_make_prompt): Remove inline_handler_p arg. * libguile/vm-i-system.c (prompt): * module/language/assembly/decompile-bytecode.scm (decode-load-program): * module/language/assembly/compile-bytecode.scm (write-bytecode): Adapt to prompt changes. * module/language/glil.scm (make-glil-prompt, glil-prompt-inline?): Remove inline? flag. (parse-glil, unparse-glil): * module/language/glil/compile-assembly.scm (glil->assembly): Adapt to <glil-prompt> change. * module/language/tree-il/compile-glil.scm (flatten): Require the handler of a <prompt> to be a lambda-case. * module/language/tree-il/primitives.scm (*primitive-expand-table*): Ensure that the handler of a <prompt> is a lambda-case. * module/language/tree-il/inline.scm (inline!): Simplify a degenerate case: (lambda args (apply (lambda ...) args)) => (lambda ...).
2010-02-19new VM operations: fluid-ref, fluid-setAndy Wingo1-0/+41
* libguile/vm-i-system.c (fluid-ref, fluid-set): New VM ops.
2010-02-19vm caches the dynamic state in a local varAndy Wingo1-2/+2
* libguile/vm-engine.c (vm_engine): Cache the dynamic state in a local var when we enter the VM. * libguile/vm-i-system.c (wind-fluids, unwind-fluids): Use the cached dynamic state instead of going through SCM_I_CURRENT_THREAD.
2010-02-19rename <control> to <abort>Andy Wingo1-3/+3
* libguile/vm-i-system.c (abort): Rename instruction from `throw'. * libguile/vm.c (vm_abort): Rename from vm_throw. * module/language/tree-il.scm (<abort>, make-abort, abort-src, abort-tag, abort-args: Rename from <control> & company. * module/language/tree-il/analyze.scm: * module/language/tree-il/compile-glil.scm: * module/language/tree-il/primitives.scm: Fix all callers.
2010-02-19<prompt> has no pre-unwind-handler, it's unnecessaryAndy Wingo1-5/+3
* libguile/control.h: * libguile/control.c (scm_c_make_prompt, SCM_PROMPT_PRE_UNWIND_HANDLER): * libguile/vm-i-system.c (prompt) * module/language/tree-il.scm (<prompt> prompt-pre-unwind-handler): * module/language/tree-il/analyze.scm: * module/language/tree-il/compile-glil.scm: * module/language/tree-il/inline.scm: * module/language/tree-il/primitives.scm: Remove the "pre-unwind" handler from prompt; it turns out not to be necessary. Adapt all references.
2010-02-18add wind-fluids, unwind-fluids VM opsAndy Wingo1-0/+22
* libguile/vm-i-system.c (wind-fluids, unwind-fluids): New instructions, for dynamic binding.
2010-02-08continuations return multiple values on the stackAndy Wingo1-33/+32
* libguile/vm.h (struct scm_vm_cont): Instead of saving the "IP", save "RA" and "MVRA". That is, save singly-valued and multiply-valued return addresses, so that we can return multiple values on the stack. (scm_i_vm_reinstate_continuation): Remove. * libguile/vm.c (vm_capture_continuation): Rename from capture_vm_cont, and change the prototype so we can capture the RA and MVRA, and so that tail calls to call/cc can capture a continuation without the call/cc application frame. (vm_return_to_continuation): Rename from reinstate_vm_cont, and take arguments to return to the continuation. Handles returning to single or multiple-value RA. (scm_i_vm_capture_continuation): Change to invoke vm_capture_continuation. Kept around for the benefit of make-stack. * libguile/vm-i-system.c (continuation-call): Handle reinstatement of the VM stack, with arguments. (call/cc, tail-call/cc): Adapt to new vm_capture_continuation prototype. tail-call/cc captures tail continuations. * libguile/stacks.c (scm_make_stack): Update for scm_vm_cont structure change. * libguile/continuations.h (struct scm_contregs): Remove throw_value member, which was used to return a value to a continuation. (scm_i_check_continuation): New internal function, checks that a continuation may be reinstated. (scm_i_reinstate_continuation): Replaces scm_i_continuation_call; just reinstates the C stack. (scm_i_contregs_vm, scm_i_contregs_vm_cont): New internal accessors. * libguile/continuations.c (scm_i_make_continuation): Return SCM_UNDEFINED if we are returning again. (grow_stack, copy_stack_and_call, scm_dynthrow): Remove extra arg, as vm opcodes handle value returns. (copy_stack): No need to instate VM continuation. (scm_i_reinstate_continuation): Adapt.
2010-02-08scm_i_make_continuation takes vm and vm_cont args explicitlyAndy Wingo1-2/+2
* libguile/continuations.h: * libguile/continuations.c (scm_i_make_continuation): Take VM and VM continuation arguments as well; I'm not convinced that saving all VM continuations was the right thing, and in any case we only ever saved the latest. Running a new VM should create a continuation barrier. * libguile/stacks.c (scm_make_stack): * libguile/vm-i-system.c (call/cc, tail-call/cc): Adapt callers. * libguile/vm.h (scm_i_vm_capture_continuation) (scm_i_vm_reinstate_continuation): Change to be internal, and to only capture and reinstate continuations for a particular VM.
2010-02-08make scm_make_continuation internalAndy Wingo1-2/+2
* libguile/continuations.h: * libguile/continuations.c (scm_i_make_continuation): Change from scm_make_continuation, and make internal. * libguile/vm-i-system.c (call/cc, tail-call/cc): Adapt callers. * test-suite/standalone/test-unwind.c (check_cont_body): Adapt a test. * doc/ref/api-control.texi (Continuations): Update docs.
2010-02-08continuations are vm proceduresAndy Wingo1-0/+9
* libguile/vm-i-system.c (continuation-call): New op, like subr-call or foreign-call, but for continuations. * libguile/continuations.h: Add scm_i_continuation_call internal declaration. (SCM_CONTINUATIONP): Reimplement in terms of SCM_PROGRAM_IS_CONTINUATION. (scm_tc16_continuation, SCM_CONTREGS, SCM_CONTINUATION_LENGTH) (SCM_SET_CONTINUATION_LENGTH, SCM_JMPBUF, SCM_DYNENV, SCM_THROW_VALUE) (SCM_CONTINUATION_ROOT, SCM_DFRAME): Remove these from the exposed API. (scm_i_continuation_to_frame): New internal declaration. * libguile/continuations.c * libguile/continuations.c: Add trickery like in foreign.c, smob.c, and gsubr.c, so that we can make procedural trampolines for continuations. (scm_i_continuation_to_frame): New internal function, from stacks.c. * libguile/programs.h (SCM_F_PROGRAM_IS_CONTINUATION) (SCM_PROGRAM_IS_CONTINUATION): Add a flag for programs that are continuations. Probably should add flags for the other trampoline types too. * libguile/programs.c (scm_i_program_print): Print continuations as before. * libguile/stacks.c (scm_stack_id, scm_make_stack): Use scm_i_continuation_to_frame in the continuation case.
2010-02-08connect a few more wires to promptensteinAndy Wingo1-4/+6
* libguile/tags.h (scm_tc7_prompt): Allocate a tc7 for prompt objects. * libguile/control.h (SCM_F_PROMPT_INLINE, SCM_F_PROMPT_ESCAPE) (SCM_PROMPT_P, SCM_PROMPT_FLAGS, SCM_PROMPT_INLINE_P) (SCM_PROMPT_ESCAPE_P, SCM_PROMPT_TAG, SCM_PROMPT_REGISTERS) (SCM_PROMPT_DYNENV, SCM_PROMPT_HANDLER) (SCM_PROMPT_PRE_UNWIND_HANDLER, SCM_PROMPT_SETJMP) (struct scm_prompt_registers): * libguile/control.c (scm_c_make_prompt): Flesh out a simple prompts implementation. * libguile/vm-i-system.c (prompt): Wire up the implementation. * libguile/vm.c: Add a needed #include.
2010-01-31add return/nvaluesAndy Wingo1-0/+9
* libguile/vm-i-system.c (return/nvalues): New instruction, like call/nargs.
2010-01-31initial VM support for delimited continuations and dynamic-windAndy Wingo1-0/+81
* libguile/vm-i-system.c (prompt, wind, throw, unwind): New instructions, for implementing dynamic-wind and delimited continuations. * libguile/vm.c: Add some stub support for the new instructions. * libguile/vm-engine.c: Some new error conditions.
2010-01-27fix to variable-bound? instruction prototypeAndy Wingo1-1/+1
* libguile/vm-i-system.c (variable-bound?): Correctly declare as popping one item.
2010-01-26implement foreign-callAndy Wingo1-1/+1
* libguile/foreign.h: * libguile/foreign.c (scm_i_foreign_call): New internal function, actually implementing foreign calls. Untested. * libguile/vm-i-system.c (foreign-call): Wire up the call to scm_i_foreign_call.
2010-01-26renumber VM opcodesAndy Wingo1-26/+54
* libguile/vm-i-loader.c: * libguile/vm-i-scheme.c: * libguile/vm-i-system.c: Renumber ops. Add a foreign-call op stub. Rearrange some ops. * libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump
2010-01-26foreign.h presents a more pointer-centric interfaceAndy Wingo1-1/+1
* libguile/foreign.c: * libguile/foreign.h: Rework interface to be more pointer-centric. Details are: (SCM_FOREIGN_TYPE_STRUCT, SCM_FOREIGN_TYPE_POINTER): Removed; now the pointer in a foreign is first-class. If it points to a native type like uint32, then it still has a tag; but if it points to something else, like a struct or a pointer or something, then its type is VOID (i.e., void*). (SCM_FOREIGN_POINTER): Rename from SCM_FOREIGN_OBJECT. (SCM_FOREIGN_VALUE_REF, SCM_FOREIGN_VALUE_SET): Rename from SCM_FOREIGN_OBJECT_REF and SCM_FOREIGN_OBJECT_SET, to indicate that they only work with value types. (SCM_FOREIGN_HAS_FINALIZER): Reserve a bit to indicate if the foreign pointer in question has a finalizer registered. (SCM_FOREIGN_LEN): For void* pointers, optionally store the length in bytes of the associated memory region. (SCM_FOREIGN_VALUE_P): Rename from SCM_FOREIGN_SIMPLE_P. (SCM_VALIDATE_FOREIGN_VALUE): Rename from SCM_VALIDATE_FOREIGN_SIMPLE. (scm_take_foreign_pointer): Rename from scm_c_take_foreign. Remove scm_c_from_foreign. (scm_foreign_type): New accessor. (scm_foreign_ref, scm_foreign_set_x): Take some optional args, used when dereferencing void pointers. * libguile/dynl.h: * libguile/dynl.c (scm_dynamic_pointer): New function, used by scm_dynamic_func. Adapt code to foreign.h changes. * libguile/goops.c (scm_enable_primitive_generic_x) (scm_set_primitive_generic_x): Use the SCM_SET_SUBR_GENERIC macro. * libguile/gsubr.c (create_gsubr): Adapt to API change. * libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Store the pointer directly, not indirected. * libguile/snarf.h (SCM_DEFINE, SCM_IMMUTABLE_FOREIGN): Store subr pointers directly. Adapt to SCM_FOREIGN_TYPE_VOID change. * libguile/vm-i-system.c (subr-call): Access the void* directly.
2010-01-13RETURN_HOOK communicates the number of returned valuesAndy Wingo1-2/+2
* libguile/vm-engine.h (RUN_HOOK1): Add some machinery whereby a hook can push an arg on the stack, run the hook, then drop the value. (RETURN_HOOK): Use it here, so we push the number of returned values. * libguile/vm-i-system.c (return, return-values): Adapt to RETURN_HOOK changes.
2010-01-09fix bug in subr-call and smob-callAndy Wingo1-2/+0
* libguile/vm-i-system.c (subr-call, smob-call): Unlike the previous situation, in which a call to a subr or a smob didn't actually build a frame, we no longer need to explicitly pop the procedure and its arguments. Indeed the procedure and its arguments must remain on the stack, for hooks and ticks and such always to see frames with valid procedures. Two lines out, two bugs less, and faster to boot.
2010-01-09allocate free variables inline to closuresAndy Wingo1-11/+22
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump. * libguile/programs.h (SCM_PROGRAM_FREE_VARIABLES) (SCM_PROGRAM_FREE_VARIABLE_REF, SCM_PROGRAM_FREE_VARIABLE_SET) (SCM_PROGRAM_NUM_FREE_VARIABLES): * libguile/programs.c (scm_make_program, scm_program_num_free_variables) (scm_program_free_variable_ref, scm_program_free_variable_set_x): Allocate free variables inline with programs, instead of being in a vect. Should improve locality, and require fewer local variables in the VM. * libguile/vm-engine.c (vm_engine): Remove free_vars and free_vars_count variables. * libguile/vm-engine.h (CACHE_PROGRAM): No need to muck with free_vars and free_vars_count. (CHECK_FREE_VARIABLE): Update for inline free vars. * libguile/vm-i-system.c (FREE_VARIABLE_REF): Update for inline free vars. (make-closure, fix-closure): Take the closure vals as separate stack args, and copy or fix them inline into the appropriate closure. * module/language/objcode/spec.scm (program-free-variables): Define a local version of this removed function. * module/language/tree-il/compile-glil.scm (flatten): Adjust to not make a vector when making closures. * module/system/vm/program.scm: Export program-num-free-variables, program-free-variable-ref, program-free-variable-set!, and remove program-free-variables. * test-suite/tests/tree-il.test ("lambda"): Update to not make vectors when making closures.
2010-01-09smobs are applied with vm trampoline proceduresAndy Wingo1-145/+114
* libguile/smob.c: Instead of having special evaluator support for applying smobs, we use the same strategy that gsubr uses, that smob application should happen via a trampoline VM procedure, which uses a special opcode (smob-apply). So statically allocate all of the desired trampoline procedures here. (scm_i_smob_apply_trampoline): Unfortunately there's no real place to put the trampoline, so instead use a weak-key hash. It's nasty, but I think the benefits of speeding up procedure calls in the general case are worth it. * libguile/smob.h (scm_smob_descriptor): Remove fields apply_0, apply_1, apply_2, and apply_3; these were never public. Also remove the gsubr_type field. Instead cache the trampoline objcode here. (SCM_SMOB_APPLY_0, SCM_SMOB_APPLY_1, SCM_SMOB_APPLY_2, SCM_SMOB_APPLY_3): Just go through scm_call_0, etc here. * libguile/vm-i-system.c (call, tail-call, mv-call): Simplify. All procedure calls are VM calls now. (smob-call): New instruction, used in smob trampoline procedures. * libguile/vm.c (apply_foreign): Remove. Yay! * libguile/procprop.c (scm_i_procedure_arity): Refactor a bit for the smob changes.
2010-01-07add subr-call VM opAndy Wingo1-0/+69
* libguile/vm-i-system.c (subr_call): Add subr-call VM op.
2010-01-03rename goto/args and friends to tail-call, tail-apply, etcAndy Wingo1-10/+10
* libguile/vm-i-system.c (tail-call, tail-call/nargs, tail-apply) (tail-call/cc): Rename these back to tail-* from goto/*. We should reserve the rename-then-goto name for when you actually do a rename and goto, not when you shuffle the stack. * doc/ref/vm.texi: * module/language/glil/decompile-assembly.scm: * module/language/tree-il/compile-glil.scm: * test-suite/tests/tree-il.test: Adapt all callers and documentation.
2009-12-20handle interrupts in mv-call, return/valuesAndy Wingo1-0/+4
* libguile/vm-i-system.c (mv-call, return/values): Interrupt before entering and leaving MV frames as well as normal frames.
2009-12-15Don't use GCC zero-length arrays.Ludovic Courtès1-3/+3
* libguile/frames.c, libguile/objcodes.c, libguile/programs.c, libguile/vm-engine.c, libguile/vm-i-system.c, libguile/vm.c: Use `SCM_C_OBJCODE_BASE ()' instead of accessing the `base' field of `struct scm_objcode'. * libguile/objcodes.h (struct scm_objcode)[base]: Remove.
2009-12-11vm no longer measures bogoclock or times, relies on os for thatAndy Wingo1-1/+0
* libguile/vm.h (struct scm_vm): Remove "time" and "clock" members. The time was bogusly measured, and the "clock" measured instructions retired, which is not a very useful measurement, and it was causing lots of memory accesses. Not that I have done a proper profile, though... (scm_vm_stats): Remove this procedure, which provided access to "time" and "clock". * libguile/vm.c: * libguile/vm-engine.h: * libguile/vm-engine.c: * libguile/vm-i-system.c: Adapt to scm_vm changes and scm_vm_stats removal. * module/system/repl/command.scm: * module/system/vm/vm.scm: Adapt to vm-stats removal by removing vm-stats from <repl>.
2009-12-11vm: handle interrupts on backwards jumpsAndy Wingo1-0/+4
* libguile/vm-i-system.c (BR, br): Handle interrupts on backwards jumps, so we can Ctrl-C an endless loop.
2009-12-11less overhead for handling interrupts in the vmAndy Wingo1-6/+5
* libguile/__scm.h (SCM_ASYNC_TICK): Add some branch prediction. (SCM_ASYNC_TICK_WITH_CODE): New helper for when BUILDING_LIBGUILE, runs code only if we're going to call async_click(). * libguile/vm-engine.h (VM_HANDLE_INTERRUPTS): New helper, uses SCM_ASYNC_TICK_WITH_CODE to only save regs if we'll handle an interrupt. * libguile/vm-i-system.c (call, goto/args, return): use VM_HANDLE_INTERRUPTS.
2009-12-11merge from master to elispAndy Wingo1-146/+405
* module/language/elisp/compile-tree-il.scm: Update for changes to tree-il (lambda-case, mainly). * module/language/elisp/spec.scm: Update GPL version to 3. Update reader for new taking a port and environment argument. * libguile/_scm.h: Bump objcode version. * libguile/vm-i-system.c: Fix conflicts. * module/Makefile.am: Fix conflicts, and add elisp modules to the build.
2009-12-07procedures-with-setters implemented in terms of structsAndy Wingo1-16/+0
* libguile/tags.h (scm_tc7_pws): No more. * libguile/procs.c (scm_procedure_with_setter_p) (scm_make_procedure_with_setter, scm_procedure, scm_setter): Implement procedures-with-setters in terms of applicable structs with setters. * libguile/procs.h: Remove a big, outdated comment, and the deprecated macros. * libguile/deprecated.h (SCM_PROCEDURE_WITH_SETTER_P, SCM_PROCEDURE) (SCM_SETTER): Deprecate these. SCM_PROCEDURE and SCM_SETTER are bad names. * libguile/evalext.c (scm_self_evaluating_p): * libguile/gc.c (scm_i_tag_name): * libguile/goops.c: (scm_class_of): * libguile/print.c (iprin1): * libguile/procprop.c (scm_i_procedure_arity): * libguile/procs.c (scm_procedure_p): * libguile/debug.c (scm_procedure_source): Remove a tc7_pws case. * libguile/goops.h: * libguile/goops.c (scm_class_procedure_with_setter): Remove this class; it is subsumed by applicable_struct_with_setter. * libguile/struct.h: Update a comment. * libguile/vm-i-system.c (call, goto/args, mv-call): Remove PWS cases.