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

235 commits

Author SHA1 Message Date
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
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
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
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
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
4f66bcdeff initial VM support for delimited continuations and dynamic-wind
* 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-31 20:40:21 +01:00
Andy Wingo
7055591c2e vm.c uses scm_c_take_bytevector instead of scm_take_u8vector
* libguile/vm.c (really_make_boot_program): Use scm_c_take_bytevector to
  avoid loading srfi-4 at boot time.
2010-01-14 13:55:50 +01:00
Thien-Thi Nguyen
4168aa4675 Add cast in `make_vm' to silence compiler warning.
* libguile/vm.c (make_vm): Add cast for .stack_base assignment.

Signed-off-by: Thien-Thi Nguyen <ttn@gnuvola.org>
2010-01-09 23:27:28 +01:00
Andy Wingo
75c3ed2820 smobs are applied with vm trampoline procedures
* 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-09 14:21:03 +01:00
Andy Wingo
cc7005bc37 remove scm_tc7_gsubr
* libguile/tags.h (scm_tc7_gsubr): Return to the pool of unused tc7s, as
  there are no more gsubrs. Yay :)

* libguile/programs.h (SCM_F_PROGRAM_IS_PRIMITIVE):
  (SCM_PROGRAM_IS_PRIMITIVE): New flag and accessor.

* libguile/gsubr.c (create_gsubr):
* libguile/snarf.h (SCM_STATIC_PROGRAM): Give subrs a PRIMITIVE flag.

* libguile/smob.h:
* libguile/smob.c (scm_i_smob_arity): New internal procedure. Uses the
  old GSUBR type macros, local to the file.

* libguile/procprop.c (scm_i_procedure_arity): Call out to
  scm_i_smob_arity, and remove a gsubr case.

* libguile/gc.c (scm_i_tag_name):
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (scm_class_of):
* libguile/vm.c (apply_foreign):
* libguile/hash.c (scm_hasher):
* libguile/debug.c (scm_procedure_name):
* libguile/print.c (iprin1): Remove gsubr cases.

* libguile/gsubr.h (SCM_PRIMITIVE_P): Fix to work with the new VM
  program regimen.
  (SCM_GSUBR_TYPE, SCM_GSUBR_MAKTYPE, SCM_GSUBR_MAX, SCM_GSUBR_REQ)
  (SCM_GSUBR_OPT, SCM_GSUBR_REST): Remove these macros, that are no
  longer useful.
* libguile/gsubr.c (scm_i_gsubr_apply, scm_i_gsubr_apply_list)
  (scm_i_gsubr_apply_array): Remove internal gsubr application
  functions.
2010-01-07 23:49:39 +01:00
Andy Wingo
6f3b0cc29e tc7 tags for vm-related data
* libguile/tags.h (scm_tc7_frame, scm_tc7_objcode, scm_tc7_vm)
  (scm_tc7_vm_cont): Take more tc7s for VM-related data structures.

* libguile/evalext.c (scm_self_evaluating_p):
* libguile/gc.c (scm_i_tag_name):
* libguile/goops.c (scm_class_of, create_standard_classes):
* libguile/print.c (iprin1): Add cases for the new tc7s.

* libguile/frames.c:
* libguile/frames.h:
* libguile/objcodes.c:
* libguile/objcodes.h:
* libguile/vm.c:
* libguile/vm.h: Desmobify.

* libguile/vm.c (scm_vm_apply): Export to Scheme, because VM objects are
  no longer applicable.

* module/system/repl/command.scm (profile):
* module/system/vm/trace.scm (vm-trace):
* module/system/vm/vm.scm (vm-load): Call vm-apply to run a program in a
  VM instead of treating the VM as applicable.
2010-01-07 23:42:41 +01:00
Andy Wingo
a6029b97ea properly integrate vm bootstrapping into init.c
* libguile/Makefile.am (modinclude_HEADERS):
* libguile/vm-bootstrap.h: Remove vm-bootstrap.h.

* libguile/frames.c: No more vm-bootstrap.h.

* libguile/instructions.c (scm_init_instructions):
* libguile/objcodes.c (scm_init_objcodes):
* libguile/programs.c (scm_init_programs): No need to call
  scm_bootstrap_vm, init.c does that for us.

* libguile/vm.c (scm_bootstrap_vm): No need call e.g.
  scm_bootstrap_frames, init.c does that. Remove a twice-calling guard,
  should be unnecessary. Don't define the load-compiled subr here.

* libguile/load.c (scm_init_load): Define the load-compiled subr here.

* libguile/vm.h: Declare scm_bootstrap_vm here.

* libguile/init.c (scm_i_init_guile): Properly integrate VM
  bootstrapping into this file.
2010-01-07 23:42:41 +01:00
Andy Wingo
f6a8e79197 keyword arg errors throw to 'keyword-argument-error
* libguile/vm-engine.c (VM_NAME): Keyword arg errors are now thrown to
  'keyword-argument-error.

* libguile/vm.c: Define sym_keyword_argument_error, and statically
  allocate some other symbols.

* module/ice-9/optargs.scm (parse-lambda-case): Throw to
  'keyword-argument-error in kwarg error cases.

* module/ice-9/psyntax.scm (build-lambda-case): Remove a couple
  workarounds for the old memoizer. Throw to 'wrong-number-of-args if
  the lambda-case fails to parse.

* module/ice-9/psyntax-pp.scm: Regenerated.

* test-suite/tests/optargs.test: Update expected exceptions.
2009-12-23 22:59:12 +01:00
Andy Wingo
7656f19446 rework vm tracing
* libguile/vm-engine.c (VM_NAME): Engines take the VM itself (not the
  vp), so they can pass the VM to hooks. No more hook args, we dispatch
  without them.

* libguile/vm-engine.h (RUN_HOOK): Dispatch the hook if the trace level
  is positive (instead of if the hook is there). Don't cache registers
  on return from the dispatch.

* libguile/vm.h:
* libguile/vm.c (vm_dispatch_hook): Don't bother with a dynwind; instead
  decrement the trace level when going into a hook, and if we have a
  nonlocal exit, the trace level never gets incremented again. Worse is
  better.
  (make_vm, scm_vm_trace_level, scm_set_vm_trace_level_x): New concept,
  trace level. If positive, we run the hooks, otherwise we don't. Should
  work. Removed scm_vm_trace_frame, I don't think that was the right way
  to do it.

* module/system/vm/vm.scm: Replace vm-trace-frame with vm-trace-level
  and set-vm-trace-level!; the hooks actually get the frame as an
  argument now.
2009-12-21 21:57:20 +01:00
Ludovic Courtès
bc4adf1739 Remove unneeded #include <assert.h>.
* libguile/backtrace.c, libguile/eval.c, libguile/gc.c,
  libguile/goops.c, libguile/memoize.c, libguile/threads.c,
  libguile/uniform.c, libguile/vm.c,
  test-suite/standalone/test-conversion.c,
  test-suite/standalone/test-list.c: Don't include <assert.h>.
2009-12-15 20:20:38 +01:00
Ludovic Courtès
3dbbe28dfd Don't use GCC zero-length arrays.
* 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-15 01:01:16 +01:00
Andy Wingo
6c20a0b34b vm no longer measures bogoclock or times, relies on os for that
* 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-11 12:39:02 +01:00
Andy Wingo
f39448c5a3 remove a bunch of needless scm_permanent_object calls
* libguile/array-handle.c:
* libguile/bytevectors.c:
* libguile/deprecated.c:
* libguile/eval.c:
* libguile/feature.c:
* libguile/filesys.c:
* libguile/gc.c:
* libguile/gdbint.c:
* libguile/goops.c:
* libguile/instructions.c:
* libguile/load.c:
* libguile/modules.c:
* libguile/numbers.c:
* libguile/options.c:
* libguile/ports.c:
* libguile/scmsigs.c:
* libguile/srcprop.c:
* libguile/srfi-4.c:
* libguile/stacks.c:
* libguile/threads.c:
* libguile/vm.c: Remove calls to scm_permanent_object, as they are no
  longer needed with the BDW GC.
2009-12-05 11:32:50 +01:00
Andy Wingo
314b87163e eval.c closures are now applicable smobs, not tc3s
* libguile/debug.c (scm_procedure_name): Remove a SCM_CLOSUREP case and
  some dead code.
  (scm_procedure_module): Remove. This was introduced a few months ago
  for the hygienic expander, but now it is no longer needed, as the
  expander keeps track of this information itself.

* libguile/debug.h: Remove scm_procedure_module.

* libguile/eval.c: Instead of using tc3 closures, define a "boot
  closure" applicable smob type, and represent closures with that. The
  advantage is that after eval.scm is compiled, boot closures take up no
  address space (besides a smob number) in the runtime, and require no
  special cases in procedure dispatch.

* libguile/eval.h: Remove the internal functions scm_i_call_closure_0
  and scm_closure_apply, and the public function scm_closure.

* libguile/gc.c (scm_storage_prehistory): No tc3_closure displacement
  registration.
  (scm_i_tag_name): Remove closure case, and a dead cclo case.

* libguile/vm.c (apply_foreign):
* libguile/print.c (iprin1):
* libguile/procs.c (scm_procedure_p, scm_procedure_documentation);
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (scm_class_of): Remove tc3_closure/tcs_closure cases.
* libguile/hash.c (scm_hasher):

* libguile/hooks.c (scm_add_hook_x): Use new scm_i_procedure_arity.

* libguile/macros.c (macro_print): Print all macros using the same code.
  (scm_macro_transformer): Return any procedure, not just programs.

* libguile/procprop.h:
* libguile/procprop.c (scm_i_procedure_arity): Instead of returning a
  list that the caller has to parse, have the same prototype as
  scm_i_program_arity. An incompatible change, but it's an internal
  function anyway.
  (scm_procedure_properties, scm_set_procedure_properties)
  (scm_procedure_property, scm_set_procedure_property): Remove closure
  cases, and use scm_i_program_arity for arity.

* libguile/procs.h (SCM_CLOSUREP, SCM_CLOSCAR, SCM_CODE)
  (SCM_CLOSURE_NUM_REQUIRED_ARGS, SCM_CLOSURE_HAS_REST_ARGS)
  (SCM_CLOSURE_BODY, SCM_PROCPROPS, SCM_SETPROCPROPS, SCM_ENV)
  (SCM_TOP_LEVEL): Remove these macros that pertain to boot closures
  only. Only eval.c should know abut boot closures.
* libguile/procs.c (scm_closure_p): Remove this function. There is a
  simple stub in deprecated.scm now.
  (scm_thunk_p): Use scm_i_program_arity.
* libguile/tags.h (scm_tc3_closure): Remove. Yay, another tc3 to play
  with!
  (scm_tcs_closures): Remove.

* libguile/validate.h (SCM_VALIDATE_CLOSURE): Remove.

* module/ice-9/deprecated.scm (closure?): Add stub.

* module/ice-9/documentation.scm (object-documentation)
* module/ice-9/session.scm (help-doc, arity)
* module/oop/goops.scm (compute-getters-n-setters)
* module/oop/goops/describe.scm (describe)
* module/system/repl/describe.scm (display-object, display-type):
  Remove calls to closure?.
2009-12-04 19:20:11 +01:00
Andy Wingo
f36878ba2d remove cxrs
* libguile/pairs.h:
* libguile/pairs.c: Previously scm_cdadr et al were implemented as
  #defines that called scm_i_chase_pairs, and the Scheme-exposed
  functions themselves were cxr subrs, which got special help in the
  interpreter. Since now the special help is unnecessary (because the
  compiler inlines and expands calls to car, cdadr, etc), the complexity
  is a loss. So just implement cdadr etc using normal functions. There's
  an advantage too, in that the compiler can unroll the cxring, reducing
  branches.

* libguile/tags.h (scm_tc7_cxr): Remove this tag.
  (scm_tcs_subrs): Now there's only one kind of subr, yay!

* libguile/debug.c (scm_procedure_name)
* libguile/evalext.c (scm_self_evaluating_p)
* libguile/gc.c (scm_i_tag_name)
* libguile/goops.c (scm_class_of)
* libguile/hash.c (scm_hasher)
* libguile/print.c (iprin1)
* libguile/procprop.c (scm_i_procedure_arity)
* libguile/procs.c (scm_procedure_p, scm_subr_p)
  (scm_make_procedure_with_setter)
* libguile/vm.c (apply_foreign): Remove cxr cases. Replace uses of
  scm_tcs_subrs with scm_tc7_gsubr.
2009-12-04 16:39:34 +01:00
Andy Wingo
8a1f4f98e1 remove rpsubrs
* libguile/tags.h: Remove rpsubrs (I chose to interpret the terse name
  as "recursive predicate subrs"). Just use gsubrs with rest arguments,
  or do a fold yourself.

* libguile/array-map.c (scm_i_array_equal_p): Do the comparison in
  order, why not.

* libguile/chars.c:
* libguile/eq.c:
* libguile/numbers.c:
* libguile/strorder.c: Add 0,2,1 gsubr wrappers for rpsubrs like eq?, <,
  etc.

* libguile/goops.c (scm_class_of)
* libguile/procprop.c (scm_i_procedure_arity)
* libguile/procs.c (scm_thunk_p)
* libguile/vm.c (apply_foreign): Remove rpsubr cases.

* test-suite/tests/numbers.test ("=", "<"): Turn a couple xfails into
  passes.
2009-12-04 13:05:00 +01:00
Andy Wingo
31d845b4bc remove asubrs
* libguile/tags.h (scm_tcs_subrs, scm_tc7_asubr): Remove definitions.

* libguile/goops.c (scm_class_of)
* libguile/procprop.c (scm_i_procedure_arity)
* libguile/procs.c (scm_thunk_p)
* libguile/vm.c (apply_foreign): Remove cases for asubrs.

* libguile/array-map.c: Gut all of the optimizations, because there are
  no more asubrs, soon won't be rpsubrs, and all of this should happen
  on the Scheme level, ideally.
2009-12-03 17:05:14 +01:00
Andy Wingo
a941cde9e5 simplify apply_foreign
* libguile/vm.c (apply_foreign): Simplify.
2009-12-03 15:55:54 +01:00
Andy Wingo
b04ab0c624 remove scm_tc7_dsubr
* libguile/tags.h: Remove scm_tc7_dsubr. There are no more users of
  this.

* libguile/array-map.c:
* libguile/eval.c:
* libguile/eval.i.c:
* libguile/goops.c:
* libguile/procprop.c:
* libguile/procs.h: Remove all dsubr cases.
2009-12-03 15:33:09 +01:00
Andy Wingo
df338a2264 remove tc7_subr_* and tc7_lsubr_*
* libguile/tags.h: Remove tc7 #defines for subrs, replacing them with
  placeholders. These were public, but hopfully unused. I don't see how
  to usefully deprecate them.

* libguile/array-map.c (scm_array_map_x): Remove special cases for
  certain subr types. This might make things slower for the moment,
  otoh, native compilation should moot that question.

* libguile/eval.i.c:
* libguile/eval.c: Remove subr-handling cases. To regain this speed and
  more won't have to wait for native compilation, though -- this change
  smooths the way for subr dispatch in the VM.

* libguile/gsubr.c (scm_i_gsubr_apply): Fix a bug in which we didn't
  detect too-many-arguments. This would only show up when using ceval,
  as only ceval called this function.

* test-suite/tests/ramap.test ("array-map!"): Change the expected
  exception if passed a procedure of the wrong arity. It now gives
  wrong-num-args.
  more won't have to wait for native compilation, though -- this change
  smooths the way for subr dispatch in the VM.

* libguile/goops.c (scm_class_of): Remove subr cases. No speed
  implication.

* libguile/objects.c (scm_valid_object_procedure_p): Remove this public
  but undocumented, and useless, function. I do not think this will
  affect anyone at all.
  (scm_set_object_procedure_x): Replace a call to
  scm_valid_object_procedure_p with scm_procedure_p, and actually wrap
  with a scm_is_true.

* module/oop/goops.scm (initialize-object-procedure): Don't call
  valid-object-procedure?.
2009-12-03 15:22:07 +01:00
Andy Wingo
aa3f69519f replace frame implementation with VM frames
* libguile/stacks.h: Rework so that a stack doesn't copy information out
  of VM frames, it just holds onto a VM frame, along with the stack id
  and length. VM frames are now the only representation of frames in
  Guile.
  (scm_t_info_frame, SCM_FRAME_N_SLOTS, SCM_FRAME_REF, SCM_FRAME_NUMBER)
  (SCM_FRAME_FLAGS, SCM_FRAME_SOURCE, SCM_FRAME_PROC, SCM_FRAME_ARGS)
  (SCM_FRAME_PREV, SCM_FRAME_NEXT)
  (SCM_FRAMEF_VOID, SCM_FRAMEF_REAL, SCM_FRAMEF_PROC)
  (SCM_FRAMEF_EVAL_ARGS, SCM_FRAMEF_OVERFLOW)
  (SCM_FRAME_VOID_P, SCM_FRAME_REAL_P, SCM_FRAME_PROC_P)
  (SCM_FRAME_EVAL_ARGS_P, SCM_FRAME_OVERFLOW_P): Remove these macros
  corresponding to the old frame implementation.
  (scm_frame_p scm_frame_source, scm_frame_procedure)
  (scm_frame_arguments): These definitions are now in frames.h.
  (scm_last_stack_frame): Remove declaration of previously-removed
  constructor. Probably should re-instate it though.
  (scm_frame_number, scm_frame_previous, scm_frame_next)
  (scm_frame_real_p, scm_frame_procedure_p, scm_frame_evaluating_args_p)
  (scm_frame_overflow_p) : Remove these procedures corresponding to the
  old stack implementation.

* libguile/stacks.c: Update for new frames implementation.

* libguile/frames.h:
* libguile/frames.c: Rename functions operating on VM frames to have a
  scm_frame prefix, not scm_vm_frame -- because they really are the only
  frames we have. Rename corresponding Scheme functions too, from
  vm-frame-foo to frame-foo.

* libguile/deprecated.h: Remove scm_stack and scm_info_frame data types.

* libguile/vm.c (vm_dispatch_hook): Adapt to scm_c_make_frame name
  change.

* module/system/vm/frame.scm: No need to export functions provided
  frames.c now, as we load those procedures into the default environment
  now. Rename functions, and remove a couple of outdated, unused
  functions. The bottom half of this file is still bitrotten, though.

* libguile/backtrace.c: Rework to operate on the new frame
  representation. Also fix a bug displaying file names for compiled
  procedures.

* libguile/init.c: Load the VM much earlier, just because we can. Also
  it allows us to have frames.[ch] loaded in time for stacks to be
  initialized, so that scm_frame_arguments can do the right thing.
2009-12-03 14:42:51 +01:00
Andy Wingo
14aa25e410 remove debug frames
* libguile/debug.h (scm_t_debug_frame): Remove this type, as it was
  internal to the old evaluator.
  (SCM_EVALFRAME, SCM_APPLYFRAME, SCM_VOIDFRAME, SCM_MACROEXPF)
  (SCM_TAILREC, SCM_TRACED_FRAME, SCM_ARGS_READY, SCM_DOVERFLOW)
  (SCM_MAX_FRAME_SIZE, SCM_FRAMETYPE)
  (SCM_EVALFRAMEP, SCM_APPLYFRAMEP, SCM_VOIDFRAMEP, SCM_MACROEXPFP)
  (SCM_TAILRECP, SCM_TRACED_FRAME_P, SCM_ARGS_READY_P, SCM_OVERFLOWP)
  (SCM_SET_MACROEXP, SCM_SET_TAILREC, SCM_SET_TRACED_FRAME)
  (SCM_SET_ARGSREADY, SCM_SET_OVERFLOW)
  (SCM_CLEAR_MACROEXP, SCM_CLEAR_TRACED_FRAME, SCM_CLEAR_ARGSREADY):
  Remove macro accessors to scm_t_debug_frame.
  (SCM_DEBUGOBJP, SCM_DEBUGOBJ_FRAME, SCM_SET_DEBUGOBJ_FRAME):
  (scm_debug_object_p, scm_make_debugobj): Remove debugobj accessors.
  (scm_i_unmemoize_expr): Remove unused declaration.

* libguile/debug.c (scm_debug_options): No more max limit on frame
  sizes.
  (scm_start_stack): Just call out to scm_vm_call_with_new_stack.
  (scm_debug_object_p, scm_make_debugobj, scm_init_debug): No more
  debugobj smob type.

* libguile/deprecated.h:
* libguile/deprecated.c (scm_i_deprecated_last_debug_frame)
  (scm_last_debug_frame): Remove deprecated debug-frame bits.

* libguile/stacks.c (scm_make_stack): Rework this function and its
  dependents to only walk VM frames.
  (scm_stack_id): Call out to the holder of the VM frame in question,
  which should be a VM or a VM continuation, for the stack ID. Currently
  this bit is stubbed out.
  (scm_last_stack_frame): Removed. It seems this is mainly useful for a
  debugger, and we need to rewrite the debugger to work on the Scheme
  level.

* test-suite/tests/continuations.test ("continuations"): Remove test for
  last-stack-frame.

* libguile/continuations.h (struct scm_t_contregs):
* libguile/continuations.c (scm_make_continuation):
  (copy_stack_and_call, scm_i_with_continuation_barrier): No need to
  save and restore debug frames.

* libguile/threads.h (scm_i_thread): Don't track debug frames.
  (scm_i_last_debug_frame, scm_i_set_last_debug_frame): Remove macro
  accessors.

* libguile/threads.c (guilify_self_1): Don't track debug frames.

* libguile/throw.c: No need to track debug frames in a jmpbuf.

* libguile/vm-engine.c (vm_engine, VM_PUSH_DEBUG_FRAMES): Don't push
  debug frames.

* libguile/vm.h:
* libguile/vm.c (scm_vm_call_with_new_stack): New function. Currently
  stubbed out though.
2009-12-03 11:03:39 +01:00
Andy Wingo
67e2d80a6a apply goes to the vm, not the interpreter
* libguile/eval.c (eval): Call scm_vm_apply instead of apply.
  (apply): Deleted, no longer referenced. Heh.
  (scm_apply): Call scm_vm_apply.

* libguile/init.c (scm_i_init_guile): Bootstrap the VM before the
  evaluator.

* libguile/vm.c (scm_vm_apply): Actually it's not necessary that the
  procedure is a program; so that's cool, relax the check.
2009-12-01 22:20:03 +01:00
Andy Wingo
23f276dea7 first step to make the vm stop calling the interpreter
* libguile/eval.h:
* libguile/eval.c (scm_closure_apply): New function, applies a closure.
  Won't be necessary in the future, but for now here it is, with
  internal linkage.

* libguile/gsubr.h:
* libguile/gsubr.c (scm_i_gsubr_apply_array): New function, applies a
  gsubr to an array of values, potentially extending that array for
  optional arguments and rest arguments and such.

* libguile/vm.c (apply_foreign): New function, applies a foreign
  function to arguments on the stack, in place.

* libguile/vm-i-system.c (call): Add a case for procedures-with-setters
  (will go away when they are applicable structs). Instead of calling
  the evaluator for foreign functions, call apply_foreign.
2009-12-01 21:59:42 +01:00
Ludovic Courtès
8b22ed7abd Remove remaining uses of discouraged constructs, really.
* libguile/throw.c, libguile/vm-engine.h, libguile/vm-i-system.c,
  libguile/vm.c:  Replace uses of discouraged constructs by their
  current counterparts.
2009-11-28 22:52:16 +01:00
Ludovic Courtès
5c8cefe591 Remove remaining uses of discouraged constructs.
* libguile/frames.c, libguile/instructions.c, libguile/objcodes.c,
  libguile/programs.c, libguile/throw.c, libguile/vm-i-scheme.c,
  libguile/vm.c:  Replace uses of discouraged constructs by their
  current counterparts.
2009-11-28 15:11:31 +01:00
Ludovic Courtès
9bd48cb17b Remove uses of discouraged constructs.
* libguile/vm-i-scheme.c, libguile/vm-i-system.c, libguile/vm.c: Replace
  uses of discouraged constructs by their current counterparts.
2009-11-25 23:46:17 +01:00
Ludovic Courtès
7f991c7d32 Fix C99-style declarations after statements.
* libguile/eval.i.c (ceval): Move declarations before statements.

* libguile/read.c (scm_read_extended_symbol): Likewise.

* libguile/struct.c (scm_make_struct_layout): Likewise.

* libguile/threads.c (fat_mutex_unlock): Likewise.

* libguile/vm-i-system.c (br_if_nargs_ne, br_if_nargs_lt): Likewise.

* libguile/vm.c (make_vm): Likewise.
2009-11-17 23:13:58 +01:00
Ludovic Courtès
6f6f0dac01 Fix C99-style comments.
* libguile/generalized-vectors.c, libguile/programs.c, libguile/vm.c:
  Replace C99-style comments by plain old C89 comments.
2009-11-08 01:13:46 +01:00
Andy Wingo
56164a5a6c de-nargs struct scm_objcode; procedure-property refactor
* libguile/objcodes.h (struct scm_objcode): Remove nargs, nrest, and
  nlocs, as they are no longer needed. Also obviates the need for a
  padding word.

* libguile/procs.c (scm_thunk_p): Use scm_i_program_arity for programs.

* libguile/procprop.c (scm_i_procedure_arity): Use scm_i_program_arity
  for programs.
  (scm_procedure_properties, scm_set_procedure_properties_x)
  (scm_procedure_property, scm_set_procedure_property_x): Rework so that
  non-closure properties are stored directly in a weak hash, instead of
  needing a weak hash of "stand-in" closures to hold the properties. Fix
  docstrings also.

* libguile/root.h (scm_stand_in_procs): Remove from the scm_sys_protects
  set. Actually with libGC, we should be able to store the elements of
  scm_sys_protects directly as global variables.
* libguile/gc.c (scm_init_storage): Remove scm_stand_in_procs
  initialization.

* libguile/programs.c (scm_i_program_arity): New private accessor, tries
  to determine the "minimum arity" of a program.

* libguile/vm.c (really_make_boot_program): Adapt to changes in
  struct scm_objcode.

* module/language/assembly.scm (*program-header-len*, byte-length):
* module/language/assembly/compile-bytecode.scm (write-bytecode):
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
* module/language/assembly/disassemble.scm (disassemble-load-program):
  Adapt to changes in objcode.

* module/system/xref.scm (program-callee-rev-vars): Adapt to changes in
  assembly.

* module/language/glil.scm: Remove nargs, nrest, and nlocs from
  glil-program.

* module/language/glil/compile-assembly.scm (make-meta, glil->assembly):
* module/language/glil/decompile-assembly.scm (decompile-toplevel):
  (decompile-load-program): Adapt to changes in GLIL and assembly.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Adapt to
  changes in GLIL.

* test-suite/tests/asm-to-bytecode.test: Adapt to assembly and bytecode
  changes.
* test-suite/tests/tree-il.test: Adapt to GLIL changes.
2009-10-23 14:51:19 +02:00
Andy Wingo
97fcf583b7 jumps encoded using 24 bits, not 19; blocks no longer aligned
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (FETCH_OFFSET, BR): Labels are no longer 8-byte
  aligned; instead, jumps are encoded into 3 bytes instead of 2.
  (br, br-if, br-if-not, br-if-eq, br-if-not-eq, br-if-null)
  (br-if-not-null, mv-call): Adapt for new length of br instructions (3
  bytes instead of 2).

* libguile/vm.c (really_make_boot_program): Adapt hand-coded bytecode
  for new offset regime.

* module/language/assembly.scm (align-block): No alignment necessary.

* module/language/assembly/compile-bytecode.scm (write-bytecode): Write
  out breaks as 24-bit relative jumps.
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
  Decompile break instructions.
2009-10-16 15:56:11 +02:00
Neil Jerram
ba20f78a6c Fix omission of VM frames from backtrace
From the time when a #<program> was a SMOB, really_make_boot_program
in vm.c was still using SCM_SET_SMOB_FLAGS to set the
SCM_F_PROGRAM_IS_BOOT flag - which meant that it was setting flag
1<<32 :-) which obviously was then missed by the SCM_PROGRAM_IS_BOOT
calls in stacks.c.

* libguile/programs.h (SCM_F_PROGRAM_IS_BOOT): Use a less significant
  bit for this flag, now that programs use a tc7 type.

* libguile/vm.c (really_make_boot_program): Don't use
  SCM_SET_SMOB_FLAGS, now that programs aren't SMOBs.
2009-09-17 00:19:47 +01:00
Ludovic Courtès
8071c4907f Make the precise stack mark procedure more robust.
* libguile/vm.c (vm_stack_mark): Return if VM is NULL.
2009-09-15 00:40:00 +02:00
Ludovic Courtès
1c44468d77 Rename "boehm-gc.h" to "bdw-gc.h"; add to the distribution.
* libguile/Makefile.am (modinclude_HEADERS): Add `bdw-gc.h'.

* libguile/bdw-gc.h: Rename from "boehm-gc.h"; users updated.  Update to
  LGPLv3+.
2009-09-14 00:42:25 +02:00
Ludovic Courtès
d7e7a02a62 Fix leaky behavior of `scm_take_TAGvector ()'.
* libguile/srfi-4.c (free_user_data): New function.

* libguile/srfi-4.i.c (scm_take_TAGvector): Register `free_user_data ()'
  as a finalizer for DATA.

* libguile/objcodes.c (scm_objcode_to_bytecode): Allocate with
  `scm_malloc ()' since the memory taken by `scm_take_u8vector ()' will
  eventually be free(3)d.

* libguile/vm.c (really_make_boot_program): Likewise.
2009-09-01 23:53:58 +02:00
Ludovic Courtès
7af531508c Merge branch 'master' into boehm-demers-weiser-gc
Conflicts:
	libguile/Makefile.am
	libguile/bytevectors.c
	libguile/gc-card.c
	libguile/gc-mark.c
	libguile/programs.c
	libguile/srcprop.c
	libguile/srfi-14.c
	libguile/symbols.c
	libguile/threads.c
	libguile/unif.c
	libguile/vm.c
2009-08-28 19:16:46 +02:00
Andy Wingo
03e6c16596 reorder frame layout
* libguile/frames.h: Reorder the frame layout so the return address
  comes below the arguments.working
  (SCM_FRAME_SET_RETURN_ADDRESS, SCM_FRAME_SET_MV_RETURN_ADDRESS): New
  macros.

* libguile/frames.c (scm_vm_frame_arguments): Use the macros to access
  the arguments.

* libguile/vm-engine.c (vm_engine): Fix for new calling convention.

* libguile/vm-engine.h (INIT_FRAME): New macro. Does part of what
  NEW_FRAME used to do.

* libguile/vm-i-system.c (call, mv-call): Shuffle args up to make room
  for the stack, and adapt to new calling convention.
  (goto/args): Shuffling down is easier now.
  (return, return/args): Adapt to new frame layout.

* libguile/vm.c (vm_mark_stack): Adapt to new frame layout, and the
  possibility of there being crap on the stack.
  (really_make_boot_program): Remove extraneous comment.
2009-08-20 18:52:49 +02:00
Ludovic Courtès
78747ac6fb Relax assumptions made in the precise VM stack marking procedure.
* libguile/vm.c (vm_stack_mark): Change assertions into checks to
  determine whether VM points to a sane (initialized) object.  The
  assumption previously was that free-list elements would be zeroed, as
  implied by the comment in <gc/gc_mark.h>, but this doesn't appear to
  be the case.
2009-08-20 12:18:57 +02:00
Ludovic Courtès
e3eb628d88 Implement precise marking of the VM stack.
Suggested by Andy Wingo.

* libguile/vm.c (VM_ENABLE_PRECISE_STACK_GC_SCAN): New macro.
  (vm_stack_gc_kind): New variable.
  (make_vm)[VM_ENABLE_PRECISE_STACK_GC_SCAN]: Use `GC_generic_malloc ()'
  to allocate the stack.
  (vm_stack_mark): New function.
  (scm_bootstrap_vm)[VM_ENABLE_PRECISE_STACK_GC_SCAN]: Initialize
  `vm_stack_gc_kind'.
2009-08-20 01:56:47 +02:00
Ludovic Courtès
75d315e1fb Fix bogus computation of `vm->stack_limit'.
* libguile/vm.c (make_vm): Remove bogus "- 3" when computing
  `stack_size'.

* libguile/vm-engine.h (CHECK_OVERFLOW): Change accordingly.
2009-08-20 01:20:58 +02:00
Ludovic Courtès
fbb857a472 Merge branch 'master' into boehm-demers-weiser-gc
Conflicts:
	lib/Makefile.am
	libguile/Makefile.am
	libguile/frames.c
	libguile/gc-card.c
	libguile/gc-freelist.c
	libguile/gc-mark.c
	libguile/gc-segment.c
	libguile/gc_os_dep.c
	libguile/load.c
	libguile/macros.c
	libguile/objcodes.c
	libguile/programs.c
	libguile/strings.c
	libguile/vm.c
	m4/gnulib-cache.m4
	m4/gnulib-comp.m4
	m4/inline.m4
2009-08-18 00:06:45 +02:00
Andy Wingo
e5dc27b86d increase range of relative jumps by aligning blocks to 8-byte boundaries
* libguile/objcodes.c (OBJCODE_COOKIE): Bump again, as our jump offsets
  are now multiplied by 8.

* libguile/vm-i-system.c (BR): Interpret the 16-bit offset as a relative
  jump to the nearest 8-byte-aligned block -- increasing relative jump
  range from +/-32K to +/-240K.
  (mvra): Do the same for the mvra jump.

* libguile/vm.c (really_make_boot_program): Align the mvra.

* module/language/assembly.scm (align-block): New export, for aligning
  blocks.

* module/language/assembly/compile-bytecode.scm (write-bytecode): Emit
  jumps to the nearest 8-byte-aligned block. Effectively our range is 18
  bits in either direction. I would like to do this differently -- have
  long-br and long-br-if, and all the other br instructions go to 8 bits
  only. But the assembler doesn't have an appropriate representation to
  allow me to do this yet, so for now this is what we have.

* module/language/assembly/decompile-bytecode.scm (decode-load-program):
  Decode the 19-bit jumps.
2009-07-26 14:01:56 +02:00
Andy Wingo
28b119ee3d make sure all programs are 8-byte aligned
* libguile/objcodes.c (OBJCODE_COOKIE): Bump objcode cookie, as we added
  to struct scm_objcode.
* libguile/objcodes.h (struct scm_objcode): Add a uint32 after metalen
  and before base, so that if the structure has 8-byte alignment, base
  will have 8-byte alignment too. (Before, base was 12 bytes from the
  start of the structure, now it's 16 bytes.)

* libguile/vm-engine.h (ASSERT_ALIGNED_PROCEDURE): Add a check that can
  be turned on with VM_ENABLE_PARANOID_ASSERTIONS.
  (CACHE_PROGRAM): Call ASSERT_ALIGNED_PROCEDURE.

* libguile/vm-i-system.c (long-local-ref): Add a missing semicolon.

* libguile/vm.c (really_make_boot_program): Rework to operate directly
  on a malloc'd buffer, so that the program will be 8-byte aligned.

* module/language/assembly.scm (*program-header-len*): Add another 4 for
  the padding.
  (object->assembly): Fix case in which we would return (make-int8 0)
  instead of (make-int8:0). This would throw off compile-assembly.scm's
  use of addr+.

* module/language/assembly/compile-bytecode.scm (write-bytecode): Write
  out the padding int.

* module/language/assembly/decompile-bytecode.scm (decode-load-program):
  And pop off the padding int too.

* module/language/glil/compile-assembly.scm (glil->assembly): Don't pack
  the assembly, assume that assembly.scm has done it for us. If a
  program has a meta, pad out the program so that meta will be aligned.

* test-suite/tests/asm-to-bytecode.test: Adapt to expect programs to
  have the extra 4-byte padding int.
2009-07-26 12:57:11 +02:00
Andy Wingo
51e9ba2f38 increase default stack size to 64 kilowords
* libguile/vm.c (VM_DEFAULT_STACK_SIZE): Increase to 64 kilowords.
  Really, we should simply add overflow handlers, but in the meantime,
  this will do.
2009-07-24 12:05:54 +02:00