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

78 commits

Author SHA1 Message Date
Andy Wingo
2b14df4bc7 fix list validation bug in @abort
* libguile/control.c (scm_at_abort): Fix to ensure that we store the
  return of scm_ilength in a signed integer, even if later we copy it to
  an unsigned.  See
  http://article.gmane.org/gmane.lisp.guile.devel/12685.
2011-07-28 18:17:45 +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
572eef50c2 fix prompt and abort with the boot evaluator
* libguile/control.h:
* libguile/control.c (scm_i_prompt_pop_abort_args_x): Take a VM instead
  of a prompt, given that it's the VM's registers that record the abort
  arguments, not the prompt registers (which actually point right below
  the abort values).

* libguile/eval.c (eval):
* libguile/throw.c (pre_init_catch): Pass the vm instead of a prompt.
2011-03-29 17:41:31 +02:00
Andy Wingo
f9654187b1 objcode type is an enumeration, not flags
* libguile/objcodes.h (SCM_OBJCODE_TYPE_MMAP)
  (SCM_OBJCODE_TYPE_BYTEVECTOR, SCM_OBJCODE_TYPE_SLICE)
  (SCM_OBJCODE_TYPE_STATIC): Enumerate objcode types instead of
  expressing them as flags.
  (SCM_OBJCODE_TYPE): Type is held in bits 8-15.
  (SCM_OBJCODE_FLAGS): Flags are now shifted by 16 bits, not 8.
  (SCM_MAKE_OBJCODE_TAG): New helper.

* libguile/continuations.c (STATIC_OBJCODE_TAG):
* libguile/control.c (STATIC_OBJCODE_TAG):
* libguile/foreign.c (STATIC_OBJCODE_TAG):
* libguile/gsubr.c (STATIC_OBJCODE_TAG):
* libguile/smob.c (STATIC_OBJCODE_TAG):
* libguile/objcodes.c (make_objcode_by_mmap, scm_c_make_objcode_slice)
  (scm_bytecode_to_objcode): : Use SCM_MAKE_OBJCODE_TAG.
2011-01-27 13:08:01 +01:00
Ludovic Courtès
cdd47ec7e5 Include <alloca.h> wherever `alloca' is used.
Patch provided by <carlo.bramix@libero.it> (tiny change).

* libguile/control.c, libguile/fluids.c, libguile/foreign.c,
  libguile/hashtab.c, libguile/strings.c: Include <alloca.h>.
2010-11-19 14:14:53 +01:00
Ludovic Courtès
8684029d21 Have `@abort' honor VM changes by winds.
* libguile/control.c (scm_c_abort): Update VM after the `scm_dowinds'
  call.

* test-suite/tests/control.test ("the-vm"): New test prefix.
2010-09-27 01:07:21 +02:00
Andy Wingo
1c05a2a16d use scm_malloc_pointerless to alloc aligned blocks in fallback
* libguile/continuations.c (SCM_DECLARE_STATIC_ALIGNED_ARRAY)
  (SCM_STATIC_ALIGNED_ARRAY)
* libguile/control.c (SCM_DECLARE_STATIC_ALIGNED_ARRAY)
  (SCM_STATIC_ALIGNED_ARRAY): Tweak backslashes. Use
  scm_malloc_pointerless to ensure alignment.
2010-07-17 13:31:06 +02:00
Ludovic Courtès
1880c97df1 Fix parenthesizing of the `ROUND_UP' macro; factorize.
* libguile/_scm.h (ROUND_UP): New macro.

* libguile/continuations.c (ROUND_UP): Remove.

* libguile/control.c (ROUND_UP): Remove.

* libguile/foreign.c (ROUND_UP): Remove.
2010-05-30 22:41:36 +02:00
Andy Wingo
9f07451836 add abort to unknown prompt test
* libguile/control.c (scm_c_abort): Change error string if a prompt
  isn't found.

* test-suite/tests/control.test ("abort to unknown prompt"): New test.
2010-03-11 22:36:15 +01:00
Andy Wingo
c6a32a2cd5 remove internal treatment of default prompt tag, it seems there was no need
* libguile/control.h (scm_sys_default_prompt_tag):
* libguile/control.c (scm_init_control): Remove the logic that defined
  %default-prompt-tag.
  (scm_c_abort): Remove check for default prompt tag, it wasn't useful.

* libguile/throw.c (sym_pre_init_catch_tag): Define as the pre-init
  prompt tag.
  (pre_init_catch, pre_init_throw): Use sym_pre_init_catch_tag.

* module/ice-9/boot-9.scm (default-prompt-tag): Define as a simple
  value, not a fluid. Perhaps we can expose it as a fluid later.
2010-03-11 22:31:29 +01:00
Andy Wingo
2150e9a84a partial continuations print as #<partial-continuation ...>
* libguile/control.c (reify_partial_continuation):
* libguile/programs.c (scm_i_program_print):
* libguile/programs.h (SCM_F_PROGRAM_IS_PARTIAL_CONTINUATION)
  (SCM_PROGRAM_IS_PARTIAL_CONTINUATION): Distinguish partial
  continuations from full continuations.
2010-03-04 13:14:43 +01:00
Andy Wingo
bbb2ecd1d1 add printers for prompts and with-fluids objects
* libguile/control.c:
* libguile/control.h (scm_i_prompt_print):
* libguile/fluids.c:
* libguile/fluids.h (scm_i_with_fluids_print):
* libguile/print.c (iprin1): Add printers for prompts and with-fluids
  objects.
2010-03-04 13:14:43 +01:00
Ken Raeburn
69c9600678 Use libguile/control.x explicitly. 2010-03-02 00:41:26 -05: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
b8af64db76 simplify handling of nonlocal prompt returns from c
* libguile/control.h:
* libguile/control.c (scm_i_prompt_pop_abort_args_x): New helper.

* libguile/eval.c (eval): Use the new helper.
2010-02-25 20:59:55 +01:00
Andy Wingo
211fcbc8cd fix escape-only prompts
* libguile/control.c (scm_c_make_prompt): Whoops, set the escape-only
  flag properly here.
2010-02-24 23:19:41 +01:00
Andy Wingo
3ccee39194 add %default-prompt-tag, and error (not abort()) on an abort to bad tag
* libguile/init.c (scm_i_init_guile): Call scm_init_control after
  initing fluids.
* libguile/control.h (scm_sys_default_prompt_tag): New internal var.
* libguile/control.c (scm_c_abort): If abort is called for an unknown
  tag, raise an exception, except if the tag was the default prompt tag,
  in which case really abort -- to prevent recursion when some other
  patches land.
  (scm_init_control): Define %default-prompt-tag in the default
  environment.
2010-02-24 18:55:34 +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
6d804376e9 record IP in partial continuations
* libguile/control.c (reify_partial_continuation): Assert some
  invariants, and record the IP as the MVRA of the continuation.
2010-02-24 16:56:05 +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
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
adaf86ec49 connect a few more wires to promptenstein
* 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-02-08 12:38:18 +01:00
Andy Wingo
b9c100d008 add @control and @prompt stub primitives
* libguile/Makefile.am:
* libguile/control.c:
* libguile/control.h:
* libguile/init.c: Add stub @control and @prompt primitives, for use
  when bootstrapping (ice-9 control).
2010-01-31 20:40:24 +01:00