Initial revision
[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
48#undef VM_TABLE
49#if VM_ENGINE == SCM_VM_REGULAR_ENGINE
50#define VM_NAME scm_regular_vm
51#define VM_TABLE scm_regular_instruction_table
52#else
53#if VM_ENGINE == SCM_VM_DEBUG_ENGINE
54#define VM_NAME scm_debug_vm
55#define VM_TABLE scm_debug_instruction_table
56#endif
57#endif
58
59static SCM
60VM_NAME (SCM vm, SCM program)
61#define FUNC_NAME "vm-engine"
62{
63 /* Copies of VM registers */
64 SCM ac = SCM_PACK (0);
65 SCM *pc = NULL;
66 SCM *sp = NULL;
67 SCM *fp = NULL;
68
69 /* Stack boundaries */
70 SCM *stack_base = NULL;
71 SCM *stack_limit = NULL;
72
73 /* Function arguments */
74 int an = 0;
75 SCM a2 = SCM_PACK (0);
76 SCM a3 = SCM_PACK (0);
77
78 /* Miscellaneous variables */
79 SCM dynwinds = SCM_EOL;
80 struct scm_vm *vmp = NULL;
81
82#if VM_USE_HOOK
83 SCM hook_args = SCM_LIST1 (vm);
84#endif
85
86 /* Initialize the instruction table at the first time.
87 * This code must be here because the following table contains
88 * pointers to the labels defined in this function. */
89 if (!VM_TABLE)
90 {
91 static struct scm_instruction table[] = {
92#include "vm_system.vi"
93#include "vm_scheme.vi"
94#include "vm_number.vi"
95 { op_last }
96 };
97 VM_TABLE = table;
98 return SCM_UNSPECIFIED;
99 }
100
101 SCM_VALIDATE_VM (1, vm);
102 SCM_VALIDATE_PROGRAM (2, program);
103
104 /* Initialize the VM */
105 vmp = SCM_VM_DATA (vm);
106 vmp->pc = SCM_PROGRAM_BASE (program);
107 vmp->sp = vmp->stack_limit;
108 LOAD ();
109
110 /* top frame */
111 VM_NEW_FRAME (fp, program, SCM_BOOL_F,
112 SCM_VM_MAKE_ADDRESS (0),
113 SCM_VM_MAKE_ADDRESS (0));
114
115 /* Let's go! */
116 VM_BOOT_HOOK ();
117
118#ifndef HAVE_LABELS_AS_VALUES
119 vm_start: switch (*pc++) {
120#endif
121
122#include "vm_system.c"
123#include "vm_scheme.c"
124#include "vm_number.c"
125
126#ifndef HAVE_LABELS_AS_VALUES
127 }
128#endif
129
130 abort (); /* never reached */
131}
132#undef FUNC_NAME