guile/src/vm_engine.c

178 lines
5 KiB
C
Raw Normal View History

2000-08-22 15:54:19 +00:00
/* Copyright (C) 2000 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* As a special exception, the Free Software Foundation gives permission
* for additional uses of the text contained in its release of GUILE.
*
* The exception is that, if you link the GUILE library with other files
* to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the GUILE library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the
* Free Software Foundation under the name GUILE. If you copy
* code from other Free Software Foundation releases into a copy of
* GUILE, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for GUILE, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice. */
2001-04-01 05:03:41 +00:00
/* This file is included in vm.c twice */
2000-08-22 15:54:19 +00:00
#include "vm_engine.h"
static SCM
2001-04-11 20:57:44 +00:00
vm_run (SCM vm, SCM program, SCM args)
2000-08-22 15:54:19 +00:00
#define FUNC_NAME "vm-engine"
{
2001-04-01 05:03:41 +00:00
/* VM registers */
register scm_byte_t *ip IP_REG; /* instruction pointer */
register SCM *sp SP_REG; /* stack pointer */
register SCM *fp FP_REG; /* frame pointer */
2000-08-22 15:54:19 +00:00
2000-08-22 19:02:22 +00:00
/* Cache variables */
2001-04-06 00:17:39 +00:00
struct scm_vm *vp = SCM_VM_DATA (vm); /* VM data pointer */
2001-04-01 05:03:41 +00:00
struct scm_program *bp = NULL; /* program base pointer */
2001-04-11 20:57:44 +00:00
SCM external = SCM_EOL; /* external environment */
2001-04-01 05:03:41 +00:00
SCM *objects = NULL; /* constant objects */
2001-04-06 00:17:39 +00:00
SCM *stack_base = vp->stack_base; /* stack base address */
SCM *stack_limit = vp->stack_limit; /* stack limit address */
2000-08-22 15:54:19 +00:00
2000-08-22 19:02:22 +00:00
/* Internal variables */
2001-04-01 05:03:41 +00:00
int nargs = 0;
2001-04-06 00:17:39 +00:00
long start_time = scm_c_get_internal_run_time ();
2001-04-01 05:03:41 +00:00
// SCM dynwinds = SCM_EOL;
SCM err_msg;
SCM err_args;
#if VM_USE_HOOKS
2000-08-22 15:54:19 +00:00
SCM hook_args = SCM_LIST1 (vm);
#endif
2001-04-01 05:03:41 +00:00
#ifdef HAVE_LABELS_AS_VALUES
/* Jump talbe */
static void *jump_table[] = {
2001-04-01 05:03:41 +00:00
#define VM_INSTRUCTION_TO_LABEL 1
2000-09-29 18:08:00 +00:00
#include "vm_expand.h"
#include "vm_system.i"
#include "vm_scheme.i"
2001-04-01 05:03:41 +00:00
#include "vm_loader.i"
2000-09-29 18:08:00 +00:00
#undef VM_INSTRUCTION_TO_LABEL
};
2001-04-01 05:03:41 +00:00
#endif
2000-08-22 15:54:19 +00:00
2001-04-06 00:17:39 +00:00
/* Initialization */
{
2001-04-06 05:00:10 +00:00
SCM prog = program;
/* Boot program */
2001-04-06 00:17:39 +00:00
scm_byte_t bytes[3] = {scm_op_call, 0, scm_op_halt};
bytes[1] = scm_ilength (args);
2001-04-06 05:00:10 +00:00
program = scm_c_make_program (bytes, 3, SCM_BOOL_T);
2000-08-22 15:54:19 +00:00
2001-04-06 00:17:39 +00:00
/* Initial frame */
CACHE_REGISTER ();
2001-04-06 05:00:10 +00:00
CACHE_PROGRAM ();
2001-04-07 09:39:38 +00:00
PUSH (program);
2001-04-06 00:17:39 +00:00
NEW_FRAME ();
2001-04-01 05:03:41 +00:00
2001-04-06 00:17:39 +00:00
/* Initial arguments */
2001-04-07 09:39:38 +00:00
PUSH (prog);
2001-04-06 00:17:39 +00:00
for (; !SCM_NULLP (args); args = SCM_CDR (args))
PUSH (SCM_CAR (args));
}
2000-08-22 15:54:19 +00:00
/* Let's go! */
2001-04-01 05:03:41 +00:00
BOOT_HOOK ();
2000-08-22 15:54:19 +00:00
#ifndef HAVE_LABELS_AS_VALUES
2001-04-01 05:03:41 +00:00
vm_start:
switch (*ip++) {
2000-08-22 15:54:19 +00:00
#endif
2000-09-29 18:08:00 +00:00
#include "vm_expand.h"
2000-08-22 15:54:19 +00:00
#include "vm_system.c"
#include "vm_scheme.c"
2001-04-01 05:03:41 +00:00
#include "vm_loader.c"
2000-08-22 15:54:19 +00:00
#ifndef HAVE_LABELS_AS_VALUES
}
#endif
2001-04-01 05:03:41 +00:00
/* Errors */
{
vm_error_unbound:
err_msg = scm_makfrom0str ("Unbound variable: ~A");
goto vm_error;
2001-04-07 23:32:30 +00:00
vm_error_wrong_type_arg:
err_msg = scm_makfrom0str ("Wrong type argument");
err_args = SCM_EOL;
goto vm_error;
2001-04-01 05:03:41 +00:00
vm_error_wrong_num_args:
err_msg = scm_makfrom0str ("Wrong number of arguments");
err_args = SCM_EOL;
goto vm_error;
vm_error_wrong_type_apply:
err_msg = scm_makfrom0str ("Wrong type to apply: ~S");
err_args = SCM_LIST1 (program);
goto vm_error;
#if VM_CHECK_IP
vm_error_invalid_address:
err_msg = scm_makfrom0str ("Invalid program address");
err_args = SCM_EOL;
goto vm_error;
#endif
vm_error_stack_overflow:
err_msg = scm_makfrom0str ("Stack overflow");
err_args = SCM_EOL;
goto vm_error;
vm_error_stack_underflow:
err_msg = scm_makfrom0str ("Stack underflow");
err_args = SCM_EOL;
goto vm_error;
vm_error:
SYNC_ALL ();
scm_ithrow (sym_vm_error,
2001-04-11 20:57:44 +00:00
SCM_LIST4 (sym_vm_run, err_msg, err_args,
2001-04-01 05:03:41 +00:00
scm_vm_current_frame (vm)),
1);
}
2000-08-22 15:54:19 +00:00
abort (); /* never reached */
}
#undef FUNC_NAME
2001-04-01 05:03:41 +00:00
/*
Local Variables:
c-file-style: "gnu"
End:
*/