Commit | Line | Data |
---|---|---|
8f5cfc81 | 1 | /* Copyright (C) 2001 Free Software Foundation, Inc. |
a98cef7e KN |
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 | ||
17e90c5e | 42 | /* This file is included in vm.c twice */ |
a98cef7e | 43 | |
83495480 | 44 | #include "vm-engine.h" |
a98cef7e | 45 | |
238e7a11 | 46 | |
a98cef7e | 47 | static SCM |
41f248a8 | 48 | vm_run (SCM vm, SCM program, SCM args) |
a98cef7e KN |
49 | #define FUNC_NAME "vm-engine" |
50 | { | |
17e90c5e KN |
51 | /* VM registers */ |
52 | register scm_byte_t *ip IP_REG; /* instruction pointer */ | |
53 | register SCM *sp SP_REG; /* stack pointer */ | |
54 | register SCM *fp FP_REG; /* frame pointer */ | |
a98cef7e | 55 | |
d608d68d | 56 | /* Cache variables */ |
3d5ee0cd | 57 | struct scm_vm *vp = SCM_VM_DATA (vm); /* VM data pointer */ |
17e90c5e | 58 | struct scm_program *bp = NULL; /* program base pointer */ |
41f248a8 | 59 | SCM external = SCM_EOL; /* external environment */ |
17e90c5e | 60 | SCM *objects = NULL; /* constant objects */ |
2fda0242 | 61 | size_t object_count = 0; /* length of OBJECTS */ |
3d5ee0cd KN |
62 | SCM *stack_base = vp->stack_base; /* stack base address */ |
63 | SCM *stack_limit = vp->stack_limit; /* stack limit address */ | |
a98cef7e | 64 | |
d608d68d | 65 | /* Internal variables */ |
17e90c5e | 66 | int nargs = 0; |
ef24c01b | 67 | int nvalues = 0; |
3d5ee0cd | 68 | long start_time = scm_c_get_internal_run_time (); |
17e90c5e KN |
69 | // SCM dynwinds = SCM_EOL; |
70 | SCM err_msg; | |
71 | SCM err_args; | |
72 | #if VM_USE_HOOKS | |
a98cef7e KN |
73 | SCM hook_args = SCM_LIST1 (vm); |
74 | #endif | |
17d1b4bf AW |
75 | struct vm_unwind_data wind_data; |
76 | ||
77 | /* dynwind ended in the halt instruction */ | |
78 | scm_dynwind_begin (SCM_F_DYNWIND_REWINDABLE); | |
79 | wind_data.vp = vp; | |
80 | wind_data.sp = vp->sp; | |
81 | wind_data.fp = vp->fp; | |
17d1b4bf | 82 | scm_dynwind_unwind_handler (vm_reset_stack, &wind_data, 0); |
bfffd258 AW |
83 | |
84 | /* could do this if we reified all vm stacks -- for now, don't bother changing | |
85 | *the-vm* | |
86 | if (scm_fluid_ref (scm_the_vm_fluid) != vm) | |
87 | scm_dynwind_fluid (scm_the_vm_fluid, vm); | |
88 | */ | |
a98cef7e | 89 | |
17e90c5e | 90 | #ifdef HAVE_LABELS_AS_VALUES |
2d80426a | 91 | /* Jump table */ |
4b482259 | 92 | static void *jump_table[] = { |
17e90c5e | 93 | #define VM_INSTRUCTION_TO_LABEL 1 |
83495480 AW |
94 | #include "vm-expand.h" |
95 | #include "vm-i-system.i" | |
96 | #include "vm-i-scheme.i" | |
97 | #include "vm-i-loader.i" | |
77c04abe | 98 | #undef VM_INSTRUCTION_TO_LABEL |
4b482259 | 99 | }; |
17e90c5e | 100 | #endif |
a98cef7e | 101 | |
3d5ee0cd KN |
102 | /* Initialization */ |
103 | { | |
499a4c07 KN |
104 | SCM prog = program; |
105 | ||
106 | /* Boot program */ | |
2fda0242 | 107 | program = vm_make_boot_program (scm_ilength (args)); |
a98cef7e | 108 | |
3d5ee0cd KN |
109 | /* Initial frame */ |
110 | CACHE_REGISTER (); | |
499a4c07 | 111 | CACHE_PROGRAM (); |
3616e9e9 | 112 | PUSH (program); |
3d5ee0cd | 113 | NEW_FRAME (); |
17e90c5e | 114 | |
3d5ee0cd | 115 | /* Initial arguments */ |
3616e9e9 | 116 | PUSH (prog); |
3d5ee0cd KN |
117 | for (; !SCM_NULLP (args); args = SCM_CDR (args)) |
118 | PUSH (SCM_CAR (args)); | |
3d5ee0cd | 119 | } |
a98cef7e KN |
120 | |
121 | /* Let's go! */ | |
17e90c5e | 122 | BOOT_HOOK (); |
a98cef7e KN |
123 | |
124 | #ifndef HAVE_LABELS_AS_VALUES | |
17e90c5e KN |
125 | vm_start: |
126 | switch (*ip++) { | |
a98cef7e KN |
127 | #endif |
128 | ||
83495480 AW |
129 | #include "vm-expand.h" |
130 | #include "vm-i-system.c" | |
131 | #include "vm-i-scheme.c" | |
132 | #include "vm-i-loader.c" | |
a98cef7e KN |
133 | |
134 | #ifndef HAVE_LABELS_AS_VALUES | |
135 | } | |
136 | #endif | |
137 | ||
17e90c5e KN |
138 | /* Errors */ |
139 | { | |
140 | vm_error_unbound: | |
fa19602c | 141 | err_msg = scm_from_locale_string ("VM: Unbound variable: ~A"); |
17e90c5e KN |
142 | goto vm_error; |
143 | ||
4c9ad01d | 144 | vm_error_wrong_type_arg: |
fa19602c | 145 | err_msg = scm_from_locale_string ("VM: Wrong type argument"); |
4c9ad01d KN |
146 | err_args = SCM_EOL; |
147 | goto vm_error; | |
148 | ||
17e90c5e | 149 | vm_error_wrong_num_args: |
9a8cc8e7 | 150 | /* nargs and program are valid */ |
0570c3f1 | 151 | SYNC_ALL (); |
9a8cc8e7 AW |
152 | scm_wrong_num_args (program); |
153 | /* shouldn't get here */ | |
17e90c5e KN |
154 | goto vm_error; |
155 | ||
156 | vm_error_wrong_type_apply: | |
0b5f0e49 LC |
157 | err_msg = scm_from_locale_string ("VM: Wrong type to apply: ~S " |
158 | "[IP offset: ~a]"); | |
159 | err_args = SCM_LIST2 (program, | |
160 | SCM_I_MAKINUM (ip - bp->base)); | |
17e90c5e KN |
161 | goto vm_error; |
162 | ||
ac02b386 | 163 | vm_error_stack_overflow: |
fa19602c | 164 | err_msg = scm_from_locale_string ("VM: Stack overflow"); |
17e90c5e KN |
165 | err_args = SCM_EOL; |
166 | goto vm_error; | |
17e90c5e | 167 | |
ac02b386 | 168 | vm_error_stack_underflow: |
fa19602c | 169 | err_msg = scm_from_locale_string ("VM: Stack underflow"); |
17e90c5e KN |
170 | err_args = SCM_EOL; |
171 | goto vm_error; | |
172 | ||
1f40459f AW |
173 | vm_error_improper_list: |
174 | err_msg = scm_from_locale_string ("VM: Attempt to unroll an improper list: tail is ~A"); | |
175 | goto vm_error; | |
176 | ||
5e390de6 AW |
177 | vm_error_not_a_pair: |
178 | SYNC_ALL (); | |
179 | scm_wrong_type_arg_msg (FUNC_NAME, 1, err_args, "pair"); | |
180 | /* shouldn't get here */ | |
181 | goto vm_error; | |
182 | ||
a222b0fa AW |
183 | vm_error_no_values: |
184 | err_msg = scm_from_locale_string ("VM: 0-valued return"); | |
185 | err_args = SCM_EOL; | |
186 | goto vm_error; | |
187 | ||
d51406fe AW |
188 | vm_error_not_enough_values: |
189 | err_msg = scm_from_locale_string ("VM: Not enough values for mv-bind"); | |
190 | err_args = SCM_EOL; | |
191 | goto vm_error; | |
192 | ||
fd358575 AW |
193 | vm_error_no_such_module: |
194 | err_msg = scm_from_locale_string ("VM: No such module: ~A"); | |
195 | goto vm_error; | |
196 | ||
ac02b386 KN |
197 | #if VM_CHECK_IP |
198 | vm_error_invalid_address: | |
fa19602c | 199 | err_msg = scm_from_locale_string ("VM: Invalid program address"); |
17e90c5e KN |
200 | err_args = SCM_EOL; |
201 | goto vm_error; | |
ac02b386 KN |
202 | #endif |
203 | ||
204 | #if VM_CHECK_EXTERNAL | |
205 | vm_error_external: | |
fa19602c | 206 | err_msg = scm_from_locale_string ("VM: Invalid external access"); |
ac02b386 KN |
207 | err_args = SCM_EOL; |
208 | goto vm_error; | |
209 | #endif | |
17e90c5e | 210 | |
0b5f0e49 LC |
211 | #if VM_CHECK_OBJECT |
212 | vm_error_object: | |
213 | err_msg = scm_from_locale_string ("VM: Invalid object table access"); | |
214 | err_args = SCM_EOL; | |
215 | goto vm_error; | |
216 | #endif | |
217 | ||
17e90c5e KN |
218 | vm_error: |
219 | SYNC_ALL (); | |
a52b2d3d | 220 | |
ac99cb0c | 221 | scm_ithrow (sym_vm_error, SCM_LIST3 (sym_vm_run, err_msg, err_args), 1); |
17e90c5e KN |
222 | } |
223 | ||
a98cef7e KN |
224 | abort (); /* never reached */ |
225 | } | |
226 | #undef FUNC_NAME | |
17e90c5e KN |
227 | |
228 | /* | |
229 | Local Variables: | |
230 | c-file-style: "gnu" | |
231 | End: | |
232 | */ |