summaryrefslogtreecommitdiff
path: root/libguile/vm-i-system.c
AgeCommit message (Collapse)AuthorFilesLines
2011-10-24refactor tc7 and tc16 checksAndy Wingo1-3/+3
* libguile/tags.h (SCM_HAS_TYP7, SCM_HAS_TYP7S, SCM_HAS_TYP16): New macros. * libguile/bytevectors.h (SCM_BYTEVECTOR_P): * libguile/control.h (SCM_PROMPT_P): * libguile/filesys.h (SCM_DIRP): * libguile/fluids.h (SCM_WITH_FLUIDS_P, SCM_FLUID_P) (SCM_I_DYNAMIC_STATE_P): * libguile/foreign.h (SCM_POINTER_P): * libguile/fports.h (SCM_FPORTP): * libguile/frames.h (SCM_VM_FRAME_P): * libguile/hashtab.h (SCM_HASHTABLE_P): * libguile/inline.h (scm_get_byte_or_eof): * libguile/numbers.h (SCM_REALP, SCM_BIGP, SCM_COMPLEXP, SCM_FRACTIONP): * libguile/objcodes.h (SCM_OBJCODE_P): * libguile/ports.h (SCM_OUTPUT_PORT_P): * libguile/programs.h (SCM_PROGRAM_P): * libguile/smob.h (SCM_SMOB_PREDICATE): * libguile/srfi-14.h (SCM_CHARSETP): * libguile/strings.c (IS_STRING): * libguile/strports.h (SCM_STRPORTP): * libguile/symbols.h (scm_is_symbol): * libguile/variable.h (SCM_VARIABLEP): * libguile/vectors.h (SCM_I_IS_VECTOR, SCM_I_IS_NONWEAK_VECTOR): * libguile/vm-i-system.c (call, tail-call, mv-call) * libguile/vm.h (SCM_VM_P, SCM_VM_CONT_P): * libguile/weak-set.c (SCM_WEAK_SET_P): * libguile/weak-table.c (SCM_WEAK_TABLE_P): * libguile/weak-vector.h (SCM_I_WVECTP): Use them.
2011-05-13more care regarding SCM_PACK and SCM_UNPACKAndy Wingo1-6/+6
* libguile/control.c (reify_partial_continuation): * libguile/eval.c (RETURN_BOOT_CLOSURE): * libguile/frames.c (scm_frame_num_locals, scm_frame_local_ref) (scm_frame_local_set_x) * libguile/frames.h (SCM_FRAME_SET_RETURN_ADDRESS): (SCM_FRAME_SET_MV_RETURN_ADDRESS, SCM_FRAME_SET_DYNAMIC_LINK): * libguile/goops.c (scm_class_of, scm_primitive_generic_generic) (scm_c_extend_primitive_generic, compute_getters_n_setters) (scm_sys_initialize_object): * libguile/guardians.c (finalize_guarded): * libguile/list.c (SCM_I_CONS): * libguile/macros.c (scm_i_make_primitive_macro) (scm_make_syntax_transformer): * libguile/memoize.c (MAKMEMO, SCM_MAKE_MEMOIZER) (SCM_MAKE_REST_MEMOIZER): * libguile/modules.c (scm_module_reverse_lookup) * libguile/print.c (iprin1): * libguile/promises.c (scm_make_promise) * libguile/srcprop.c (scm_make_srcprops): * libguile/vectors.c (scm_c_vector_ref): * libguile/vm-engine.c (vm_engine) * libguile/vm-i-scheme.c (REL, add1, sub1): * libguile/vm-i-system.c (new_frame, call_cc) * libguile/weaks.h (SCM_WEAK_PAIR_WORD_DELETED_P): Be more careful about SCM_PACK / SCM_UNPACK.
2011-05-13scm_is_eq for SCM vals, not == or !=Andy Wingo1-10/+4
* libguile/bytevectors.c (scm_make_bytevector, STRING_TO_UTF) (UTF_TO_STRING): * libguile/continuations.c (scm_i_check_continuation): * libguile/expand.h (SCM_EXPANDED_P): * libguile/fluids.c (scm_i_make_with_fluids): * libguile/generalized-vectors.c (scm_make_generalized_vector): * libguile/goops.c (SCM_GOOPS_UNBOUNDP, slot_definition_using_name): (scm_c_extend_primitive_generic, more_specificp, scm_make) * libguile/i18n.c (SCM_VALIDATE_OPTIONAL_LOCALE_COPY): (scm_locale_string_to_integer) * libguile/modules.c (resolve_duplicate_binding): (scm_module_reverse_lookup) * libguile/posix.c (scm_to_resource): * libguile/r6rs-ports.c (scm_put_bytevector): * libguile/socket.c (scm_connect, scm_bind, scm_sendto * libguile/stacks.c (find_prompt): * libguile/variable.c (scm_variable_ref, scm_variable_bound_p): * libguile/vm-engine.h (ASSERT_BOUND_VARIABLE, ASSERT_BOUND) * libguile/vm-i-system.c (VARIABLE_BOUNDP, local_bound) (long_local_bound, fluid_ref): Use scm_is_eq to compare, not == / !=.
2011-05-06avoid tls gets when handling interrupts in the vmAndy Wingo1-4/+4
* libguile/__scm.h (SCM_ASYNC_TICK_WITH_CODE): Redefine to take a scm_i_thread* as well. OK to do because it's within a BUILDING_LIBGUILE block. * libguile/vm-engine.c (vm_engine): Cache the scm_i_thread* instead of the dynstate, so we can use the thread for ticks. * libguile/vm-engine.h (VM_HANDLE_INTERRUPTS): Tick with the scm_i_thread* local var, to avoid excessive tls calls. * libguile/vm-i-system.c: Fix dynstate users to use current_thread->dynamic_state.
2011-05-05VM tweaksAndy Wingo1-23/+29
* libguile/vm-engine.c (VM_CHECK_OBJECT, VM_CHECK_FREE_VARIABLES): Set to 0 for both engines. These are really internal debugging variables, which don't affect user-visible features, provided that the compiler is correct of course. (VM_CHECK_UNDERFLOW): New var, also off by default: whether to check for stack underflow when popping values. (vm_engine): Don't declare object_count if we are not checking object table accesses. * libguile/vm-engine.h (CACHE_PROGRAM): Don't muck with object_count if we are not checking object table accesses. (CHECK_UNDERFLOW, PRE_CHECK_UNDERFLOW): Nop out if we are not checking underflow. (POP2, POP3): New macros which check for underflow before popping more than one value. * libguile/vm-i-loader.c (load_array): * libguile/vm-i-scheme.c (set_car, set_cdr, vector_set, slot_set) (BV_SET_WITH_ENDIANNESS, BV_FIXABLE_INT_SET, BV_INT_SET) (BV_FLOAT_SET): * libguile/vm-i-system.c (partial_cont_call, fix_closure, prompt) (fluid_set): Use POP2 / POP3. (local_set, long_local_set): Pop to locals instead of using values on the stack then dropping; allows for underflow to be checked before the value is accessed. (BR): Don't NULLSTACK or DROP after the operation. (br_if, br_if_not, br_if_eq, br_if_not_eq, br_if_null) (br_if_not_null): Pop to locals before doing the compare and jump.
2011-03-19fix new-frame push in call/ccAndy Wingo1-1/+1
* libguile/vm-i-system.c (call/cc): Whoops, fix the new-frame push here. A little birdie tells me a test case is coming soon.
2011-03-15fix frame dynamic linkage in the face of partial continuation applicationAndy Wingo1-13/+36
* libguile/vm-i-system.c (new-frame): Though it was appealing to set the dynamic link here on the incomplete frame, we no longer do that, for the reasons mentioned in the code. (call, mv-call): Adapt to set the frame's dynamic link. * libguile/vm-engine.c (vm_engine): Don't set dynamic link here, even for boot program. * libguile/frames.c (scm_frame_num_locals, scm_frame_local_ref) (scm_frame_local_set_x): Fix up not-yet-active frame detection.
2011-01-27fix error handling in variable-ref family of instructionsAndy Wingo1-5/+27
* libguile/vm-i-system.c (variable-ref, variable-set, variable-bound?): Check that the argument is actually a variable. Thanks to Kevin Holmes for the report. * libguile/vm-engine.c (vm_engine): Error handling down here. * THANKS: Update.
2010-12-07unbound fluidsBrian Templeton1-1/+9
* libguile/fluids.c (scm_make_undefined_fluid, scm_fluid_unset_x) (scm_fluid_bound_p): New functions. (fluid_ref): New function; like scm_fluid_ref, but will not throw an error for unbound fluids. (scm_fluid_ref, swap_fluid): Use `fluid_ref'. * libguile/fluids.h (scm_make_undefined_fluid, scm_fluid_unset_x) (scm_fluid_bound_p): New prototypes. * libguile/vm-i-system.c (fluid_ref): If fluid is unbound, jump to `vm_error_unbound_fluid'. * libguile/vm-engine.c (VM_NAME)[vm_error_unbound_fluid]: New error message. * test-suite/tests/fluids.test ("unbound fluids")["fluid-ref of unbound fluid", "fluid-bound? of bound fluid", "fluid-bound? of unbound fluid", "unbound fluids can be set", "bound fluids can be unset"]: New tests.
2010-12-07better unbound variable errors in the vmAndy Wingo1-3/+3
* libguile/vm-i-system.c (variable-ref, toplevel-ref) (long-toplevel-ref): Fixup callers. * libguile/vm-engine.c (vm_error_unbound): Don't use vm-error for unbound vars, use misc-error. Don't include VM: in the string. Take the name directly in finish_args, not as a list.
2010-10-14Unresolved var errors don't work for top-level varsMichael Gran1-8/+10
* libguile/vm-i-system.c (toplevel_ref, long_toplevel_ref): modified
2010-10-13fix bug in with-fluids in a non-tail positionAndy Wingo1-4/+5
* libguile/vm-i-system.c (VM_DEFINE_INSTRUCTION): Drop the stack items corresponding the the with-fluids object. Thanks very much to Stefan Israelsson Tampe for the fix.
2010-10-08inline symbol? and vector? to opcodes, and a psyntax inlining tweakAndy Wingo1-92/+92
* libguile/vm-i-scheme.c (symbol?, vector?): New instructions. Renumbered the rest. * libguile/vm-i-system.c: Renumber instructions. * libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump. * module/ice-9/psyntax.scm (binding-type, binding-value): Define using macros so that we inline to car and cdr opcodes. Oh, for an inliner :) * module/language/tree-il/compile-glil.scm (*primcall-ops*) * module/language/tree-il/primitives.scm (*interesting-primitive-names*, *effect-free-primitives*) (*effect+exception-free-primitives*): Add symbol? and vector? inlines.
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.