diff options
author | Andy Wingo <wingo@pobox.com> | 2009-02-04 23:47:56 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-02-04 23:47:56 +0100 |
commit | 6d14383e866f447a0d2656fd319ba68a5737202c (patch) | |
tree | 85eeff88a88f7eb96e865aacd83cb2eedf7bc4c3 /libguile/vm.c | |
parent | bef959110427b00bd07b0ac35b1baa2db2bc4828 (diff) | |
download | guile-6d14383e866f447a0d2656fd319ba68a5737202c.tar.gz |
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.
Diffstat (limited to 'libguile/vm.c')
-rw-r--r-- | libguile/vm.c | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/libguile/vm.c b/libguile/vm.c index 074bec63c..90a1f68c1 100644 --- a/libguile/vm.c +++ b/libguile/vm.c @@ -43,6 +43,7 @@ # include <config.h> #endif +#include <alloca.h> #include <string.h> #include "vm-bootstrap.h" #include "frames.h" @@ -216,15 +217,14 @@ static void enfalsen_frame (void *p) } static void -vm_dispatch_hook (SCM vm, SCM hook, SCM hook_args) +vm_dispatch_hook (struct scm_vm *vp, SCM hook, SCM hook_args) { - struct scm_vm *vp = SCM_VM_DATA (vm); - if (!SCM_FALSEP (vp->trace_frame)) return; scm_dynwind_begin (0); - vp->trace_frame = scm_c_make_vm_frame (vm, vp->fp, vp->sp, vp->ip, 0); + // FIXME, stack holder should be the vm + vp->trace_frame = scm_c_make_vm_frame (SCM_BOOL_F, vp->fp, vp->sp, vp->ip, 0); scm_dynwind_unwind_handler (enfalsen_frame, vp, SCM_F_WIND_EXPLICITLY); scm_c_run_hook (hook, hook_args); @@ -288,23 +288,25 @@ vm_make_boot_program (long nargs) #define VM_DEFAULT_STACK_SIZE (16 * 1024) -#define VM_REGULAR_ENGINE 0 -#define VM_DEBUG_ENGINE 1 - -#if 0 #define VM_NAME vm_regular_engine -#define VM_ENGINE VM_REGULAR_ENGINE +#define FUNC_NAME "vm-regular-engine" +#define VM_ENGINE SCM_VM_REGULAR_ENGINE #include "vm-engine.c" #undef VM_NAME +#undef FUNC_NAME #undef VM_ENGINE -#endif #define VM_NAME vm_debug_engine -#define VM_ENGINE VM_DEBUG_ENGINE +#define FUNC_NAME "vm-debug-engine" +#define VM_ENGINE SCM_VM_DEBUG_ENGINE #include "vm-engine.c" #undef VM_NAME +#undef FUNC_NAME #undef VM_ENGINE +static const scm_t_vm_engine vm_engines[] = + { vm_regular_engine, vm_debug_engine }; + scm_t_bits scm_tc16_vm; static SCM @@ -328,6 +330,7 @@ make_vm (void) vp->ip = NULL; vp->sp = vp->stack_base - 1; vp->fp = NULL; + vp->engine = SCM_VM_DEBUG_ENGINE; vp->time = 0; vp->clock = 0; vp->options = SCM_EOL; @@ -375,11 +378,33 @@ vm_free (SCM obj) } SCM +scm_c_vm_run (struct scm_vm *vp, SCM program, SCM *argv, int nargs) +{ + return vm_engines[vp->engine](vp, program, argv, nargs); +} + +SCM scm_vm_apply (SCM vm, SCM program, SCM args) #define FUNC_NAME "scm_vm_apply" { - SCM_VALIDATE_PROGRAM (1, program); - return vm_run (vm, program, args); + SCM *argv; + int i, nargs; + + SCM_VALIDATE_VM (1, vm); + SCM_VALIDATE_PROGRAM (2, program); + + 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); + } + + return scm_c_vm_run (SCM_VM_DATA (vm), program, argv, nargs); } #undef FUNC_NAME @@ -600,7 +625,7 @@ SCM scm_load_compiled_with_vm (SCM file) SCM program = scm_make_program (scm_load_objcode (file), SCM_BOOL_F, SCM_EOL); - return vm_run (scm_the_vm (), program, SCM_EOL); + return scm_c_vm_run (SCM_VM_DATA (scm_the_vm ()), program, NULL, 0); } void |