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

162 commits

Author SHA1 Message Date
Andy Wingo
dfadcf85cb Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/debug.h
	module/ice-9/psyntax-pp.scm
	module/ice-9/psyntax.scm
	module/language/tree-il/peval.scm
	module/language/tree-il/primitives.scm
2012-01-30 20:27:35 +01:00
Andy Wingo
252acfe8e7 Merge commit '3d51e57cfb'
Conflicts:
	libguile/foreign.c
	libguile/hashtab.c
	module/ice-9/psyntax-pp.scm
	module/language/tree-il/compile-glil.scm
2012-01-30 18:52:46 +01:00
Andy Wingo
a39b116f00 Revert "attempt to clear stale references on VM C stack"
This reverts commit 04b2d77354.

Since it wasn't fixing the "lexical vars are collectable" test, it added
complexity with no benefit.
2012-01-29 22:30:21 +01:00
Ludovic Courtès
5e80f2cea3 Revert "Work around instruction reordering on SPARC and HPPA in the VM."
This reverts commit 2b264d7e4f, which is
unnecessary after commit f5ea0499a4
("Build with `-fno-strict-aliasing' when available.").
2012-01-29 22:18:15 +01:00
Andy Wingo
04b2d77354 attempt to clear stale references on VM C stack
* libguile/vm-engine.h (DEAD): New macro, nulls out a value.

* libguile/vm-i-system.c:
* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c: Use DEAD when variables become dead.

Later we can #ifdef this out, but I want to give the buildbots a try
with this patch to make sure it's correct.
2012-01-27 19:34:19 +01:00
Ludovic Courtès
2b264d7e4f Work around instruction reordering on SPARC and HPPA in the VM.
Fixes part of <http://bugs.gnu.org/10520>.
Reported by Bruno Haible <bruno@clisp.org>.

* libguile/vm-i-system.c (COMPILER_BARRIER): New macro.
  (halt, return, return_values): Insert compiler barrier after each
  assignment to `fp'.
2012-01-24 23:39:43 +01:00
Andy Wingo
b2208d2e98 Merge remote-tracking branch 'origin/stable-2.0'
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-12-01 23:31:50 +01:00
Andy Wingo
aafb4ed724 optional default-value arg to make-fluid
* libguile/fluids.c (grow_dynamic_state, new_fluid): Arrange for the
  default value in the dynamic-state vector to be SCM_UNDEFINED instead
  of SCM_BOOL_F.  If the value in the dynamic-state is #f, default to a
  value attached to the fluid instead.  This allows useful default
  values.
  (scm_make_fluid_with_default): New function, allows the user to
  specify a default value for the fluid.  Defaults to #f.  Bound to
  `make-fluid' on the Scheme side.
  (scm_make_unbound_fluid): Use SCM_UNDEFINED as the default in all
  threads.
  (scm_fluid_unset_x): Also unset the default value.  Not sure if this
  is the right thing.
  (fluid_ref): Update to the new default-value strategy.

* libguile/threads.c (scm_i_reset_fluid): Reset to SCM_UNDEFINED.
* libguile/threads.h: Remove extra arg to scm_i_reset_fluid.
* libguile/vm-i-system.c (fluid-ref): Update to new default-value
  strategy.

* module/ice-9/vlist.scm (block-growth-factor): Default to 2 in all
  threads.  Fixes http://debbugs.gnu.org/10093.
2011-11-23 12:53:38 +01:00
Andy Wingo
dc7da0be90 refactor tc7 and tc16 checks
* 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-10-24 18:54:01 +02:00
Andy Wingo
b2b33168b1 more care regarding SCM_PACK and SCM_UNPACK
* 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-13 15:28:08 +02:00
Andy Wingo
d223c3fcdd scm_is_eq for SCM vals, not == or !=
* 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-13 13:49:32 +02:00
Andy Wingo
a2a6c0e319 avoid tls gets when handling interrupts in the vm
* 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-06 00:17:35 +02:00
Andy Wingo
eae2438d2b VM tweaks
* 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-05-05 14:04:23 +02:00
Andy Wingo
6f2ff78299 fix new-frame push in call/cc
* 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-19 23:12:40 +01:00
Andy Wingo
9b709b0fe1 fix frame dynamic linkage in the face of partial continuation application
* 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-03-15 23:45:58 +01:00
Andy Wingo
dce0252bf2 fix error handling in variable-ref family of instructions
* 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.
2011-01-27 10:49:51 +01:00
Brian Templeton
ef94624eaf unbound fluids
* 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-07 13:21:01 +01:00
Andy Wingo
d107921794 better unbound variable errors in the vm
* 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-12-07 13:21:01 +01:00
Michael Gran
45dc6b347d Unresolved var errors don't work for top-level vars
* libguile/vm-i-system.c (toplevel_ref, long_toplevel_ref): modified
2010-10-14 18:27:41 -07:00
Andy Wingo
2b41a37b3c fix bug in with-fluids in a non-tail position
* 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-13 21:20:23 +02:00
Andy Wingo
cf45ff030c inline symbol? and vector? to opcodes, and a psyntax inlining tweak
* 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-10-08 12:31:56 +02:00
Andy Wingo
f312025167 add vm-abort-continuation-hook, vm-restore-continuation-hook
* 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-16 12:48:41 +02:00
Andy Wingo
c45d4d775d trim our set of vm hooks
* 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-09-16 12:16:02 +02:00
Ludovic Courtès
5b46a8c2c8 Use "pointer" instead of "foreign" when dealing with wrapped pointers.
* 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-28 12:24:25 +02:00
Ludovic Courtès
d4149a510e Simplify the (system foreign) API.
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-26 19:38:52 +02:00
Ludovic Courtès
1af772303b Import unbound variable reports in the VM.
* 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-26 19:38:52 +02:00
Andy Wingo
6f8d7b12bb SCM_I_FLUID_P -> SCM_FLUID_P
* 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-17 13:31:06 +02:00
Andy Wingo
41e49280f3 better error reporting from the vm
* 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-07-15 12:44:15 +02:00
Andy Wingo
de45d8eef9 add assert-nargs-ee/locals instruction
* 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-05-02 13:41:31 +02:00
Andy Wingo
2533f10b40 nil is null, whee
* 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-30 10:31:27 +02:00
Andy Wingo
d38b431ace nil is false, whee
* 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-30 10:31:27 +02:00
Andy Wingo
f7cea64566 more vm gc fixen
* 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-03-16 15:55:24 +01:00
Andy Wingo
adbdfd6d24 rewinding prompts works
* 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-26 13:05:25 +01:00
Andy Wingo
d296431516 fix a prompt bug
* 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-26 11:05:44 +01:00
Andy Wingo
b3950ad6d8 error if given an unrewindable partial continuation
* 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-25 00:43:51 +01:00
Andy Wingo
9a1c6f1f0c rewind the dynamic state when entering a partial continuation
* 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-24 17:43:02 +01:00
Andy Wingo
078014374c partial-cont-call works
* 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-24 16:57:33 +01:00
Andy Wingo
cee1d22c3c actually capture partial continuations
* 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-22 23:00:19 +01:00
Andy Wingo
2d026f04cc abort always dispatches to VM bytecode, to detect same-invocation aborts
* 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-22 21:54:06 +01:00
Andy Wingo
747022e4cb prompt as part of guile's primitive language
* 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-19 22:44:24 +01:00
Andy Wingo
eaefabee34 add scm_c_abort, wire it up to the abort opcode
* 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-19 16:55:36 +01:00
Andy Wingo
ea6b18e82f prompt handlers are always inline
* 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-19 15:30:34 +01:00
Andy Wingo
1e7a0337f1 new VM operations: fluid-ref, fluid-set
* libguile/vm-i-system.c (fluid-ref, fluid-set): New VM ops.
2010-02-19 12:10:11 +01:00
Andy Wingo
26e6f99fc3 vm caches the dynamic state in a local var
* 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-19 12:10:11 +01:00
Andy Wingo
6e84cb95b1 rename <control> to <abort>
* 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 12:10:11 +01:00
Andy Wingo
07a0c7d5d9 <prompt> has no pre-unwind-handler, it's unnecessary
* 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-19 12:10:11 +01:00
Andy Wingo
e084b27e79 add wind-fluids, unwind-fluids VM ops
* libguile/vm-i-system.c (wind-fluids, unwind-fluids): New instructions,
  for dynamic binding.
2010-02-18 22:15:44 +01:00
Andy Wingo
d8873dfe47 continuations return multiple values on the stack
* 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-08 22:59:25 +01:00
Andy Wingo
269479e31f scm_i_make_continuation takes vm and vm_cont args explicitly
* 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-08 13:35:42 +01:00
Andy Wingo
997659f898 make scm_make_continuation internal
* 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-08 13:35:06 +01:00