1 /* Copyright (C) 2000 Free Software Foundation, Inc.
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)
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.
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
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
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.
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
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.
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. */
42 /* This file is included in vm_engine.c */
49 /* This must be the first instruction! */
50 VM_DEFINE_INSTRUCTION (nop
, "nop", 0)
55 VM_DEFINE_INSTRUCTION (halt
, "halt", 0)
64 VM_DEFINE_INSTRUCTION (drop
, "drop", 0)
70 VM_DEFINE_INSTRUCTION (dup
, "dup", 0)
81 VM_DEFINE_INSTRUCTION (void, "void", 0)
83 PUSH (SCM_UNSPECIFIED
);
87 VM_DEFINE_INSTRUCTION (mark
, "mark", 0)
93 VM_DEFINE_INSTRUCTION (make_true
, "make-true", 0)
99 VM_DEFINE_INSTRUCTION (make_false
, "make-false", 0)
105 VM_DEFINE_INSTRUCTION (make_eol
, "make-eol", 0)
111 VM_DEFINE_INSTRUCTION (make_int8
, "make-int8", 1)
113 PUSH (SCM_MAKINUM ((signed char) FETCH ()));
117 VM_DEFINE_INSTRUCTION (make_int8_0
, "make-int8:0", 0)
119 PUSH (SCM_MAKINUM (0));
123 VM_DEFINE_INSTRUCTION (make_int8_1
, "make-int8:1", 0)
125 PUSH (SCM_MAKINUM (1));
129 VM_DEFINE_INSTRUCTION (make_int16
, "make-int16", 2)
131 PUSH (SCM_MAKINUM ((signed short) FETCH2 ()));
135 VM_DEFINE_INSTRUCTION (make_char8
, "make-char8", 1)
137 PUSH (SCM_MAKE_CHAR (FETCH ()));
146 #define OBJECT_REF(i) objects[i]
147 #define OBJECT_SET(i,o) objects[i] = o
149 #define LOCAL_REF(i) SCM_VM_FRAME_VARIABLE (fp, i)
150 #define LOCAL_SET(i,o) SCM_VM_FRAME_VARIABLE (fp, i) = o
152 #define VARIABLE_REF(v) SCM_CDR (v)
153 #define VARIABLE_SET(v,o) SCM_SETCDR (v, o)
155 VM_DEFINE_INSTRUCTION (external
, "external", 1)
159 CONS (external
, SCM_UNDEFINED
, external
);
165 VM_DEFINE_INSTRUCTION (object_ref
, "object-ref", 1)
167 PUSH (OBJECT_REF (FETCH ()));
171 VM_DEFINE_INSTRUCTION (object_ref_2
, "object-ref*2", 2)
173 PUSH (OBJECT_REF (FETCH2 ()));
177 VM_DEFINE_INSTRUCTION (local_ref
, "local-ref", 1)
179 PUSH (LOCAL_REF (FETCH ()));
183 VM_DEFINE_INSTRUCTION (local_ref_0
, "local-ref:0", 0)
185 PUSH (LOCAL_REF (0));
189 VM_DEFINE_INSTRUCTION (local_ref_2
, "local-ref*2", 2)
191 PUSH (LOCAL_REF (FETCH2 ()));
195 VM_DEFINE_INSTRUCTION (external_ref
, "external-ref", 1)
199 for (i
= FETCH (); i
; i
--)
205 VM_DEFINE_INSTRUCTION (module_ref
, "module-ref", 1)
208 SCM o
, x
= OBJECT_REF (i
);
209 o
= VARIABLE_REF (x
);
212 err_args
= SCM_LIST1 (SCM_CAR (x
));
213 goto vm_error_unbound
;
219 VM_DEFINE_INSTRUCTION (module_ref_2
, "module-ref*2", 2)
222 SCM o
, x
= OBJECT_REF (i
);
223 o
= VARIABLE_REF (x
);
226 err_args
= SCM_LIST1 (SCM_CAR (x
));
227 goto vm_error_unbound
;
233 VM_DEFINE_INSTRUCTION (variable_ref
, "variable-ref", 0)
236 SCM o
= VARIABLE_REF (x
);
239 err_args
= SCM_LIST1 (SCM_CAR (x
));
240 goto vm_error_unbound
;
248 VM_DEFINE_INSTRUCTION (local_set
, "local-set", 1)
250 LOCAL_SET (FETCH (), *sp
);
255 VM_DEFINE_INSTRUCTION (local_set_2
, "local-set*2", 2)
257 LOCAL_SET (FETCH2 (), *sp
);
262 VM_DEFINE_INSTRUCTION (external_set
, "external-set", 1)
266 for (i
= FETCH (); i
; i
--)
273 VM_DEFINE_INSTRUCTION (module_set
, "module-set", 1)
276 SCM x
= OBJECT_REF (i
);
277 VARIABLE_SET (x
, *sp
);
282 VM_DEFINE_INSTRUCTION (module_set_2
, "module-set*2", 2)
285 SCM x
= OBJECT_REF (i
);
286 VARIABLE_SET (x
, *sp
);
291 VM_DEFINE_INSTRUCTION (variable_set
, "variable-set", 0)
293 VARIABLE_SET (sp
[0], sp
[1]);
305 signed char offset = FETCH (); \
312 VM_DEFINE_INSTRUCTION (br_if
, "br-if", 1)
314 BR (!SCM_FALSEP (*sp
));
317 VM_DEFINE_INSTRUCTION (br_if_not
, "br-if-not", 1)
319 BR (SCM_FALSEP (*sp
));
322 VM_DEFINE_INSTRUCTION (br_if_eq
, "br-if-eq", 1)
324 BR (SCM_EQ_P (sp
[0], sp
--[1]));
327 VM_DEFINE_INSTRUCTION (br_if_not_eq
, "br-if-not-eq", 1)
329 BR (!SCM_EQ_P (sp
[0], sp
--[1]));
332 VM_DEFINE_INSTRUCTION (br_if_null
, "br-if-null", 1)
334 BR (SCM_NULLP (*sp
));
337 VM_DEFINE_INSTRUCTION (br_if_not_null
, "br-if-not-null", 1)
339 BR (!SCM_NULLP (*sp
));
342 VM_DEFINE_INSTRUCTION (jump
, "jump", 1)
344 ip
+= (signed char) FETCH ();
353 VM_DEFINE_INSTRUCTION (make_closure
, "make-closure", 0)
356 *sp
= scm_c_make_vclosure (*sp
, external
);
360 VM_DEFINE_INSTRUCTION (call
, "call", 1)
369 if (SCM_PROGRAM_P (program
))
382 if (!SCM_FALSEP (scm_procedure_p (program
)))
385 *sp
= scm_apply (program
, *sp
, SCM_EOL
);
386 program
= SCM_VM_FRAME_PROGRAM (fp
);
392 if (SCM_VM_CONT_P (program
))
395 /* Check the number of arguments */
397 scm_wrong_num_args (program
);
399 /* Reinstate the continuation */
401 reinstate_vm_cont (vmp
, program
);
403 /* We don't need to set the return value here
404 because it is already on the top of the stack. */
408 goto vm_error_wrong_type_apply
;
411 VM_DEFINE_INSTRUCTION (tail_call
, "tail-call", 1)
417 SCM_TICK
; /* allow interrupt here */
420 * Tail recursive call
422 if (SCM_EQ_P (x
, program
))
430 SCM
*base
= fp
+ bp
->nlocs
;
431 for (i
= 0; i
< bp
->nargs
; i
++)
436 sp
= SCM_VM_FRAME_LOWER_ADDRESS (fp
);
444 if (SCM_PROGRAM_P (program
))
447 int n
= SCM_VM_FRAME_LOWER_ADDRESS (fp
) - sp
;
450 /* Exit the current frame */
456 for (i
= 0; i
< n
; i
++)
459 /* Call the program */
465 if (!SCM_FALSEP (scm_procedure_p (program
)))
468 *sp
= scm_apply (program
, *sp
, SCM_EOL
);
469 program
= SCM_VM_FRAME_PROGRAM (fp
);
475 if (SCM_VM_CONT_P (program
))
478 goto vm_error_wrong_type_apply
;
481 VM_DEFINE_INSTRUCTION (call_cc
, "call/cc", 1)
484 PUSH (capture_vm_cont (vmp
));
490 VM_DEFINE_INSTRUCTION (return, "return", 0)
499 /* Cache the last program */
500 program
= SCM_VM_FRAME_PROGRAM (fp
);
511 VM_DEFINE_INSTRUCTION (raise
, "raise", 1)
515 VM_DEFINE_INSTRUCTION (catch, "catch", 0)
519 VM_DEFINE_INSTRUCTION (stack_catch
, "stach_catch", 0)