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_nil
, "make-nil", 0, 0, 1)
110 PUSH (SCM_ELISP_NIL
);
114 VM_DEFINE_INSTRUCTION (9, make_eol
, "make-eol", 0, 0, 1)
120 VM_DEFINE_INSTRUCTION (10, make_int8
, "make-int8", 1, 0, 1)
122 PUSH (SCM_I_MAKINUM ((signed char) FETCH ()));
126 VM_DEFINE_INSTRUCTION (11, make_int8_0
, "make-int8:0", 0, 0, 1)
132 VM_DEFINE_INSTRUCTION (12, make_int8_1
, "make-int8:1", 0, 0, 1)
134 PUSH (SCM_I_MAKINUM (1));
138 VM_DEFINE_INSTRUCTION (13, make_int16
, "make-int16", 2, 0, 1)
142 PUSH (SCM_I_MAKINUM ((signed short) (h
<< 8) + l
));
146 VM_DEFINE_INSTRUCTION (14, make_int64
, "make-int64", 8, 0, 1)
150 v
<<= 8; v
+= FETCH ();
151 v
<<= 8; v
+= FETCH ();
152 v
<<= 8; v
+= FETCH ();
153 v
<<= 8; v
+= FETCH ();
154 v
<<= 8; v
+= FETCH ();
155 v
<<= 8; v
+= FETCH ();
156 v
<<= 8; v
+= FETCH ();
157 PUSH (scm_from_int64 ((scm_t_int64
) v
));
161 VM_DEFINE_INSTRUCTION (15, make_uint64
, "make-uint64", 8, 0, 1)
165 v
<<= 8; v
+= FETCH ();
166 v
<<= 8; v
+= FETCH ();
167 v
<<= 8; v
+= FETCH ();
168 v
<<= 8; v
+= FETCH ();
169 v
<<= 8; v
+= FETCH ();
170 v
<<= 8; v
+= FETCH ();
171 v
<<= 8; v
+= FETCH ();
172 PUSH (scm_from_uint64 (v
));
176 VM_DEFINE_INSTRUCTION (16, make_char8
, "make-char8", 1, 0, 1)
181 PUSH (SCM_MAKE_CHAR (v
));
182 /* Don't simplify this to PUSH (SCM_MAKE_CHAR (FETCH ())). The
183 contents of SCM_MAKE_CHAR may be evaluated more than once,
184 resulting in a double fetch. */
188 VM_DEFINE_INSTRUCTION (17, make_char32
, "make-char32", 4, 0, 1)
192 v
<<= 8; v
+= FETCH ();
193 v
<<= 8; v
+= FETCH ();
194 v
<<= 8; v
+= FETCH ();
195 PUSH (SCM_MAKE_CHAR (v
));
201 VM_DEFINE_INSTRUCTION (18, list
, "list", 2, -1, 1)
203 unsigned h
= FETCH ();
204 unsigned l
= FETCH ();
205 unsigned len
= ((h
<< 8) + l
);
210 VM_DEFINE_INSTRUCTION (19, vector
, "vector", 2, -1, 1)
212 unsigned h
= FETCH ();
213 unsigned l
= FETCH ();
214 unsigned len
= ((h
<< 8) + l
);
220 vect
= scm_make_vector (scm_from_uint (len
), SCM_BOOL_F
);
221 memcpy (SCM_I_VECTOR_WELTS(vect
), sp
, sizeof(SCM
) * len
);
233 #define OBJECT_REF(i) objects[i]
234 #define OBJECT_SET(i,o) objects[i] = o
236 #define LOCAL_REF(i) SCM_FRAME_VARIABLE (fp, i)
237 #define LOCAL_SET(i,o) SCM_FRAME_VARIABLE (fp, i) = o
239 /* For the variable operations, we _must_ obviously avoid function calls to
240 `scm_variable_ref ()', `scm_variable_bound_p ()' and friends which do
241 nothing more than the corresponding macros. */
242 #define VARIABLE_REF(v) SCM_VARIABLE_REF (v)
243 #define VARIABLE_SET(v,o) SCM_VARIABLE_SET (v, o)
244 #define VARIABLE_BOUNDP(v) (VARIABLE_REF (v) != SCM_UNDEFINED)
246 #define FREE_VARIABLE_REF(i) free_vars[i]
250 VM_DEFINE_INSTRUCTION (20, object_ref
, "object-ref", 1, 0, 1)
252 register unsigned objnum
= FETCH ();
253 CHECK_OBJECT (objnum
);
254 PUSH (OBJECT_REF (objnum
));
258 /* FIXME: necessary? elt 255 of the vector could be a vector... */
259 VM_DEFINE_INSTRUCTION (21, long_object_ref
, "long-object-ref", 2, 0, 1)
261 unsigned int objnum
= FETCH ();
264 CHECK_OBJECT (objnum
);
265 PUSH (OBJECT_REF (objnum
));
269 VM_DEFINE_INSTRUCTION (22, local_ref
, "local-ref", 1, 0, 1)
271 PUSH (LOCAL_REF (FETCH ()));
276 VM_DEFINE_INSTRUCTION (23, long_local_ref
, "long-local-ref", 2, 0, 1)
278 unsigned int i
= FETCH ();
281 PUSH (LOCAL_REF (i
));
286 VM_DEFINE_INSTRUCTION (24, local_bound
, "local-bound?", 1, 0, 1)
288 if (LOCAL_REF (FETCH ()) == SCM_UNDEFINED
)
295 VM_DEFINE_INSTRUCTION (25, long_local_bound
, "long-local-bound?", 2, 0, 1)
297 unsigned int i
= FETCH ();
300 if (LOCAL_REF (i
) == SCM_UNDEFINED
)
307 VM_DEFINE_INSTRUCTION (26, variable_ref
, "variable-ref", 0, 1, 1)
311 if (!VARIABLE_BOUNDP (x
))
313 finish_args
= scm_list_1 (x
);
314 /* Was: finish_args = SCM_LIST1 (SCM_CAR (x)); */
315 goto vm_error_unbound
;
319 SCM o
= VARIABLE_REF (x
);
326 VM_DEFINE_INSTRUCTION (27, variable_bound
, "variable-bound?", 0, 0, 1)
328 if (VARIABLE_BOUNDP (*sp
))
335 VM_DEFINE_INSTRUCTION (28, toplevel_ref
, "toplevel-ref", 1, 0, 1)
337 unsigned objnum
= FETCH ();
339 CHECK_OBJECT (objnum
);
340 what
= OBJECT_REF (objnum
);
342 if (!SCM_VARIABLEP (what
))
345 what
= resolve_variable (what
, scm_program_module (program
));
346 if (!VARIABLE_BOUNDP (what
))
348 finish_args
= scm_list_1 (what
);
349 goto vm_error_unbound
;
351 OBJECT_SET (objnum
, what
);
354 PUSH (VARIABLE_REF (what
));
358 VM_DEFINE_INSTRUCTION (29, long_toplevel_ref
, "long-toplevel-ref", 2, 0, 1)
361 unsigned int objnum
= FETCH ();
364 CHECK_OBJECT (objnum
);
365 what
= OBJECT_REF (objnum
);
367 if (!SCM_VARIABLEP (what
))
370 what
= resolve_variable (what
, scm_program_module (program
));
371 if (!VARIABLE_BOUNDP (what
))
373 finish_args
= scm_list_1 (what
);
374 goto vm_error_unbound
;
376 OBJECT_SET (objnum
, what
);
379 PUSH (VARIABLE_REF (what
));
385 VM_DEFINE_INSTRUCTION (30, local_set
, "local-set", 1, 1, 0)
387 LOCAL_SET (FETCH (), *sp
);
392 VM_DEFINE_INSTRUCTION (31, long_local_set
, "long-local-set", 2, 1, 0)
394 unsigned int i
= FETCH ();
402 VM_DEFINE_INSTRUCTION (32, variable_set
, "variable-set", 0, 2, 0)
404 VARIABLE_SET (sp
[0], sp
[-1]);
409 VM_DEFINE_INSTRUCTION (33, toplevel_set
, "toplevel-set", 1, 1, 0)
411 unsigned objnum
= FETCH ();
413 CHECK_OBJECT (objnum
);
414 what
= OBJECT_REF (objnum
);
416 if (!SCM_VARIABLEP (what
))
419 what
= resolve_variable (what
, scm_program_module (program
));
420 OBJECT_SET (objnum
, what
);
423 VARIABLE_SET (what
, *sp
);
428 VM_DEFINE_INSTRUCTION (34, long_toplevel_set
, "long-toplevel-set", 2, 1, 0)
431 unsigned int objnum
= FETCH ();
434 CHECK_OBJECT (objnum
);
435 what
= OBJECT_REF (objnum
);
437 if (!SCM_VARIABLEP (what
))
440 what
= resolve_variable (what
, scm_program_module (program
));
441 OBJECT_SET (objnum
, what
);
444 VARIABLE_SET (what
, *sp
);
454 /* offset must be at least 24 bits wide, and signed */
455 #define FETCH_OFFSET(offset) \
457 offset = FETCH () << 16; \
458 offset += FETCH () << 8; \
459 offset += FETCH (); \
460 offset -= (offset & (1<<23)) << 1; \
465 scm_t_int32 offset; \
466 FETCH_OFFSET (offset); \
474 VM_DEFINE_INSTRUCTION (35, br
, "br", 3, 0, 0)
477 FETCH_OFFSET (offset
);
482 VM_DEFINE_INSTRUCTION (36, br_if
, "br-if", 3, 0, 0)
484 BR (scm_is_true_and_not_nil (*sp
));
487 VM_DEFINE_INSTRUCTION (37, br_if_not
, "br-if-not", 3, 0, 0)
489 BR (scm_is_false_or_nil (*sp
));
492 VM_DEFINE_INSTRUCTION (38, br_if_eq
, "br-if-eq", 3, 0, 0)
494 sp
--; /* underflow? */
495 BR (scm_is_eq (sp
[0], sp
[1]));
498 VM_DEFINE_INSTRUCTION (39, br_if_not_eq
, "br-if-not-eq", 3, 0, 0)
500 sp
--; /* underflow? */
501 BR (!scm_is_eq (sp
[0], sp
[1]));
504 VM_DEFINE_INSTRUCTION (40, br_if_null
, "br-if-null", 3, 0, 0)
506 BR (scm_is_null_or_nil (*sp
));
509 VM_DEFINE_INSTRUCTION (41, br_if_not_null
, "br-if-not-null", 3, 0, 0)
511 BR (!scm_is_null_or_nil (*sp
));
519 VM_DEFINE_INSTRUCTION (42, br_if_nargs_ne
, "br-if-nargs-ne", 5, 0, 0)
525 FETCH_OFFSET (offset
);
526 if (sp
- (fp
- 1) != n
)
531 VM_DEFINE_INSTRUCTION (43, br_if_nargs_lt
, "br-if-nargs-lt", 5, 0, 0)
537 FETCH_OFFSET (offset
);
538 if (sp
- (fp
- 1) < n
)
543 VM_DEFINE_INSTRUCTION (44, br_if_nargs_gt
, "br-if-nargs-gt", 5, 0, 0)
550 FETCH_OFFSET (offset
);
551 if (sp
- (fp
- 1) > n
)
556 VM_DEFINE_INSTRUCTION (45, assert_nargs_ee
, "assert-nargs-ee", 2, 0, 0)
561 if (sp
- (fp
- 1) != n
)
562 goto vm_error_wrong_num_args
;
566 VM_DEFINE_INSTRUCTION (46, assert_nargs_ge
, "assert-nargs-ge", 2, 0, 0)
571 if (sp
- (fp
- 1) < n
)
572 goto vm_error_wrong_num_args
;
576 VM_DEFINE_INSTRUCTION (47, bind_optionals
, "bind-optionals", 2, -1, -1)
581 while (sp
- (fp
- 1) < n
)
582 PUSH (SCM_UNDEFINED
);
586 VM_DEFINE_INSTRUCTION (48, bind_optionals_shuffle
, "bind-optionals/shuffle", 6, -1, -1)
589 scm_t_ptrdiff nreq
, nreq_and_opt
, ntotal
;
590 nreq
= FETCH () << 8;
592 nreq_and_opt
= FETCH () << 8;
593 nreq_and_opt
+= FETCH ();
594 ntotal
= FETCH () << 8;
597 /* look in optionals for first keyword or last positional */
598 /* starting after the last required positional arg */
600 while (/* while we have args */
602 /* and we still have positionals to fill */
603 && walk
- fp
< nreq_and_opt
604 /* and we haven't reached a keyword yet */
605 && !scm_is_keyword (*walk
))
606 /* bind this optional arg (by leaving it in place) */
608 /* now shuffle up, from walk to ntotal */
610 scm_t_ptrdiff nshuf
= sp
- walk
+ 1, i
;
611 sp
= (fp
- 1) + ntotal
+ nshuf
;
613 for (i
= 0; i
< nshuf
; i
++)
614 sp
[-i
] = walk
[nshuf
-i
-1];
616 /* and fill optionals & keyword args with SCM_UNDEFINED */
617 while (walk
<= (fp
- 1) + ntotal
)
618 *walk
++ = SCM_UNDEFINED
;
623 /* Flags that determine whether other keywords are allowed, and whether a
624 rest argument is expected. These values must match those used by the
625 glil->assembly compiler. */
626 #define F_ALLOW_OTHER_KEYS 1
629 VM_DEFINE_INSTRUCTION (49, bind_kwargs
, "bind-kwargs", 5, 0, 0)
633 int kw_and_rest_flags
;
637 /* XXX: We don't actually use NKW. */
640 kw_and_rest_flags
= FETCH ();
642 if (!(kw_and_rest_flags
& F_REST
)
643 && ((sp
- (fp
- 1) - nkw
) % 2))
644 goto vm_error_kwargs_length_not_even
;
647 kw
= OBJECT_REF (idx
);
649 /* Switch NKW to be a negative index below SP. */
650 for (nkw
= -(sp
- (fp
- 1) - nkw
) + 1; nkw
< 0; nkw
++)
654 if (scm_is_keyword (sp
[nkw
]))
656 for (walk
= kw
; scm_is_pair (walk
); walk
= SCM_CDR (walk
))
658 if (scm_is_eq (SCM_CAAR (walk
), sp
[nkw
]))
660 SCM si
= SCM_CDAR (walk
);
661 LOCAL_SET (SCM_I_INUMP (si
) ? SCM_I_INUM (si
) : scm_to_long (si
),
666 if (!(kw_and_rest_flags
& F_ALLOW_OTHER_KEYS
) && !scm_is_pair (walk
))
667 goto vm_error_kwargs_unrecognized_keyword
;
671 else if (!(kw_and_rest_flags
& F_REST
))
672 goto vm_error_kwargs_invalid_keyword
;
678 #undef F_ALLOW_OTHER_KEYS
682 VM_DEFINE_INSTRUCTION (50, push_rest
, "push-rest", 2, -1, -1)
688 while (sp
- (fp
- 1) > n
)
689 /* No need to check for underflow. */
690 CONS (rest
, *sp
--, rest
);
695 VM_DEFINE_INSTRUCTION (51, bind_rest
, "bind-rest", 4, -1, -1)
704 while (sp
- (fp
- 1) > n
)
705 /* No need to check for underflow. */
706 CONS (rest
, *sp
--, rest
);
711 VM_DEFINE_INSTRUCTION (52, reserve_locals
, "reserve-locals", 2, -1, -1)
724 *++old_sp
= SCM_UNDEFINED
;
727 NULLSTACK (old_sp
- sp
);
732 VM_DEFINE_INSTRUCTION (53, new_frame
, "new-frame", 0, 0, 3)
734 /* NB: if you change this, see frames.c:vm-frame-num-locals */
735 /* and frames.h, vm-engine.c, etc of course */
736 PUSH ((SCM
)fp
); /* dynamic link */
742 VM_DEFINE_INSTRUCTION (54, call
, "call", 1, -1, 1)
751 SCM_TICK
; /* allow interrupt here */
756 if (SCM_PROGRAM_P (x
))
761 ASSERT (SCM_FRAME_RETURN_ADDRESS (fp
) == 0);
762 ASSERT (SCM_FRAME_MV_RETURN_ADDRESS (fp
) == 0);
763 SCM_FRAME_SET_RETURN_ADDRESS (fp
, ip
);
764 SCM_FRAME_SET_MV_RETURN_ADDRESS (fp
, 0);
770 if (SCM_STRUCTP (x
) && SCM_STRUCT_APPLICABLE_P (x
))
772 sp
[-nargs
] = SCM_STRUCT_PROCEDURE (x
);
776 * Other interpreted or compiled call
778 if (!scm_is_false (scm_procedure_p (x
)))
781 /* At this point, the stack contains the frame, the procedure and each one
784 ret
= apply_foreign (sp
[-nargs
],
787 vp
->stack_limit
- sp
+ 1);
788 NULLSTACK_FOR_NONLOCAL_EXIT ();
789 DROPN (nargs
+ 1); /* drop args and procedure */
792 if (SCM_UNLIKELY (SCM_VALUESP (ret
)))
794 /* truncate values */
795 ret
= scm_struct_ref (ret
, SCM_INUM0
);
796 if (scm_is_null (ret
))
797 goto vm_error_not_enough_values
;
798 PUSH (SCM_CAR (ret
));
806 goto vm_error_wrong_type_apply
;
809 VM_DEFINE_INSTRUCTION (55, goto_args
, "goto/args", 1, -1, 1)
817 SCM_TICK
; /* allow interrupt here */
822 if (SCM_PROGRAM_P (x
))
825 #ifdef VM_ENABLE_STACK_NULLING
832 /* switch programs */
835 /* shuffle down the program and the arguments */
836 for (i
= -1, sp
= sp
- nargs
+ 1; i
< nargs
; i
++)
837 SCM_FRAME_STACK_ADDRESS (fp
)[i
] = sp
[i
];
841 NULLSTACK (old_sp
- sp
);
849 if (SCM_STRUCTP (x
) && SCM_STRUCT_APPLICABLE_P (x
))
851 sp
[-nargs
] = SCM_STRUCT_PROCEDURE (x
);
855 * Other interpreted or compiled call
857 if (!scm_is_false (scm_procedure_p (x
)))
861 ret
= apply_foreign (sp
[-nargs
],
864 vp
->stack_limit
- sp
+ 1);
865 NULLSTACK_FOR_NONLOCAL_EXIT ();
866 DROPN (nargs
+ 1); /* drop args and procedure */
868 if (SCM_UNLIKELY (SCM_VALUESP (ret
)))
870 /* multiple values returned to continuation */
871 ret
= scm_struct_ref (ret
, SCM_INUM0
);
872 nvalues
= scm_ilength (ret
);
873 PUSH_LIST (ret
, scm_is_null
);
874 goto vm_return_values
;
885 goto vm_error_wrong_type_apply
;
888 VM_DEFINE_INSTRUCTION (56, goto_nargs
, "goto/nargs", 0, 0, 1)
892 nargs
= scm_to_int (x
);
893 /* FIXME: should truncate values? */
897 VM_DEFINE_INSTRUCTION (57, call_nargs
, "call/nargs", 0, 0, 1)
901 nargs
= scm_to_int (x
);
902 /* FIXME: should truncate values? */
906 VM_DEFINE_INSTRUCTION (58, mv_call
, "mv-call", 4, -1, 1)
913 FETCH_OFFSET (offset
);
922 if (SCM_PROGRAM_P (x
))
927 ASSERT (SCM_FRAME_RETURN_ADDRESS (fp
) == 0);
928 ASSERT (SCM_FRAME_MV_RETURN_ADDRESS (fp
) == 0);
929 SCM_FRAME_SET_RETURN_ADDRESS (fp
, ip
);
930 SCM_FRAME_SET_MV_RETURN_ADDRESS (fp
, mvra
);
936 if (SCM_STRUCTP (x
) && SCM_STRUCT_APPLICABLE_P (x
))
938 sp
[-nargs
] = SCM_STRUCT_PROCEDURE (x
);
942 * Other interpreted or compiled call
944 if (!scm_is_false (scm_procedure_p (x
)))
947 /* At this point, the stack contains the frame, the procedure and each one
950 ret
= apply_foreign (sp
[-nargs
],
953 vp
->stack_limit
- sp
+ 1);
954 NULLSTACK_FOR_NONLOCAL_EXIT ();
955 DROPN (nargs
+ 1); /* drop args and procedure */
958 if (SCM_VALUESP (ret
))
961 ret
= scm_struct_ref (ret
, SCM_INUM0
);
962 len
= scm_length (ret
);
963 PUSH_LIST (ret
, scm_is_null
);
973 goto vm_error_wrong_type_apply
;
976 VM_DEFINE_INSTRUCTION (59, apply
, "apply", 1, -1, 1)
985 len
= scm_ilength (ls
);
987 goto vm_error_wrong_type_arg
;
989 PUSH_LIST (ls
, SCM_NULL_OR_NIL_P
);
995 VM_DEFINE_INSTRUCTION (60, goto_apply
, "goto/apply", 1, -1, 1)
1002 ASSERT (nargs
>= 2);
1004 len
= scm_ilength (ls
);
1006 goto vm_error_wrong_type_arg
;
1008 PUSH_LIST (ls
, SCM_NULL_OR_NIL_P
);
1014 VM_DEFINE_INSTRUCTION (61, call_cc
, "call/cc", 0, 1, 1)
1020 cont
= scm_make_continuation (&first
);
1023 PUSH ((SCM
)fp
); /* dynamic link */
1024 PUSH (0); /* mvra */
1031 ASSERT (sp
== vp
->sp
);
1032 ASSERT (fp
== vp
->fp
);
1033 else if (SCM_VALUESP (cont
))
1035 /* multiple values returned to continuation */
1037 values
= scm_struct_ref (cont
, SCM_INUM0
);
1038 if (scm_is_null (values
))
1039 goto vm_error_no_values
;
1040 /* non-tail context does not accept multiple values? */
1041 PUSH (SCM_CAR (values
));
1051 VM_DEFINE_INSTRUCTION (62, goto_cc
, "goto/cc", 0, 1, 1)
1057 cont
= scm_make_continuation (&first
);
1058 ASSERT (sp
== vp
->sp
);
1059 ASSERT (fp
== vp
->fp
);
1067 else if (SCM_VALUESP (cont
))
1069 /* multiple values returned to continuation */
1071 values
= scm_struct_ref (cont
, SCM_INUM0
);
1072 nvalues
= scm_ilength (values
);
1073 PUSH_LIST (values
, scm_is_null
);
1074 goto vm_return_values
;
1083 VM_DEFINE_INSTRUCTION (63, return, "return", 0, 1, 1)
1089 SCM_TICK
; /* allow interrupt here */
1095 #ifdef VM_ENABLE_STACK_NULLING
1099 /* Restore registers */
1100 sp
= SCM_FRAME_LOWER_ADDRESS (fp
);
1101 ip
= SCM_FRAME_RETURN_ADDRESS (fp
);
1102 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
1104 #ifdef VM_ENABLE_STACK_NULLING
1105 NULLSTACK (old_sp
- sp
);
1108 /* Set return value (sp is already pushed) */
1112 /* Restore the last program */
1113 program
= SCM_FRAME_PROGRAM (fp
);
1119 VM_DEFINE_INSTRUCTION (64, return_values
, "return/values", 1, -1, -1)
1121 /* nvalues declared at top level, because for some reason gcc seems to think
1122 that perhaps it might be used without declaration. Fooey to that, I say. */
1128 if (nvalues
!= 1 && SCM_FRAME_MV_RETURN_ADDRESS (fp
))
1130 /* A multiply-valued continuation */
1131 SCM
*vals
= sp
- nvalues
;
1133 /* Restore registers */
1134 sp
= SCM_FRAME_LOWER_ADDRESS (fp
) - 1;
1135 ip
= SCM_FRAME_MV_RETURN_ADDRESS (fp
);
1136 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
1138 /* Push return values, and the number of values */
1139 for (i
= 0; i
< nvalues
; i
++)
1141 *++sp
= SCM_I_MAKINUM (nvalues
);
1143 /* Finally null the end of the stack */
1144 NULLSTACK (vals
+ nvalues
- sp
);
1146 else if (nvalues
>= 1)
1148 /* Multiple values for a single-valued continuation -- here's where I
1149 break with guile tradition and try and do something sensible. (Also,
1150 this block handles the single-valued return to an mv
1152 SCM
*vals
= sp
- nvalues
;
1153 /* Restore registers */
1154 sp
= SCM_FRAME_LOWER_ADDRESS (fp
) - 1;
1155 ip
= SCM_FRAME_RETURN_ADDRESS (fp
);
1156 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
1158 /* Push first value */
1161 /* Finally null the end of the stack */
1162 NULLSTACK (vals
+ nvalues
- sp
);
1165 goto vm_error_no_values
;
1167 /* Restore the last program */
1168 program
= SCM_FRAME_PROGRAM (fp
);
1174 VM_DEFINE_INSTRUCTION (65, return_values_star
, "return/values*", 1, -1, -1)
1179 ASSERT (nvalues
>= 1);
1183 while (scm_is_pair (l
))
1189 if (SCM_UNLIKELY (!SCM_NULL_OR_NIL_P (l
))) {
1190 finish_args
= scm_list_1 (l
);
1191 goto vm_error_improper_list
;
1194 goto vm_return_values
;
1197 VM_DEFINE_INSTRUCTION (66, truncate_values
, "truncate-values", 2, -1, -1)
1202 nvalues
= scm_to_int (x
);
1209 if (nvalues
< nbinds
)
1210 goto vm_error_not_enough_values
;
1213 POP_LIST (nvalues
- nbinds
);
1215 DROPN (nvalues
- nbinds
);
1220 VM_DEFINE_INSTRUCTION (67, box
, "box", 1, 1, 0)
1225 LOCAL_SET (FETCH (), scm_cell (scm_tc7_variable
, SCM_UNPACK (val
)));
1230 (let ((a *undef*) (b *undef*) ...)
1231 (set! a (lambda () (b ...)))
1234 VM_DEFINE_INSTRUCTION (68, empty_box
, "empty-box", 1, 0, 0)
1237 LOCAL_SET (FETCH (),
1238 scm_cell (scm_tc7_variable
, SCM_UNPACK (SCM_UNDEFINED
)));
1242 VM_DEFINE_INSTRUCTION (69, local_boxed_ref
, "local-boxed-ref", 1, 0, 1)
1244 SCM v
= LOCAL_REF (FETCH ());
1245 ASSERT_BOUND_VARIABLE (v
);
1246 PUSH (VARIABLE_REF (v
));
1250 VM_DEFINE_INSTRUCTION (70, local_boxed_set
, "local-boxed-set", 1, 1, 0)
1253 v
= LOCAL_REF (FETCH ());
1255 ASSERT_VARIABLE (v
);
1256 VARIABLE_SET (v
, val
);
1260 VM_DEFINE_INSTRUCTION (71, free_ref
, "free-ref", 1, 0, 1)
1262 scm_t_uint8 idx
= FETCH ();
1264 CHECK_FREE_VARIABLE (idx
);
1265 PUSH (FREE_VARIABLE_REF (idx
));
1269 /* no free-set -- if a var is assigned, it should be in a box */
1271 VM_DEFINE_INSTRUCTION (72, free_boxed_ref
, "free-boxed-ref", 1, 0, 1)
1274 scm_t_uint8 idx
= FETCH ();
1275 CHECK_FREE_VARIABLE (idx
);
1276 v
= FREE_VARIABLE_REF (idx
);
1277 ASSERT_BOUND_VARIABLE (v
);
1278 PUSH (VARIABLE_REF (v
));
1282 VM_DEFINE_INSTRUCTION (73, free_boxed_set
, "free-boxed-set", 1, 1, 0)
1285 scm_t_uint8 idx
= FETCH ();
1287 CHECK_FREE_VARIABLE (idx
);
1288 v
= FREE_VARIABLE_REF (idx
);
1289 ASSERT_BOUND_VARIABLE (v
);
1290 VARIABLE_SET (v
, val
);
1294 VM_DEFINE_INSTRUCTION (74, make_closure
, "make-closure", 0, 2, 1)
1299 /* fixme underflow */
1300 *sp
= scm_double_cell (scm_tc7_program
, (scm_t_bits
)SCM_PROGRAM_OBJCODE (*sp
),
1301 (scm_t_bits
)SCM_PROGRAM_OBJTABLE (*sp
), (scm_t_bits
)vect
);
1305 VM_DEFINE_INSTRUCTION (75, make_variable
, "make-variable", 0, 0, 1)
1308 /* fixme underflow */
1309 PUSH (scm_cell (scm_tc7_variable
, SCM_UNPACK (SCM_UNDEFINED
)));
1313 VM_DEFINE_INSTRUCTION (76, fix_closure
, "fix-closure", 2, 0, 1)
1316 unsigned int i
= FETCH ();
1320 /* FIXME CHECK_LOCAL (i) */
1322 /* FIXME ASSERT_PROGRAM (x); */
1323 SCM_SET_CELL_WORD_3 (x
, vect
);
1327 VM_DEFINE_INSTRUCTION (77, define
, "define", 0, 0, 2)
1333 VARIABLE_SET (scm_sym2var (sym
, scm_current_module_lookup_closure (),
1339 VM_DEFINE_INSTRUCTION (78, make_keyword
, "make-keyword", 0, 1, 1)
1343 *sp
= scm_symbol_to_keyword (*sp
);
1347 VM_DEFINE_INSTRUCTION (79, make_symbol
, "make-symbol", 0, 1, 1)
1351 *sp
= scm_string_to_symbol (*sp
);
1357 (defun renumber-ops ()
1358 "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
1361 (let ((counter -1)) (goto-char (point-min))
1362 (while (re-search-forward "^VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t)
1364 (number-to-string (setq counter (1+ counter)))