1 /* Copyright (C) 2001,2008,2009 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 /* This file is included in vm_engine.c */
27 VM_DEFINE_INSTRUCTION (0, nop
, "nop", 0, 0, 0)
32 VM_DEFINE_INSTRUCTION (1, halt
, "halt", 0, 0, 0)
34 vp
->time
+= scm_c_get_internal_run_time () - start_time
;
36 nvalues
= SCM_I_INUM (*sp
--);
45 finish_args
= scm_values (finish_args
);
49 #ifdef VM_ENABLE_STACK_NULLING
53 /* Restore registers */
54 sp
= SCM_FRAME_LOWER_ADDRESS (fp
) - 1;
55 /* Setting the ip here doesn't actually affect control flow, as the calling
56 code will restore its own registers, but it does help when walking the
58 ip
= SCM_FRAME_RETURN_ADDRESS (fp
);
59 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
60 NULLSTACK (old_sp
- sp
);
66 VM_DEFINE_INSTRUCTION (2, break, "break", 0, 0, 0)
72 VM_DEFINE_INSTRUCTION (3, drop
, "drop", 0, 1, 0)
78 VM_DEFINE_INSTRUCTION (4, dup
, "dup", 0, 0, 1)
90 VM_DEFINE_INSTRUCTION (5, void, "void", 0, 0, 1)
92 PUSH (SCM_UNSPECIFIED
);
96 VM_DEFINE_INSTRUCTION (6, make_true
, "make-true", 0, 0, 1)
102 VM_DEFINE_INSTRUCTION (7, make_false
, "make-false", 0, 0, 1)
108 VM_DEFINE_INSTRUCTION (8, make_eol
, "make-eol", 0, 0, 1)
114 VM_DEFINE_INSTRUCTION (9, make_int8
, "make-int8", 1, 0, 1)
116 PUSH (SCM_I_MAKINUM ((signed char) FETCH ()));
120 VM_DEFINE_INSTRUCTION (10, make_int8_0
, "make-int8:0", 0, 0, 1)
126 VM_DEFINE_INSTRUCTION (11, make_int8_1
, "make-int8:1", 0, 0, 1)
128 PUSH (SCM_I_MAKINUM (1));
132 VM_DEFINE_INSTRUCTION (12, make_int16
, "make-int16", 2, 0, 1)
136 PUSH (SCM_I_MAKINUM ((signed short) (h
<< 8) + l
));
140 VM_DEFINE_INSTRUCTION (13, make_int64
, "make-int64", 8, 0, 1)
144 v
<<= 8; v
+= FETCH ();
145 v
<<= 8; v
+= FETCH ();
146 v
<<= 8; v
+= FETCH ();
147 v
<<= 8; v
+= FETCH ();
148 v
<<= 8; v
+= FETCH ();
149 v
<<= 8; v
+= FETCH ();
150 v
<<= 8; v
+= FETCH ();
151 PUSH (scm_from_int64 ((scm_t_int64
) v
));
155 VM_DEFINE_INSTRUCTION (14, make_uint64
, "make-uint64", 8, 0, 1)
159 v
<<= 8; v
+= FETCH ();
160 v
<<= 8; v
+= FETCH ();
161 v
<<= 8; v
+= FETCH ();
162 v
<<= 8; v
+= FETCH ();
163 v
<<= 8; v
+= FETCH ();
164 v
<<= 8; v
+= FETCH ();
165 v
<<= 8; v
+= FETCH ();
166 PUSH (scm_from_uint64 (v
));
170 VM_DEFINE_INSTRUCTION (15, make_char8
, "make-char8", 1, 0, 1)
175 PUSH (SCM_MAKE_CHAR (v
));
176 /* Don't simplify this to PUSH (SCM_MAKE_CHAR (FETCH ())). The
177 contents of SCM_MAKE_CHAR may be evaluated more than once,
178 resulting in a double fetch. */
182 VM_DEFINE_INSTRUCTION (16, make_char32
, "make-char32", 4, 0, 1)
186 v
<<= 8; v
+= FETCH ();
187 v
<<= 8; v
+= FETCH ();
188 v
<<= 8; v
+= FETCH ();
189 PUSH (SCM_MAKE_CHAR (v
));
195 VM_DEFINE_INSTRUCTION (17, list
, "list", 2, -1, 1)
197 unsigned h
= FETCH ();
198 unsigned l
= FETCH ();
199 unsigned len
= ((h
<< 8) + l
);
204 VM_DEFINE_INSTRUCTION (18, vector
, "vector", 2, -1, 1)
206 unsigned h
= FETCH ();
207 unsigned l
= FETCH ();
208 unsigned len
= ((h
<< 8) + l
);
214 vect
= scm_make_vector (scm_from_uint (len
), SCM_BOOL_F
);
215 memcpy (SCM_I_VECTOR_WELTS(vect
), sp
, sizeof(SCM
) * len
);
227 #define OBJECT_REF(i) objects[i]
228 #define OBJECT_SET(i,o) objects[i] = o
230 #define LOCAL_REF(i) SCM_FRAME_VARIABLE (fp, i)
231 #define LOCAL_SET(i,o) SCM_FRAME_VARIABLE (fp, i) = o
233 /* For the variable operations, we _must_ obviously avoid function calls to
234 `scm_variable_ref ()', `scm_variable_bound_p ()' and friends which do
235 nothing more than the corresponding macros. */
236 #define VARIABLE_REF(v) SCM_VARIABLE_REF (v)
237 #define VARIABLE_SET(v,o) SCM_VARIABLE_SET (v, o)
238 #define VARIABLE_BOUNDP(v) (VARIABLE_REF (v) != SCM_UNDEFINED)
240 #define FREE_VARIABLE_REF(i) free_vars[i]
244 VM_DEFINE_INSTRUCTION (19, object_ref
, "object-ref", 1, 0, 1)
246 register unsigned objnum
= FETCH ();
247 CHECK_OBJECT (objnum
);
248 PUSH (OBJECT_REF (objnum
));
252 /* FIXME: necessary? elt 255 of the vector could be a vector... */
253 VM_DEFINE_INSTRUCTION (20, long_object_ref
, "long-object-ref", 2, 0, 1)
255 unsigned int objnum
= FETCH ();
258 CHECK_OBJECT (objnum
);
259 PUSH (OBJECT_REF (objnum
));
263 VM_DEFINE_INSTRUCTION (21, local_ref
, "local-ref", 1, 0, 1)
265 PUSH (LOCAL_REF (FETCH ()));
270 VM_DEFINE_INSTRUCTION (22, long_local_ref
, "long-local-ref", 2, 0, 1)
272 unsigned int i
= FETCH ();
275 PUSH (LOCAL_REF (i
));
280 VM_DEFINE_INSTRUCTION (23, local_bound
, "local-bound?", 1, 0, 1)
282 if (LOCAL_REF (FETCH ()) == SCM_UNDEFINED
)
289 VM_DEFINE_INSTRUCTION (24, long_local_bound
, "long-local-bound?", 2, 0, 1)
291 unsigned int i
= FETCH ();
294 if (LOCAL_REF (i
) == SCM_UNDEFINED
)
301 VM_DEFINE_INSTRUCTION (25, variable_ref
, "variable-ref", 0, 0, 1)
305 if (!VARIABLE_BOUNDP (x
))
307 finish_args
= scm_list_1 (x
);
308 /* Was: finish_args = SCM_LIST1 (SCM_CAR (x)); */
309 goto vm_error_unbound
;
313 SCM o
= VARIABLE_REF (x
);
320 VM_DEFINE_INSTRUCTION (26, variable_bound
, "variable-bound?", 0, 0, 1)
322 if (VARIABLE_BOUNDP (*sp
))
329 VM_DEFINE_INSTRUCTION (27, toplevel_ref
, "toplevel-ref", 1, 0, 1)
331 unsigned objnum
= FETCH ();
333 CHECK_OBJECT (objnum
);
334 what
= OBJECT_REF (objnum
);
336 if (!SCM_VARIABLEP (what
))
339 what
= resolve_variable (what
, scm_program_module (program
));
340 if (!VARIABLE_BOUNDP (what
))
342 finish_args
= scm_list_1 (what
);
343 goto vm_error_unbound
;
345 OBJECT_SET (objnum
, what
);
348 PUSH (VARIABLE_REF (what
));
352 VM_DEFINE_INSTRUCTION (28, long_toplevel_ref
, "long-toplevel-ref", 2, 0, 1)
355 unsigned int objnum
= FETCH ();
358 CHECK_OBJECT (objnum
);
359 what
= OBJECT_REF (objnum
);
361 if (!SCM_VARIABLEP (what
))
364 what
= resolve_variable (what
, scm_program_module (program
));
365 if (!VARIABLE_BOUNDP (what
))
367 finish_args
= scm_list_1 (what
);
368 goto vm_error_unbound
;
370 OBJECT_SET (objnum
, what
);
373 PUSH (VARIABLE_REF (what
));
379 VM_DEFINE_INSTRUCTION (29, local_set
, "local-set", 1, 1, 0)
381 LOCAL_SET (FETCH (), *sp
);
386 VM_DEFINE_INSTRUCTION (30, long_local_set
, "long-local-set", 2, 1, 0)
388 unsigned int i
= FETCH ();
396 VM_DEFINE_INSTRUCTION (31, variable_set
, "variable-set", 0, 1, 0)
398 VARIABLE_SET (sp
[0], sp
[-1]);
403 VM_DEFINE_INSTRUCTION (32, toplevel_set
, "toplevel-set", 1, 1, 0)
405 unsigned objnum
= FETCH ();
407 CHECK_OBJECT (objnum
);
408 what
= OBJECT_REF (objnum
);
410 if (!SCM_VARIABLEP (what
))
413 what
= resolve_variable (what
, scm_program_module (program
));
414 OBJECT_SET (objnum
, what
);
417 VARIABLE_SET (what
, *sp
);
422 VM_DEFINE_INSTRUCTION (33, long_toplevel_set
, "long-toplevel-set", 2, 1, 0)
425 unsigned int objnum
= FETCH ();
428 CHECK_OBJECT (objnum
);
429 what
= OBJECT_REF (objnum
);
431 if (!SCM_VARIABLEP (what
))
434 what
= resolve_variable (what
, scm_program_module (program
));
435 OBJECT_SET (objnum
, what
);
438 VARIABLE_SET (what
, *sp
);
448 /* offset must be at least 24 bits wide, and signed */
449 #define FETCH_OFFSET(offset) \
451 offset = FETCH () << 16; \
452 offset += FETCH () << 8; \
453 offset += FETCH (); \
454 offset -= (offset & (1<<23)) << 1; \
459 scm_t_int32 offset; \
460 FETCH_OFFSET (offset); \
468 VM_DEFINE_INSTRUCTION (34, br
, "br", 3, 0, 0)
471 FETCH_OFFSET (offset
);
476 VM_DEFINE_INSTRUCTION (35, br_if
, "br-if", 3, 0, 0)
478 BR (scm_is_true_and_not_nil (*sp
));
481 VM_DEFINE_INSTRUCTION (36, br_if_not
, "br-if-not", 3, 0, 0)
483 BR (scm_is_false_or_nil (*sp
));
486 VM_DEFINE_INSTRUCTION (37, br_if_eq
, "br-if-eq", 3, 0, 0)
488 sp
--; /* underflow? */
489 BR (scm_is_eq (sp
[0], sp
[1]));
492 VM_DEFINE_INSTRUCTION (38, br_if_not_eq
, "br-if-not-eq", 3, 0, 0)
494 sp
--; /* underflow? */
495 BR (!scm_is_eq (sp
[0], sp
[1]));
498 VM_DEFINE_INSTRUCTION (39, br_if_null
, "br-if-null", 3, 0, 0)
500 BR (scm_is_null_or_nil (*sp
));
503 VM_DEFINE_INSTRUCTION (40, br_if_not_null
, "br-if-not-null", 3, 0, 0)
505 BR (!scm_is_null_or_nil (*sp
));
513 VM_DEFINE_INSTRUCTION (41, br_if_nargs_ne
, "br-if-nargs-ne", 5, 0, 0)
519 FETCH_OFFSET (offset
);
520 if (sp
- (fp
- 1) != n
)
525 VM_DEFINE_INSTRUCTION (42, br_if_nargs_lt
, "br-if-nargs-lt", 5, 0, 0)
531 FETCH_OFFSET (offset
);
532 if (sp
- (fp
- 1) < n
)
537 VM_DEFINE_INSTRUCTION (43, br_if_nargs_gt
, "br-if-nargs-gt", 5, 0, 0)
544 FETCH_OFFSET (offset
);
545 if (sp
- (fp
- 1) > n
)
550 VM_DEFINE_INSTRUCTION (44, assert_nargs_ee
, "assert-nargs-ee", 2, 0, 0)
555 if (sp
- (fp
- 1) != n
)
556 goto vm_error_wrong_num_args
;
560 VM_DEFINE_INSTRUCTION (45, assert_nargs_ge
, "assert-nargs-ge", 2, 0, 0)
565 if (sp
- (fp
- 1) < n
)
566 goto vm_error_wrong_num_args
;
570 VM_DEFINE_INSTRUCTION (46, bind_optionals
, "bind-optionals", 2, -1, -1)
575 while (sp
- (fp
- 1) < n
)
576 PUSH (SCM_UNDEFINED
);
580 VM_DEFINE_INSTRUCTION (47, bind_optionals_shuffle
, "bind-optionals/shuffle", 6, -1, -1)
583 scm_t_ptrdiff nreq
, nreq_and_opt
, ntotal
;
584 nreq
= FETCH () << 8;
586 nreq_and_opt
= FETCH () << 8;
587 nreq_and_opt
+= FETCH ();
588 ntotal
= FETCH () << 8;
591 /* look in optionals for first keyword or last positional */
592 /* starting after the last required positional arg */
594 while (/* while we have args */
596 /* and we still have positionals to fill */
597 && walk
- fp
< nreq_and_opt
598 /* and we haven't reached a keyword yet */
599 && !scm_is_keyword (*walk
))
600 /* bind this optional arg (by leaving it in place) */
602 /* now shuffle up, from walk to ntotal */
604 scm_t_ptrdiff nshuf
= sp
- walk
+ 1, i
;
605 sp
= (fp
- 1) + ntotal
+ nshuf
;
607 for (i
= 0; i
< nshuf
; i
++)
608 sp
[-i
] = walk
[nshuf
-i
-1];
610 /* and fill optionals & keyword args with SCM_UNDEFINED */
611 while (walk
<= (fp
- 1) + ntotal
)
612 *walk
++ = SCM_UNDEFINED
;
617 /* Flags that determine whether other keywords are allowed, and whether a
618 rest argument is expected. These values must match those used by the
619 glil->assembly compiler. */
620 #define F_ALLOW_OTHER_KEYS 1
623 VM_DEFINE_INSTRUCTION (48, bind_kwargs
, "bind-kwargs", 5, 0, 0)
627 int kw_and_rest_flags
;
631 /* XXX: We don't actually use NKW. */
634 kw_and_rest_flags
= FETCH ();
636 if (!(kw_and_rest_flags
& F_REST
)
637 && ((sp
- (fp
- 1) - nkw
) % 2))
638 goto vm_error_kwargs_length_not_even
;
641 kw
= OBJECT_REF (idx
);
643 /* Switch NKW to be a negative index below SP. */
644 for (nkw
= -(sp
- (fp
- 1) - nkw
) + 1; nkw
< 0; nkw
++)
648 if (scm_is_keyword (sp
[nkw
]))
650 for (walk
= kw
; scm_is_pair (walk
); walk
= SCM_CDR (walk
))
652 if (scm_is_eq (SCM_CAAR (walk
), sp
[nkw
]))
654 SCM si
= SCM_CDAR (walk
);
655 LOCAL_SET (SCM_I_INUMP (si
) ? SCM_I_INUM (si
) : scm_to_long (si
),
660 if (!(kw_and_rest_flags
& F_ALLOW_OTHER_KEYS
) && !scm_is_pair (walk
))
661 goto vm_error_kwargs_unrecognized_keyword
;
665 else if (!(kw_and_rest_flags
& F_REST
))
666 goto vm_error_kwargs_invalid_keyword
;
672 #undef F_ALLOW_OTHER_KEYS
676 VM_DEFINE_INSTRUCTION (49, push_rest
, "push-rest", 2, -1, -1)
682 while (sp
- (fp
- 1) > n
)
683 /* No need to check for underflow. */
684 CONS (rest
, *sp
--, rest
);
689 VM_DEFINE_INSTRUCTION (50, bind_rest
, "bind-rest", 4, -1, -1)
698 while (sp
- (fp
- 1) > n
)
699 /* No need to check for underflow. */
700 CONS (rest
, *sp
--, rest
);
705 VM_DEFINE_INSTRUCTION (51, reserve_locals
, "reserve-locals", 2, -1, -1)
718 *++old_sp
= SCM_UNDEFINED
;
721 NULLSTACK (old_sp
- sp
);
726 VM_DEFINE_INSTRUCTION (52, new_frame
, "new-frame", 0, 0, 3)
728 /* NB: if you change this, see frames.c:vm-frame-num-locals */
729 /* and frames.h, vm-engine.c, etc of course */
730 PUSH ((SCM
)fp
); /* dynamic link */
736 VM_DEFINE_INSTRUCTION (53, call
, "call", 1, -1, 1)
745 SCM_TICK
; /* allow interrupt here */
750 if (SCM_PROGRAM_P (x
))
755 ASSERT (SCM_FRAME_RETURN_ADDRESS (fp
) == 0);
756 ASSERT (SCM_FRAME_MV_RETURN_ADDRESS (fp
) == 0);
757 SCM_FRAME_SET_RETURN_ADDRESS (fp
, ip
);
758 SCM_FRAME_SET_MV_RETURN_ADDRESS (fp
, 0);
764 if (SCM_STRUCTP (x
) && SCM_STRUCT_APPLICABLE_P (x
))
766 sp
[-nargs
] = SCM_STRUCT_PROCEDURE (x
);
769 if (SCM_STRUCTP (x
) && SCM_OBJ_CLASS_FLAGS (x
) & SCM_CLASSF_PURE_GENERIC
)
776 args
= scm_cons (*walk
--, args
);
777 *walk
= scm_mcache_compute_cmethod (SCM_GENERIC_METHOD_CACHE (x
), args
);
781 * Other interpreted or compiled call
783 if (!SCM_FALSEP (scm_procedure_p (x
)))
786 /* At this point, the stack contains the frame, the procedure and each one
790 DROP (); /* drop the procedure */
794 PUSH (scm_apply (x
, args
, SCM_EOL
));
795 NULLSTACK_FOR_NONLOCAL_EXIT ();
796 if (SCM_UNLIKELY (SCM_VALUESP (*sp
)))
798 /* truncate values */
801 values
= scm_struct_ref (values
, SCM_INUM0
);
802 if (scm_is_null (values
))
803 goto vm_error_not_enough_values
;
804 PUSH (SCM_CAR (values
));
810 goto vm_error_wrong_type_apply
;
813 VM_DEFINE_INSTRUCTION (54, goto_args
, "goto/args", 1, -1, 1)
821 SCM_TICK
; /* allow interrupt here */
826 if (SCM_PROGRAM_P (x
))
829 #ifdef VM_ENABLE_STACK_NULLING
836 /* switch programs */
839 /* shuffle down the program and the arguments */
840 for (i
= -1, sp
= sp
- nargs
+ 1; i
< nargs
; i
++)
841 SCM_FRAME_STACK_ADDRESS (fp
)[i
] = sp
[i
];
845 NULLSTACK (old_sp
- sp
);
853 if (SCM_STRUCTP (x
) && SCM_STRUCT_APPLICABLE_P (x
))
855 sp
[-nargs
] = SCM_STRUCT_PROCEDURE (x
);
858 if (SCM_STRUCTP (x
) && SCM_OBJ_CLASS_FLAGS (x
) & SCM_CLASSF_PURE_GENERIC
)
865 args
= scm_cons (*walk
--, args
);
866 *walk
= scm_mcache_compute_cmethod (SCM_GENERIC_METHOD_CACHE (x
), args
);
871 * Other interpreted or compiled call
873 if (!SCM_FALSEP (scm_procedure_p (x
)))
880 *sp
= scm_apply (x
, args
, SCM_EOL
);
881 NULLSTACK_FOR_NONLOCAL_EXIT ();
883 if (SCM_UNLIKELY (SCM_VALUESP (*sp
)))
885 /* multiple values returned to continuation */
888 values
= scm_struct_ref (values
, SCM_INUM0
);
889 nvalues
= scm_ilength (values
);
890 PUSH_LIST (values
, scm_is_null
);
891 goto vm_return_values
;
899 goto vm_error_wrong_type_apply
;
902 VM_DEFINE_INSTRUCTION (55, goto_nargs
, "goto/nargs", 0, 0, 1)
906 nargs
= scm_to_int (x
);
907 /* FIXME: should truncate values? */
911 VM_DEFINE_INSTRUCTION (56, call_nargs
, "call/nargs", 0, 0, 1)
915 nargs
= scm_to_int (x
);
916 /* FIXME: should truncate values? */
920 VM_DEFINE_INSTRUCTION (57, mv_call
, "mv-call", 4, -1, 1)
927 FETCH_OFFSET (offset
);
936 if (SCM_PROGRAM_P (x
))
941 ASSERT (SCM_FRAME_RETURN_ADDRESS (fp
) == 0);
942 ASSERT (SCM_FRAME_MV_RETURN_ADDRESS (fp
) == 0);
943 SCM_FRAME_SET_RETURN_ADDRESS (fp
, ip
);
944 SCM_FRAME_SET_MV_RETURN_ADDRESS (fp
, mvra
);
950 if (SCM_STRUCTP (x
) && SCM_STRUCT_APPLICABLE_P (x
))
952 sp
[-nargs
] = SCM_STRUCT_PROCEDURE (x
);
955 if (SCM_STRUCTP (x
) && SCM_OBJ_CLASS_FLAGS (x
) & SCM_CLASSF_PURE_GENERIC
)
962 args
= scm_cons (*walk
--, args
);
963 *walk
= scm_mcache_compute_cmethod (SCM_GENERIC_METHOD_CACHE (x
), args
);
967 * Other interpreted or compiled call
969 if (!SCM_FALSEP (scm_procedure_p (x
)))
972 /* At this point, the stack contains the procedure and each one of its
976 DROP (); /* drop the procedure */
980 PUSH (scm_apply (x
, args
, SCM_EOL
));
981 NULLSTACK_FOR_NONLOCAL_EXIT ();
982 if (SCM_VALUESP (*sp
))
986 values
= scm_struct_ref (values
, SCM_INUM0
);
987 len
= scm_length (values
);
988 PUSH_LIST (values
, scm_is_null
);
996 goto vm_error_wrong_type_apply
;
999 VM_DEFINE_INSTRUCTION (58, apply
, "apply", 1, -1, 1)
1006 ASSERT (nargs
>= 2);
1008 len
= scm_ilength (ls
);
1010 goto vm_error_wrong_type_arg
;
1012 PUSH_LIST (ls
, SCM_NULL_OR_NIL_P
);
1018 VM_DEFINE_INSTRUCTION (59, goto_apply
, "goto/apply", 1, -1, 1)
1025 ASSERT (nargs
>= 2);
1027 len
= scm_ilength (ls
);
1029 goto vm_error_wrong_type_arg
;
1031 PUSH_LIST (ls
, SCM_NULL_OR_NIL_P
);
1037 VM_DEFINE_INSTRUCTION (60, call_cc
, "call/cc", 0, 1, 1)
1043 cont
= scm_make_continuation (&first
);
1046 PUSH ((SCM
)fp
); /* dynamic link */
1047 PUSH (0); /* mvra */
1054 ASSERT (sp
== vp
->sp
);
1055 ASSERT (fp
== vp
->fp
);
1056 else if (SCM_VALUESP (cont
))
1058 /* multiple values returned to continuation */
1060 values
= scm_struct_ref (cont
, SCM_INUM0
);
1061 if (scm_is_null (values
))
1062 goto vm_error_no_values
;
1063 /* non-tail context does not accept multiple values? */
1064 PUSH (SCM_CAR (values
));
1074 VM_DEFINE_INSTRUCTION (61, goto_cc
, "goto/cc", 0, 1, 1)
1080 cont
= scm_make_continuation (&first
);
1081 ASSERT (sp
== vp
->sp
);
1082 ASSERT (fp
== vp
->fp
);
1090 else if (SCM_VALUESP (cont
))
1092 /* multiple values returned to continuation */
1094 values
= scm_struct_ref (cont
, SCM_INUM0
);
1095 nvalues
= scm_ilength (values
);
1096 PUSH_LIST (values
, scm_is_null
);
1097 goto vm_return_values
;
1106 VM_DEFINE_INSTRUCTION (62, return, "return", 0, 1, 1)
1112 SCM_TICK
; /* allow interrupt here */
1118 #ifdef VM_ENABLE_STACK_NULLING
1122 /* Restore registers */
1123 sp
= SCM_FRAME_LOWER_ADDRESS (fp
);
1124 ip
= SCM_FRAME_RETURN_ADDRESS (fp
);
1125 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
1127 #ifdef VM_ENABLE_STACK_NULLING
1128 NULLSTACK (old_sp
- sp
);
1131 /* Set return value (sp is already pushed) */
1135 /* Restore the last program */
1136 program
= SCM_FRAME_PROGRAM (fp
);
1142 VM_DEFINE_INSTRUCTION (63, return_values
, "return/values", 1, -1, -1)
1144 /* nvalues declared at top level, because for some reason gcc seems to think
1145 that perhaps it might be used without declaration. Fooey to that, I say. */
1151 if (nvalues
!= 1 && SCM_FRAME_MV_RETURN_ADDRESS (fp
))
1153 /* A multiply-valued continuation */
1154 SCM
*vals
= sp
- nvalues
;
1156 /* Restore registers */
1157 sp
= SCM_FRAME_LOWER_ADDRESS (fp
) - 1;
1158 ip
= SCM_FRAME_MV_RETURN_ADDRESS (fp
);
1159 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
1161 /* Push return values, and the number of values */
1162 for (i
= 0; i
< nvalues
; i
++)
1164 *++sp
= SCM_I_MAKINUM (nvalues
);
1166 /* Finally null the end of the stack */
1167 NULLSTACK (vals
+ nvalues
- sp
);
1169 else if (nvalues
>= 1)
1171 /* Multiple values for a single-valued continuation -- here's where I
1172 break with guile tradition and try and do something sensible. (Also,
1173 this block handles the single-valued return to an mv
1175 SCM
*vals
= sp
- nvalues
;
1176 /* Restore registers */
1177 sp
= SCM_FRAME_LOWER_ADDRESS (fp
) - 1;
1178 ip
= SCM_FRAME_RETURN_ADDRESS (fp
);
1179 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
1181 /* Push first value */
1184 /* Finally null the end of the stack */
1185 NULLSTACK (vals
+ nvalues
- sp
);
1188 goto vm_error_no_values
;
1190 /* Restore the last program */
1191 program
= SCM_FRAME_PROGRAM (fp
);
1197 VM_DEFINE_INSTRUCTION (64, return_values_star
, "return/values*", 1, -1, -1)
1202 ASSERT (nvalues
>= 1);
1206 while (scm_is_pair (l
))
1212 if (SCM_UNLIKELY (!SCM_NULL_OR_NIL_P (l
))) {
1213 finish_args
= scm_list_1 (l
);
1214 goto vm_error_improper_list
;
1217 goto vm_return_values
;
1220 VM_DEFINE_INSTRUCTION (65, truncate_values
, "truncate-values", 2, -1, -1)
1225 nvalues
= scm_to_int (x
);
1232 if (nvalues
< nbinds
)
1233 goto vm_error_not_enough_values
;
1236 POP_LIST (nvalues
- nbinds
);
1238 DROPN (nvalues
- nbinds
);
1243 VM_DEFINE_INSTRUCTION (66, box
, "box", 1, 1, 0)
1248 LOCAL_SET (FETCH (), scm_cell (scm_tc7_variable
, SCM_UNPACK (val
)));
1253 (let ((a *undef*) (b *undef*) ...)
1254 (set! a (lambda () (b ...)))
1257 VM_DEFINE_INSTRUCTION (67, empty_box
, "empty-box", 1, 0, 0)
1260 LOCAL_SET (FETCH (),
1261 scm_cell (scm_tc7_variable
, SCM_UNPACK (SCM_UNDEFINED
)));
1265 VM_DEFINE_INSTRUCTION (68, local_boxed_ref
, "local-boxed-ref", 1, 0, 1)
1267 SCM v
= LOCAL_REF (FETCH ());
1268 ASSERT_BOUND_VARIABLE (v
);
1269 PUSH (VARIABLE_REF (v
));
1273 VM_DEFINE_INSTRUCTION (69, local_boxed_set
, "local-boxed-set", 1, 1, 0)
1276 v
= LOCAL_REF (FETCH ());
1278 ASSERT_VARIABLE (v
);
1279 VARIABLE_SET (v
, val
);
1283 VM_DEFINE_INSTRUCTION (70, free_ref
, "free-ref", 1, 0, 1)
1285 scm_t_uint8 idx
= FETCH ();
1287 CHECK_FREE_VARIABLE (idx
);
1288 PUSH (FREE_VARIABLE_REF (idx
));
1292 /* no free-set -- if a var is assigned, it should be in a box */
1294 VM_DEFINE_INSTRUCTION (71, free_boxed_ref
, "free-boxed-ref", 1, 0, 1)
1297 scm_t_uint8 idx
= FETCH ();
1298 CHECK_FREE_VARIABLE (idx
);
1299 v
= FREE_VARIABLE_REF (idx
);
1300 ASSERT_BOUND_VARIABLE (v
);
1301 PUSH (VARIABLE_REF (v
));
1305 VM_DEFINE_INSTRUCTION (72, free_boxed_set
, "free-boxed-set", 1, 1, 0)
1308 scm_t_uint8 idx
= FETCH ();
1310 CHECK_FREE_VARIABLE (idx
);
1311 v
= FREE_VARIABLE_REF (idx
);
1312 ASSERT_BOUND_VARIABLE (v
);
1313 VARIABLE_SET (v
, val
);
1317 VM_DEFINE_INSTRUCTION (73, make_closure
, "make-closure", 0, 2, 1)
1322 /* fixme underflow */
1323 *sp
= scm_double_cell (scm_tc7_program
, (scm_t_bits
)SCM_PROGRAM_OBJCODE (*sp
),
1324 (scm_t_bits
)SCM_PROGRAM_OBJTABLE (*sp
), (scm_t_bits
)vect
);
1328 VM_DEFINE_INSTRUCTION (74, make_variable
, "make-variable", 0, 0, 1)
1331 /* fixme underflow */
1332 PUSH (scm_cell (scm_tc7_variable
, SCM_UNPACK (SCM_UNDEFINED
)));
1336 VM_DEFINE_INSTRUCTION (75, fix_closure
, "fix-closure", 2, 0, 1)
1339 unsigned int i
= FETCH ();
1343 /* FIXME CHECK_LOCAL (i) */
1345 /* FIXME ASSERT_PROGRAM (x); */
1346 SCM_SET_CELL_WORD_3 (x
, vect
);
1350 VM_DEFINE_INSTRUCTION (76, define
, "define", 0, 0, 2)
1356 VARIABLE_SET (scm_sym2var (sym
, scm_current_module_lookup_closure (),
1362 VM_DEFINE_INSTRUCTION (77, make_keyword
, "make-keyword", 0, 1, 1)
1366 *sp
= scm_symbol_to_keyword (*sp
);
1370 VM_DEFINE_INSTRUCTION (78, make_symbol
, "make-symbol", 0, 1, 1)
1374 *sp
= scm_string_to_symbol (*sp
);
1380 (defun renumber-ops ()
1381 "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
1384 (let ((counter -1)) (goto-char (point-min))
1385 (while (re-search-forward "^VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t)
1387 (number-to-string (setq counter (1+ counter)))