2010-01-05 18:50:17 +01:00
|
|
|
|
/* Copyright (C) 2001, 2009, 2010 Free Software Foundation, Inc.
|
2000-08-22 15:54:19 +00:00
|
|
|
|
*
|
2009-05-26 22:23:44 +02:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
|
* as published by the Free Software Foundation; either version 3 of
|
|
|
|
|
|
* the License, or (at your option) any later version.
|
2000-08-22 15:54:19 +00:00
|
|
|
|
*
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* This library is distributed in the hope that it will be useful, but
|
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
2009-05-26 22:23:44 +02:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
* Lesser General Public License for more details.
|
2000-08-22 15:54:19 +00:00
|
|
|
|
*
|
2009-05-26 22:23:44 +02:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
|
* 02110-1301 USA
|
2009-05-26 22:23:44 +02:00
|
|
|
|
*/
|
2000-08-22 15:54:19 +00:00
|
|
|
|
|
2008-05-20 11:46:52 +02:00
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
|
|
# include <config.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2009-04-05 20:15:11 +02:00
|
|
|
|
#include <stdlib.h>
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
#include <alloca.h>
|
2010-06-01 00:40:00 +02:00
|
|
|
|
#include <alignof.h>
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#include <string.h>
|
2009-08-20 01:56:47 +02:00
|
|
|
|
|
2009-09-13 15:59:31 +02:00
|
|
|
|
#include "libguile/bdw-gc.h"
|
2009-08-20 01:56:47 +02:00
|
|
|
|
#include <gc/gc_mark.h>
|
|
|
|
|
|
|
2009-05-26 22:23:44 +02:00
|
|
|
|
#include "_scm.h"
|
2010-02-02 22:59:55 +01:00
|
|
|
|
#include "control.h"
|
2001-04-22 02:13:48 +00:00
|
|
|
|
#include "frames.h"
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#include "instructions.h"
|
2001-04-16 03:43:48 +00:00
|
|
|
|
#include "objcodes.h"
|
2001-04-22 02:13:48 +00:00
|
|
|
|
#include "programs.h"
|
2000-08-22 15:54:19 +00:00
|
|
|
|
#include "vm.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* I sometimes use this for debugging. */
|
|
|
|
|
|
#define vm_puts(OBJ) \
|
|
|
|
|
|
{ \
|
enable inlining; speed!
* module/system/il/inline.scm: New module, implements generic inlining of
scheme functions. It even does the right thing regarding (define
arity:nopt caddr) and such. So now there are many more inlines: the
arithmetics, `apply', the caddr family, etc. This makes the benchmarks
*much* faster.
* module/language/scheme/translate.scm (trans): Remove the
%scheme-primitives code in favor of the generic (scheme il inline)
code. Adds inlining for +, -, =, etc.
* src/vm.c (vm_puts): Fix to work.
* module/system/base/compile.scm (system): Export load/compile also.
* module/system/il/compile.scm (optimize): Further debitrotting, but I
haven't tried this function yet. It seems that <ghil-inst> was what
<ghil-inline> is.
* module/system/il/ghil.scm (*core-primitives*, *macro-module*)
(ghil-primitive-macro?, ghil-macro-expander, ghil-primitive?): Remove
these unused things.
* module/system/il/macros.scm: Removed, replaced with inline.scm.
* module/system/vm/assemble.scm (stack->bytes): Before, the final
serialization code did an (apply u8vector (apply append (map
u8vector->list ...))). Aside from the misspelling of append-map, this
ends up pushing all elements of the u8vector on the stack -- assuredly
not what you want. But besides even that, I think that pushing more
than 32k arguments on the stack brings out some other bug that I think
was hidden before, because now we actually use the `apply' VM
instruction. Further testing is needed here, I think. Fixed the code to
be more efficient, which fixes the manifestation of this particular
bug: a failure to self-compile after inlining was enabled.
* module/system/vm/bootstrap.scm: New module, serves to bootstrap
boot-9's `load-compiled'. That way when we load (system vm core), we're
loading compiled code already.
* module/system/vm/core.scm: Use (system vm bootstrap).
* src/guilec.in: Use the bootstrap code, so that we really are compiling
with an entirely compiled compiler.
* module/system/repl/repl.scm (default-catch-handler): An attempt at
making the repl print a backtrace; more work needed here.
* module/system/vm/frame.scm (make-frame-chain): Fix some misspellings --
I think, anyway.
2008-05-25 13:13:15 +02:00
|
|
|
|
scm_display (OBJ, scm_current_error_port ()); \
|
|
|
|
|
|
scm_newline (scm_current_error_port ()); \
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
precise stack marking, fix some missed references, still imperfect
* libguile/vm-engine.h (CHECK_STACK_LEAK, NULLSTACK): Add a new mode,
VM_ENABLE_STACK_NULLING, that tries to ensure that all stack data past
the top of the stack is NULL. This helps to verify the VM's
consistency. If VM_ENABLE_STACK_NULLING is not defined, there is no
overhead.
(DROP, DROPN): Hook into NULLSTACK.
(POP_LIST): Hoo, fix a good bug: if CONS triggered a GC, the elements
of the list that had not yet been consed would not be marked, because
the sp was already below them.
(NEXT): Hook into CHECK_STACK_LEAK.
(INIT_ARGS): Add a note that consing the rest arg can cause GC.
(NEW_FRAME): Cons up the external data after initializing the frame, so
that if GC is triggered, the precise marker sees a well-formed frame.
* libguile/vm-i-loader.c (load-program): In the four-integers case, use
the POP macro so that we can hook into NULLSTACK (if necessary).
* libguile/vm-i-scheme.c (ARGS2, ARGS3): Hook into NULLSTACK.
* libguile/vm-i-system.c (halt): Null the nvalues. Rework some asserts
into using ASSERT, and null the stack when we free the frame.
(variable-set): Use DROPN instead of sp -= 2.
(BR): Hook into NULLSTACK.
(goto/args): Hook into NULLSTACK. In the non-self case, delay updating
the frame until after INIT_ARGS so that GC sees a well-formed frame.
Delay consing the externals until after the frame is set up, as in
NEW_FRAME.
(call/cc): Add some asserts.
(return): Rework some asserts into ASSERT, and hook into NULLSTACK.
(return/values): Hook into NULLSTACK, and use ASSERT.
(return/values*) Use ASSERT.
* libguile/vm.c (VM_ENABLE_ASSERTIONS, VM_ENABLE_STACK_NULLING): These
are the variables that control assertions and nulling. Perhaps we can
do these per-engine when we start compiling the debug engine separate
from a speedy engine.
(vm_mark_stack): Add a precise stack marker. Yay!
(vm_cont_mark): Mark the continuation stack precisely.
(capture_vm_cont): Record the difference from the vp's stack_base too,
so that we can translate the dynamic links when marking the
continuation stack. Memset the stack to NULL if we are doing nulling.
(reinstate_vm_cont): If we are nulling, null out the relevant part
of the stack.
(vm_reset_stack): When resetting sp due to a nonlocal exit, null out
the stack too.
(vm_mark): If we are nulling, assert that there are no extra values on
the stack. Mark the stack precisely.
2008-10-03 16:00:30 +02:00
|
|
|
|
/* The VM has a number of internal assertions that shouldn't normally be
|
|
|
|
|
|
necessary, but might be if you think you found a bug in the VM. */
|
|
|
|
|
|
#define VM_ENABLE_ASSERTIONS
|
|
|
|
|
|
|
|
|
|
|
|
/* We can add a mode that ensures that all stack items above the stack pointer
|
|
|
|
|
|
are NULL. This is useful for checking the internal consistency of the VM's
|
|
|
|
|
|
assumptions and its operators, but isn't necessary for normal operation. It
|
2009-01-12 22:37:29 +01:00
|
|
|
|
will ensure that assertions are enabled. Slows down the VM by about 30%. */
|
2009-02-04 00:09:38 +01:00
|
|
|
|
/* NB! If you enable this, search for NULLING in throw.c */
|
2009-01-12 22:37:29 +01:00
|
|
|
|
/* #define VM_ENABLE_STACK_NULLING */
|
precise stack marking, fix some missed references, still imperfect
* libguile/vm-engine.h (CHECK_STACK_LEAK, NULLSTACK): Add a new mode,
VM_ENABLE_STACK_NULLING, that tries to ensure that all stack data past
the top of the stack is NULL. This helps to verify the VM's
consistency. If VM_ENABLE_STACK_NULLING is not defined, there is no
overhead.
(DROP, DROPN): Hook into NULLSTACK.
(POP_LIST): Hoo, fix a good bug: if CONS triggered a GC, the elements
of the list that had not yet been consed would not be marked, because
the sp was already below them.
(NEXT): Hook into CHECK_STACK_LEAK.
(INIT_ARGS): Add a note that consing the rest arg can cause GC.
(NEW_FRAME): Cons up the external data after initializing the frame, so
that if GC is triggered, the precise marker sees a well-formed frame.
* libguile/vm-i-loader.c (load-program): In the four-integers case, use
the POP macro so that we can hook into NULLSTACK (if necessary).
* libguile/vm-i-scheme.c (ARGS2, ARGS3): Hook into NULLSTACK.
* libguile/vm-i-system.c (halt): Null the nvalues. Rework some asserts
into using ASSERT, and null the stack when we free the frame.
(variable-set): Use DROPN instead of sp -= 2.
(BR): Hook into NULLSTACK.
(goto/args): Hook into NULLSTACK. In the non-self case, delay updating
the frame until after INIT_ARGS so that GC sees a well-formed frame.
Delay consing the externals until after the frame is set up, as in
NEW_FRAME.
(call/cc): Add some asserts.
(return): Rework some asserts into ASSERT, and hook into NULLSTACK.
(return/values): Hook into NULLSTACK, and use ASSERT.
(return/values*) Use ASSERT.
* libguile/vm.c (VM_ENABLE_ASSERTIONS, VM_ENABLE_STACK_NULLING): These
are the variables that control assertions and nulling. Perhaps we can
do these per-engine when we start compiling the debug engine separate
from a speedy engine.
(vm_mark_stack): Add a precise stack marker. Yay!
(vm_cont_mark): Mark the continuation stack precisely.
(capture_vm_cont): Record the difference from the vp's stack_base too,
so that we can translate the dynamic links when marking the
continuation stack. Memset the stack to NULL if we are doing nulling.
(reinstate_vm_cont): If we are nulling, null out the relevant part
of the stack.
(vm_reset_stack): When resetting sp due to a nonlocal exit, null out
the stack too.
(vm_mark): If we are nulling, assert that there are no extra values on
the stack. Mark the stack precisely.
2008-10-03 16:00:30 +02:00
|
|
|
|
|
static opcodes; refactor program/objcode division; use new assembly pipeline
* gdbinit: Untested attempts to get the stack fondling macros to deal
with the new program representation.
* libguile/frames.c (scm_vm_frame_arguments, scm_vm_frame_source)
(scm_vm_frame_local_ref, scm_vm_frame_local_set_x): SCM_PROGRAM_DATA is
a struct scm_objcode*.
* libguile/instructions.h:
* libguile/instructions.c: Hide the instruction table and the struct
scm_instruction structure; all access to instructions now goes through
procedures. This is because instructions are no longer in a packed
array indexed by opcode. Also, declare a mask that all instructions
should fit in.
* libguile/objcodes.h:
* libguile/objcodes.c: Rewrite so that object code directly maps its
arity and length from its bytecode. This makes it unnecessary to keep
this information in programs, allowing programs to be simple conses
between the code (objcodes) and data (the object table and the closure
variables).
* libguile/programs.c (scm_make_program): Rework so that make-program
takes objcode, an object table, and externals as arguments. It's much
clearer this way, and we avoid malloc().
* libguile/stacks.c (is_vm_bootstrap_frame): Update for program/objcode
changes.
* libguile/vm-engine.c (vm_run): Initialize the jump table on the first
run, with the opcodes declared in the instruction sources, and with bad
instructions raising an error instead of wandering off into the
Unknown.
* libguile/vm-engine.h (FETCH_LENGTH): Always represent lengths as 3
bytes. The old code was too error-prone.
(NEXT_JUMP): Mask the instruction with SCM_VM_INSTRUCTION_MASK.
(NEW_FRAME): Update for program/objcode changes.
* libguile/vm-expand.h (VM_DEFINE_FUNCTION, VM_DEFINE_INSTRUCTION)
(VM_DEFINE_LOADER): Update so that we explicitly specify opcodes, so
that we have a stable bytecode API.
* libguile/vm-i-loader.c: Update license to LGPLv2+. Explicitly declare
opcodes.
(load-integer): Use an int instead of a long as the accumulator; still
need to revisit this code at some point, I think.
(load-program): Simplify, thankfully!! Just creates the objcode slice
and rolls with it.
* libguile/vm-i-scheme.c: Number the opcodes explicitly.
* libguile/vm-i-system.c: Update license to LGPLv2+. Explicitly declare
opcodes.
(make-closure): Update for new program API.
* libguile/vm.c (vm_make_boot_program): Update for new program/objcode
API. Still a bit ugly.
(scm_load_compiled_with_vm): Update for new program/objcode API.
* module/language/assembly.scm (byte-length): Fix byte-length calculation
for loaders, and load-program.
(code-pack, code-unpack): Start to move things from (system vm conv)
here.
(object->code, code->object): More things from conv.scm.
* module/language/glil.scm (<glil-program>): Add a new field,
closure-level.
(make-glil-program, compute-closure-level): Calculate the "closure
level" when making a glil program. This is the maximum depth of
external binding refs in this closure.
(unparse-glil): Fix label serialization.
* module/language/glil/compile-assembly.scm (make-meta): Prepend #f for
the meta's object table, though maybe in the future we can avoid
creating assembly in the first place.
(assoc-ref-or-acons, object-index-and-alist): GRRR! Caught again by the
different sets of arguments to assoc and assoc-ref!
(glil->assembly): Attempt to make the <glil-program> case more
readable, and fix the bugs. Sorry I don't know how to comment this
change any more than this.
(glil->assembly): For <glil-module> serialize the whole key, not just
the name.
(dump-object): subprogram-code is already a list. Serialize integers as
strings, not u8vectors. Fix the order of lists and vectors.
* module/language/glil/spec.scm (glil): Switch orders, so we prefer glil
-> assembly -> objcode. Actually glil->objcode doesn't work any more,
needs to be removed I think.
* module/language/objcode/spec.scm (objcode->value):
s/objcode->program/make-program/.
* module/language/scheme/inline.scm: Add acons inline.
* module/system/vm/conv.scm (make-byte-decoder): Skip the first 8 bytes,
they are header. Handle subprograms properly. Still needs help though.
(decode-length): Lengths are always 3 bytes now.
* module/system/vm/disasm.scm: Superficial changes to keep things
working. I'd like to fix this better in the future.
* module/system/vm/frame.scm (bootstrap-frame?): Fixes for
program-bytecode.
* module/system/vm/program.scm: Export make-program. It's program-objcode
now, no more program-bytecode.
* module/system/vm/vm.scm (vm-load): Use make-program.
* test-suite/tests/asm-to-bytecode.test: New test, very minimal.
* module/system/vm/objcode.scm: Export word-size, byte-order, and
write-objcode.
2009-01-29 21:09:04 +01:00
|
|
|
|
/* #define VM_ENABLE_PARANOID_ASSERTIONS */
|
|
|
|
|
|
|
precise stack marking, fix some missed references, still imperfect
* libguile/vm-engine.h (CHECK_STACK_LEAK, NULLSTACK): Add a new mode,
VM_ENABLE_STACK_NULLING, that tries to ensure that all stack data past
the top of the stack is NULL. This helps to verify the VM's
consistency. If VM_ENABLE_STACK_NULLING is not defined, there is no
overhead.
(DROP, DROPN): Hook into NULLSTACK.
(POP_LIST): Hoo, fix a good bug: if CONS triggered a GC, the elements
of the list that had not yet been consed would not be marked, because
the sp was already below them.
(NEXT): Hook into CHECK_STACK_LEAK.
(INIT_ARGS): Add a note that consing the rest arg can cause GC.
(NEW_FRAME): Cons up the external data after initializing the frame, so
that if GC is triggered, the precise marker sees a well-formed frame.
* libguile/vm-i-loader.c (load-program): In the four-integers case, use
the POP macro so that we can hook into NULLSTACK (if necessary).
* libguile/vm-i-scheme.c (ARGS2, ARGS3): Hook into NULLSTACK.
* libguile/vm-i-system.c (halt): Null the nvalues. Rework some asserts
into using ASSERT, and null the stack when we free the frame.
(variable-set): Use DROPN instead of sp -= 2.
(BR): Hook into NULLSTACK.
(goto/args): Hook into NULLSTACK. In the non-self case, delay updating
the frame until after INIT_ARGS so that GC sees a well-formed frame.
Delay consing the externals until after the frame is set up, as in
NEW_FRAME.
(call/cc): Add some asserts.
(return): Rework some asserts into ASSERT, and hook into NULLSTACK.
(return/values): Hook into NULLSTACK, and use ASSERT.
(return/values*) Use ASSERT.
* libguile/vm.c (VM_ENABLE_ASSERTIONS, VM_ENABLE_STACK_NULLING): These
are the variables that control assertions and nulling. Perhaps we can
do these per-engine when we start compiling the debug engine separate
from a speedy engine.
(vm_mark_stack): Add a precise stack marker. Yay!
(vm_cont_mark): Mark the continuation stack precisely.
(capture_vm_cont): Record the difference from the vp's stack_base too,
so that we can translate the dynamic links when marking the
continuation stack. Memset the stack to NULL if we are doing nulling.
(reinstate_vm_cont): If we are nulling, null out the relevant part
of the stack.
(vm_reset_stack): When resetting sp due to a nonlocal exit, null out
the stack too.
(vm_mark): If we are nulling, assert that there are no extra values on
the stack. Mark the stack precisely.
2008-10-03 16:00:30 +02:00
|
|
|
|
#if defined (VM_ENABLE_STACK_NULLING) && !defined (VM_ENABLE_ASSERTIONS)
|
|
|
|
|
|
#define VM_ENABLE_ASSERTIONS
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2009-08-20 01:56:47 +02:00
|
|
|
|
/* When defined, arrange so that the GC doesn't scan the VM stack beyond its
|
|
|
|
|
|
current SP. This should help avoid excess data retention. See
|
|
|
|
|
|
http://thread.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/3001
|
|
|
|
|
|
for a discussion. */
|
|
|
|
|
|
#define VM_ENABLE_PRECISE_STACK_GC_SCAN
|
|
|
|
|
|
|
2010-05-26 23:00:58 +02:00
|
|
|
|
/* Size in SCM objects of the stack reserve. The reserve is used to run
|
|
|
|
|
|
exception handling code in case of a VM stack overflow. */
|
|
|
|
|
|
#define VM_STACK_RESERVE_SIZE 512
|
|
|
|
|
|
|
2009-08-20 01:56:47 +02:00
|
|
|
|
|
2000-08-22 15:54:19 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* VM Continuation
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2010-01-05 19:45:56 +01:00
|
|
|
|
void
|
|
|
|
|
|
scm_i_vm_cont_print (SCM x, SCM port, scm_print_state *pstate)
|
|
|
|
|
|
{
|
|
|
|
|
|
scm_puts ("#<vm-continuation ", port);
|
|
|
|
|
|
scm_uintprint (SCM_UNPACK (x), 16, port);
|
|
|
|
|
|
scm_puts (">", port);
|
|
|
|
|
|
}
|
2001-04-01 05:03:41 +00:00
|
|
|
|
|
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
|
|
|
|
/* In theory, a number of vm instances can be active in the call trace, and we
|
|
|
|
|
|
only want to reify the continuations of those in the current continuation
|
|
|
|
|
|
root. I don't see a nice way to do this -- ideally it would involve dynwinds,
|
|
|
|
|
|
and previous values of the *the-vm* fluid within the current continuation
|
|
|
|
|
|
root. But we don't have access to continuation roots in the dynwind stack.
|
|
|
|
|
|
So, just punt for now, we just capture the continuation for the current VM.
|
|
|
|
|
|
|
|
|
|
|
|
While I'm on the topic, ideally we could avoid copying the C stack if the
|
|
|
|
|
|
continuation root is inside VM code, and call/cc was invoked within that same
|
|
|
|
|
|
call to vm_run; but that's currently not implemented.
|
|
|
|
|
|
*/
|
2010-02-22 23:00:19 +01:00
|
|
|
|
SCM
|
|
|
|
|
|
scm_i_vm_capture_stack (SCM *stack_base, SCM *fp, SCM *sp, scm_t_uint8 *ra,
|
|
|
|
|
|
scm_t_uint8 *mvra, scm_t_uint32 flags)
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
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
|
|
|
|
struct scm_vm_cont *p;
|
|
|
|
|
|
|
|
|
|
|
|
p = scm_gc_malloc (sizeof (*p), "capture_vm_cont");
|
|
|
|
|
|
p->stack_size = sp - stack_base + 1;
|
2005-04-22 16:00:33 +00:00
|
|
|
|
p->stack_base = scm_gc_malloc (p->stack_size * sizeof (SCM),
|
|
|
|
|
|
"capture_vm_cont");
|
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
|
|
|
|
#if defined(VM_ENABLE_STACK_NULLING) && 0
|
|
|
|
|
|
/* Tail continuations leave their frame on the stack for subsequent
|
|
|
|
|
|
application, but don't capture the frame -- so there are some elements on
|
|
|
|
|
|
the stack then, and this check doesn't work, so disable it for now. */
|
|
|
|
|
|
if (sp >= vp->stack_base)
|
2008-10-09 14:44:43 +02:00
|
|
|
|
if (!vp->sp[0] || vp->sp[1])
|
|
|
|
|
|
abort ();
|
precise stack marking, fix some missed references, still imperfect
* libguile/vm-engine.h (CHECK_STACK_LEAK, NULLSTACK): Add a new mode,
VM_ENABLE_STACK_NULLING, that tries to ensure that all stack data past
the top of the stack is NULL. This helps to verify the VM's
consistency. If VM_ENABLE_STACK_NULLING is not defined, there is no
overhead.
(DROP, DROPN): Hook into NULLSTACK.
(POP_LIST): Hoo, fix a good bug: if CONS triggered a GC, the elements
of the list that had not yet been consed would not be marked, because
the sp was already below them.
(NEXT): Hook into CHECK_STACK_LEAK.
(INIT_ARGS): Add a note that consing the rest arg can cause GC.
(NEW_FRAME): Cons up the external data after initializing the frame, so
that if GC is triggered, the precise marker sees a well-formed frame.
* libguile/vm-i-loader.c (load-program): In the four-integers case, use
the POP macro so that we can hook into NULLSTACK (if necessary).
* libguile/vm-i-scheme.c (ARGS2, ARGS3): Hook into NULLSTACK.
* libguile/vm-i-system.c (halt): Null the nvalues. Rework some asserts
into using ASSERT, and null the stack when we free the frame.
(variable-set): Use DROPN instead of sp -= 2.
(BR): Hook into NULLSTACK.
(goto/args): Hook into NULLSTACK. In the non-self case, delay updating
the frame until after INIT_ARGS so that GC sees a well-formed frame.
Delay consing the externals until after the frame is set up, as in
NEW_FRAME.
(call/cc): Add some asserts.
(return): Rework some asserts into ASSERT, and hook into NULLSTACK.
(return/values): Hook into NULLSTACK, and use ASSERT.
(return/values*) Use ASSERT.
* libguile/vm.c (VM_ENABLE_ASSERTIONS, VM_ENABLE_STACK_NULLING): These
are the variables that control assertions and nulling. Perhaps we can
do these per-engine when we start compiling the debug engine separate
from a speedy engine.
(vm_mark_stack): Add a precise stack marker. Yay!
(vm_cont_mark): Mark the continuation stack precisely.
(capture_vm_cont): Record the difference from the vp's stack_base too,
so that we can translate the dynamic links when marking the
continuation stack. Memset the stack to NULL if we are doing nulling.
(reinstate_vm_cont): If we are nulling, null out the relevant part
of the stack.
(vm_reset_stack): When resetting sp due to a nonlocal exit, null out
the stack too.
(vm_mark): If we are nulling, assert that there are no extra values on
the stack. Mark the stack precisely.
2008-10-03 16:00:30 +02:00
|
|
|
|
memset (p->stack_base, 0, p->stack_size * sizeof (SCM));
|
|
|
|
|
|
#endif
|
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
|
|
|
|
p->ra = ra;
|
|
|
|
|
|
p->mvra = mvra;
|
|
|
|
|
|
p->sp = sp;
|
|
|
|
|
|
p->fp = fp;
|
|
|
|
|
|
memcpy (p->stack_base, stack_base, (sp + 1 - stack_base) * sizeof (SCM));
|
|
|
|
|
|
p->reloc = p->stack_base - stack_base;
|
2010-02-22 23:00:19 +01:00
|
|
|
|
p->flags = flags;
|
2010-01-05 19:45:56 +01:00
|
|
|
|
return scm_cell (scm_tc7_vm_cont, (scm_t_bits)p);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
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
|
|
|
|
vm_return_to_continuation (SCM vm, SCM cont, size_t n, SCM *argv)
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
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
|
|
|
|
struct scm_vm *vp;
|
|
|
|
|
|
struct scm_vm_cont *cp;
|
|
|
|
|
|
SCM *argv_copy;
|
|
|
|
|
|
|
|
|
|
|
|
argv_copy = alloca (n * sizeof(SCM));
|
|
|
|
|
|
memcpy (argv_copy, argv, n * sizeof(SCM));
|
|
|
|
|
|
|
|
|
|
|
|
vp = SCM_VM_DATA (vm);
|
|
|
|
|
|
cp = SCM_VM_CONT_DATA (cont);
|
|
|
|
|
|
|
|
|
|
|
|
if (n == 0 && !cp->mvra)
|
|
|
|
|
|
scm_misc_error (NULL, "Too few values returned to continuation",
|
|
|
|
|
|
SCM_EOL);
|
|
|
|
|
|
|
|
|
|
|
|
if (vp->stack_size < cp->stack_size + n + 1)
|
2010-02-24 18:51:25 +01:00
|
|
|
|
scm_misc_error ("vm-engine", "not enough space to reinstate continuation",
|
|
|
|
|
|
scm_list_2 (vm, cont));
|
|
|
|
|
|
|
precise stack marking, fix some missed references, still imperfect
* libguile/vm-engine.h (CHECK_STACK_LEAK, NULLSTACK): Add a new mode,
VM_ENABLE_STACK_NULLING, that tries to ensure that all stack data past
the top of the stack is NULL. This helps to verify the VM's
consistency. If VM_ENABLE_STACK_NULLING is not defined, there is no
overhead.
(DROP, DROPN): Hook into NULLSTACK.
(POP_LIST): Hoo, fix a good bug: if CONS triggered a GC, the elements
of the list that had not yet been consed would not be marked, because
the sp was already below them.
(NEXT): Hook into CHECK_STACK_LEAK.
(INIT_ARGS): Add a note that consing the rest arg can cause GC.
(NEW_FRAME): Cons up the external data after initializing the frame, so
that if GC is triggered, the precise marker sees a well-formed frame.
* libguile/vm-i-loader.c (load-program): In the four-integers case, use
the POP macro so that we can hook into NULLSTACK (if necessary).
* libguile/vm-i-scheme.c (ARGS2, ARGS3): Hook into NULLSTACK.
* libguile/vm-i-system.c (halt): Null the nvalues. Rework some asserts
into using ASSERT, and null the stack when we free the frame.
(variable-set): Use DROPN instead of sp -= 2.
(BR): Hook into NULLSTACK.
(goto/args): Hook into NULLSTACK. In the non-self case, delay updating
the frame until after INIT_ARGS so that GC sees a well-formed frame.
Delay consing the externals until after the frame is set up, as in
NEW_FRAME.
(call/cc): Add some asserts.
(return): Rework some asserts into ASSERT, and hook into NULLSTACK.
(return/values): Hook into NULLSTACK, and use ASSERT.
(return/values*) Use ASSERT.
* libguile/vm.c (VM_ENABLE_ASSERTIONS, VM_ENABLE_STACK_NULLING): These
are the variables that control assertions and nulling. Perhaps we can
do these per-engine when we start compiling the debug engine separate
from a speedy engine.
(vm_mark_stack): Add a precise stack marker. Yay!
(vm_cont_mark): Mark the continuation stack precisely.
(capture_vm_cont): Record the difference from the vp's stack_base too,
so that we can translate the dynamic links when marking the
continuation stack. Memset the stack to NULL if we are doing nulling.
(reinstate_vm_cont): If we are nulling, null out the relevant part
of the stack.
(vm_reset_stack): When resetting sp due to a nonlocal exit, null out
the stack too.
(vm_mark): If we are nulling, assert that there are no extra values on
the stack. Mark the stack precisely.
2008-10-03 16:00:30 +02:00
|
|
|
|
#ifdef VM_ENABLE_STACK_NULLING
|
|
|
|
|
|
{
|
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
|
|
|
|
scm_t_ptrdiff nzero = (vp->sp - cp->sp);
|
precise stack marking, fix some missed references, still imperfect
* libguile/vm-engine.h (CHECK_STACK_LEAK, NULLSTACK): Add a new mode,
VM_ENABLE_STACK_NULLING, that tries to ensure that all stack data past
the top of the stack is NULL. This helps to verify the VM's
consistency. If VM_ENABLE_STACK_NULLING is not defined, there is no
overhead.
(DROP, DROPN): Hook into NULLSTACK.
(POP_LIST): Hoo, fix a good bug: if CONS triggered a GC, the elements
of the list that had not yet been consed would not be marked, because
the sp was already below them.
(NEXT): Hook into CHECK_STACK_LEAK.
(INIT_ARGS): Add a note that consing the rest arg can cause GC.
(NEW_FRAME): Cons up the external data after initializing the frame, so
that if GC is triggered, the precise marker sees a well-formed frame.
* libguile/vm-i-loader.c (load-program): In the four-integers case, use
the POP macro so that we can hook into NULLSTACK (if necessary).
* libguile/vm-i-scheme.c (ARGS2, ARGS3): Hook into NULLSTACK.
* libguile/vm-i-system.c (halt): Null the nvalues. Rework some asserts
into using ASSERT, and null the stack when we free the frame.
(variable-set): Use DROPN instead of sp -= 2.
(BR): Hook into NULLSTACK.
(goto/args): Hook into NULLSTACK. In the non-self case, delay updating
the frame until after INIT_ARGS so that GC sees a well-formed frame.
Delay consing the externals until after the frame is set up, as in
NEW_FRAME.
(call/cc): Add some asserts.
(return): Rework some asserts into ASSERT, and hook into NULLSTACK.
(return/values): Hook into NULLSTACK, and use ASSERT.
(return/values*) Use ASSERT.
* libguile/vm.c (VM_ENABLE_ASSERTIONS, VM_ENABLE_STACK_NULLING): These
are the variables that control assertions and nulling. Perhaps we can
do these per-engine when we start compiling the debug engine separate
from a speedy engine.
(vm_mark_stack): Add a precise stack marker. Yay!
(vm_cont_mark): Mark the continuation stack precisely.
(capture_vm_cont): Record the difference from the vp's stack_base too,
so that we can translate the dynamic links when marking the
continuation stack. Memset the stack to NULL if we are doing nulling.
(reinstate_vm_cont): If we are nulling, null out the relevant part
of the stack.
(vm_reset_stack): When resetting sp due to a nonlocal exit, null out
the stack too.
(vm_mark): If we are nulling, assert that there are no extra values on
the stack. Mark the stack precisely.
2008-10-03 16:00:30 +02:00
|
|
|
|
if (nzero > 0)
|
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
|
|
|
|
memset (vp->stack_base + cp->stack_size, 0, nzero * sizeof (SCM));
|
2008-10-09 14:44:43 +02:00
|
|
|
|
/* actually nzero should always be negative, because vm_reset_stack will
|
|
|
|
|
|
unwind the stack to some point *below* this continuation */
|
precise stack marking, fix some missed references, still imperfect
* libguile/vm-engine.h (CHECK_STACK_LEAK, NULLSTACK): Add a new mode,
VM_ENABLE_STACK_NULLING, that tries to ensure that all stack data past
the top of the stack is NULL. This helps to verify the VM's
consistency. If VM_ENABLE_STACK_NULLING is not defined, there is no
overhead.
(DROP, DROPN): Hook into NULLSTACK.
(POP_LIST): Hoo, fix a good bug: if CONS triggered a GC, the elements
of the list that had not yet been consed would not be marked, because
the sp was already below them.
(NEXT): Hook into CHECK_STACK_LEAK.
(INIT_ARGS): Add a note that consing the rest arg can cause GC.
(NEW_FRAME): Cons up the external data after initializing the frame, so
that if GC is triggered, the precise marker sees a well-formed frame.
* libguile/vm-i-loader.c (load-program): In the four-integers case, use
the POP macro so that we can hook into NULLSTACK (if necessary).
* libguile/vm-i-scheme.c (ARGS2, ARGS3): Hook into NULLSTACK.
* libguile/vm-i-system.c (halt): Null the nvalues. Rework some asserts
into using ASSERT, and null the stack when we free the frame.
(variable-set): Use DROPN instead of sp -= 2.
(BR): Hook into NULLSTACK.
(goto/args): Hook into NULLSTACK. In the non-self case, delay updating
the frame until after INIT_ARGS so that GC sees a well-formed frame.
Delay consing the externals until after the frame is set up, as in
NEW_FRAME.
(call/cc): Add some asserts.
(return): Rework some asserts into ASSERT, and hook into NULLSTACK.
(return/values): Hook into NULLSTACK, and use ASSERT.
(return/values*) Use ASSERT.
* libguile/vm.c (VM_ENABLE_ASSERTIONS, VM_ENABLE_STACK_NULLING): These
are the variables that control assertions and nulling. Perhaps we can
do these per-engine when we start compiling the debug engine separate
from a speedy engine.
(vm_mark_stack): Add a precise stack marker. Yay!
(vm_cont_mark): Mark the continuation stack precisely.
(capture_vm_cont): Record the difference from the vp's stack_base too,
so that we can translate the dynamic links when marking the
continuation stack. Memset the stack to NULL if we are doing nulling.
(reinstate_vm_cont): If we are nulling, null out the relevant part
of the stack.
(vm_reset_stack): When resetting sp due to a nonlocal exit, null out
the stack too.
(vm_mark): If we are nulling, assert that there are no extra values on
the stack. Mark the stack precisely.
2008-10-03 16:00:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
#endif
|
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
|
|
|
|
vp->sp = cp->sp;
|
|
|
|
|
|
vp->fp = cp->fp;
|
|
|
|
|
|
memcpy (vp->stack_base, cp->stack_base, cp->stack_size * sizeof (SCM));
|
2008-09-24 17:04:14 +02:00
|
|
|
|
|
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
|
|
|
|
if (n == 1 || !cp->mvra)
|
|
|
|
|
|
{
|
|
|
|
|
|
vp->ip = cp->ra;
|
|
|
|
|
|
vp->sp++;
|
|
|
|
|
|
*vp->sp = argv_copy[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
size_t i;
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
vp->sp++;
|
|
|
|
|
|
*vp->sp = argv_copy[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
vp->sp++;
|
|
|
|
|
|
*vp->sp = scm_from_size_t (n);
|
|
|
|
|
|
vp->ip = cp->mvra;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2008-09-24 17:04:14 +02:00
|
|
|
|
|
|
|
|
|
|
SCM
|
2010-02-07 14:50:51 +01:00
|
|
|
|
scm_i_vm_capture_continuation (SCM vm)
|
2008-09-24 17:04:14 +02:00
|
|
|
|
{
|
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
|
|
|
|
struct scm_vm *vp = SCM_VM_DATA (vm);
|
2010-02-22 23:00:19 +01:00
|
|
|
|
return scm_i_vm_capture_stack (vp->stack_base, vp->fp, vp->sp, vp->ip, NULL, 0);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
remove heap links in VM frames, incorporate vm frames into normal backtraces
* doc/ref/vm.texi (Stack Layout): Update to remove references to the
"heap link".
* gdbinit: Update for "heap link" removal.
* libguile/frames.c:
* libguile/frames.h: Update macros and diagram for removal of "heap
link". As part of this, we also remove "heap frames", replacing them
with "vm frames", which are much like the interpreter's debug objects,
but for VM stacks. That is to say, they don't actually hold the stack
themselves, just the pointers into stack that's held by a continuation
(either captured or current).
* libguile/stacks.c (stack_depth, read_frames): Since a "stack" object is
really a copy of information that comes from somewhere else, it makes
sense to copy over info from the VM, just as `make-stack' does from the
evaluator. The tricky bit is to figure out how to interleave VM and
interpreter frames. We do that by starting in the interpreter, and
whenever the current frame's procedure is actually a program, we switch
to the VM stack, switching back when we reach a "bootstrap frame". The
last bit is hacky, but it does work...
(is_vm_bootstrap_frame): Hacky predicate to see if a VM frame is a
bootstrap frame.
(scm_make_stack): Accept a VM frame in addition to debug frames.
Probably has some bugs in this case. But in the case that the arg is
#t (a common case), do the right thing, capturing the top VM frame as
well, and interleaving those frames appropriately on the stack.
As an accident, we lost the ability to limit the number of frames in
the backtrace. We could add that back, but personally I always want
*all* frames in the trace... Narrowing still works fine, though there
are some hiccups sometimes -- e.g. an outer cut to a procedure that
does a tail-call in VM code will never find the cut, as it no longer
exists in the continuation.
* libguile/vm.h (struct scm_vm): So! Now that we have switched to save
stacks in the normal make-stack, there's no more need for `this_frame'
or `last_frame'. On the other hand, we can take this opportunity to fix
tracing: when we're in a trace hook, we set `trace_frame' on the VM,
so we know not to fire hooks when we're already in a hook.
(struct scm_vm_cont): Expose this, as make-stack needs it to make VM
frames from VM continuations.
* libguile/vm.c (scm_vm_trace_frame): New function, gets the current
trace frame.
(vm_mark, make_vm): Hook up the trace frame.
(vm_dispatch_hook): New hook dispatcher, with a dynwind so it does the
right thing if the hook exits nonlocally.
* libguile/vm-engine.c (vm_run): No more this_frame in the wind data.
* libguile/vm-engine.h (RUN_HOOK): Run hooks through the dispatcher.
(ALIGN_AS_NON_IMMEDIATE, POP_LIST_ON_STACK): Remove unused code.
(NEW_FRAME): Adapt for no HL in the frame.
* libguile/vm-i-system.c (goto/args, mv-call, return, return/values):
Adapt for no HL in the frame.
* module/system/vm/frame.scm:
* module/system/vm/vm.scm: Beginnings of some reworkings, needs more
thought.
2008-12-26 17:59:46 +01:00
|
|
|
|
static void
|
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
|
|
|
|
vm_dispatch_hook (SCM vm, int hook_num)
|
remove heap links in VM frames, incorporate vm frames into normal backtraces
* doc/ref/vm.texi (Stack Layout): Update to remove references to the
"heap link".
* gdbinit: Update for "heap link" removal.
* libguile/frames.c:
* libguile/frames.h: Update macros and diagram for removal of "heap
link". As part of this, we also remove "heap frames", replacing them
with "vm frames", which are much like the interpreter's debug objects,
but for VM stacks. That is to say, they don't actually hold the stack
themselves, just the pointers into stack that's held by a continuation
(either captured or current).
* libguile/stacks.c (stack_depth, read_frames): Since a "stack" object is
really a copy of information that comes from somewhere else, it makes
sense to copy over info from the VM, just as `make-stack' does from the
evaluator. The tricky bit is to figure out how to interleave VM and
interpreter frames. We do that by starting in the interpreter, and
whenever the current frame's procedure is actually a program, we switch
to the VM stack, switching back when we reach a "bootstrap frame". The
last bit is hacky, but it does work...
(is_vm_bootstrap_frame): Hacky predicate to see if a VM frame is a
bootstrap frame.
(scm_make_stack): Accept a VM frame in addition to debug frames.
Probably has some bugs in this case. But in the case that the arg is
#t (a common case), do the right thing, capturing the top VM frame as
well, and interleaving those frames appropriately on the stack.
As an accident, we lost the ability to limit the number of frames in
the backtrace. We could add that back, but personally I always want
*all* frames in the trace... Narrowing still works fine, though there
are some hiccups sometimes -- e.g. an outer cut to a procedure that
does a tail-call in VM code will never find the cut, as it no longer
exists in the continuation.
* libguile/vm.h (struct scm_vm): So! Now that we have switched to save
stacks in the normal make-stack, there's no more need for `this_frame'
or `last_frame'. On the other hand, we can take this opportunity to fix
tracing: when we're in a trace hook, we set `trace_frame' on the VM,
so we know not to fire hooks when we're already in a hook.
(struct scm_vm_cont): Expose this, as make-stack needs it to make VM
frames from VM continuations.
* libguile/vm.c (scm_vm_trace_frame): New function, gets the current
trace frame.
(vm_mark, make_vm): Hook up the trace frame.
(vm_dispatch_hook): New hook dispatcher, with a dynwind so it does the
right thing if the hook exits nonlocally.
* libguile/vm-engine.c (vm_run): No more this_frame in the wind data.
* libguile/vm-engine.h (RUN_HOOK): Run hooks through the dispatcher.
(ALIGN_AS_NON_IMMEDIATE, POP_LIST_ON_STACK): Remove unused code.
(NEW_FRAME): Adapt for no HL in the frame.
* libguile/vm-i-system.c (goto/args, mv-call, return, return/values):
Adapt for no HL in the frame.
* module/system/vm/frame.scm:
* module/system/vm/vm.scm: Beginnings of some reworkings, needs more
thought.
2008-12-26 17:59:46 +01:00
|
|
|
|
{
|
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
|
|
|
|
struct scm_vm *vp;
|
|
|
|
|
|
SCM hook;
|
2010-04-21 01:05:42 +02:00
|
|
|
|
struct scm_frame c_frame;
|
2010-05-28 11:09:31 +02:00
|
|
|
|
scm_t_aligned_cell frame;
|
2010-04-21 01:05:42 +02:00
|
|
|
|
SCM args[1];
|
remove heap links in VM frames, incorporate vm frames into normal backtraces
* doc/ref/vm.texi (Stack Layout): Update to remove references to the
"heap link".
* gdbinit: Update for "heap link" removal.
* libguile/frames.c:
* libguile/frames.h: Update macros and diagram for removal of "heap
link". As part of this, we also remove "heap frames", replacing them
with "vm frames", which are much like the interpreter's debug objects,
but for VM stacks. That is to say, they don't actually hold the stack
themselves, just the pointers into stack that's held by a continuation
(either captured or current).
* libguile/stacks.c (stack_depth, read_frames): Since a "stack" object is
really a copy of information that comes from somewhere else, it makes
sense to copy over info from the VM, just as `make-stack' does from the
evaluator. The tricky bit is to figure out how to interleave VM and
interpreter frames. We do that by starting in the interpreter, and
whenever the current frame's procedure is actually a program, we switch
to the VM stack, switching back when we reach a "bootstrap frame". The
last bit is hacky, but it does work...
(is_vm_bootstrap_frame): Hacky predicate to see if a VM frame is a
bootstrap frame.
(scm_make_stack): Accept a VM frame in addition to debug frames.
Probably has some bugs in this case. But in the case that the arg is
#t (a common case), do the right thing, capturing the top VM frame as
well, and interleaving those frames appropriately on the stack.
As an accident, we lost the ability to limit the number of frames in
the backtrace. We could add that back, but personally I always want
*all* frames in the trace... Narrowing still works fine, though there
are some hiccups sometimes -- e.g. an outer cut to a procedure that
does a tail-call in VM code will never find the cut, as it no longer
exists in the continuation.
* libguile/vm.h (struct scm_vm): So! Now that we have switched to save
stacks in the normal make-stack, there's no more need for `this_frame'
or `last_frame'. On the other hand, we can take this opportunity to fix
tracing: when we're in a trace hook, we set `trace_frame' on the VM,
so we know not to fire hooks when we're already in a hook.
(struct scm_vm_cont): Expose this, as make-stack needs it to make VM
frames from VM continuations.
* libguile/vm.c (scm_vm_trace_frame): New function, gets the current
trace frame.
(vm_mark, make_vm): Hook up the trace frame.
(vm_dispatch_hook): New hook dispatcher, with a dynwind so it does the
right thing if the hook exits nonlocally.
* libguile/vm-engine.c (vm_run): No more this_frame in the wind data.
* libguile/vm-engine.h (RUN_HOOK): Run hooks through the dispatcher.
(ALIGN_AS_NON_IMMEDIATE, POP_LIST_ON_STACK): Remove unused code.
(NEW_FRAME): Adapt for no HL in the frame.
* libguile/vm-i-system.c (goto/args, mv-call, return, return/values):
Adapt for no HL in the frame.
* module/system/vm/frame.scm:
* module/system/vm/vm.scm: Beginnings of some reworkings, needs more
thought.
2008-12-26 17:59:46 +01:00
|
|
|
|
|
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
|
|
|
|
vp = SCM_VM_DATA (vm);
|
|
|
|
|
|
hook = vp->hooks[hook_num];
|
remove heap links in VM frames, incorporate vm frames into normal backtraces
* doc/ref/vm.texi (Stack Layout): Update to remove references to the
"heap link".
* gdbinit: Update for "heap link" removal.
* libguile/frames.c:
* libguile/frames.h: Update macros and diagram for removal of "heap
link". As part of this, we also remove "heap frames", replacing them
with "vm frames", which are much like the interpreter's debug objects,
but for VM stacks. That is to say, they don't actually hold the stack
themselves, just the pointers into stack that's held by a continuation
(either captured or current).
* libguile/stacks.c (stack_depth, read_frames): Since a "stack" object is
really a copy of information that comes from somewhere else, it makes
sense to copy over info from the VM, just as `make-stack' does from the
evaluator. The tricky bit is to figure out how to interleave VM and
interpreter frames. We do that by starting in the interpreter, and
whenever the current frame's procedure is actually a program, we switch
to the VM stack, switching back when we reach a "bootstrap frame". The
last bit is hacky, but it does work...
(is_vm_bootstrap_frame): Hacky predicate to see if a VM frame is a
bootstrap frame.
(scm_make_stack): Accept a VM frame in addition to debug frames.
Probably has some bugs in this case. But in the case that the arg is
#t (a common case), do the right thing, capturing the top VM frame as
well, and interleaving those frames appropriately on the stack.
As an accident, we lost the ability to limit the number of frames in
the backtrace. We could add that back, but personally I always want
*all* frames in the trace... Narrowing still works fine, though there
are some hiccups sometimes -- e.g. an outer cut to a procedure that
does a tail-call in VM code will never find the cut, as it no longer
exists in the continuation.
* libguile/vm.h (struct scm_vm): So! Now that we have switched to save
stacks in the normal make-stack, there's no more need for `this_frame'
or `last_frame'. On the other hand, we can take this opportunity to fix
tracing: when we're in a trace hook, we set `trace_frame' on the VM,
so we know not to fire hooks when we're already in a hook.
(struct scm_vm_cont): Expose this, as make-stack needs it to make VM
frames from VM continuations.
* libguile/vm.c (scm_vm_trace_frame): New function, gets the current
trace frame.
(vm_mark, make_vm): Hook up the trace frame.
(vm_dispatch_hook): New hook dispatcher, with a dynwind so it does the
right thing if the hook exits nonlocally.
* libguile/vm-engine.c (vm_run): No more this_frame in the wind data.
* libguile/vm-engine.h (RUN_HOOK): Run hooks through the dispatcher.
(ALIGN_AS_NON_IMMEDIATE, POP_LIST_ON_STACK): Remove unused code.
(NEW_FRAME): Adapt for no HL in the frame.
* libguile/vm-i-system.c (goto/args, mv-call, return, return/values):
Adapt for no HL in the frame.
* module/system/vm/frame.scm:
* module/system/vm/vm.scm: Beginnings of some reworkings, needs more
thought.
2008-12-26 17:59:46 +01:00
|
|
|
|
|
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
|
|
|
|
if (SCM_LIKELY (scm_is_false (hook))
|
|
|
|
|
|
|| scm_is_null (SCM_HOOK_PROCEDURES (hook)))
|
|
|
|
|
|
return;
|
2010-04-21 01:05:42 +02:00
|
|
|
|
|
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
|
|
|
|
vp->trace_level--;
|
2010-04-21 01:05:42 +02:00
|
|
|
|
|
|
|
|
|
|
/* Allocate a frame object on the stack. This is more efficient than calling
|
|
|
|
|
|
`scm_c_make_frame ()' to allocate on the heap, but it forces hooks to not
|
|
|
|
|
|
capture frame objects.
|
|
|
|
|
|
|
|
|
|
|
|
At the same time, procedures such as `frame-procedure' make sense only
|
|
|
|
|
|
while the stack frame represented by the frame object is visible, so it
|
|
|
|
|
|
seems reasonable to limit the lifetime of frame objects. */
|
|
|
|
|
|
|
|
|
|
|
|
c_frame.stack_holder = vm;
|
|
|
|
|
|
c_frame.fp = vp->fp;
|
|
|
|
|
|
c_frame.sp = vp->sp;
|
|
|
|
|
|
c_frame.ip = vp->ip;
|
|
|
|
|
|
c_frame.offset = 0;
|
2010-05-07 15:59:50 +02:00
|
|
|
|
frame.cell.word_0 = SCM_PACK (scm_tc7_frame);
|
|
|
|
|
|
frame.cell.word_1 = PTR2SCM (&c_frame);
|
2010-04-21 01:05:42 +02:00
|
|
|
|
args[0] = PTR2SCM (&frame);
|
|
|
|
|
|
|
|
|
|
|
|
scm_c_run_hookn (hook, args, 1);
|
|
|
|
|
|
|
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
|
|
|
|
vp->trace_level++;
|
remove heap links in VM frames, incorporate vm frames into normal backtraces
* doc/ref/vm.texi (Stack Layout): Update to remove references to the
"heap link".
* gdbinit: Update for "heap link" removal.
* libguile/frames.c:
* libguile/frames.h: Update macros and diagram for removal of "heap
link". As part of this, we also remove "heap frames", replacing them
with "vm frames", which are much like the interpreter's debug objects,
but for VM stacks. That is to say, they don't actually hold the stack
themselves, just the pointers into stack that's held by a continuation
(either captured or current).
* libguile/stacks.c (stack_depth, read_frames): Since a "stack" object is
really a copy of information that comes from somewhere else, it makes
sense to copy over info from the VM, just as `make-stack' does from the
evaluator. The tricky bit is to figure out how to interleave VM and
interpreter frames. We do that by starting in the interpreter, and
whenever the current frame's procedure is actually a program, we switch
to the VM stack, switching back when we reach a "bootstrap frame". The
last bit is hacky, but it does work...
(is_vm_bootstrap_frame): Hacky predicate to see if a VM frame is a
bootstrap frame.
(scm_make_stack): Accept a VM frame in addition to debug frames.
Probably has some bugs in this case. But in the case that the arg is
#t (a common case), do the right thing, capturing the top VM frame as
well, and interleaving those frames appropriately on the stack.
As an accident, we lost the ability to limit the number of frames in
the backtrace. We could add that back, but personally I always want
*all* frames in the trace... Narrowing still works fine, though there
are some hiccups sometimes -- e.g. an outer cut to a procedure that
does a tail-call in VM code will never find the cut, as it no longer
exists in the continuation.
* libguile/vm.h (struct scm_vm): So! Now that we have switched to save
stacks in the normal make-stack, there's no more need for `this_frame'
or `last_frame'. On the other hand, we can take this opportunity to fix
tracing: when we're in a trace hook, we set `trace_frame' on the VM,
so we know not to fire hooks when we're already in a hook.
(struct scm_vm_cont): Expose this, as make-stack needs it to make VM
frames from VM continuations.
* libguile/vm.c (scm_vm_trace_frame): New function, gets the current
trace frame.
(vm_mark, make_vm): Hook up the trace frame.
(vm_dispatch_hook): New hook dispatcher, with a dynwind so it does the
right thing if the hook exits nonlocally.
* libguile/vm-engine.c (vm_run): No more this_frame in the wind data.
* libguile/vm-engine.h (RUN_HOOK): Run hooks through the dispatcher.
(ALIGN_AS_NON_IMMEDIATE, POP_LIST_ON_STACK): Remove unused code.
(NEW_FRAME): Adapt for no HL in the frame.
* libguile/vm-i-system.c (goto/args, mv-call, return, return/values):
Adapt for no HL in the frame.
* module/system/vm/frame.scm:
* module/system/vm/vm.scm: Beginnings of some reworkings, needs more
thought.
2008-12-26 17:59:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-02-22 23:00:19 +01:00
|
|
|
|
static void vm_abort (SCM vm, size_t n, scm_t_int64 cookie) SCM_NORETURN;
|
2010-01-30 15:45:37 +01:00
|
|
|
|
static void
|
2010-02-22 23:00:19 +01:00
|
|
|
|
vm_abort (SCM vm, size_t n, scm_t_int64 vm_cookie)
|
2010-01-30 15:45:37 +01:00
|
|
|
|
{
|
2010-02-19 16:55:36 +01:00
|
|
|
|
size_t i;
|
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:53:24 +01:00
|
|
|
|
ssize_t tail_len;
|
|
|
|
|
|
SCM tag, tail, *argv;
|
2010-02-19 16:55:36 +01:00
|
|
|
|
|
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:53:24 +01:00
|
|
|
|
/* FIXME: VM_ENABLE_STACK_NULLING */
|
|
|
|
|
|
tail = *(SCM_VM_DATA (vm)->sp--);
|
|
|
|
|
|
/* NULLSTACK (1) */
|
|
|
|
|
|
tail_len = scm_ilength (tail);
|
|
|
|
|
|
if (tail_len < 0)
|
2010-02-24 18:51:25 +01:00
|
|
|
|
scm_misc_error ("vm-engine", "tail values to abort should be a list",
|
|
|
|
|
|
scm_list_1 (tail));
|
|
|
|
|
|
|
2010-02-19 16:55:36 +01:00
|
|
|
|
tag = SCM_VM_DATA (vm)->sp[-n];
|
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:53:24 +01:00
|
|
|
|
argv = alloca ((n + tail_len) * sizeof (SCM));
|
2010-02-19 16:55:36 +01:00
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
|
argv[i] = SCM_VM_DATA (vm)->sp[-(n-1-i)];
|
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:53:24 +01:00
|
|
|
|
for (; i < n + tail_len; i++, tail = scm_cdr (tail))
|
|
|
|
|
|
argv[i] = scm_car (tail);
|
|
|
|
|
|
/* NULLSTACK (n + 1) */
|
2010-02-19 16:55:36 +01:00
|
|
|
|
SCM_VM_DATA (vm)->sp -= n + 1;
|
|
|
|
|
|
|
2010-02-22 23:00:19 +01:00
|
|
|
|
scm_c_abort (vm, tag, n + tail_len, argv, vm_cookie);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-02-24 16:56:45 +01:00
|
|
|
|
vm_reinstate_partial_continuation (SCM vm, SCM cont, SCM intwinds,
|
2010-02-26 13:05:25 +01:00
|
|
|
|
size_t n, SCM *argv, scm_t_int64 vm_cookie)
|
2010-02-22 23:00:19 +01:00
|
|
|
|
{
|
2010-02-24 16:56:45 +01:00
|
|
|
|
struct scm_vm *vp;
|
|
|
|
|
|
struct scm_vm_cont *cp;
|
|
|
|
|
|
SCM *argv_copy, *base;
|
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
|
|
argv_copy = alloca (n * sizeof(SCM));
|
|
|
|
|
|
memcpy (argv_copy, argv, n * sizeof(SCM));
|
|
|
|
|
|
|
|
|
|
|
|
vp = SCM_VM_DATA (vm);
|
|
|
|
|
|
cp = SCM_VM_CONT_DATA (cont);
|
|
|
|
|
|
base = SCM_FRAME_UPPER_ADDRESS (vp->fp) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
#define RELOC(scm_p) (scm_p + cp->reloc + (base - cp->stack_base))
|
|
|
|
|
|
|
|
|
|
|
|
if ((base - vp->stack_base) + cp->stack_size + n + 1 > vp->stack_size)
|
2010-02-24 18:51:25 +01:00
|
|
|
|
scm_misc_error ("vm-engine",
|
|
|
|
|
|
"not enough space to instate partial continuation",
|
|
|
|
|
|
scm_list_2 (vm, cont));
|
2010-02-24 16:56:45 +01:00
|
|
|
|
|
|
|
|
|
|
memcpy (base, cp->stack_base, cp->stack_size * sizeof (SCM));
|
|
|
|
|
|
|
|
|
|
|
|
/* now relocate frame pointers */
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM *fp;
|
|
|
|
|
|
for (fp = RELOC (cp->fp);
|
|
|
|
|
|
SCM_FRAME_LOWER_ADDRESS (fp) > base;
|
|
|
|
|
|
fp = SCM_FRAME_DYNAMIC_LINK (fp))
|
|
|
|
|
|
SCM_FRAME_SET_DYNAMIC_LINK (fp, RELOC (SCM_FRAME_DYNAMIC_LINK (fp)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vp->sp = base - 1 + cp->stack_size;
|
|
|
|
|
|
vp->fp = RELOC (cp->fp);
|
|
|
|
|
|
vp->ip = cp->mvra;
|
|
|
|
|
|
|
|
|
|
|
|
/* now push args. ip is in a MV context. */
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
vp->sp++;
|
|
|
|
|
|
*vp->sp = argv_copy[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
vp->sp++;
|
|
|
|
|
|
*vp->sp = scm_from_size_t (n);
|
2010-02-24 17:43:02 +01:00
|
|
|
|
|
2010-02-26 13:05:25 +01:00
|
|
|
|
/* Finally, rewind the dynamic state.
|
|
|
|
|
|
|
|
|
|
|
|
We have to treat prompts specially, because we could be rewinding the
|
|
|
|
|
|
dynamic state from a different thread, or just a different position on the
|
|
|
|
|
|
C and/or VM stack -- so we need to reset the jump buffers so that an abort
|
|
|
|
|
|
comes back here, with appropriately adjusted sp and fp registers. */
|
2010-02-24 17:43:02 +01:00
|
|
|
|
{
|
|
|
|
|
|
long delta = 0;
|
|
|
|
|
|
SCM newwinds = scm_i_dynwinds ();
|
|
|
|
|
|
for (; scm_is_pair (intwinds); intwinds = scm_cdr (intwinds), delta--)
|
2010-02-26 13:05:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
SCM x = scm_car (intwinds);
|
|
|
|
|
|
if (SCM_PROMPT_P (x))
|
|
|
|
|
|
/* the jmpbuf will be reset by our caller */
|
|
|
|
|
|
x = scm_c_make_prompt (SCM_PROMPT_TAG (x),
|
|
|
|
|
|
RELOC (SCM_PROMPT_REGISTERS (x)->fp),
|
|
|
|
|
|
RELOC (SCM_PROMPT_REGISTERS (x)->sp),
|
|
|
|
|
|
SCM_PROMPT_REGISTERS (x)->ip,
|
|
|
|
|
|
SCM_PROMPT_ESCAPE_P (x),
|
|
|
|
|
|
vm_cookie,
|
|
|
|
|
|
newwinds);
|
|
|
|
|
|
newwinds = scm_cons (x, newwinds);
|
|
|
|
|
|
}
|
2010-02-24 17:43:02 +01:00
|
|
|
|
scm_dowinds (newwinds, delta);
|
|
|
|
|
|
}
|
2010-02-26 13:05:25 +01:00
|
|
|
|
#undef RELOC
|
2010-01-30 15:45:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-04-01 05:03:41 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* VM Internal functions
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2010-02-24 23:32:04 +01:00
|
|
|
|
/* Unfortunately we can't snarf these: snarfed things are only loaded up from
|
|
|
|
|
|
(system vm vm), which might not be loaded before an error happens. */
|
|
|
|
|
|
static SCM sym_vm_run, sym_vm_error, sym_keyword_argument_error, sym_debug;
|
2001-04-01 05:03:41 +00:00
|
|
|
|
|
2010-01-05 19:45:56 +01:00
|
|
|
|
void
|
|
|
|
|
|
scm_i_vm_print (SCM x, SCM port, scm_print_state *pstate)
|
|
|
|
|
|
{
|
2010-04-14 23:46:41 +02:00
|
|
|
|
const struct scm_vm *vm;
|
|
|
|
|
|
|
|
|
|
|
|
vm = SCM_VM_DATA (x);
|
|
|
|
|
|
|
2010-01-05 19:45:56 +01:00
|
|
|
|
scm_puts ("#<vm ", port);
|
2010-04-14 23:46:41 +02:00
|
|
|
|
switch (vm->engine)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SCM_VM_REGULAR_ENGINE:
|
|
|
|
|
|
scm_puts ("regular-engine ", port);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SCM_VM_DEBUG_ENGINE:
|
|
|
|
|
|
scm_puts ("debug-engine ", port);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
scm_puts ("unknown-engine ", port);
|
|
|
|
|
|
}
|
2010-01-05 19:45:56 +01:00
|
|
|
|
scm_uintprint (SCM_UNPACK (x), 16, port);
|
|
|
|
|
|
scm_puts (">", port);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
move module and meta inside programs' object tables
* libguile/programs.h (struct scm_program): Remove the module and meta
fields.
* libguile/programs.c (scm_c_make_program): Add a new argument, `objs'.
If it's a vector, we'll look for the module and the metadata in there,
instead of having them in the scm_program structure.
(scm_c_make_closure, program_mark, scm_program_meta)
(scm_c_program_source, scm_program_module): Adapt to the new program
representation.
* libguile/objcodes.c (scm_objcode_to_program): Pass #f as the object
table when making the program.
* libguile/vm-engine.h (CACHE_PROGRAM):
* libguile/vm-engine.c (vm_run): Rework to use the simple vector API for
getting the current object table. Call the helper,
vm_make_boot_program, to make the boot program.
* libguile/vm-i-loader.c (load-program): Set the current module and the
meta in the object vector, which we pass to scm_c_make_program.
* libguile/vm-i-system.c (toplevel-ref, toplevel-set): Adapt to the new
program representation.
* module/language/glil/compile-objcode.scm (codegen): Clarify.
2009-01-17 16:42:53 +01:00
|
|
|
|
static SCM
|
2009-01-31 21:54:59 +01:00
|
|
|
|
really_make_boot_program (long nargs)
|
move module and meta inside programs' object tables
* libguile/programs.h (struct scm_program): Remove the module and meta
fields.
* libguile/programs.c (scm_c_make_program): Add a new argument, `objs'.
If it's a vector, we'll look for the module and the metadata in there,
instead of having them in the scm_program structure.
(scm_c_make_closure, program_mark, scm_program_meta)
(scm_c_program_source, scm_program_module): Adapt to the new program
representation.
* libguile/objcodes.c (scm_objcode_to_program): Pass #f as the object
table when making the program.
* libguile/vm-engine.h (CACHE_PROGRAM):
* libguile/vm-engine.c (vm_run): Rework to use the simple vector API for
getting the current object table. Call the helper,
vm_make_boot_program, to make the boot program.
* libguile/vm-i-loader.c (load-program): Set the current module and the
meta in the object vector, which we pass to scm_c_make_program.
* libguile/vm-i-system.c (toplevel-ref, toplevel-set): Adapt to the new
program representation.
* module/language/glil/compile-objcode.scm (codegen): Clarify.
2009-01-17 16:42:53 +01:00
|
|
|
|
{
|
2009-07-15 23:51:42 +02:00
|
|
|
|
SCM u8vec;
|
2009-09-17 14:58:31 +02:00
|
|
|
|
scm_t_uint8 text[] = { scm_op_mv_call, 0, 0, 0, 1,
|
|
|
|
|
|
scm_op_make_int8_1, scm_op_halt };
|
2009-07-26 12:56:11 +02:00
|
|
|
|
struct scm_objcode *bp;
|
2009-02-05 13:44:06 +01:00
|
|
|
|
SCM ret;
|
2009-07-15 23:51:42 +02:00
|
|
|
|
|
static opcodes; refactor program/objcode division; use new assembly pipeline
* gdbinit: Untested attempts to get the stack fondling macros to deal
with the new program representation.
* libguile/frames.c (scm_vm_frame_arguments, scm_vm_frame_source)
(scm_vm_frame_local_ref, scm_vm_frame_local_set_x): SCM_PROGRAM_DATA is
a struct scm_objcode*.
* libguile/instructions.h:
* libguile/instructions.c: Hide the instruction table and the struct
scm_instruction structure; all access to instructions now goes through
procedures. This is because instructions are no longer in a packed
array indexed by opcode. Also, declare a mask that all instructions
should fit in.
* libguile/objcodes.h:
* libguile/objcodes.c: Rewrite so that object code directly maps its
arity and length from its bytecode. This makes it unnecessary to keep
this information in programs, allowing programs to be simple conses
between the code (objcodes) and data (the object table and the closure
variables).
* libguile/programs.c (scm_make_program): Rework so that make-program
takes objcode, an object table, and externals as arguments. It's much
clearer this way, and we avoid malloc().
* libguile/stacks.c (is_vm_bootstrap_frame): Update for program/objcode
changes.
* libguile/vm-engine.c (vm_run): Initialize the jump table on the first
run, with the opcodes declared in the instruction sources, and with bad
instructions raising an error instead of wandering off into the
Unknown.
* libguile/vm-engine.h (FETCH_LENGTH): Always represent lengths as 3
bytes. The old code was too error-prone.
(NEXT_JUMP): Mask the instruction with SCM_VM_INSTRUCTION_MASK.
(NEW_FRAME): Update for program/objcode changes.
* libguile/vm-expand.h (VM_DEFINE_FUNCTION, VM_DEFINE_INSTRUCTION)
(VM_DEFINE_LOADER): Update so that we explicitly specify opcodes, so
that we have a stable bytecode API.
* libguile/vm-i-loader.c: Update license to LGPLv2+. Explicitly declare
opcodes.
(load-integer): Use an int instead of a long as the accumulator; still
need to revisit this code at some point, I think.
(load-program): Simplify, thankfully!! Just creates the objcode slice
and rolls with it.
* libguile/vm-i-scheme.c: Number the opcodes explicitly.
* libguile/vm-i-system.c: Update license to LGPLv2+. Explicitly declare
opcodes.
(make-closure): Update for new program API.
* libguile/vm.c (vm_make_boot_program): Update for new program/objcode
API. Still a bit ugly.
(scm_load_compiled_with_vm): Update for new program/objcode API.
* module/language/assembly.scm (byte-length): Fix byte-length calculation
for loaders, and load-program.
(code-pack, code-unpack): Start to move things from (system vm conv)
here.
(object->code, code->object): More things from conv.scm.
* module/language/glil.scm (<glil-program>): Add a new field,
closure-level.
(make-glil-program, compute-closure-level): Calculate the "closure
level" when making a glil program. This is the maximum depth of
external binding refs in this closure.
(unparse-glil): Fix label serialization.
* module/language/glil/compile-assembly.scm (make-meta): Prepend #f for
the meta's object table, though maybe in the future we can avoid
creating assembly in the first place.
(assoc-ref-or-acons, object-index-and-alist): GRRR! Caught again by the
different sets of arguments to assoc and assoc-ref!
(glil->assembly): Attempt to make the <glil-program> case more
readable, and fix the bugs. Sorry I don't know how to comment this
change any more than this.
(glil->assembly): For <glil-module> serialize the whole key, not just
the name.
(dump-object): subprogram-code is already a list. Serialize integers as
strings, not u8vectors. Fix the order of lists and vectors.
* module/language/glil/spec.scm (glil): Switch orders, so we prefer glil
-> assembly -> objcode. Actually glil->objcode doesn't work any more,
needs to be removed I think.
* module/language/objcode/spec.scm (objcode->value):
s/objcode->program/make-program/.
* module/language/scheme/inline.scm: Add acons inline.
* module/system/vm/conv.scm (make-byte-decoder): Skip the first 8 bytes,
they are header. Handle subprograms properly. Still needs help though.
(decode-length): Lengths are always 3 bytes now.
* module/system/vm/disasm.scm: Superficial changes to keep things
working. I'd like to fix this better in the future.
* module/system/vm/frame.scm (bootstrap-frame?): Fixes for
program-bytecode.
* module/system/vm/program.scm: Export make-program. It's program-objcode
now, no more program-bytecode.
* module/system/vm/vm.scm (vm-load): Use make-program.
* test-suite/tests/asm-to-bytecode.test: New test, very minimal.
* module/system/vm/objcode.scm: Export word-size, byte-order, and
write-objcode.
2009-01-29 21:09:04 +01:00
|
|
|
|
if (SCM_UNLIKELY (nargs > 255 || nargs < 0))
|
2010-02-24 18:51:25 +01:00
|
|
|
|
scm_misc_error ("vm-engine", "too many args when making boot procedure",
|
|
|
|
|
|
scm_list_1 (scm_from_long (nargs)));
|
|
|
|
|
|
|
2009-07-26 12:56:11 +02:00
|
|
|
|
text[1] = (scm_t_uint8)nargs;
|
|
|
|
|
|
|
2009-09-01 23:53:58 +02:00
|
|
|
|
bp = scm_malloc (sizeof (struct scm_objcode) + sizeof (text));
|
2009-12-14 23:11:47 +01:00
|
|
|
|
memcpy (SCM_C_OBJCODE_BASE (bp), text, sizeof (text));
|
2009-07-26 12:56:11 +02:00
|
|
|
|
bp->len = sizeof(text);
|
|
|
|
|
|
bp->metalen = 0;
|
|
|
|
|
|
|
2010-01-14 13:55:50 +01:00
|
|
|
|
u8vec = scm_c_take_bytevector ((scm_t_int8*)bp,
|
|
|
|
|
|
sizeof (struct scm_objcode) + sizeof (text));
|
2009-07-15 23:51:42 +02:00
|
|
|
|
ret = scm_make_program (scm_bytecode_to_objcode (u8vec),
|
2009-07-23 17:12:10 +02:00
|
|
|
|
SCM_BOOL_F, SCM_BOOL_F);
|
2009-09-17 00:14:16 +01:00
|
|
|
|
SCM_SET_CELL_WORD_0 (ret, SCM_CELL_WORD_0 (ret) | SCM_F_PROGRAM_IS_BOOT);
|
2009-07-15 23:51:42 +02:00
|
|
|
|
|
2009-02-05 13:44:06 +01:00
|
|
|
|
return ret;
|
move module and meta inside programs' object tables
* libguile/programs.h (struct scm_program): Remove the module and meta
fields.
* libguile/programs.c (scm_c_make_program): Add a new argument, `objs'.
If it's a vector, we'll look for the module and the metadata in there,
instead of having them in the scm_program structure.
(scm_c_make_closure, program_mark, scm_program_meta)
(scm_c_program_source, scm_program_module): Adapt to the new program
representation.
* libguile/objcodes.c (scm_objcode_to_program): Pass #f as the object
table when making the program.
* libguile/vm-engine.h (CACHE_PROGRAM):
* libguile/vm-engine.c (vm_run): Rework to use the simple vector API for
getting the current object table. Call the helper,
vm_make_boot_program, to make the boot program.
* libguile/vm-i-loader.c (load-program): Set the current module and the
meta in the object vector, which we pass to scm_c_make_program.
* libguile/vm-i-system.c (toplevel-ref, toplevel-set): Adapt to the new
program representation.
* module/language/glil/compile-objcode.scm (codegen): Clarify.
2009-01-17 16:42:53 +01:00
|
|
|
|
}
|
2009-01-31 21:54:59 +01:00
|
|
|
|
#define NUM_BOOT_PROGS 8
|
|
|
|
|
|
static SCM
|
|
|
|
|
|
vm_make_boot_program (long nargs)
|
|
|
|
|
|
{
|
|
|
|
|
|
static SCM programs[NUM_BOOT_PROGS] = { 0, };
|
|
|
|
|
|
|
|
|
|
|
|
if (SCM_UNLIKELY (!programs[0]))
|
|
|
|
|
|
{
|
|
|
|
|
|
int i;
|
|
|
|
|
|
for (i = 0; i < NUM_BOOT_PROGS; i++)
|
2009-12-05 11:30:09 +01:00
|
|
|
|
programs[i] = really_make_boot_program (i);
|
2009-01-31 21:54:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SCM_LIKELY (nargs < NUM_BOOT_PROGS))
|
|
|
|
|
|
return programs[nargs];
|
|
|
|
|
|
else
|
|
|
|
|
|
return really_make_boot_program (nargs);
|
|
|
|
|
|
}
|
move module and meta inside programs' object tables
* libguile/programs.h (struct scm_program): Remove the module and meta
fields.
* libguile/programs.c (scm_c_make_program): Add a new argument, `objs'.
If it's a vector, we'll look for the module and the metadata in there,
instead of having them in the scm_program structure.
(scm_c_make_closure, program_mark, scm_program_meta)
(scm_c_program_source, scm_program_module): Adapt to the new program
representation.
* libguile/objcodes.c (scm_objcode_to_program): Pass #f as the object
table when making the program.
* libguile/vm-engine.h (CACHE_PROGRAM):
* libguile/vm-engine.c (vm_run): Rework to use the simple vector API for
getting the current object table. Call the helper,
vm_make_boot_program, to make the boot program.
* libguile/vm-i-loader.c (load-program): Set the current module and the
meta in the object vector, which we pass to scm_c_make_program.
* libguile/vm-i-system.c (toplevel-ref, toplevel-set): Adapt to the new
program representation.
* module/language/glil/compile-objcode.scm (codegen): Clarify.
2009-01-17 16:42:53 +01:00
|
|
|
|
|
2000-08-22 15:54:19 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* VM
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2009-06-05 11:47:19 +02:00
|
|
|
|
static SCM
|
|
|
|
|
|
resolve_variable (SCM what, SCM program_module)
|
|
|
|
|
|
{
|
2009-11-25 23:46:17 +01:00
|
|
|
|
if (SCM_LIKELY (scm_is_symbol (what)))
|
2009-06-05 11:47:19 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (SCM_LIKELY (scm_module_system_booted_p
|
|
|
|
|
|
&& scm_is_true (program_module)))
|
|
|
|
|
|
/* might longjmp */
|
|
|
|
|
|
return scm_module_lookup (program_module, what);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM v = scm_sym2var (what, SCM_BOOL_F, SCM_BOOL_F);
|
|
|
|
|
|
if (scm_is_false (v))
|
|
|
|
|
|
scm_misc_error (NULL, "unbound variable: ~S", scm_list_1 (what));
|
|
|
|
|
|
else
|
|
|
|
|
|
return v;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM mod;
|
|
|
|
|
|
/* compilation of @ or @@
|
|
|
|
|
|
`what' is a three-element list: (MODNAME SYM INTERFACE?)
|
|
|
|
|
|
INTERFACE? is #t if we compiled @ or #f if we compiled @@
|
|
|
|
|
|
*/
|
|
|
|
|
|
mod = scm_resolve_module (SCM_CAR (what));
|
|
|
|
|
|
if (scm_is_true (SCM_CADDR (what)))
|
|
|
|
|
|
mod = scm_module_public_interface (mod);
|
2009-11-28 15:11:31 +01:00
|
|
|
|
if (scm_is_false (mod))
|
2009-06-05 11:47:19 +02:00
|
|
|
|
scm_misc_error (NULL, "no such module: ~S",
|
|
|
|
|
|
scm_list_1 (SCM_CAR (what)));
|
|
|
|
|
|
/* might longjmp */
|
|
|
|
|
|
return scm_module_lookup (mod, SCM_CADR (what));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-07-24 12:05:54 +02:00
|
|
|
|
#define VM_DEFAULT_STACK_SIZE (64 * 1024)
|
2001-04-01 05:03:41 +00:00
|
|
|
|
|
|
|
|
|
|
#define VM_NAME vm_regular_engine
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
#define FUNC_NAME "vm-regular-engine"
|
|
|
|
|
|
#define VM_ENGINE SCM_VM_REGULAR_ENGINE
|
2008-08-21 18:39:30 -07:00
|
|
|
|
#include "vm-engine.c"
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#undef VM_NAME
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
#undef FUNC_NAME
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#undef VM_ENGINE
|
|
|
|
|
|
|
|
|
|
|
|
#define VM_NAME vm_debug_engine
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
#define FUNC_NAME "vm-debug-engine"
|
|
|
|
|
|
#define VM_ENGINE SCM_VM_DEBUG_ENGINE
|
2008-08-21 18:39:30 -07:00
|
|
|
|
#include "vm-engine.c"
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#undef VM_NAME
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
#undef FUNC_NAME
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#undef VM_ENGINE
|
|
|
|
|
|
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
static const scm_t_vm_engine vm_engines[] =
|
|
|
|
|
|
{ vm_regular_engine, vm_debug_engine };
|
|
|
|
|
|
|
2009-08-20 01:56:47 +02:00
|
|
|
|
#ifdef VM_ENABLE_PRECISE_STACK_GC_SCAN
|
|
|
|
|
|
|
|
|
|
|
|
/* The GC "kind" for the VM stack. */
|
|
|
|
|
|
static int vm_stack_gc_kind;
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2000-08-22 15:54:19 +00:00
|
|
|
|
static SCM
|
2001-04-01 05:03:41 +00:00
|
|
|
|
make_vm (void)
|
|
|
|
|
|
#define FUNC_NAME "make_vm"
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
2001-04-01 05:03:41 +00:00
|
|
|
|
int i;
|
2009-11-17 01:26:25 +01:00
|
|
|
|
struct scm_vm *vp;
|
2009-02-04 00:09:38 +01:00
|
|
|
|
|
2009-11-17 01:26:25 +01:00
|
|
|
|
vp = scm_gc_malloc (sizeof (struct scm_vm), "vm");
|
2005-04-22 16:00:33 +00:00
|
|
|
|
|
2001-04-06 00:17:39 +00:00
|
|
|
|
vp->stack_size = VM_DEFAULT_STACK_SIZE;
|
2009-08-20 01:56:47 +02:00
|
|
|
|
|
|
|
|
|
|
#ifdef VM_ENABLE_PRECISE_STACK_GC_SCAN
|
2010-01-09 15:06:20 +01:00
|
|
|
|
vp->stack_base = (SCM *)
|
|
|
|
|
|
GC_generic_malloc (vp->stack_size * sizeof (SCM), vm_stack_gc_kind);
|
2009-08-20 01:56:47 +02:00
|
|
|
|
|
|
|
|
|
|
/* Keep a pointer to VP so that `vm_stack_mark ()' can know what the stack
|
|
|
|
|
|
top is. */
|
|
|
|
|
|
*vp->stack_base = PTR2SCM (vp);
|
|
|
|
|
|
vp->stack_base++;
|
|
|
|
|
|
vp->stack_size--;
|
|
|
|
|
|
#else
|
2005-04-22 16:00:33 +00:00
|
|
|
|
vp->stack_base = scm_gc_malloc (vp->stack_size * sizeof (SCM),
|
|
|
|
|
|
"stack-base");
|
2009-08-20 01:56:47 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2008-10-11 11:54:12 +02:00
|
|
|
|
#ifdef VM_ENABLE_STACK_NULLING
|
|
|
|
|
|
memset (vp->stack_base, 0, vp->stack_size * sizeof (SCM));
|
|
|
|
|
|
#endif
|
2010-05-26 23:00:58 +02:00
|
|
|
|
vp->stack_limit = vp->stack_base + vp->stack_size - VM_STACK_RESERVE_SIZE;
|
2001-04-07 09:39:38 +00:00
|
|
|
|
vp->ip = NULL;
|
|
|
|
|
|
vp->sp = vp->stack_base - 1;
|
|
|
|
|
|
vp->fp = NULL;
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
vp->engine = SCM_VM_DEBUG_ENGINE;
|
2001-04-06 00:17:39 +00:00
|
|
|
|
vp->options = SCM_EOL;
|
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
|
|
|
|
vp->trace_level = 0;
|
2001-04-01 05:03:41 +00:00
|
|
|
|
for (i = 0; i < SCM_VM_NUM_HOOKS; i++)
|
2001-04-06 00:17:39 +00:00
|
|
|
|
vp->hooks[i] = SCM_BOOL_F;
|
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:53:24 +01:00
|
|
|
|
vp->cookie = 0;
|
2010-01-05 19:45:56 +01:00
|
|
|
|
return scm_cell (scm_tc7_vm, (scm_t_bits)vp);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#undef FUNC_NAME
|
2000-08-22 15:54:19 +00:00
|
|
|
|
|
2009-08-20 01:56:47 +02:00
|
|
|
|
#ifdef VM_ENABLE_PRECISE_STACK_GC_SCAN
|
|
|
|
|
|
|
|
|
|
|
|
/* Mark the VM stack region between its base and its current top. */
|
|
|
|
|
|
static struct GC_ms_entry *
|
|
|
|
|
|
vm_stack_mark (GC_word *addr, struct GC_ms_entry *mark_stack_ptr,
|
|
|
|
|
|
struct GC_ms_entry *mark_stack_limit, GC_word env)
|
|
|
|
|
|
{
|
|
|
|
|
|
GC_word *word;
|
|
|
|
|
|
const struct scm_vm *vm;
|
|
|
|
|
|
|
|
|
|
|
|
/* The first word of the VM stack should contain a pointer to the
|
|
|
|
|
|
corresponding VM. */
|
|
|
|
|
|
vm = * ((struct scm_vm **) addr);
|
|
|
|
|
|
|
2009-09-15 00:40:00 +02:00
|
|
|
|
if (vm == NULL
|
2010-05-26 23:00:58 +02:00
|
|
|
|
|| (SCM *) addr != vm->stack_base - 1)
|
2009-08-20 01:56:47 +02:00
|
|
|
|
/* ADDR must be a pointer to a free-list element, which we must ignore
|
|
|
|
|
|
(see warning in <gc/gc_mark.h>). */
|
|
|
|
|
|
return mark_stack_ptr;
|
|
|
|
|
|
|
|
|
|
|
|
for (word = (GC_word *) vm->stack_base; word <= (GC_word *) vm->sp; word++)
|
|
|
|
|
|
mark_stack_ptr = GC_MARK_AND_PUSH ((* (GC_word **) word),
|
|
|
|
|
|
mark_stack_ptr, mark_stack_limit,
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
|
|
return mark_stack_ptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* VM_ENABLE_PRECISE_STACK_GC_SCAN */
|
|
|
|
|
|
|
|
|
|
|
|
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
SCM
|
2009-02-05 00:51:34 +01:00
|
|
|
|
scm_c_vm_run (SCM vm, SCM program, SCM *argv, int nargs)
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
{
|
2009-02-05 00:51:34 +01:00
|
|
|
|
struct scm_vm *vp = SCM_VM_DATA (vm);
|
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
|
|
|
|
return vm_engines[vp->engine](vm, program, argv, nargs);
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-01-05 19:45:56 +01:00
|
|
|
|
SCM_DEFINE (scm_vm_apply, "vm-apply", 3, 0, 0,
|
|
|
|
|
|
(SCM vm, SCM program, SCM args),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_vm_apply
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
SCM *argv;
|
|
|
|
|
|
int i, nargs;
|
|
|
|
|
|
|
|
|
|
|
|
SCM_VALIDATE_VM (1, vm);
|
2009-12-01 22:20:03 +01:00
|
|
|
|
SCM_VALIDATE_PROC (2, program);
|
enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
(VM_CHECK_OBJECT): Update to define these here, before including
vm-engine.h.
(vm_run): Change so that we can make different engines. Also, we take
an array of arguments, and the struct scm_vm directly, so as to avoid
any need to cons.
* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
bits; don't seem to help.
* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
some love, and perhaps we revert to the old way.
(VM_ENGINE): Actually make two engines, vm_regular_engine and
vm_debug_engine. Probably there is room for improvement here. Actually
their speeds are the same at the moment.
(make_vm): Choose which engine to run; currently the debug engine by
default.
(scm_c_vm_run): A thin wrapper to invoke a VM without consing.
(scm_vm_apply): Use scm_c_vm_run.
(scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
|
|
|
|
|
|
|
|
|
|
nargs = scm_ilength (args);
|
|
|
|
|
|
if (SCM_UNLIKELY (nargs < 0))
|
|
|
|
|
|
scm_wrong_type_arg_msg (FUNC_NAME, 3, args, "list");
|
|
|
|
|
|
|
|
|
|
|
|
argv = alloca(nargs * sizeof(SCM));
|
|
|
|
|
|
for (i = 0; i < nargs; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
argv[i] = SCM_CAR (args);
|
|
|
|
|
|
args = SCM_CDR (args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-02-05 00:51:34 +01:00
|
|
|
|
return scm_c_vm_run (vm, program, argv, nargs);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#undef FUNC_NAME
|
2000-08-22 15:54:19 +00:00
|
|
|
|
|
|
|
|
|
|
/* Scheme interface */
|
|
|
|
|
|
|
|
|
|
|
|
SCM_DEFINE (scm_vm_version, "vm-version", 0, 0, 0,
|
2001-04-01 05:03:41 +00:00
|
|
|
|
(void),
|
|
|
|
|
|
"")
|
2000-08-22 15:54:19 +00:00
|
|
|
|
#define FUNC_NAME s_scm_vm_version
|
|
|
|
|
|
{
|
2008-08-02 12:17:27 +02:00
|
|
|
|
return scm_from_locale_string (PACKAGE_VERSION);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
2001-04-06 05:00:10 +00:00
|
|
|
|
SCM_DEFINE (scm_the_vm, "the-vm", 0, 0, 0,
|
2008-08-20 14:32:36 -07:00
|
|
|
|
(void),
|
2001-04-06 05:00:10 +00:00
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_the_vm
|
|
|
|
|
|
{
|
2008-10-11 11:54:12 +02:00
|
|
|
|
scm_i_thread *t = SCM_I_CURRENT_THREAD;
|
2008-09-25 11:04:35 +02:00
|
|
|
|
|
2009-11-28 22:52:16 +01:00
|
|
|
|
if (SCM_UNLIKELY (scm_is_false ((t->vm))))
|
2008-10-11 11:54:12 +02:00
|
|
|
|
t->vm = make_vm ();
|
2008-09-25 11:04:35 +02:00
|
|
|
|
|
2008-10-11 11:54:12 +02:00
|
|
|
|
return t->vm;
|
2001-04-06 05:00:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-08-22 15:54:19 +00:00
|
|
|
|
SCM_DEFINE (scm_vm_p, "vm?", 1, 0, 0,
|
|
|
|
|
|
(SCM obj),
|
2001-04-01 05:03:41 +00:00
|
|
|
|
"")
|
2000-08-22 15:54:19 +00:00
|
|
|
|
#define FUNC_NAME s_scm_vm_p
|
|
|
|
|
|
{
|
2009-11-25 23:46:17 +01:00
|
|
|
|
return scm_from_bool (SCM_VM_P (obj));
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
SCM_DEFINE (scm_make_vm, "make-vm", 0, 0, 0,
|
2001-04-01 05:03:41 +00:00
|
|
|
|
(void),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_make_vm,
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
2001-04-01 05:03:41 +00:00
|
|
|
|
return make_vm ();
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
2001-04-01 05:03:41 +00:00
|
|
|
|
SCM_DEFINE (scm_vm_ip, "vm:ip", 1, 0, 0,
|
2000-08-22 15:54:19 +00:00
|
|
|
|
(SCM vm),
|
2001-04-01 05:03:41 +00:00
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_vm_ip
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM_VALIDATE_VM (1, vm);
|
2005-05-02 16:32:32 +00:00
|
|
|
|
return scm_from_ulong ((unsigned long) SCM_VM_DATA (vm)->ip);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
SCM_DEFINE (scm_vm_sp, "vm:sp", 1, 0, 0,
|
|
|
|
|
|
(SCM vm),
|
2001-04-01 05:03:41 +00:00
|
|
|
|
"")
|
2000-08-22 15:54:19 +00:00
|
|
|
|
#define FUNC_NAME s_scm_vm_sp
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM_VALIDATE_VM (1, vm);
|
2005-05-02 16:32:32 +00:00
|
|
|
|
return scm_from_ulong ((unsigned long) SCM_VM_DATA (vm)->sp);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
SCM_DEFINE (scm_vm_fp, "vm:fp", 1, 0, 0,
|
|
|
|
|
|
(SCM vm),
|
2001-04-01 05:03:41 +00:00
|
|
|
|
"")
|
2000-08-22 15:54:19 +00:00
|
|
|
|
#define FUNC_NAME s_scm_vm_fp
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM_VALIDATE_VM (1, vm);
|
2005-05-02 16:32:32 +00:00
|
|
|
|
return scm_from_ulong ((unsigned long) SCM_VM_DATA (vm)->fp);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#define VM_DEFINE_HOOK(n) \
|
|
|
|
|
|
{ \
|
2001-04-06 00:17:39 +00:00
|
|
|
|
struct scm_vm *vp; \
|
2001-04-01 05:03:41 +00:00
|
|
|
|
SCM_VALIDATE_VM (1, vm); \
|
2001-04-06 00:17:39 +00:00
|
|
|
|
vp = SCM_VM_DATA (vm); \
|
2009-11-28 22:52:16 +01:00
|
|
|
|
if (scm_is_false (vp->hooks[n])) \
|
2005-04-28 15:45:59 +00:00
|
|
|
|
vp->hooks[n] = scm_make_hook (SCM_I_MAKINUM (1)); \
|
2001-04-06 00:17:39 +00:00
|
|
|
|
return vp->hooks[n]; \
|
2001-04-01 05:03:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-09-16 12:14:55 +02:00
|
|
|
|
SCM_DEFINE (scm_vm_apply_hook, "vm-apply-hook", 1, 0, 0,
|
2001-04-01 05:03:41 +00:00
|
|
|
|
(SCM vm),
|
|
|
|
|
|
"")
|
2010-09-16 12:14:55 +02:00
|
|
|
|
#define FUNC_NAME s_scm_vm_apply_hook
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
2010-09-16 12:14:55 +02:00
|
|
|
|
VM_DEFINE_HOOK (SCM_VM_APPLY_HOOK);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
2010-09-16 12:14:55 +02:00
|
|
|
|
SCM_DEFINE (scm_vm_push_continuation_hook, "vm-push-continuation-hook", 1, 0, 0,
|
2001-04-01 05:03:41 +00:00
|
|
|
|
(SCM vm),
|
|
|
|
|
|
"")
|
2010-09-16 12:14:55 +02:00
|
|
|
|
#define FUNC_NAME s_scm_vm_push_continuation_hook
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
2010-09-16 12:14:55 +02:00
|
|
|
|
VM_DEFINE_HOOK (SCM_VM_PUSH_CONTINUATION_HOOK);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
2010-09-16 12:14:55 +02:00
|
|
|
|
SCM_DEFINE (scm_vm_pop_continuation_hook, "vm-pop-continuation-hook", 1, 0, 0,
|
2000-08-22 15:54:19 +00:00
|
|
|
|
(SCM vm),
|
2001-04-01 05:03:41 +00:00
|
|
|
|
"")
|
2010-09-16 12:14:55 +02:00
|
|
|
|
#define FUNC_NAME s_scm_vm_pop_continuation_hook
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
2010-09-16 12:14:55 +02:00
|
|
|
|
VM_DEFINE_HOOK (SCM_VM_POP_CONTINUATION_HOOK);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
2010-09-16 12:14:55 +02:00
|
|
|
|
SCM_DEFINE (scm_vm_next_hook, "vm-next-hook", 1, 0, 0,
|
2000-08-22 15:54:19 +00:00
|
|
|
|
(SCM vm),
|
2001-04-01 05:03:41 +00:00
|
|
|
|
"")
|
2010-09-16 12:14:55 +02:00
|
|
|
|
#define FUNC_NAME s_scm_vm_next_hook
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
2010-09-16 12:14:55 +02:00
|
|
|
|
VM_DEFINE_HOOK (SCM_VM_NEXT_HOOK);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
2001-04-01 05:03:41 +00:00
|
|
|
|
SCM_DEFINE (scm_vm_option, "vm-option", 2, 0, 0,
|
|
|
|
|
|
(SCM vm, SCM key),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_vm_option
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM_VALIDATE_VM (1, vm);
|
2001-04-01 05:03:41 +00:00
|
|
|
|
return scm_assq_ref (SCM_VM_DATA (vm)->options, key);
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
2001-04-01 05:03:41 +00:00
|
|
|
|
SCM_DEFINE (scm_set_vm_option_x, "set-vm-option!", 3, 0, 0,
|
|
|
|
|
|
(SCM vm, SCM key, SCM val),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_set_vm_option_x
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM_VALIDATE_VM (1, vm);
|
2001-04-01 05:03:41 +00:00
|
|
|
|
SCM_VM_DATA (vm)->options
|
|
|
|
|
|
= scm_assq_set_x (SCM_VM_DATA (vm)->options, key, val);
|
|
|
|
|
|
return SCM_UNSPECIFIED;
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
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
|
|
|
|
SCM_DEFINE (scm_vm_trace_level, "vm-trace-level", 1, 0, 0,
|
2001-04-01 05:03:41 +00:00
|
|
|
|
(SCM vm),
|
|
|
|
|
|
"")
|
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
|
|
|
|
#define FUNC_NAME s_scm_vm_trace_level
|
2000-08-22 15:54:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM_VALIDATE_VM (1, vm);
|
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
|
|
|
|
return scm_from_int (SCM_VM_DATA (vm)->trace_level);
|
|
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
SCM_DEFINE (scm_set_vm_trace_level_x, "set-vm-trace-level!", 2, 0, 0,
|
|
|
|
|
|
(SCM vm, SCM level),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_set_vm_trace_level_x
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM_VALIDATE_VM (1, vm);
|
|
|
|
|
|
SCM_VM_DATA (vm)->trace_level = scm_to_int (level);
|
|
|
|
|
|
return SCM_UNSPECIFIED;
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-04-01 05:03:41 +00:00
|
|
|
|
* Initialize
|
2000-08-22 15:54:19 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
big reorg of scheme modules -- e.g. programs.c -> (system vm program)
This reorganization kills the ugly module-export-all hacks in
bootstrap.scm and core.scm. In fact, it gets rid of core.scm entirely,
breaking out its functionality into separate files.
* module/system/vm/trace.scm:
* module/system/vm/profile.scm:
* module/system/vm/disasm.scm:
* module/system/vm/debug.scm:
* module/system/vm/conv.scm:
* module/system/vm/assemble.scm:
* module/system/repl/repl.scm:
* module/system/repl/common.scm:
* module/system/base/compile.scm:
* module/system/repl/command.scm: Update for changes, and fix a bug in
procedure-documentation.
* module/system/vm/bootstrap.scm: Just call scm_bootstrap_vm, which
handles setting load-compiled for us.
* module/system/vm/core.scm: Removed, functionality folded into other
modules.
* module/system/vm/frame.scm: Export the C frame procedures here; also
move scheme functions from core.scm here.
* module/system/vm/instruction.scm: New file, exports procedures from
instructions.c.
* module/system/vm/objcode.scm: New file, exports procedures from
objcodes.c.
* module/system/vm/program.scm: New file, exports procedures from
programs.c, and some scheme functions originally from core.scm.
* module/system/vm/vm.scm: New file, from vm.c and core.scm.
* src/Makefile.am (libguile_vm_la_SOURCES): Add bootstrap.h.
* src/bootstrap.h: New file, prototypes scm_bootstrap_vm (), which the
scm_init_* functions call.
* src/frames.h:
* src/frames.c (scm_init_frames):
* src/frames.c (scm_bootstrap_frames):
* src/vm.h:
* src/instructions.h:
* src/instructions.c (scm_init_instructions):
* src/instructions.c (scm_bootstrap_instructions):
* src/objcodes.h:
* src/objcodes.c (scm_bootstrap_objcodes):
* src/objcodes.c (scm_init_objcodes):
* src/programs.h:
* src/programs.c (scm_bootstrap_programs):
* src/programs.c (scm_init_programs):
* src/vm.c (scm_bootstrap_vm):
* src/vm.c (scm_init_vm): Call scm_bootstrap_vm() before doing anything
in an init function. Bootstrap_vm will call bootstrap_instructions(),
etc to initialize types, then set load-compiled to point to
load-compiled/vm.
* src/vm.c (scm_load_compiled_with_vm): Code to load .go files, if
they're present.
2008-08-07 13:11:27 +02:00
|
|
|
|
SCM scm_load_compiled_with_vm (SCM file)
|
|
|
|
|
|
{
|
static opcodes; refactor program/objcode division; use new assembly pipeline
* gdbinit: Untested attempts to get the stack fondling macros to deal
with the new program representation.
* libguile/frames.c (scm_vm_frame_arguments, scm_vm_frame_source)
(scm_vm_frame_local_ref, scm_vm_frame_local_set_x): SCM_PROGRAM_DATA is
a struct scm_objcode*.
* libguile/instructions.h:
* libguile/instructions.c: Hide the instruction table and the struct
scm_instruction structure; all access to instructions now goes through
procedures. This is because instructions are no longer in a packed
array indexed by opcode. Also, declare a mask that all instructions
should fit in.
* libguile/objcodes.h:
* libguile/objcodes.c: Rewrite so that object code directly maps its
arity and length from its bytecode. This makes it unnecessary to keep
this information in programs, allowing programs to be simple conses
between the code (objcodes) and data (the object table and the closure
variables).
* libguile/programs.c (scm_make_program): Rework so that make-program
takes objcode, an object table, and externals as arguments. It's much
clearer this way, and we avoid malloc().
* libguile/stacks.c (is_vm_bootstrap_frame): Update for program/objcode
changes.
* libguile/vm-engine.c (vm_run): Initialize the jump table on the first
run, with the opcodes declared in the instruction sources, and with bad
instructions raising an error instead of wandering off into the
Unknown.
* libguile/vm-engine.h (FETCH_LENGTH): Always represent lengths as 3
bytes. The old code was too error-prone.
(NEXT_JUMP): Mask the instruction with SCM_VM_INSTRUCTION_MASK.
(NEW_FRAME): Update for program/objcode changes.
* libguile/vm-expand.h (VM_DEFINE_FUNCTION, VM_DEFINE_INSTRUCTION)
(VM_DEFINE_LOADER): Update so that we explicitly specify opcodes, so
that we have a stable bytecode API.
* libguile/vm-i-loader.c: Update license to LGPLv2+. Explicitly declare
opcodes.
(load-integer): Use an int instead of a long as the accumulator; still
need to revisit this code at some point, I think.
(load-program): Simplify, thankfully!! Just creates the objcode slice
and rolls with it.
* libguile/vm-i-scheme.c: Number the opcodes explicitly.
* libguile/vm-i-system.c: Update license to LGPLv2+. Explicitly declare
opcodes.
(make-closure): Update for new program API.
* libguile/vm.c (vm_make_boot_program): Update for new program/objcode
API. Still a bit ugly.
(scm_load_compiled_with_vm): Update for new program/objcode API.
* module/language/assembly.scm (byte-length): Fix byte-length calculation
for loaders, and load-program.
(code-pack, code-unpack): Start to move things from (system vm conv)
here.
(object->code, code->object): More things from conv.scm.
* module/language/glil.scm (<glil-program>): Add a new field,
closure-level.
(make-glil-program, compute-closure-level): Calculate the "closure
level" when making a glil program. This is the maximum depth of
external binding refs in this closure.
(unparse-glil): Fix label serialization.
* module/language/glil/compile-assembly.scm (make-meta): Prepend #f for
the meta's object table, though maybe in the future we can avoid
creating assembly in the first place.
(assoc-ref-or-acons, object-index-and-alist): GRRR! Caught again by the
different sets of arguments to assoc and assoc-ref!
(glil->assembly): Attempt to make the <glil-program> case more
readable, and fix the bugs. Sorry I don't know how to comment this
change any more than this.
(glil->assembly): For <glil-module> serialize the whole key, not just
the name.
(dump-object): subprogram-code is already a list. Serialize integers as
strings, not u8vectors. Fix the order of lists and vectors.
* module/language/glil/spec.scm (glil): Switch orders, so we prefer glil
-> assembly -> objcode. Actually glil->objcode doesn't work any more,
needs to be removed I think.
* module/language/objcode/spec.scm (objcode->value):
s/objcode->program/make-program/.
* module/language/scheme/inline.scm: Add acons inline.
* module/system/vm/conv.scm (make-byte-decoder): Skip the first 8 bytes,
they are header. Handle subprograms properly. Still needs help though.
(decode-length): Lengths are always 3 bytes now.
* module/system/vm/disasm.scm: Superficial changes to keep things
working. I'd like to fix this better in the future.
* module/system/vm/frame.scm (bootstrap-frame?): Fixes for
program-bytecode.
* module/system/vm/program.scm: Export make-program. It's program-objcode
now, no more program-bytecode.
* module/system/vm/vm.scm (vm-load): Use make-program.
* test-suite/tests/asm-to-bytecode.test: New test, very minimal.
* module/system/vm/objcode.scm: Export word-size, byte-order, and
write-objcode.
2009-01-29 21:09:04 +01:00
|
|
|
|
SCM program = scm_make_program (scm_load_objcode (file),
|
2009-07-23 17:12:10 +02:00
|
|
|
|
SCM_BOOL_F, SCM_BOOL_F);
|
big reorg of scheme modules -- e.g. programs.c -> (system vm program)
This reorganization kills the ugly module-export-all hacks in
bootstrap.scm and core.scm. In fact, it gets rid of core.scm entirely,
breaking out its functionality into separate files.
* module/system/vm/trace.scm:
* module/system/vm/profile.scm:
* module/system/vm/disasm.scm:
* module/system/vm/debug.scm:
* module/system/vm/conv.scm:
* module/system/vm/assemble.scm:
* module/system/repl/repl.scm:
* module/system/repl/common.scm:
* module/system/base/compile.scm:
* module/system/repl/command.scm: Update for changes, and fix a bug in
procedure-documentation.
* module/system/vm/bootstrap.scm: Just call scm_bootstrap_vm, which
handles setting load-compiled for us.
* module/system/vm/core.scm: Removed, functionality folded into other
modules.
* module/system/vm/frame.scm: Export the C frame procedures here; also
move scheme functions from core.scm here.
* module/system/vm/instruction.scm: New file, exports procedures from
instructions.c.
* module/system/vm/objcode.scm: New file, exports procedures from
objcodes.c.
* module/system/vm/program.scm: New file, exports procedures from
programs.c, and some scheme functions originally from core.scm.
* module/system/vm/vm.scm: New file, from vm.c and core.scm.
* src/Makefile.am (libguile_vm_la_SOURCES): Add bootstrap.h.
* src/bootstrap.h: New file, prototypes scm_bootstrap_vm (), which the
scm_init_* functions call.
* src/frames.h:
* src/frames.c (scm_init_frames):
* src/frames.c (scm_bootstrap_frames):
* src/vm.h:
* src/instructions.h:
* src/instructions.c (scm_init_instructions):
* src/instructions.c (scm_bootstrap_instructions):
* src/objcodes.h:
* src/objcodes.c (scm_bootstrap_objcodes):
* src/objcodes.c (scm_init_objcodes):
* src/programs.h:
* src/programs.c (scm_bootstrap_programs):
* src/programs.c (scm_init_programs):
* src/vm.c (scm_bootstrap_vm):
* src/vm.c (scm_init_vm): Call scm_bootstrap_vm() before doing anything
in an init function. Bootstrap_vm will call bootstrap_instructions(),
etc to initialize types, then set load-compiled to point to
load-compiled/vm.
* src/vm.c (scm_load_compiled_with_vm): Code to load .go files, if
they're present.
2008-08-07 13:11:27 +02:00
|
|
|
|
|
2009-02-05 00:51:34 +01:00
|
|
|
|
return scm_c_vm_run (scm_the_vm (), program, NULL, 0);
|
big reorg of scheme modules -- e.g. programs.c -> (system vm program)
This reorganization kills the ugly module-export-all hacks in
bootstrap.scm and core.scm. In fact, it gets rid of core.scm entirely,
breaking out its functionality into separate files.
* module/system/vm/trace.scm:
* module/system/vm/profile.scm:
* module/system/vm/disasm.scm:
* module/system/vm/debug.scm:
* module/system/vm/conv.scm:
* module/system/vm/assemble.scm:
* module/system/repl/repl.scm:
* module/system/repl/common.scm:
* module/system/base/compile.scm:
* module/system/repl/command.scm: Update for changes, and fix a bug in
procedure-documentation.
* module/system/vm/bootstrap.scm: Just call scm_bootstrap_vm, which
handles setting load-compiled for us.
* module/system/vm/core.scm: Removed, functionality folded into other
modules.
* module/system/vm/frame.scm: Export the C frame procedures here; also
move scheme functions from core.scm here.
* module/system/vm/instruction.scm: New file, exports procedures from
instructions.c.
* module/system/vm/objcode.scm: New file, exports procedures from
objcodes.c.
* module/system/vm/program.scm: New file, exports procedures from
programs.c, and some scheme functions originally from core.scm.
* module/system/vm/vm.scm: New file, from vm.c and core.scm.
* src/Makefile.am (libguile_vm_la_SOURCES): Add bootstrap.h.
* src/bootstrap.h: New file, prototypes scm_bootstrap_vm (), which the
scm_init_* functions call.
* src/frames.h:
* src/frames.c (scm_init_frames):
* src/frames.c (scm_bootstrap_frames):
* src/vm.h:
* src/instructions.h:
* src/instructions.c (scm_init_instructions):
* src/instructions.c (scm_bootstrap_instructions):
* src/objcodes.h:
* src/objcodes.c (scm_bootstrap_objcodes):
* src/objcodes.c (scm_init_objcodes):
* src/programs.h:
* src/programs.c (scm_bootstrap_programs):
* src/programs.c (scm_init_programs):
* src/vm.c (scm_bootstrap_vm):
* src/vm.c (scm_init_vm): Call scm_bootstrap_vm() before doing anything
in an init function. Bootstrap_vm will call bootstrap_instructions(),
etc to initialize types, then set load-compiled to point to
load-compiled/vm.
* src/vm.c (scm_load_compiled_with_vm): Code to load .go files, if
they're present.
2008-08-07 13:11:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-04-01 05:03:41 +00:00
|
|
|
|
void
|
big reorg of scheme modules -- e.g. programs.c -> (system vm program)
This reorganization kills the ugly module-export-all hacks in
bootstrap.scm and core.scm. In fact, it gets rid of core.scm entirely,
breaking out its functionality into separate files.
* module/system/vm/trace.scm:
* module/system/vm/profile.scm:
* module/system/vm/disasm.scm:
* module/system/vm/debug.scm:
* module/system/vm/conv.scm:
* module/system/vm/assemble.scm:
* module/system/repl/repl.scm:
* module/system/repl/common.scm:
* module/system/base/compile.scm:
* module/system/repl/command.scm: Update for changes, and fix a bug in
procedure-documentation.
* module/system/vm/bootstrap.scm: Just call scm_bootstrap_vm, which
handles setting load-compiled for us.
* module/system/vm/core.scm: Removed, functionality folded into other
modules.
* module/system/vm/frame.scm: Export the C frame procedures here; also
move scheme functions from core.scm here.
* module/system/vm/instruction.scm: New file, exports procedures from
instructions.c.
* module/system/vm/objcode.scm: New file, exports procedures from
objcodes.c.
* module/system/vm/program.scm: New file, exports procedures from
programs.c, and some scheme functions originally from core.scm.
* module/system/vm/vm.scm: New file, from vm.c and core.scm.
* src/Makefile.am (libguile_vm_la_SOURCES): Add bootstrap.h.
* src/bootstrap.h: New file, prototypes scm_bootstrap_vm (), which the
scm_init_* functions call.
* src/frames.h:
* src/frames.c (scm_init_frames):
* src/frames.c (scm_bootstrap_frames):
* src/vm.h:
* src/instructions.h:
* src/instructions.c (scm_init_instructions):
* src/instructions.c (scm_bootstrap_instructions):
* src/objcodes.h:
* src/objcodes.c (scm_bootstrap_objcodes):
* src/objcodes.c (scm_init_objcodes):
* src/programs.h:
* src/programs.c (scm_bootstrap_programs):
* src/programs.c (scm_init_programs):
* src/vm.c (scm_bootstrap_vm):
* src/vm.c (scm_init_vm): Call scm_bootstrap_vm() before doing anything
in an init function. Bootstrap_vm will call bootstrap_instructions(),
etc to initialize types, then set load-compiled to point to
load-compiled/vm.
* src/vm.c (scm_load_compiled_with_vm): Code to load .go files, if
they're present.
2008-08-07 13:11:27 +02:00
|
|
|
|
scm_bootstrap_vm (void)
|
2001-04-01 05:03:41 +00:00
|
|
|
|
{
|
2010-03-16 21:18:12 +01:00
|
|
|
|
scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
|
|
|
|
|
|
"scm_init_vm",
|
2009-03-27 18:40:15 -07:00
|
|
|
|
(scm_t_extension_init_func)scm_init_vm, NULL);
|
|
|
|
|
|
|
2010-02-25 00:43:44 +01:00
|
|
|
|
sym_vm_run = scm_from_locale_symbol ("vm-run");
|
|
|
|
|
|
sym_vm_error = scm_from_locale_symbol ("vm-error");
|
|
|
|
|
|
sym_keyword_argument_error = scm_from_locale_symbol ("keyword-argument-error");
|
|
|
|
|
|
sym_debug = scm_from_locale_symbol ("debug");
|
2010-02-24 23:32:04 +01:00
|
|
|
|
|
2009-08-20 01:56:47 +02:00
|
|
|
|
#ifdef VM_ENABLE_PRECISE_STACK_GC_SCAN
|
|
|
|
|
|
vm_stack_gc_kind =
|
|
|
|
|
|
GC_new_kind (GC_new_free_list (),
|
|
|
|
|
|
GC_MAKE_PROC (GC_new_proc (vm_stack_mark), 0),
|
|
|
|
|
|
0, 1);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
big reorg of scheme modules -- e.g. programs.c -> (system vm program)
This reorganization kills the ugly module-export-all hacks in
bootstrap.scm and core.scm. In fact, it gets rid of core.scm entirely,
breaking out its functionality into separate files.
* module/system/vm/trace.scm:
* module/system/vm/profile.scm:
* module/system/vm/disasm.scm:
* module/system/vm/debug.scm:
* module/system/vm/conv.scm:
* module/system/vm/assemble.scm:
* module/system/repl/repl.scm:
* module/system/repl/common.scm:
* module/system/base/compile.scm:
* module/system/repl/command.scm: Update for changes, and fix a bug in
procedure-documentation.
* module/system/vm/bootstrap.scm: Just call scm_bootstrap_vm, which
handles setting load-compiled for us.
* module/system/vm/core.scm: Removed, functionality folded into other
modules.
* module/system/vm/frame.scm: Export the C frame procedures here; also
move scheme functions from core.scm here.
* module/system/vm/instruction.scm: New file, exports procedures from
instructions.c.
* module/system/vm/objcode.scm: New file, exports procedures from
objcodes.c.
* module/system/vm/program.scm: New file, exports procedures from
programs.c, and some scheme functions originally from core.scm.
* module/system/vm/vm.scm: New file, from vm.c and core.scm.
* src/Makefile.am (libguile_vm_la_SOURCES): Add bootstrap.h.
* src/bootstrap.h: New file, prototypes scm_bootstrap_vm (), which the
scm_init_* functions call.
* src/frames.h:
* src/frames.c (scm_init_frames):
* src/frames.c (scm_bootstrap_frames):
* src/vm.h:
* src/instructions.h:
* src/instructions.c (scm_init_instructions):
* src/instructions.c (scm_bootstrap_instructions):
* src/objcodes.h:
* src/objcodes.c (scm_bootstrap_objcodes):
* src/objcodes.c (scm_init_objcodes):
* src/programs.h:
* src/programs.c (scm_bootstrap_programs):
* src/programs.c (scm_init_programs):
* src/vm.c (scm_bootstrap_vm):
* src/vm.c (scm_init_vm): Call scm_bootstrap_vm() before doing anything
in an init function. Bootstrap_vm will call bootstrap_instructions(),
etc to initialize types, then set load-compiled to point to
load-compiled/vm.
* src/vm.c (scm_load_compiled_with_vm): Code to load .go files, if
they're present.
2008-08-07 13:11:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
scm_init_vm (void)
|
|
|
|
|
|
{
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#ifndef SCM_MAGIC_SNARFER
|
2009-03-16 23:39:29 +01:00
|
|
|
|
#include "libguile/vm.x"
|
2001-04-01 05:03:41 +00:00
|
|
|
|
#endif
|
2000-08-22 15:54:19 +00:00
|
|
|
|
}
|
2001-04-01 05:03:41 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|