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, 0, 0)
55 VM_DEFINE_INSTRUCTION (halt
, "halt", 0, 0, 0)
58 vp
->time
+= scm_c_get_internal_run_time () - start_time
;
65 VM_DEFINE_INSTRUCTION (drop
, "drop", 0, 1, 0)
71 VM_DEFINE_INSTRUCTION (dup
, "dup", 0, 0, 1)
82 VM_DEFINE_INSTRUCTION (void, "void", 0, 0, 1)
84 PUSH (SCM_UNSPECIFIED
);
88 VM_DEFINE_INSTRUCTION (mark
, "mark", 0, 0, 1)
94 VM_DEFINE_INSTRUCTION (make_true
, "make-true", 0, 0, 1)
100 VM_DEFINE_INSTRUCTION (make_false
, "make-false", 0, 0, 1)
106 VM_DEFINE_INSTRUCTION (make_eol
, "make-eol", 0, 0, 1)
112 VM_DEFINE_INSTRUCTION (make_int8
, "make-int8", 1, 0, 1)
114 PUSH (SCM_MAKINUM ((signed char) FETCH ()));
118 VM_DEFINE_INSTRUCTION (make_int8_0
, "make-int8:0", 0, 0, 1)
120 PUSH (SCM_MAKINUM (0));
124 VM_DEFINE_INSTRUCTION (make_int8_1
, "make-int8:1", 0, 0, 1)
126 PUSH (SCM_MAKINUM (1));
130 VM_DEFINE_INSTRUCTION (make_int16
, "make-int16", 2, 0, 1)
134 PUSH (SCM_MAKINUM ((signed short) (h
<< 8) + l
));
138 VM_DEFINE_INSTRUCTION (make_char8
, "make-char8", 1, 0, 1)
140 PUSH (SCM_MAKE_CHAR (FETCH ()));
149 #define OBJECT_REF(i) objects[i]
150 #define OBJECT_SET(i,o) objects[i] = o
152 #define LOCAL_REF(i) SCM_VM_FRAME_VARIABLE (fp, i)
153 #define LOCAL_SET(i,o) SCM_VM_FRAME_VARIABLE (fp, i) = o
155 #define VARIABLE_REF(v) SCM_CDR (v)
156 #define VARIABLE_SET(v,o) SCM_SETCDR (v, o)
160 VM_DEFINE_INSTRUCTION (object_ref
, "object-ref", 1, 0, 1)
162 PUSH (OBJECT_REF (FETCH ()));
166 VM_DEFINE_INSTRUCTION (local_ref
, "local-ref", 1, 0, 1)
168 PUSH (LOCAL_REF (FETCH ()));
172 VM_DEFINE_INSTRUCTION (external_ref
, "external-ref", 1, 0, 1)
176 for (i
= FETCH (); i
; i
--)
182 VM_DEFINE_INSTRUCTION (variable_ref
, "variable-ref", 0, 0, 1)
185 SCM o
= VARIABLE_REF (x
);
188 /* Try autoload here */
189 err_args
= SCM_LIST1 (SCM_CAR (x
));
190 goto vm_error_unbound
;
198 VM_DEFINE_INSTRUCTION (local_set
, "local-set", 1, 1, 0)
200 LOCAL_SET (FETCH (), *sp
);
205 VM_DEFINE_INSTRUCTION (external_set
, "external-set", 1, 1, 0)
209 for (i
= FETCH (); i
; i
--)
216 VM_DEFINE_INSTRUCTION (variable_set
, "variable-set", 0, 1, 0)
218 VARIABLE_SET (sp
[0], sp
[1]);
230 signed char offset = FETCH (); \
237 VM_DEFINE_INSTRUCTION (br_if
, "br-if", 1, 0, 0)
239 BR (!SCM_FALSEP (*sp
));
242 VM_DEFINE_INSTRUCTION (br_if_not
, "br-if-not", 1, 0, 0)
244 BR (SCM_FALSEP (*sp
));
247 VM_DEFINE_INSTRUCTION (br_if_eq
, "br-if-eq", 1, 0, 0)
249 BR (SCM_EQ_P (sp
[0], sp
--[1]));
252 VM_DEFINE_INSTRUCTION (br_if_not_eq
, "br-if-not-eq", 1, 0, 0)
254 BR (!SCM_EQ_P (sp
[0], sp
--[1]));
257 VM_DEFINE_INSTRUCTION (br_if_null
, "br-if-null", 1, 0, 0)
259 BR (SCM_NULLP (*sp
));
262 VM_DEFINE_INSTRUCTION (br_if_not_null
, "br-if-not-null", 1, 0, 0)
264 BR (!SCM_NULLP (*sp
));
267 VM_DEFINE_INSTRUCTION (jump
, "jump", 1, 0, 0)
269 ip
+= (signed char) FETCH ();
278 VM_DEFINE_INSTRUCTION (make_closure
, "make-closure", 0, 1, 1)
281 *sp
= scm_c_make_closure (*sp
, external
);
285 VM_DEFINE_INSTRUCTION (call
, "call", 1, -1, 1)
294 if (SCM_PROGRAM_P (program
))
298 CACHE_PROGRAM (program
);
302 /* Init local variables */
303 for (i
= 0; i
< bp
->nlocs
; i
++)
304 LOCAL_SET (i
, SCM_UNDEFINED
);
306 /* Create external variables */
307 for (i
= 0; i
< bp
->nexts
; i
++)
308 CONS (external
, SCM_UNDEFINED
, external
);
317 if (!SCM_FALSEP (scm_procedure_p (program
)))
320 *sp
= scm_apply (program
, *sp
, SCM_EOL
);
321 program
= SCM_VM_FRAME_PROGRAM (fp
);
327 if (SCM_VM_CONT_P (program
))
330 /* Check the number of arguments */
332 scm_wrong_num_args (program
);
334 /* Reinstate the continuation */
336 reinstate_vm_cont (vp
, program
);
338 /* We don't need to set the return value here
339 because it is already on the top of the stack. */
343 goto vm_error_wrong_type_apply
;
346 VM_DEFINE_INSTRUCTION (tail_call
, "tail-call", 1, -1, 1)
352 SCM_TICK
; /* allow interrupt here */
355 * Tail recursive call
357 if (SCM_EQ_P (x
, program
))
365 SCM
*base
= fp
+ bp
->nlocs
;
366 for (i
= 0; i
< bp
->nargs
; i
++)
371 sp
= SCM_VM_FRAME_LOWER_ADDRESS (fp
);
379 if (SCM_PROGRAM_P (program
))
384 /* Exit the current frame */
390 for (i
= 0; i
< nargs
; i
++)
393 /* Call the program */
394 goto vm_call_program
;
399 if (!SCM_FALSEP (scm_procedure_p (program
)))
402 *sp
= scm_apply (program
, *sp
, SCM_EOL
);
403 program
= SCM_VM_FRAME_PROGRAM (fp
);
409 if (SCM_VM_CONT_P (program
))
412 goto vm_error_wrong_type_apply
;
415 VM_DEFINE_INSTRUCTION (call_cc
, "call/cc", 1, 1, 1)
418 PUSH (capture_vm_cont (vp
));
424 VM_DEFINE_INSTRUCTION (return, "return", 0, 0, 1)
433 /* Cache the last program */
434 program
= SCM_VM_FRAME_PROGRAM (fp
);
435 CACHE_PROGRAM (program
);