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

168 commits

Author SHA1 Message Date
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
Andy Wingo
1d1cae0e2e continuations are vm procedures
* 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-08 13:00:54 +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
2d9260d12c add return/nvalues
* libguile/vm-i-system.c (return/nvalues): New instruction, like
  call/nargs.
2010-01-31 20:40:24 +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
0515661235 fix to variable-bound? instruction prototype
* libguile/vm-i-system.c (variable-bound?): Correctly declare as popping
  one item.
2010-01-27 21:47:01 +01:00
Andy Wingo
4d9130a5b7 implement foreign-call
* 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-26 22:56:41 +01:00
Andy Wingo
827dc8dcb6 renumber VM opcodes
* 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-26 22:56:41 +01:00
Andy Wingo
52fd9639fd foreign.h presents a more pointer-centric interface
* libguile/foreign.c:
* libguile/foreign.h: Rework interface to be more pointer-centric.
  Details are:
  (SCM_FOREIGN_TYPE_STRUCT, SCM_FOREIGN_TYPE_POINTER): Removed; now the
  pointer in a foreign is first-class. If it points to a native type
  like uint32, then it still has a tag; but if it points to something
  else, like a struct or a pointer or something, then its type is VOID
  (i.e., void*).
  (SCM_FOREIGN_POINTER): Rename from SCM_FOREIGN_OBJECT.
  (SCM_FOREIGN_VALUE_REF, SCM_FOREIGN_VALUE_SET): Rename from
  SCM_FOREIGN_OBJECT_REF and SCM_FOREIGN_OBJECT_SET, to indicate that
  they only work with value types.
  (SCM_FOREIGN_HAS_FINALIZER): Reserve a bit to indicate if the foreign
  pointer in question has a finalizer registered.
  (SCM_FOREIGN_LEN): For void* pointers, optionally store the length in
  bytes of the associated memory region.
  (SCM_FOREIGN_VALUE_P): Rename from SCM_FOREIGN_SIMPLE_P.
  (SCM_VALIDATE_FOREIGN_VALUE): Rename from SCM_VALIDATE_FOREIGN_SIMPLE.
  (scm_take_foreign_pointer): Rename from scm_c_take_foreign. Remove
  scm_c_from_foreign.
  (scm_foreign_type): New accessor.
  (scm_foreign_ref, scm_foreign_set_x): Take some optional args, used
  when dereferencing void pointers.

* libguile/dynl.h:
* libguile/dynl.c (scm_dynamic_pointer): New function, used by
  scm_dynamic_func. Adapt code to foreign.h changes.

* libguile/goops.c (scm_enable_primitive_generic_x)
  (scm_set_primitive_generic_x): Use the SCM_SET_SUBR_GENERIC macro.

* libguile/gsubr.c (create_gsubr): Adapt to API change.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Store the pointer
  directly, not indirected.

* libguile/snarf.h (SCM_DEFINE, SCM_IMMUTABLE_FOREIGN): Store subr
  pointers directly. Adapt to SCM_FOREIGN_TYPE_VOID change.

* libguile/vm-i-system.c (subr-call): Access the void* directly.
2010-01-26 22:56:41 +01:00
Andy Wingo
45cc48673a RETURN_HOOK communicates the number of returned values
* libguile/vm-engine.h (RUN_HOOK1): Add some machinery whereby a hook
  can push an arg on the stack, run the hook, then drop the value.
  (RETURN_HOOK): Use it here, so we push the number of returned values.

* libguile/vm-i-system.c (return, return-values): Adapt to RETURN_HOOK
  changes.
2010-01-13 23:14:12 +01:00
Andy Wingo
fc7648637b fix bug in subr-call and smob-call
* libguile/vm-i-system.c (subr-call, smob-call): Unlike the previous
  situation, in which a call to a subr or a smob didn't actually build a
  frame, we no longer need to explicitly pop the procedure and its
  arguments. Indeed the procedure and its arguments must remain on the
  stack, for hooks and ticks and such always to see frames with valid
  procedures. Two lines out, two bugs less, and faster to boot.
2010-01-09 21:48:16 +01:00
Andy Wingo
6f16379e9a allocate free variables inline to closures
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* libguile/programs.h (SCM_PROGRAM_FREE_VARIABLES)
  (SCM_PROGRAM_FREE_VARIABLE_REF, SCM_PROGRAM_FREE_VARIABLE_SET)
  (SCM_PROGRAM_NUM_FREE_VARIABLES):
* libguile/programs.c (scm_make_program, scm_program_num_free_variables)
  (scm_program_free_variable_ref, scm_program_free_variable_set_x):
  Allocate free variables inline with programs, instead of being in a
  vect. Should improve locality, and require fewer local variables in
  the VM.

* libguile/vm-engine.c (vm_engine): Remove free_vars and free_vars_count
  variables.

* libguile/vm-engine.h (CACHE_PROGRAM): No need to muck with free_vars
  and free_vars_count.
  (CHECK_FREE_VARIABLE): Update for inline free vars.

* libguile/vm-i-system.c (FREE_VARIABLE_REF): Update for inline free
  vars.
  (make-closure, fix-closure): Take the closure vals as separate stack
  args, and copy or fix them inline into the appropriate closure.

* module/language/objcode/spec.scm (program-free-variables): Define a
  local version of this removed function.

* module/language/tree-il/compile-glil.scm (flatten): Adjust to not make
  a vector when making closures.

* module/system/vm/program.scm: Export program-num-free-variables,
  program-free-variable-ref, program-free-variable-set!, and remove
  program-free-variables.

* test-suite/tests/tree-il.test ("lambda"): Update to not make vectors
  when making closures.
2010-01-09 16:43:26 +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
fd62932244 add subr-call VM op
* libguile/vm-i-system.c (subr_call): Add subr-call VM op.
2010-01-07 10:19:53 +01:00
Andy Wingo
a5bbb22e83 rename goto/args and friends to tail-call, tail-apply, etc
* libguile/vm-i-system.c (tail-call, tail-call/nargs, tail-apply)
  (tail-call/cc): Rename these back to tail-* from goto/*. We should
  reserve the rename-then-goto name for when you actually do a rename
  and goto, not when you shuffle the stack.

* doc/ref/vm.texi:
* module/language/glil/decompile-assembly.scm:
* module/language/tree-il/compile-glil.scm:
* test-suite/tests/tree-il.test: Adapt all callers and documentation.
2010-01-03 14:49:40 +01:00
Andy Wingo
7d94e4af98 handle interrupts in mv-call, return/values
* libguile/vm-i-system.c (mv-call, return/values): Interrupt before
  entering and leaving MV frames as well as normal frames.
2009-12-20 23:24:39 +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
5b09b37f81 vm: handle interrupts on backwards jumps
* libguile/vm-i-system.c (BR, br): Handle interrupts on backwards jumps,
  so we can Ctrl-C an endless loop.
2009-12-11 11:17:03 +01:00
Andy Wingo
e8c3777214 less overhead for handling interrupts in the vm
* libguile/__scm.h (SCM_ASYNC_TICK): Add some branch prediction.
  (SCM_ASYNC_TICK_WITH_CODE): New helper for when BUILDING_LIBGUILE,
  runs code only if we're going to call async_click().
* libguile/vm-engine.h (VM_HANDLE_INTERRUPTS): New helper, uses
  SCM_ASYNC_TICK_WITH_CODE to only save regs if we'll handle an
  interrupt.
* libguile/vm-i-system.c (call, goto/args, return): use
  VM_HANDLE_INTERRUPTS.
2009-12-11 11:15:12 +01:00
Andy Wingo
e42573315b merge from master to elisp
* module/language/elisp/compile-tree-il.scm: Update for changes to
  tree-il (lambda-case, mainly).

* module/language/elisp/spec.scm: Update GPL version to 3. Update reader
  for new taking a port and environment argument.

* libguile/_scm.h: Bump objcode version.

* libguile/vm-i-system.c: Fix conflicts.

* module/Makefile.am: Fix conflicts, and add elisp modules to the build.
2009-12-11 10:45:18 +01:00
Andy Wingo
ea68d342f1 procedures-with-setters implemented in terms of structs
* libguile/tags.h (scm_tc7_pws): No more.

* libguile/procs.c (scm_procedure_with_setter_p)
  (scm_make_procedure_with_setter, scm_procedure, scm_setter): Implement
  procedures-with-setters in terms of applicable structs with setters.

* libguile/procs.h: Remove a big, outdated comment, and the deprecated
  macros.

* libguile/deprecated.h (SCM_PROCEDURE_WITH_SETTER_P, SCM_PROCEDURE)
  (SCM_SETTER): Deprecate these. SCM_PROCEDURE and SCM_SETTER are bad
  names.

* libguile/evalext.c (scm_self_evaluating_p):
* libguile/gc.c (scm_i_tag_name):
* libguile/goops.c: (scm_class_of):
* libguile/print.c (iprin1):
* libguile/procprop.c (scm_i_procedure_arity):
* libguile/procs.c (scm_procedure_p):
* libguile/debug.c (scm_procedure_source): Remove a tc7_pws case.

* libguile/goops.h:
* libguile/goops.c (scm_class_procedure_with_setter): Remove this class;
  it is subsumed by applicable_struct_with_setter.

* libguile/struct.h: Update a comment.

* libguile/vm-i-system.c (call, goto/args, mv-call): Remove PWS cases.
2009-12-07 09:56:58 +01:00
Andy Wingo
cc8d1f5fcd vm doesn't call the evaluator at all (at least not directly)
* libguile/vm-i-system.c (goto/args, mv-call): Finish the port to use
  apply_foreign instead of scm_apply.
2009-12-01 22:11:15 +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
Andy Wingo
156d6fa1b5 fixes to variable-ref, variable-set vm ops
* libguile/vm-i-system.c (variable-ref, variable-set): Fix declared
  number of pops and pushes.
2009-12-01 21:00:26 +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
Andy Wingo
9022ff183c remove code that manages the method cache
* libguile/goops.h (SCM_MCACHE_N_SPECIALIZED)
  (SCM_SET_MCACHE_N_SPECIALIZED, SCM_INITIAL_MCACHE_SIZE)
  (scm_make_method_cache, scm_memoize_method, scm_mcache_lookup_cmethod)
  (scm_mcache_compute_cmethod):
* libguile/goops.c: Remove these procedures which managed the method
  cache. There's still a slot there but it's not initialized. The method
  cache is no longer necessary.

* module/oop/goops/dispatch.scm (memoize-method!): Change to not take a
  "cache" argument.

* libguile/eval.i.c:
* libguile/vm-i-system.c: Remove dispatch via the method cache.
2009-11-26 00:25:07 +01:00
Andy Wingo
2f652c6884 generics now dispatch as applicable structs
* libguile/eval.i.c (CEVAL, SCM_APPLY): Dispatch applicable structs
  before pure generics. In practice what this means is that we never hit
  the mcache case, because all pure generics are applicable structs.
  We're moving over to having generics dispatch themselves. Also, they
  don't prepend the struct as an arg; in order to have that effect, the
  user has closures.

* libguile/goops.c (scm_apply_generic, scm_call_generic_0):
  (scm_call_generic_1, scm_call_generic_2, scm_call_generic_3): Dispatch
  directly to the struct procedures.
  (scm_var_make_extended_generic): Remove a duplicate definition for
  scm_var_make_extended_generic.
  (create_standard_classes): Mark all instances of
  <applicable-struct-class> (themselves classes) as applicable classes.
  Meaning: generics are now applicable structs.

* libguile/goops.h (SCM_CLASS_CLASS_LAYOUT): The hashsets are actually
  uw slots -- or at least, making subclasses maps the int slots to be uw
  slots

* libguile/vm-i-system.c (call, goto/args, mv-call): Dispatch applicable
  structs in the VM.

* module/oop/goops/dispatch.scm (emit-linear-dispatch): Fix bug in the
  non-rest cache miss case.
  (delayed-compile): Rework to avoid fluids.
  (cache-dispatch): Don't call `equal?', it causes bootstrapping
  problems with the primitive-generic equal?. Using our own version is
  faster anyway.
2009-11-26 00:25:07 +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
Andy Wingo
ff74e44ecb with a rest arg, allow for keywords anywhere
* libguile/vm-i-system.c (br-if-nargs-gt): Fix variable declaration
  placement.
  (bind-kwargs): Patch mostly by Ludovic: it seems that in the mode in
  which we have rest args, the keywords can appear anywhere. Bummer.
  Change to allow for this.

* module/ice-9/optargs.scm (parse-lambda-case): Same, add a
  permissive-keys clause that handles the case in which there's a rest
  argument.
2009-11-16 22:32:54 +01:00
Andy Wingo
521ac49bde SCM_GENERIC_METHOD_CACHE macro splits from SCM_ENTITY_PROCEDURE
* libguile/goops.h (SCM_GENERIC_METHOD_CACHE)
  (SCM_SET_GENERIC_METHOD_CACHE): Two new macros; the same as
  SCM_[SET_]ENTITY_PROCEDURE, but more reflecting the reality of the
  generic hack.

* libguile/eval.i.c:
* libguile/goops.c:
* libguile/objects.c:
* libguile/vm-i-system.c: Use the new macros when it is appropriate to
  do so.
2009-11-15 20:28:11 +01:00
Andy Wingo
352c87d7e4 generic dispatch in the vm (sorta)
* libguile/vm-i-system.c (call, goto/args, mv-call): Add a case for
  generics, so we can avoid the evaluator in that case. Still have to
  cons up a list -- the real solution comes later.
2009-11-15 20:28:11 +01:00
Mark H Weaver
b02b05332f fix nil handling in the vm
* libguile/vm-i-scheme.c (not, not-not): Treat nil as false.
  (null?, not-null?): Treat nil as null.

* libguile/vm-i-system.c (br-if, br-if-not): Treat nil as false.
  (br-if-null, br-if-not-null): Treat nil as null.
2009-10-27 23:26:30 +01:00
Andy Wingo
3092a14d67 vm support for optional/kwarg init code, and bugfixes
* libguile/vm-i-system.c (local-bound?, long-local-bound?)
  (variable-bound?): New instructions, push #f unless the local is
  bound. You can get unbound locals from optional arguments.
  (bind-optionals/shuffle): A number of bugfixes.
  (bind-kwargs): Bugfixes. If we enocunter an improper kwarg list but
  the procedure has a rest argument, just stop kwarg processing, but
  without an error.
  Renumbered ops.

* libguile/_scm.h (SCM_OBJCODE_MAJOR_VERSION): Bump.
2009-10-23 15:59:07 +02:00
Andy Wingo
899d37a6cf more work towards compiling and interpreting keyword args
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bumparoo
* libguile/vm-i-system.c (push-rest, bind-rest): Logically there are
  actually two rest binders -- one that pops, conses, and pushes, and
  one that pops, conses, and local-sets. The latter is used on keyword
  arguments, because the keyword arguments themselves have been shuffled
  up on the stack. Renumber ops again.

* module/language/tree-il/compile-glil.scm (flatten): Attempt to handle
  compilation of lambda-case with keyword arguments. Might need some
  help.

* module/ice-9/psyntax.scm (build-lambda-case): An attempt to handle the
  interpreted case correctly. This might need a couple iterations, but
  at least it looks like the compile-glil code.

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

* module/language/glil.scm (<glil>): Rename "rest?" to "rest" in
  <glil-opt-prelude> and <glil-kw-prelude>, as it is no longer a simple
  boolean, but if true is an integer: the index of the local variable to
  which the rest should be bound.

* module/language/glil/compile-assembly.scm (glil->assembly): Adapt to
  "rest" vs "rest?". In the keyword case, use "bind-rest" instead of
  "push-rest".

* test-suite/tests/tree-il.test: Update for opt-prelude change.
2009-10-23 15:20:22 +02:00
Andy Wingo
7e01997e88 finish support for optional & keyword args; update ecmascript compiler
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (br-if-nargs-ne, br-if-args-lt)
  (br-if-nargs-gt): New instructions, for use by different lambda cases.
  (bind-optionals, bind-optionals/shuffle, bind-kwargs): New
  instructions, for binding optional and keyword arguments. Renumber
  other ops.

* module/language/ecmascript/compile-tree-il.scm (comp, comp-body):
  Update for new tree-il. Use the new optional argument mechanism
  instead of emulating it with rest arguments.

* module/language/glil/compile-assembly.scm (glil->assembly): Tweaks for
  optional and keyword argument compilation.

* module/language/tree-il.scm (parse-tree-il, unparse-tree-il): Make the
  else case optional, in the s-expression serialization of tree-il.

* module/language/tree-il/compile-glil.scm (flatten): Handle all of the
  lambda-case capabilities.
2009-10-23 15:10:25 +02:00
Andy Wingo
258344b4db flesh out glil support for optional and keyword arguments
* libguile/vm-i-system.c (bind-rest): Renamed from push-rest-list.
  (reserve-locals): Change so that instead of reserving space for some
  additional number of locals, reserve-locals takes the absolute number
  of locals, including the arguments.

* module/language/glil.scm (<glil-std-prelude>, <glil-opt-prelude>)
  (<glil-kw-prelude>): New GLIL constructs, to replace <glil-arity>.

* module/language/glil/compile-assembly.scm (glil->assembly): Compile
  the new preludes. Some instructions are not yet implemented, though.

* module/language/tree-il/analyze.scm (analyze-lexicals): The nlocs for
  a lambda will now be the total number of locals, including arguments.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Update to
  write the new prelude.

* module/system/vm/program.scm (program-bindings-for-ip): If a given
  index doesn't have a binding at the ip given, don't cons it on the
  resulting list.

* test-suite/tests/tree-il.test: Update for GLIL changes.
2009-10-23 14:51:19 +02:00
Andy Wingo
a6f15a1eba callees now check their args, cons rest list, reserve locals
* gdbinit: Ignore SIGPWR and SIGXCPU, which the BDW GC seems to use.

* libguile/vm-engine.h (FETCH_WIDTH): Remove unused macro.
  (INIT_ARGS, INIT_FRAME): Remove; callees now check their args and
  reserve space for their locals.

* libguile/vm-engine.c:
* libguile/vm-i-system.c: Turn on callee arg checking and local
  reservation. Seems to work!
2009-10-23 14:51:18 +02:00
Andy Wingo
55d9bc947e callees reserve their own local vars
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (reserve-locals): New instruction, to reserve
  space for local vars. Other ops renumbered.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Emit
  reserve-locals instructions as necessary.

* test-suite/tests/tree-il.test: Update to expect reserve-locals as
  appropriate.
2009-10-23 14:51:18 +02:00
Andy Wingo
6c6a44390b runtime and debugging support for callee-parsed procedure args
* libguile/objcodes.h: Bump for metadata format change.

* libguile/frames.h: Rework so we don't frob the program's nargs, nlocs,
  etc at runtime. Instead we don't really know what's a local var, an
  argument, or an intermediate value. It's a little unfortunate, but
  this will allow for case-lambda, and eventually for good polymorphic
  generic dispatch; and the nlocs etc can be heuristically
  reconstructed. Such a reconstruction would be better done at the
  Scheme level, though.
  (SCM_FRAME_STACK_ADDRESS): New macro, the pointer to the base of the
  stack elements (not counting the program).
  (SCM_FRAME_UPPER_ADDRESS): Repurpose to be the address of the last
  element in the bookkeeping part of the stack -- i.e. to point to the
  return address.

* libguile/vm-engine.h:
* libguile/vm-i-system.c: Adapt to removal of stack_base. Though we
  still detect stack-smashing underflow, we don't do so as precisely as
  we did before, because now we only detect overwriting of the frame
  metadata.

* libguile/vm-engine.c (vm_engine): Remove the stack_base variable. It
  is unnecessary, and difficult to keep track of in the face of
  case-lambda. Also fix miscommented "ra" and "mvra" pushes. Push the
  vp->ip as the first ra...
* libguile/vm-i-system.c (halt): ...because here we can restore the
  vp->ip instead of setting ip to 0. Allows us to introspect ips all
  down the stack, including in recursive VM invocations.

* libguile/frames.h:
* libguile/frames.c (scm_vm_frame_stack): Removed, because it's getting
  more difficult to tell what's an argument and what's a temporary stack
  element.
  (scm_vm_frame_num_locals): New accessor.
  (scm_vm_frame_instruction_pointer): New accessor.
  (scm_vm_frame_arguments): Defer to an implementation in Scheme.
  (scm_vm_frame_num_locals scm_vm_frame_local_ref)
  (scm_vm_frame_local_set_x): Since we can get not-yet-active frames on
  the stack now, with our current calling convention, we have to add a
  heuristic here to jump over those frames -- because frames have
  pointers in them, not Scheme values.

* libguile/programs.h:
* libguile/programs.c (scm_program_arity): Remove, in favor of..
  (scm_program_arities): ...this, which a list of arities, in a new
  format, occupying a slot in the metadata.

* module/language/assembly/decompile-bytecode.scm (decode-load-program):
  Fix mv-call decompilation.

* module/system/vm/frame.scm (vm-frame-bindings, vm-frame-binding-ref)
  (vm-frame-binding-set!): New functions, to access bindings by name in
  a frame.
  (vm-frame-arguments): Function now implemented in Scheme. Commented
  fairly extensively.

* module/system/vm/program.scm (program-bindings-by-index)
  (program-bindings-for-ip): New accessors, parsing the program bindings
  metadata into something more useful.
  (program-arities, program-arguments): In a case-lambda world, we have
  to assume that programs can have multiple arities. But it's tough to
  detect this algorithmically; instead we're going to require that the
  program metadata include information about the arities, and the parts
  of the program that that metadata applies to.
  (program-lambda-list): New accessor.
  (write-program): Show multiple arities.

* module/language/glil/compile-assembly.scm (glil->assembly): Add
  "arities" to the state of the compiler, and add arities entries as
  appropriate.
2009-10-23 14:51:17 +02:00
Andy Wingo
1e2a8c266d steps on the way to have the callee check the number of arguments
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* libguile/vm-i-system.c (assert-nargs-ee, assert-nargs-ge)
  (push-rest-list): New instructions, which for now don't actually do
  anything. Renumber the rest of the ops in this file.

* module/language/glil.scm (<glil-arity>): New GLIL type, an entity that
  checks the number of args for a block, optionally consing a rest list,
  and either branching or erroring if the arity doesn't match.

* module/language/glil/compile-assembly.scm (glil->assembly): Compile
  <glil-arity> to assembly. Some of these VM ops are not implemented --
  notably the branching case.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Emit
  <glil-arity>.

* test-suite/tests/tree-il.test: Update.
2009-10-23 14:51:17 +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
Daniel Kraft
ff81007918 Merge branch 'master' of git://git.savannah.gnu.org/guile into elisp 2009-08-27 19:26:04 +02:00
Andy Wingo
2fb924f64f programs have their own tc7 now
* libguile/tags.h (scm_tc7_program):
* libguile/programs.h: Programs now have their own tc7 code. Fix up the
  macros appropriately.

* libguile/programs.c: Remove smobby bits, leaving marking, printing,
  and application for other parts of Guile.

* libguile/debug.c (scm_procedure_source):
* libguile/eval.c (scm_trampoline_0, scm_trampoline_1)
  (scm_trampoline_2): Add cases for tc7_program.
* libguile/eval.i.c (CEVAL, SCM_APPLY):
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/gc-card.c (scm_i_sweep_card, scm_i_tag_name):
* libguile/gc-mark.c (1):
* libguile/print.c (iprin1):
* libguile/procs.c (scm_procedure_p, scm_thunk_p)
* libguile/vm-i-system.c (make-closure): Adapt to new procedure
  representation.

* libguile/procprop.c (scm_i_procedure_arity): Do the right thing for
  programs.
* test-suite/tests/procprop.test ("procedure-arity"): Arity test now
  succeeds.

* libguile/goops.c (scm_class_of): Programs now belong to the class
  <procedure>, not a smob class.

* libguile/vm.h (struct vm, struct vm_cont):
* libguile/vm-engine.c (vm_engine):
* libguile/frames.h (SCM_FRAME_BYTE_CAST, struct vm_frame):
* libguile/frames.c (scm_c_make_vm_frame): Fix usages of scm_byte_t,
  changing them to scm_t_uint8.
2009-08-20 18:52:51 +02:00