*** empty log message ***
[bpt/guile.git] / src / vm_engine.c
CommitLineData
a98cef7e
KN
1/* Copyright (C) 2000 Free Software Foundation, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
41
42/* This file is included in vm.c two times! */
43
44#include "vm_engine.h"
45
46/* VM names */
47#undef VM_NAME
a98cef7e
KN
48#if VM_ENGINE == SCM_VM_REGULAR_ENGINE
49#define VM_NAME scm_regular_vm
a98cef7e
KN
50#else
51#if VM_ENGINE == SCM_VM_DEBUG_ENGINE
52#define VM_NAME scm_debug_vm
a98cef7e
KN
53#endif
54#endif
55
56static SCM
57VM_NAME (SCM vm, SCM program)
58#define FUNC_NAME "vm-engine"
59{
60 /* Copies of VM registers */
d608d68d
KN
61 SCM ac = SCM_PACK (0); /* accumulator */
62 SCM *pc = NULL; /* program counter */
63 SCM *sp = NULL; /* stack pointer */
64 SCM *fp = NULL; /* frame pointer */
a98cef7e 65
d608d68d
KN
66 /* Cache variables */
67 struct scm_vm *vmp = NULL; /* the VM data pointer */
68 SCM ext = SCM_BOOL_F; /* the current external frame */
69 SCM *stack_base = NULL; /* stack base address */
70 SCM *stack_limit = NULL; /* stack limit address */
a98cef7e 71
d608d68d 72 /* Internal variables */
382693fe 73 int nargs = 0; /* the number of arguments */
a98cef7e 74 SCM dynwinds = SCM_EOL;
a98cef7e
KN
75#if VM_USE_HOOK
76 SCM hook_args = SCM_LIST1 (vm);
77#endif
78
4b482259
KN
79 /* Jump talbe */
80 static void *jump_table[] = {
77c04abe
KN
81#define VM_INSTRUCTION_TO_LABEL
82#include "vm_expand.h"
83#include "vm_system.i"
84#include "vm_scheme.i"
85#include "vm_number.i"
86#undef VM_INSTRUCTION_TO_LABEL
4b482259 87 };
a98cef7e 88
a98cef7e
KN
89 /* Initialize the VM */
90 vmp = SCM_VM_DATA (vm);
91 vmp->pc = SCM_PROGRAM_BASE (program);
92 vmp->sp = vmp->stack_limit;
93 LOAD ();
94
95 /* top frame */
96 VM_NEW_FRAME (fp, program, SCM_BOOL_F,
97 SCM_VM_MAKE_ADDRESS (0),
98 SCM_VM_MAKE_ADDRESS (0));
99
100 /* Let's go! */
101 VM_BOOT_HOOK ();
102
103#ifndef HAVE_LABELS_AS_VALUES
104 vm_start: switch (*pc++) {
105#endif
106
77c04abe 107#include "vm_expand.h"
a98cef7e
KN
108#include "vm_system.c"
109#include "vm_scheme.c"
110#include "vm_number.c"
111
112#ifndef HAVE_LABELS_AS_VALUES
113 }
114#endif
115
116 abort (); /* never reached */
117}
118#undef FUNC_NAME