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

58 commits

Author SHA1 Message Date
Andy Wingo
4b7af0b7fd Update frames.h comments.
* libguile/frames.h: Update to match reality.
2018-07-23 11:23:18 +02:00
Andy Wingo
043432fd57 Reserve frame word for machine return address
* libguile/frames.h: Add machine return address to diagram.
  (SCM_FRAME_MACHINE_RETURN_ADDRESS):
  (SCM_FRAME_SET_MACHINE_RETURN_ADDRESS): New macros.
  (SCM_FRAME_PREVIOUS_SP):
  (SCM_FRAME_DYNAMIC_LINK):
  (SCM_FRAME_SET_DYNAMIC_LINK): Adapt for new frame size.
* libguile/vm-engine.c (halt): Set frame size to 3.
  (call, call-label): Set mRA to 0.
* libguile/vm.c (push_interrupt_frame, reinstate_continuation_x):
  (scm_call_n): Set frame size to 3.  In push_interrupt_frame, init the
  mRA of the frame.
  (vm_builtin_call_with_values_code, vm_handle_interrupt_code): Allocate
  larger frames.
* module/language/cps/slot-allocation.scm (allocate-slots): Frame size
  is 3.
* module/system/vm/disassembler.scm (define-clobber-parser): Bump frame
  size.
2018-07-20 11:42:30 +02:00
Andy Wingo
b1705bd0f0 Prepare for frames having separate virtual and machine return addrs
* libguile/frames.c (scm_frame_return_address): Use
  SCM_FRAME_VIRTUAL_RETURN_ADDRESS.
  (scm_c_frame_previous): Likewise.
* libguile/frames.h: Update diagram for new names.
  (union scm_vm_stack_element): Rename "as_ip" to "as_vcode", and
  add "as_mcode" for machine code pointers.
  (SCM_FRAME_VIRTUAL_RETURN_ADDRESS)
  (SCM_FRAME_SET_VIRTUAL_RETURN_ADDRESS): Rename to these, from
  SCM_FRAME_RETURN_ADDRESS and SCM_FRAME_SET_RETURN_ADDRESS.
* libguile/vm-engine.c (halt, call, call-label, return-values)
  (return-from-interrupt): Adapt to renamings.  Make "halt" have frame
  size as a parameter.
* libguile/vm.c (scm_i_vm_mark_stack): Adapt to renaming.
  (push_interrupt_frame): Take mRA as additional argument.  In future we
  will set it as frame mRA.
  (capture_continuation): Adapt to renaming.
  (scm_call_n): Adapt to renaming and make frame size adjustable.
  (push_interrupt_frame, reinstate_continuation_x): Make frame size
  adjustable.
* module/language/cps/slot-allocation.scm (allocate-slots): Make frame
  size adjustable.
* libguile/intrinsics.h (scm_t_thread_mra_intrinsic): New type; use for
  push_interrupt_frame.
  (scm_t_thread_u8_scm_sp_vra_intrinsic): Rename from the same but was
  "ra" instead of "vra", and change type to uint32_t*.
* module/system/vm/disassembler.scm (define-clobber-parser):
  Parameterize clobber set for calls by frame size.
2018-07-20 11:42:30 +02:00
Andy Wingo
6ad1fc9ce0 Use ptrdiff_t instead of scm_t_ptrdiff
* libguile/continuations.h:
* libguile/control.c:
* libguile/control.h:
* libguile/dynstack.c:
* libguile/dynstack.h:
* libguile/eval.c:
* libguile/foreign.c:
* libguile/frames.h:
* libguile/gen-scmconfig.c:
* libguile/gsubr.c:
* libguile/gsubr.h:
* libguile/loader.c:
* libguile/numbers.h:
* libguile/stacks.c:
* libguile/throw.c:
* libguile/vm-engine.c:
* libguile/vm.c:
* libguile/vm.h: Use ptrdiff_t from stddef.h.
2018-06-21 20:20:01 +02:00
Andy Wingo
16879cabed Replace uses of scm_t_int8, scm_t_uintmax, etc with stdint types
* libguile/bitvectors.c:
* libguile/bitvectors.h:
* libguile/bytevectors.c:
* libguile/bytevectors.h:
* libguile/chars.c:
* libguile/continuations.c:
* libguile/control.c:
* libguile/conv-integer.i.c:
* libguile/conv-uinteger.i.c:
* libguile/dynstack.c:
* libguile/dynstack.h:
* libguile/foreign.c:
* libguile/frames.c:
* libguile/frames.h:
* libguile/gc-inline.h:
* libguile/gc.h:
* libguile/gsubr.c:
* libguile/gsubr.h:
* libguile/hash.c:
* libguile/i18n.c:
* libguile/instructions.c:
* libguile/intrinsics.c:
* libguile/intrinsics.h:
* libguile/loader.c:
* libguile/loader.h:
* libguile/numbers.c:
* libguile/numbers.h:
* libguile/pairs.c:
* libguile/ports-internal.h:
* libguile/ports.c:
* libguile/ports.h:
* libguile/posix.c:
* libguile/print.c:
* libguile/print.h:
* libguile/programs.c:
* libguile/programs.h:
* libguile/r6rs-ports.c:
* libguile/random.c:
* libguile/random.h:
* libguile/scm.h:
* libguile/socket.c:
* libguile/srfi-4.c:
* libguile/srfi-4.h:
* libguile/stacks.c:
* libguile/stime.c:
* libguile/strings.c:
* libguile/struct.c:
* libguile/struct.h:
* libguile/symbols.c:
* libguile/threads.c:
* libguile/threads.h:
* libguile/uniform.c:
* libguile/vm-engine.c:
* libguile/vm.c:
* libguile/vm.h:
* libguile/vports.c:
* test-suite/standalone/test-conversion.c:
* test-suite/standalone/test-ffi-lib.c:
* test-suite/standalone/test-scm-take-u8vector.c:
* test-suite/standalone/test-srfi-4.c: Replace e.g. scm_t_uint8 with
  uint8_t.
2018-06-21 20:18:54 +02:00
Andy Wingo
1234bb1850 Update license notices in all C files
Update to newest recommended license notices from the FSF.  Everything
stays LGPLv3+ except guile-readline which is GPLv3+.
2018-06-20 20:07:34 +02:00
Andy Wingo
c836c28496 libguile header files have uniform format for copyright declarations 2018-06-20 19:44:45 +02:00
Andy Wingo
791eb0c01a Remove (C) from copyright statements
As the FSF advises, 'There is no legal significance to using the
three-character sequence “(C)”, but it does no harm.'  It does take up
space though!  For that reason, we remove it here from our C files.
2018-06-20 19:17:06 +02:00
Andy Wingo
97cc65fee4 Rename __scm.h to scm.h
* libguile/scm.h: Rename.  Update all includers.
2018-06-20 16:33:33 +02:00
Andy Wingo
c495b44714 Remove Emacs local variables comments in Guile source
The .dir-locals.el file in the repository is sufficient for Emacs
users.

* libguile/__scm.h:
* libguile/alist.c:
* libguile/alist.h:
* libguile/array-handle.c:
* libguile/array-handle.h:
* libguile/array-map.c:
* libguile/array-map.h:
* libguile/arrays.c:
* libguile/arrays.h:
* libguile/async.c:
* libguile/async.h:
* libguile/backtrace.c:
* libguile/backtrace.h:
* libguile/bitvectors.c:
* libguile/bitvectors.h:
* libguile/boolean.c:
* libguile/boolean.h:
* libguile/chars.c:
* libguile/chars.h:
* libguile/chooks.c:
* libguile/chooks.h:
* libguile/continuations.c:
* libguile/continuations.h:
* libguile/control.c:
* libguile/conv-integer.i.c:
* libguile/debug-malloc.h:
* libguile/debug.c:
* libguile/debug.h:
* libguile/deprecation.c:
* libguile/deprecation.h:
* libguile/dynl.c:
* libguile/dynl.h:
* libguile/dynstack.c:
* libguile/dynstack.h:
* libguile/dynwind.c:
* libguile/dynwind.h:
* libguile/eq.c:
* libguile/eq.h:
* libguile/error.c:
* libguile/error.h:
* libguile/eval.c:
* libguile/eval.h:
* libguile/evalext.c:
* libguile/evalext.h:
* libguile/expand.c:
* libguile/expand.h:
* libguile/extensions.c:
* libguile/extensions.h:
* libguile/feature.c:
* libguile/feature.h:
* libguile/filesys.c:
* libguile/filesys.h:
* libguile/fluids.c:
* libguile/fluids.h:
* libguile/foreign.c:
* libguile/fports.c:
* libguile/fports.h:
* libguile/frames.c:
* libguile/frames.h:
* libguile/gc-inline.h:
* libguile/gc.c:
* libguile/gc.h:
* libguile/generalized-arrays.c:
* libguile/generalized-arrays.h:
* libguile/generalized-vectors.c:
* libguile/generalized-vectors.h:
* libguile/gettext.c:
* libguile/gettext.h:
* libguile/goops.c:
* libguile/goops.h:
* libguile/gsubr.c:
* libguile/gsubr.h:
* libguile/guardians.c:
* libguile/guardians.h:
* libguile/guile.c:
* libguile/hash.c:
* libguile/hash.h:
* libguile/hashtab.c:
* libguile/hashtab.h:
* libguile/hooks.c:
* libguile/hooks.h:
* libguile/i18n.c:
* libguile/i18n.h:
* libguile/init.c:
* libguile/init.h:
* libguile/instructions.c:
* libguile/instructions.h:
* libguile/intrinsics.c:
* libguile/intrinsics.h:
* libguile/ioext.c:
* libguile/ioext.h:
* libguile/iselect.h:
* libguile/keywords.c:
* libguile/keywords.h:
* libguile/list.c:
* libguile/list.h:
* libguile/load.c:
* libguile/load.h:
* libguile/loader.c:
* libguile/loader.h:
* libguile/macros.c:
* libguile/macros.h:
* libguile/mallocs.c:
* libguile/mallocs.h:
* libguile/memmove.c:
* libguile/memoize.c:
* libguile/memoize.h:
* libguile/modules.c:
* libguile/modules.h:
* libguile/net_db.c:
* libguile/net_db.h:
* libguile/null-threads.c:
* libguile/null-threads.h:
* libguile/numbers.c:
* libguile/numbers.h:
* libguile/objprop.c:
* libguile/objprop.h:
* libguile/options.c:
* libguile/options.h:
* libguile/pairs.c:
* libguile/pairs.h:
* libguile/poll.c:
* libguile/poll.h:
* libguile/ports.c:
* libguile/ports.h:
* libguile/posix.c:
* libguile/posix.h:
* libguile/print.c:
* libguile/print.h:
* libguile/procprop.c:
* libguile/procprop.h:
* libguile/procs.c:
* libguile/procs.h:
* libguile/programs.c:
* libguile/programs.h:
* libguile/promises.c:
* libguile/promises.h:
* libguile/pthread-threads.h:
* libguile/random.c:
* libguile/random.h:
* libguile/rdelim.c:
* libguile/rdelim.h:
* libguile/read.c:
* libguile/read.h:
* libguile/regex-posix.c:
* libguile/regex-posix.h:
* libguile/rw.c:
* libguile/rw.h:
* libguile/scmsigs.c:
* libguile/scmsigs.h:
* libguile/script.c:
* libguile/script.h:
* libguile/simpos.c:
* libguile/simpos.h:
* libguile/smob.c:
* libguile/smob.h:
* libguile/snarf.h:
* libguile/socket.c:
* libguile/socket.h:
* libguile/sort.c:
* libguile/sort.h:
* libguile/srcprop.c:
* libguile/srcprop.h:
* libguile/stackchk.c:
* libguile/stackchk.h:
* libguile/stacks.c:
* libguile/stacks.h:
* libguile/stime.c:
* libguile/stime.h:
* libguile/strerror.c:
* libguile/strings.c:
* libguile/strings.h:
* libguile/strorder.c:
* libguile/strorder.h:
* libguile/strports.c:
* libguile/strports.h:
* libguile/struct.c:
* libguile/struct.h:
* libguile/symbols.c:
* libguile/symbols.h:
* libguile/syntax.c:
* libguile/syscalls.h:
* libguile/tags.h:
* libguile/threads.c:
* libguile/threads.h:
* libguile/throw.c:
* libguile/throw.h:
* libguile/trees.h:
* libguile/unicode.c:
* libguile/unicode.h:
* libguile/uniform.c:
* libguile/uniform.h:
* libguile/values.c:
* libguile/values.h:
* libguile/variable.c:
* libguile/variable.h:
* libguile/vectors.c:
* libguile/vectors.h:
* libguile/version.c:
* libguile/vm-engine.c:
* libguile/vm-expand.h:
* libguile/vm.c:
* libguile/vm.h:
* libguile/vports.c:
* libguile/vports.h:
* libguile/weak-list.h:
* libguile/weak-set.c:
* libguile/weak-set.h:
* libguile/weak-table.c:
* libguile/weak-table.h:
* libguile/weak-vector.c:
* libguile/weak-vector.h: Remove needless trailing comments.
2018-06-20 14:32:28 +02:00
Andy Wingo
2b95d6faa4 Devolve gc.h
* libguile/_scm.h: Remove gc.h.
* libguile/arrays.h:
* libguile/bytevectors.h:
* libguile/foreign.h:
* libguile/fports.h:
* libguile/frames.h:
* libguile/hashtab.h:
* libguile/modules.h:
* libguile/numbers.h:
* libguile/print.h:
* libguile/programs.h:
* libguile/smob.h:
* libguile/snarf.h:
* libguile/strports.h:
* libguile/struct.h:
* libguile/symbols.h:
* libguile/variable.h:
* libguile/vectors.h:
* libguile/vm.h: Add gc.h to users of scm_cell_* interfaces.  Not really
  visible right now given that e.g. numbers.h is already included in
  _scm.h.
2018-06-18 22:27:29 +02:00
Andy Wingo
83584ef231 Fix libguile subcomponent headers not to include <libguile.h>
* libguile/bytevectors.h: Include uniform.h, for use in the macros.
* libguile/extensions.h: Include libpath.h, for the
  SCM_EFFECTIVE_VERSION, which is almost always used with these
  routines.
* libguile/frames.h:
* libguile/instructions.h:
* libguile/intrinsics.h:
* libguile/loader.h:
* libguile/programs.h:
* libguile/vm.h: Include <libguile/__scm.h> instead of <libguile.h>.
  Cuts a circular include, but also precipitates a lot of maintenance in
  the .c files.

* libguile/*.c: Update C files to add needed all needed includes that
  before were getting automatically pulled in by the indirect inclusion
  of libguile.h.
2018-06-14 22:20:47 +02:00
Andy Wingo
00ed4043c2 VM continuations store FP/SP by offset
* libguile/continuations.c (scm_i_continuation_to_frame):
* libguile/stacks.c (scm_make_stack):
* libguile/vm.c (scm_i_vm_cont_to_frame, scm_i_vm_capture_stack):
  (vm_return_to_continuation_inner)
  (struct vm_reinstate_partial_continuation_data):
  (vm_reinstate_partial_continuation_inner):
  (vm_reinstate_partial_continuation):
* libguile/vm.h (sstruct scm_vm_cont): Simplify VM continuations by
  recording the top FP by offset, not value + reloc.
* libguile/frames.c (frame_offset, scm_i_vm_frame_offset): Remove unused
  functions.
* libguile/frames.h (SCM_VALIDATE_VM_FRAME, scm_i_vm_frame_offset):
  Remove.
* libguile/control.c (reify_partial_continuation): Once we know the
  base_fp, relocate the dynamic stack.
* libguile/dynstack.h:
* libguile/dynstack.c (scm_dynstack_relocate_prompts): New function.
  (scm_dynstack_wind_prompt): Adapt to add new fp offset.
2017-02-12 20:31:14 +01:00
Andy Wingo
67e8aa85e8 Remove frame-local-ref, frame-local-set!
* libguile/frames.h (scm_frame_num_locals, scm_frame_local_ref)
  (scm_frame_local_set_x): Remove.  As long as we are changing the
  interface in a backward-incompatible way, we might as well remove
  these.
* libguile/frames.c (scm_frame_num_locals, scm_frame_local_ref)
  (scm_frame_local_set_x, scm_init_frames_builtins, scm_init_frames):
  Arrange to make frame-local-ref et al private to frames.scm.

* module/system/vm/frame.scm: Load scm_init_frames_builtins extensions.
  (frame-instruction-pointer-or-primitive-procedure-name): New public
  function.
  (frame-binding-ref, frame-binding-set!): Allow binding objects as
  vars.

* module/system/repl/debug.scm (print-locals): Pass binding directly to
  frame-binding-ref.

* module/statprof.scm (sample-stack-procs, count-call): Use new
  frame-instruction-pointer-or-primitive-procedure-name function.
2016-01-31 10:45:02 +01:00
Andy Wingo
8bf77f7192 Add support for unboxed s64 values
* libguile/frames.c (enum stack_item_representation):
  (scm_to_stack_item_representation):
  (scm_frame_local_ref, scm_frame_local_set_x): Support for S64
  representations.

* libguile/frames.h (union scm_vm_stack_element): Add signed 64-bit
  integer field.

* libguile/vm-engine.c (scm->s64, s64->scm, load-s64): New
  instructions.

* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/slot-allocation.scm (compute-var-representations)
  (compute-needs-slot, allocate-slots):
* module/language/cps/utils.scm (compute-constant-values):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Add support for new primcalls.

* module/language/cps/types.scm (&s64): New type.
  (&s64-min, &s64-max, &u64-max): New convenience definitions.
  (&range-min, &range-max): Use &s64-min and &u64-max names.
  (scm->s64, load-s64, s64->scm): Add support for new primcalls.

* module/system/vm/assembler.scm (emit-scm->s64, emit-s64->scm)
  (emit-load-s64): New exports.
* module/system/vm/assembler.scm (write-arities): Support for s64
  slots.

* module/system/vm/debug.scm (arity-definitions): Support for s64
  slots.
2015-12-01 15:42:19 +01:00
Andy Wingo
dfbe869e24 Add low-level support for unboxed 64-bit unsigned ints
* libguile/frames.c (enum stack_item_representation)
* libguile/frames.c (scm_to_stack_item_representation):
  (scm_frame_local_ref, scm_frame_local_set_x): Support 'u64 slots.
* libguile/frames.h (union scm_vm_stack_element): Add as_u64 member.

* libguile/vm-engine.c (SP_REF_U64, SP_SET_U64): New helpers.
  (scm->u64, u64->scm): New instructions.

* module/language/cps/cse.scm (compute-equivalent-subexpressions):
  Scalar replacement for u64->scm and scm->u64.

* module/language/cps/effects-analysis.scm (scm->u64, u64->scm): Add
  cases.

* module/language/cps/slot-allocation.scm (compute-var-representations):
  (allocate-slots): Represent the result of scm->u64 as a "u64" slot.

* module/language/cps/types.scm (&u64): New type.
  (scm->u64, u64->scm): Add support for these ops.

* module/system/vm/assembler.scm (write-arities):
* module/system/vm/debug.scm (arity-definitions): Support u64
  representations.
2015-12-01 11:30:54 +01:00
Andy Wingo
58153e3a08 Remove frame-procedure
* libguile/frames.h:
* libguile/frames.c (scm_frame_procedure): Remove.
* test-suite/tests/eval.test ("stacks"): Adapt test.
* NEWS: Add news item.
* doc/ref/api-debug.texi (Frames): Document frame-procedure-name instead
  of frame-procedure.
2015-12-01 11:30:54 +01:00
Andy Wingo
39090e677e Add frame-procedure-name
* libguile/frames.c (frame_procedure_name_var): New static definition.
  (init_frame_procedure_name_var): New helper.
  (scm_frame_procedure_name): New function that returns the name of the
  frame's procedure, as frame-procedure is to be deprecated.

* libguile/frames.h (scm_frame_procedure_name): Export.

* module/ice-9/boot-9.scm (exception-printers): Use frame-procedure-name
  instead of procedure-name on frame-procedure.

* module/system/vm/frame.scm (frame-procedure-name): New private
  function, implementing scm_frame_procedure_name.
  (frame-call-representation): Use frame-procedure-name to get the
  procedure name to print.
2015-12-01 11:30:54 +01:00
Andy Wingo
fc87033bf0 Stack slots can hold a double
* libguile/frames.h (union scm_vm_stack_element): Add double member.
* libguile/frames.c (scm_frame_local_ref, scm_frame_local_set_x): Wire
  up f64 support.
2015-10-28 17:47:48 +00:00
Andy Wingo
e3cc0eeb3a Reflection support for unboxed f64 slots
* module/system/vm/assembler.scm (emit-definition): Add representation
  field.
  (write-arities): Emit representations into the arities section.

* module/system/vm/debug.scm (arity-definitions): Read representations.

* module/system/vm/frame.scm (<binding>): Add representation field and
  binding-representation getter.
  (available-bindings): Pass representation to make-binding.
  (frame-binding-set!, frame-binding-ref, frame-call-representation):
  Pass representation to frame-local-ref / frame-local-set!.

* test-suite/tests/rtl.test: Update definition instructions.

* module/language/cps/slot-allocation.scm ($allocation): Add
  representations field.
  (lookup-representation): New public function.
  (allocate-slots): Pass representations to make-$allocation.

* module/language/cps/compile-bytecode.scm (compile-function): Adapt to
  emit-definition change.

* libguile/frames.h:
* libguile/frames.c (scm_frame_local_ref, scm_frame_local_set_x): Take
  representation argument.
  (scm_to_stack_item_representation): New internal helper.
2015-10-28 17:43:55 +00:00
Andy Wingo
72353de77d Replace dynamic link on stack with previous frame size
* libguile/frames.h (SCM_FRAME_DYNAMIC_LINK)
  (SCM_FRAME_SET_DYNAMIC_LINK): Instead of storing the absolute value of
  the previous FP, store its offset from the current FP.  This allows us
  to avoid relinking when composing continuations or when relocating the
  stack.

* libguile/frames.c (scm_frame_dynamic_link, scm_c_frame_previous): No
  need to relocate the dynamic link.

* libguile/vm.c (vm_return_to_continuation_inner):
  (vm_reinstate_partial_continuation_inner, vm_expand_stack_inner):
  Don't relocate the frame pointer chain.
  (scm_i_vm_mark_stack): Terminate when FP is above stack_top, not when
  0.
  (make_vm): Init FP to stack_top.
2015-10-21 11:49:20 +02:00
Andy Wingo
8f027385db Rename union scm_vm_stack_element members
* libguile/frames.h (union scm_vm_stack_element): Rename members from
  scm, ip, etc to as_scm, as_ip, etc.  Adapt users.
2015-10-21 11:49:20 +02:00
Andy Wingo
0007507340 VM stack grows downward
Adapt VM stack to grow downward.  This will make native compilation look
more like the VM code, as we will be able to use native CALL
instructions, taking proper advantage of the return address buffer.

* libguile/continuations.c (scm_i_continuation_to_frame): Record offsets
  from stack top.

* libguile/control.c (scm_i_prompt_pop_abort_args_x): Adapt for reversed
  order of arguments, and instead of relying on the abort to push on the
  number of arguments, make the caller save the stack depth, which
  allows us to compute the number of arguments ourselves.
  (reify_partial_continuation, scm_c_abort): Adapt to reversed stack
  order.

* libguile/dynstack.c (scm_dynstack_wind_prompt): Since we wind the
  stack in a downward direction, subtract the reloc instead of adding
  it.

* libguile/dynstack.h (SCM_F_DYNSTACK_PROMPT_ESCAPE_ONLY): Remove flag;
  instead rely on prompt-establishing code to save the stack depth.

* libguile/eval.c (eval): Remove extraneous "volatile" declarations for
  variables that are not re-set between the setjmp and any longjmp.
  Adapt to save stack depth before instating the prompt.

* libguile/foreign.c (scm_i_foreign_call): Adapt to receive arguments in
  reverse order.

* libguile/frames.c (frame_stack_top, scm_i_frame_stack_top): Adapt to
  compute stack top instead of stack bottom.
  (scm_c_frame_closure): Adapt to stack growth change.
  (scm_frame_num_locals, scm_frame_local_ref, scm_frame_set_x): Use
  union data type to access stack.
  (RELOC): Reformat.
  (scm_c_frame_previous): Adapt to stack growth change.

* libguile/frames.h: Adapt stack diagram to indicate that the stack
  grows up.
  (union scm_vm_stack_element): New data type used to access items on
  the stack.
  (SCM_FRAME_PREVIOUS_SP)
  (SCM_FRAME_RETURN_ADDRESS, SCM_FRAME_SET_RETURN_ADDRESS)
  (SCM_FRAME_DYNAMIC_LINK, SCM_FRAME_SET_DYNAMIC_LINK)
  (SCM_FRAME_LOCAL, SCM_FRAME_NUM_LOCALS): Adapt to stack representation
  change.
  (SCM_FRAME_SLOT): New helper.
  (SCM_VM_FRAME_FP, SCM_VM_FRAME_SP): Adapt to stack growth change.

* libguile/stacks.c (scm_make_stack): Record offsets from top of stack.

* libguile/throw.c (catch): Adapt to scm_i_prompt_pop_abort_args_x
  change.

* libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME):
  (FRAME_LOCALS_COUNT_FROM): Adapt to stack growth change.
  (LOCAL_ADDRESS): Use SCM_FRAME_SLOT to get the address as the proper
  data type.
  (RETURN_ONE_VALUE, RETURN_VALUE_LIST): Adapt to stack growth change.
  (apply): Shuffling up the SMOB apply args can cause the stack to
  expand, so use ALLOC_FRAME instead of RESET_FRAME.
  (vm_engine): Adapt for stack growth change.

* libguile/vm.c (vm_increase_sp, vm_push_sp, vm_restore_sp): Adapt to
  stack representation change.
  (scm_i_vm_cont_to_frame): Adapt to take offsets from the top.
  (scm_i_vm_capture_stack): Adapt to capture from the top.
  (vm_return_to_continuation_inner): Adapt for data type changes.
  (vm_return_to_continuation): Likewise, and instead of looping, just
  splat the saved arguments on with memcpy.
  (vm_dispatch_hook): Adapt to receive arguments in the reverse order.
  Adapt callers.
  (vm_abort): There is never a tail argument.  Adapt to stack
  representation change.
  (vm_reinstate_partial_continuation)
  (vm_reinstate_partial_continuation_inner): Adapt to stack growth
  change.
  (allocate_stack, free_stack): Adapt to data type change.
  (expand_stack): Don't try to mremap(), as you can't grow a mapping
  from the bottom.  Without knowing that there's a free mapping space
  right below the old stack, which there usually isn't on Linux, we have
  to copy.  We can't use MAP_GROWSDOWN because Linux is buggy.
  (make_vm): Adapt to stack representation changes.
  (return_unused_stack_to_os): Round down instead of up, as the stack
  grows down.
  (scm_i_vm_mark_stack): Adapt to walk up the stack.
  (scm_i_vm_free_stack): Adapt to scm_vm changes.
  (vm_expand_stack_inner, reset_stack_limit, vm_expand_stack): Adapt to
  the stack growing down.
  (scm_call_n): Adapt to the stack growing down.  Don't allow argv to
  point into the stack.

* libguile/vm.h (struct scm_vm, struct scm_vm_cont): Adapt to hold the
  stack top and bottom.
2015-10-21 11:49:20 +02:00
Andy Wingo
18aa6da21e Remove SCM_FRAME_PROGRAM
* libguile/frames.h: Remove SCM_FRAME_PROGRAM, now unused.
2014-04-16 19:20:42 +02:00
Andy Wingo
4819276185 Better backtraces from C, especially for optimized closures
* libguile/frames.h:
* libguile/frames.c (scm_frame_call_representation): New interface;
  dispatches to Scheme.

* libguile/backtrace.c (display_application): Use
  scm_frame_call_representation.  This should be monotonically better,
  given that scm_frame_arguments (which was previously called) also
  dispatched to Scheme and actually ended up calling
  frame-call-representation.
2014-04-16 14:33:20 +02:00
Andy Wingo
3b14dd2f27 Optimize make-stack
* libguile/continuations.h:
* libguile/continuations.c (scm_i_continuation_to_frame): Operate on
  low-level C structures instead of heap objects.

* libguile/frames.h:
* libguile/frames.c (frame_offset, frame_stack_base): Const args.
  (scm_c_frame_closure): New helper.
  (scm_frame_procedure): Use the new helper.

* libguile/stacks.c (stack_depth, narrow_stack, scm_make_stack): Rework
  to avoid allocating frames as we traverse the stack, and to avoid an
  n**2 case where there are outer cuts.
2014-04-14 16:31:02 +02:00
Andy Wingo
8de051da47 scm_c_make_frame takes struct scm_frame as arg
* libguile/frames.h:
* libguile/frames.c (scm_c_make_frame): Adapt to take a const struct
  scm_frame as the argument.  Adapt callers.

* libguile/continuations.c:
* libguile/stacks.c: Adapt callers.
2014-04-14 15:14:26 +02:00
Andy Wingo
44d9705464 Refactor to frames code
* libguile/frames.h:
* libguile/frames.c (scm_c_frame_previous): New internal helper.
  (scm_frame_previous): Use the helper.
  (RELOC): Take kind and low-level frame args separately.  Adapt
  callers.
  (frame_stack_base, frame_offset): New helpers.
  (scm_i_frame_offset, scm_i_frame_stack_base): Use low-level helpers.
2014-04-14 14:54:14 +02:00
Andy Wingo
5515edc5f2 Heap frame "stack holders" are raw scm_vm / scm_vm_cont pointers
* libguile/frames.h (struct scm_frame): stack_holder is a void*.
* libguile/frames.c (scm_i_frame_stack_base, scm_i_frame_offset): Expect
  stack_holder to be the raw struct scm_vm or scm_vm_cont.

* libguile/continuations.c (scm_i_continuation_to_frame):
* libguile/stacks.c (scm_make_stack)
* libguile/vm.c (vm_dispatch_hook): Adapt creators.
2013-11-21 17:21:37 +01:00
Andy Wingo
050a40db5b Heap frames have a "frame kind" bit
* libguile/frames.h (enum scm_vm_frame_kind, SCM_VM_FRAME_KIND)
  (scm_c_make_frame): Add a "frame kind" bit to the first word.  This
  will allow the "stack holder" to be a non-SCM object.

* libguile/continuations.c (scm_i_continuation_to_frame):
* libguile/frames.c (scm_c_make_frame, scm_frame_previous)
* libguile/stacks.c (scm_make_stack):
* libguile/vm.c (vm_dispatch_hook): Adapt frame creators to set the
  frame kind bit.
2013-11-21 17:13:18 +01:00
Andy Wingo
0bca90aac9 The dynamic stack records SP and FP values as offsets
* libguile/dynstack.h:
* libguile/dynstack.c (PROMPT_FP, PROMPT_SP):
  (scm_dynstack_push_prompt, scm_dynstack_find_prompt): Prompts on the
  dynstack are recorded as offsets from the base stack address in this
  thread.

* libguile/control.c (scm_c_abort):
* libguile/eval.c (eval):
* libguile/stacks.c (find_prompt, narrow_stack):
* libguile/throw.c (pre_init_catch):
* libguile/vm-engine.c (prompt): Adapt.
2013-11-21 16:51:15 +01:00
Andy Wingo
89b235afd3 Scheme frame objects hold relative stack offsets
* libguile/frames.h: Wrap the C interface to VM frames in
  BUILDING_LIBGUILE.  Change VM frames to record relative offsets into a
  stack held by some other object, so that if the stack moves they will
  remain valid.
* libguile/frames.c (scm_c_make_frame): Remove offset argument.
  (scm_i_frame_offset): Instead, compute the offset from the stack
  holder.
  (scm_i_frame_stack_base): New helper.
  (scm_frame_previous): Adapt.

* libguile/stacks.c (scm_make_stack)
* libguile/vm.c (vm_dispatch_hook):
* libguile/continuations.c (scm_i_continuation_to_frame): Adapt.
2013-11-21 11:20:19 +01:00
Andy Wingo
9121d9f1ac All instruction pointers are now scm_t_uint32*
* libguile/frames.h (SCM_FRAME_RTL_RETURN_ADDRESS)
  (SCM_FRAME_SET_RTL_RETURN_ADDRESS): Remove.  The variants without _RTL
  now work fine.
  (struct scm_vm_frame): Change the return address to be a
  scm_t_uint32*.
  (struct scm_frame): Change IP to be scm_t_uint32*.

* libguile/frames.c (scm_c_make_frame)
* libguile/control.c (reify_partial_continuation, scm_c_abort)
* libguile/dynstack.c (PROMPT_IP)
  (scm_dynstack_push_prompt, scm_dynstack_find_prompt)
* libguile/dynstack.h:
* libguile/vm-engine.c (SYNC_IP, RETURN_ONE_VALUE)
  (call, return-values, prompt): Adapt.
2013-11-19 18:09:34 +01:00
Andy Wingo
b636cdb0f3 Frame pointer points to local 0 instead of local 1
* libguile/frames.h: Change so that fp points at local 0 instead of
  local 1, and clean up a bit.
  (struct scm_vm_frame): Remove program, and rename stack to locals.
  (SCM_FRAME_DATA_ADDRESS): Remove; it was redundant with
  SCM_FRAME_LOWER_ADDRESS.
  (SCM_FRAME_STACK_ADDRESS): Remove; replace with the new
  SCM_FRAME_LOCALS_ADDRESS.
  (SCM_FRAME_UPPER_ADDRESS): Remove; unused.
  (SCM_FRAME_NUM_LOCALS, SCM_FRAME_PREVIOUS_SP): New defines.
  (SCM_FRAME_BYTE_CAST, SCM_FRAME_STACK_CAST): Remove; unused;
  (SCM_FRAME_LOCAL): New define, replaces SCM_FRAME_VARIABLE.
  (SCM_FRAME_PROGRAM): Add cautionary commentary.

* libguile/frames.c: Adapt static asserts.
  (scm_frame_num_locals, scm_frame_local_ref, scm_frame_local_set_x):
  Adapt.  This means that frame-local-ref 0 now returns the procedure.

* libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME)
  (FRAME_LOCALS_COUNT, LOCAL_REF, LOCAL_SET, RETURN_VALUE_LIST): Adapt
  to change in fp.
  (LOCAL_ADDRESS): New helper.
  (POP_CONTINUATION_HOOK): Reimplement, taking the previous FP as an
  argument.
  (ABORT_CONTINUATION_HOOK): Reimplement, taking no arguments.
  (RETURN_ONE_VALUE): Reimplement.
  (RETURN_VALUE_LIST): Adapt to FP change.
  (halt, return-values, subr-call, foreign-call, prompt)
  (continuation-call, compose-continuation, call/cc, abort): Adapt to FP
  change, mostly via using LOCAL_ADDRESS, etc abstractions instead of
  using the raw frame pointer.

* libguile/control.c (reify_partial_continuation): Update for fp
  change.

* libguile/vm.c (vm_reinstate_partial_continuation): Adapt to removal of
  SCM_FRAME_UPPER_ADDRESS.

* module/system/vm/frame.scm (frame-call-representation): Adapt to
  frame-local-ref change.

* module/system/vm/trace.scm (print-return): Remove unused
  frame-num-locals call.
2013-11-17 22:07:44 +01:00
Andy Wingo
f8085163d6 Remove MVRA from VM frames
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump for frame layout
  change.

* libguile/frames.c: Update some static checks.
  (scm_frame_num_locals, scm_frame_local_ref, scm_frame_local_set_x):
  Update to not skip over uninitialized frames, as that's not a thing
  any more.

* libguile/frames.h: Update to remove MVRA.  Woo!

* libguile/vm-engine.c (ALLOC_FRAME, RETURN_ONE_VALUE):
  (rtl_vm_engine): Update for 3 words per frame instead of 4.

* libguile/vm.c (vm_return_to_continuation): Likewise.

* module/language/cps/slot-allocation.scm (allocate-slots): 3 words per
  frame, not 4.

* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.  Also
  remove a couple of tc7's that aren't around any more.
2013-11-15 17:13:27 +01:00
Andy Wingo
840ec33422 Remove MVRA accessors in libguile
* libguile/vm.c (scm_i_vm_capture_stack): Remove MVRA argument, in
  preparation for removing MVRA from frames.
  (scm_i_capture_current_stack): Adapt to scm_i_vm_capture_stack
  change.
  (vm_reinstate_partial_continuation): Remove references to MVRA.

* libguile/vm.h (struct scm_vm_cont): Remove mvra member.

* libguile/vm-engine.c (call): Set MVRA to 0.  Will remove later.
  (return-values): Return to RA.
  (call/cc): Remove MVRA from capture call.

* libguile/frames.c:
* libguile/frames.h (SCM_FRAME_MV_RETURN_ADDRESS)
  (SCM_FRAME_RTL_MV_RETURN_ADDRESS, scm_frame_mv_return_address): Remove
  accessors.

* libguile/control.c (reify_partial_continuation): Adapt to
  scm_i_vm_capture_stack change.
2013-11-15 15:39:38 +01:00
Andy Wingo
510ca12687 add new rtl vm
* libguile/vm-engine.c (rtl_vm_engine): Add new VM.
  (vm_engine): Add support for calling RTL programs.

* libguile/tags.h (scm_tc7_rtl_program): New type for procedures that
  run on the new VM.
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (scm_class_of):
* libguile/print.c (iprin1):
* libguile/procprop.c (scm_i_procedure_arity):
* libguile/procs.c (scm_procedure_p): Add hooks for the new tc7.

* libguile/programs.h:
* libguile/programs.c (scm_make_rtl_program, scm_i_rtl_program_print)
  (scm_rtl_program_p, scm_rtl_program_code):
* module/system/vm/program.scm: Add constructors and accessors for the
  new "RTL programs".

* libguile/vm.c (rtl_boot_continuation): Define a boot program.
  (rtl_apply, rtl_values): New static RTL programs.

* libguile/frames.c (scm_frame_num_locals): Adapt for frames of RTL
  programs.

* libguile/frames.h: Add description of RTL frames.

* libguile/Makefile.am: Add rules to generate vm-operations.h.
* .gitignore: Ignore vm-operations.h.
* module/system/vm/instruction.scm:
* libguile/instructions.c:
* libguile/instructions.h: Use vm-operations.h to define enumerated
  values for the new RTL opcodes.  Define some helper macros to pack and
  unpack 32-bit instruction words.
  (rtl-instruction-list): New function, exported by (system vm
  instruction).

* libguile/objcodes.c: Wire up the bits needed to detect the new RTL
  bytecode and load it, as appropriate.
2013-05-31 09:48:16 -04: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
Ludovic Courtès
0fc9040fa2 Parenthesize and type SCM_FRAME' macros; check layout of scm_vm_frame'.
* libguile/frames.c: Add compile-time assertions on the layout of
  `struct scm_vm_frame'.
  (RELOC): Parenthesize and type VAL.

* libguile/frames.h (SCM_FRAME_STRUCT): Write in terms of
  `SCM_FRAME_DATA_ADDRESS'.
  (SCM_FRAME_DATA_ADDRESS): Parenthesize and type FP.
  (SCM_FRAME_SET_DYNAMIC_LINK): Write in terms of
  `SCM_FRAME_DYNAMIC_LINK'.

* libguile/vm.c (RELOC): Parenthesize and type SCM_P.
2012-01-22 23:23:44 +01:00
Andy Wingo
4938d3cb74 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	GUILE-VERSION
	libguile/deprecated.c
	libguile/gc-malloc.c
	module/language/tree-il/peval.scm
2011-10-27 13:45:04 +02: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
3e54fdfc21 slight frames.h refactor
* libguile/frames.h: Instead of doing a lot of nasty pointer match and
  casts here, simply define a struct that aliases the contents of a
  stack frame.  There are some naming issues here, that the SCM_FRAME
  macros access the scm_vm_frame structure, but SCM_VM_FRAME macros
  access scm_frame; oh well.
2011-10-19 11:55:27 +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
542f975e60 add ,registers
* libguile/frames.h:
* libguile/frames.c (scm_frame_stack_pointer): New function.

* module/system/repl/debug.scm (print-registers): New function, prints
  out registers.

* module/system/repl/command.scm (registers): New debugging
  meta-command.
  (inspect): Not a stack-command, a normal meta-command.
2010-09-30 21:29:20 +02:00
Andy Wingo
2e30f3989c add scm_frame_address / frame-address
* libguile/frames.h:
* libguile/frames.c (scm_frame_address): New accessor, returns a frame's
  fp.
2010-09-23 13:19:49 +02: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
93dbc31b9a expose frame-previous, once again
* libguile/frames.h:
* libguile/frames.c (scm_frame_previous): Rename from scm_c_frame_prev,
  and expose to Scheme. Skip boot frames.

* libguile/stacks.c (stack_depth, narrow_stack, scm_make_stack)
  (scm_stack_ref): Adjust for scm_frame_previous skipping boot frames.
2009-12-15 00:22:02 +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
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
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