1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02: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.
This commit is contained in:
Andy Wingo 2009-02-04 23:47:56 +01:00
parent bef9591104
commit 6d14383e86
4 changed files with 84 additions and 37 deletions

View file

@ -39,14 +39,27 @@
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice. */
/* This file is included in vm.c twice */
/* This file is included in vm.c multiple times */
#if (VM_ENGINE == SCM_VM_REGULAR_ENGINE)
#define VM_USE_HOOKS 0 /* Various hooks */
#define VM_USE_CLOCK 0 /* Bogoclock */
#define VM_CHECK_EXTERNAL 1 /* Check external link */
#define VM_CHECK_OBJECT 1 /* Check object table */
#elif (VM_ENGINE == SCM_VM_DEBUG_ENGINE)
#define VM_USE_HOOKS 1
#define VM_USE_CLOCK 1
#define VM_CHECK_EXTERNAL 1
#define VM_CHECK_OBJECT 1
#else
#error unknown debug engine VM_ENGINE
#endif
#include "vm-engine.h"
static SCM
vm_run (SCM vm, SCM program, SCM args)
#define FUNC_NAME "vm-engine"
VM_NAME (struct scm_vm *vp, SCM program, SCM *argv, int nargs)
{
/* VM registers */
register scm_byte_t *ip IP_REG; /* instruction pointer */
@ -54,7 +67,6 @@ vm_run (SCM vm, SCM program, SCM args)
register SCM *fp FP_REG; /* frame pointer */
/* Cache variables */
struct scm_vm *vp = SCM_VM_DATA (vm); /* VM data pointer */
struct scm_objcode *bp = NULL; /* program base pointer */
SCM external = SCM_EOL; /* external environment */
SCM *objects = NULL; /* constant objects */
@ -63,14 +75,12 @@ vm_run (SCM vm, SCM program, SCM args)
SCM *stack_limit = vp->stack_limit; /* stack limit address */
/* Internal variables */
int nargs = 0;
int nvalues = 0;
long start_time = scm_c_get_internal_run_time ();
// SCM dynwinds = SCM_EOL;
SCM err_msg;
SCM err_args;
#if VM_USE_HOOKS
SCM hook_args = SCM_LIST1 (vm);
SCM hook_args = SCM_EOL;
#endif
#ifdef HAVE_LABELS_AS_VALUES
@ -96,7 +106,7 @@ vm_run (SCM vm, SCM program, SCM args)
SCM prog = program;
/* Boot program */
program = vm_make_boot_program (scm_ilength (args));
program = vm_make_boot_program (nargs);
/* Initial frame */
CACHE_REGISTER ();
@ -106,8 +116,10 @@ vm_run (SCM vm, SCM program, SCM args)
/* Initial arguments */
PUSH (prog);
for (; !SCM_NULLP (args); args = SCM_CDR (args))
PUSH (SCM_CAR (args));
if (SCM_UNLIKELY (sp + nargs >= stack_limit))
goto vm_error_too_many_args;
while (nargs--)
PUSH (*argv++);
}
/* Let's go! */
@ -146,6 +158,11 @@ vm_run (SCM vm, SCM program, SCM args)
err_args = SCM_EOL;
goto vm_error;
vm_error_too_many_args:
err_msg = scm_from_locale_string ("VM: Too many arguments");
err_args = SCM_LIST1 (scm_from_int (nargs));
goto vm_error;
vm_error_wrong_num_args:
/* nargs and program are valid */
SYNC_ALL ();
@ -223,7 +240,11 @@ vm_run (SCM vm, SCM program, SCM args)
abort (); /* never reached */
}
#undef FUNC_NAME
#undef VM_USE_HOOKS
#undef VM_USE_CLOCK
#undef VM_CHECK_EXTERNAL
#undef VM_CHECK_OBJECT
/*
Local Variables: