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)
35 nvalues
= SCM_I_INUM (*sp
--);
44 finish_args
= scm_values (finish_args
);
48 #ifdef VM_ENABLE_STACK_NULLING
52 /* Restore registers */
53 sp
= SCM_FRAME_LOWER_ADDRESS (fp
) - 1;
54 /* Setting the ip here doesn't actually affect control flow, as the calling
55 code will restore its own registers, but it does help when walking the
57 ip
= SCM_FRAME_RETURN_ADDRESS (fp
);
58 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
59 NULLSTACK (old_sp
- sp
);
65 VM_DEFINE_INSTRUCTION (2, break, "break", 0, 0, 0)
71 VM_DEFINE_INSTRUCTION (3, drop
, "drop", 0, 1, 0)
77 VM_DEFINE_INSTRUCTION (4, dup
, "dup", 0, 0, 1)
89 VM_DEFINE_INSTRUCTION (5, void, "void", 0, 0, 1)
91 PUSH (SCM_UNSPECIFIED
);
95 VM_DEFINE_INSTRUCTION (6, make_true
, "make-true", 0, 0, 1)
101 VM_DEFINE_INSTRUCTION (7, make_false
, "make-false", 0, 0, 1)
107 VM_DEFINE_INSTRUCTION (8, make_nil
, "make-nil", 0, 0, 1)
109 PUSH (SCM_ELISP_NIL
);
113 VM_DEFINE_INSTRUCTION (9, make_eol
, "make-eol", 0, 0, 1)
119 VM_DEFINE_INSTRUCTION (10, make_int8
, "make-int8", 1, 0, 1)
121 PUSH (SCM_I_MAKINUM ((signed char) FETCH ()));
125 VM_DEFINE_INSTRUCTION (11, make_int8_0
, "make-int8:0", 0, 0, 1)
131 VM_DEFINE_INSTRUCTION (12, make_int8_1
, "make-int8:1", 0, 0, 1)
133 PUSH (SCM_I_MAKINUM (1));
137 VM_DEFINE_INSTRUCTION (13, make_int16
, "make-int16", 2, 0, 1)
141 PUSH (SCM_I_MAKINUM ((signed short) (h
<< 8) + l
));
145 VM_DEFINE_INSTRUCTION (14, make_int64
, "make-int64", 8, 0, 1)
149 v
<<= 8; v
+= FETCH ();
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 PUSH (scm_from_int64 ((scm_t_int64
) v
));
160 VM_DEFINE_INSTRUCTION (15, make_uint64
, "make-uint64", 8, 0, 1)
164 v
<<= 8; v
+= FETCH ();
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 PUSH (scm_from_uint64 (v
));
175 VM_DEFINE_INSTRUCTION (16, make_char8
, "make-char8", 1, 0, 1)
180 PUSH (SCM_MAKE_CHAR (v
));
181 /* Don't simplify this to PUSH (SCM_MAKE_CHAR (FETCH ())). The
182 contents of SCM_MAKE_CHAR may be evaluated more than once,
183 resulting in a double fetch. */
187 VM_DEFINE_INSTRUCTION (17, make_char32
, "make-char32", 4, 0, 1)
191 v
<<= 8; v
+= FETCH ();
192 v
<<= 8; v
+= FETCH ();
193 v
<<= 8; v
+= FETCH ();
194 PUSH (SCM_MAKE_CHAR (v
));
200 VM_DEFINE_INSTRUCTION (18, list
, "list", 2, -1, 1)
202 unsigned h
= FETCH ();
203 unsigned l
= FETCH ();
204 unsigned len
= ((h
<< 8) + l
);
209 VM_DEFINE_INSTRUCTION (19, vector
, "vector", 2, -1, 1)
211 unsigned h
= FETCH ();
212 unsigned l
= FETCH ();
213 unsigned len
= ((h
<< 8) + l
);
219 vect
= scm_make_vector (scm_from_uint (len
), SCM_BOOL_F
);
220 memcpy (SCM_I_VECTOR_WELTS(vect
), sp
, sizeof(SCM
) * len
);
232 #define OBJECT_REF(i) objects[i]
233 #define OBJECT_SET(i,o) objects[i] = o
235 #define LOCAL_REF(i) SCM_FRAME_VARIABLE (fp, i)
236 #define LOCAL_SET(i,o) SCM_FRAME_VARIABLE (fp, i) = o
238 /* For the variable operations, we _must_ obviously avoid function calls to
239 `scm_variable_ref ()', `scm_variable_bound_p ()' and friends which do
240 nothing more than the corresponding macros. */
241 #define VARIABLE_REF(v) SCM_VARIABLE_REF (v)
242 #define VARIABLE_SET(v,o) SCM_VARIABLE_SET (v, o)
243 #define VARIABLE_BOUNDP(v) (VARIABLE_REF (v) != SCM_UNDEFINED)
245 #define FREE_VARIABLE_REF(i) free_vars[i]
249 VM_DEFINE_INSTRUCTION (20, object_ref
, "object-ref", 1, 0, 1)
251 register unsigned objnum
= FETCH ();
252 CHECK_OBJECT (objnum
);
253 PUSH (OBJECT_REF (objnum
));
257 /* FIXME: necessary? elt 255 of the vector could be a vector... */
258 VM_DEFINE_INSTRUCTION (21, long_object_ref
, "long-object-ref", 2, 0, 1)
260 unsigned int objnum
= FETCH ();
263 CHECK_OBJECT (objnum
);
264 PUSH (OBJECT_REF (objnum
));
268 VM_DEFINE_INSTRUCTION (22, local_ref
, "local-ref", 1, 0, 1)
270 PUSH (LOCAL_REF (FETCH ()));
275 VM_DEFINE_INSTRUCTION (23, long_local_ref
, "long-local-ref", 2, 0, 1)
277 unsigned int i
= FETCH ();
280 PUSH (LOCAL_REF (i
));
285 VM_DEFINE_INSTRUCTION (24, local_bound
, "local-bound?", 1, 0, 1)
287 if (LOCAL_REF (FETCH ()) == SCM_UNDEFINED
)
294 VM_DEFINE_INSTRUCTION (25, long_local_bound
, "long-local-bound?", 2, 0, 1)
296 unsigned int i
= FETCH ();
299 if (LOCAL_REF (i
) == SCM_UNDEFINED
)
306 VM_DEFINE_INSTRUCTION (26, variable_ref
, "variable-ref", 0, 1, 1)
310 if (!VARIABLE_BOUNDP (x
))
312 finish_args
= scm_list_1 (x
);
313 /* Was: finish_args = SCM_LIST1 (SCM_CAR (x)); */
314 goto vm_error_unbound
;
318 SCM o
= VARIABLE_REF (x
);
325 VM_DEFINE_INSTRUCTION (27, variable_bound
, "variable-bound?", 0, 0, 1)
327 if (VARIABLE_BOUNDP (*sp
))
334 VM_DEFINE_INSTRUCTION (28, toplevel_ref
, "toplevel-ref", 1, 0, 1)
336 unsigned objnum
= FETCH ();
338 CHECK_OBJECT (objnum
);
339 what
= OBJECT_REF (objnum
);
341 if (!SCM_VARIABLEP (what
))
344 what
= resolve_variable (what
, scm_program_module (program
));
345 if (!VARIABLE_BOUNDP (what
))
347 finish_args
= scm_list_1 (what
);
348 goto vm_error_unbound
;
350 OBJECT_SET (objnum
, what
);
353 PUSH (VARIABLE_REF (what
));
357 VM_DEFINE_INSTRUCTION (29, long_toplevel_ref
, "long-toplevel-ref", 2, 0, 1)
360 unsigned int objnum
= FETCH ();
363 CHECK_OBJECT (objnum
);
364 what
= OBJECT_REF (objnum
);
366 if (!SCM_VARIABLEP (what
))
369 what
= resolve_variable (what
, scm_program_module (program
));
370 if (!VARIABLE_BOUNDP (what
))
372 finish_args
= scm_list_1 (what
);
373 goto vm_error_unbound
;
375 OBJECT_SET (objnum
, what
);
378 PUSH (VARIABLE_REF (what
));
384 VM_DEFINE_INSTRUCTION (30, local_set
, "local-set", 1, 1, 0)
386 LOCAL_SET (FETCH (), *sp
);
391 VM_DEFINE_INSTRUCTION (31, long_local_set
, "long-local-set", 2, 1, 0)
393 unsigned int i
= FETCH ();
401 VM_DEFINE_INSTRUCTION (32, variable_set
, "variable-set", 0, 2, 0)
403 VARIABLE_SET (sp
[0], sp
[-1]);
408 VM_DEFINE_INSTRUCTION (33, toplevel_set
, "toplevel-set", 1, 1, 0)
410 unsigned objnum
= FETCH ();
412 CHECK_OBJECT (objnum
);
413 what
= OBJECT_REF (objnum
);
415 if (!SCM_VARIABLEP (what
))
418 what
= resolve_variable (what
, scm_program_module (program
));
419 OBJECT_SET (objnum
, what
);
422 VARIABLE_SET (what
, *sp
);
427 VM_DEFINE_INSTRUCTION (34, long_toplevel_set
, "long-toplevel-set", 2, 1, 0)
430 unsigned int objnum
= FETCH ();
433 CHECK_OBJECT (objnum
);
434 what
= OBJECT_REF (objnum
);
436 if (!SCM_VARIABLEP (what
))
439 what
= resolve_variable (what
, scm_program_module (program
));
440 OBJECT_SET (objnum
, what
);
443 VARIABLE_SET (what
, *sp
);
453 /* offset must be at least 24 bits wide, and signed */
454 #define FETCH_OFFSET(offset) \
456 offset = FETCH () << 16; \
457 offset += FETCH () << 8; \
458 offset += FETCH (); \
459 offset -= (offset & (1<<23)) << 1; \
464 scm_t_int32 offset; \
465 FETCH_OFFSET (offset); \
469 VM_HANDLE_INTERRUPTS; \
475 VM_DEFINE_INSTRUCTION (35, br
, "br", 3, 0, 0)
478 FETCH_OFFSET (offset
);
481 VM_HANDLE_INTERRUPTS
;
485 VM_DEFINE_INSTRUCTION (36, br_if
, "br-if", 3, 0, 0)
487 BR (scm_is_true_and_not_nil (*sp
));
490 VM_DEFINE_INSTRUCTION (37, br_if_not
, "br-if-not", 3, 0, 0)
492 BR (scm_is_false_or_nil (*sp
));
495 VM_DEFINE_INSTRUCTION (38, br_if_eq
, "br-if-eq", 3, 0, 0)
497 sp
--; /* underflow? */
498 BR (scm_is_eq (sp
[0], sp
[1]));
501 VM_DEFINE_INSTRUCTION (39, br_if_not_eq
, "br-if-not-eq", 3, 0, 0)
503 sp
--; /* underflow? */
504 BR (!scm_is_eq (sp
[0], sp
[1]));
507 VM_DEFINE_INSTRUCTION (40, br_if_null
, "br-if-null", 3, 0, 0)
509 BR (scm_is_null_or_nil (*sp
));
512 VM_DEFINE_INSTRUCTION (41, br_if_not_null
, "br-if-not-null", 3, 0, 0)
514 BR (!scm_is_null_or_nil (*sp
));
522 VM_DEFINE_INSTRUCTION (42, br_if_nargs_ne
, "br-if-nargs-ne", 5, 0, 0)
528 FETCH_OFFSET (offset
);
529 if (sp
- (fp
- 1) != n
)
534 VM_DEFINE_INSTRUCTION (43, br_if_nargs_lt
, "br-if-nargs-lt", 5, 0, 0)
540 FETCH_OFFSET (offset
);
541 if (sp
- (fp
- 1) < n
)
546 VM_DEFINE_INSTRUCTION (44, br_if_nargs_gt
, "br-if-nargs-gt", 5, 0, 0)
553 FETCH_OFFSET (offset
);
554 if (sp
- (fp
- 1) > n
)
559 VM_DEFINE_INSTRUCTION (45, assert_nargs_ee
, "assert-nargs-ee", 2, 0, 0)
564 if (sp
- (fp
- 1) != n
)
565 goto vm_error_wrong_num_args
;
569 VM_DEFINE_INSTRUCTION (46, assert_nargs_ge
, "assert-nargs-ge", 2, 0, 0)
574 if (sp
- (fp
- 1) < n
)
575 goto vm_error_wrong_num_args
;
579 VM_DEFINE_INSTRUCTION (47, bind_optionals
, "bind-optionals", 2, -1, -1)
584 while (sp
- (fp
- 1) < n
)
585 PUSH (SCM_UNDEFINED
);
589 VM_DEFINE_INSTRUCTION (48, bind_optionals_shuffle
, "bind-optionals/shuffle", 6, -1, -1)
592 scm_t_ptrdiff nreq
, nreq_and_opt
, ntotal
;
593 nreq
= FETCH () << 8;
595 nreq_and_opt
= FETCH () << 8;
596 nreq_and_opt
+= FETCH ();
597 ntotal
= FETCH () << 8;
600 /* look in optionals for first keyword or last positional */
601 /* starting after the last required positional arg */
603 while (/* while we have args */
605 /* and we still have positionals to fill */
606 && walk
- fp
< nreq_and_opt
607 /* and we haven't reached a keyword yet */
608 && !scm_is_keyword (*walk
))
609 /* bind this optional arg (by leaving it in place) */
611 /* now shuffle up, from walk to ntotal */
613 scm_t_ptrdiff nshuf
= sp
- walk
+ 1, i
;
614 sp
= (fp
- 1) + ntotal
+ nshuf
;
616 for (i
= 0; i
< nshuf
; i
++)
617 sp
[-i
] = walk
[nshuf
-i
-1];
619 /* and fill optionals & keyword args with SCM_UNDEFINED */
620 while (walk
<= (fp
- 1) + ntotal
)
621 *walk
++ = SCM_UNDEFINED
;
626 /* Flags that determine whether other keywords are allowed, and whether a
627 rest argument is expected. These values must match those used by the
628 glil->assembly compiler. */
629 #define F_ALLOW_OTHER_KEYS 1
632 VM_DEFINE_INSTRUCTION (49, bind_kwargs
, "bind-kwargs", 5, 0, 0)
636 int kw_and_rest_flags
;
640 /* XXX: We don't actually use NKW. */
643 kw_and_rest_flags
= FETCH ();
645 if (!(kw_and_rest_flags
& F_REST
)
646 && ((sp
- (fp
- 1) - nkw
) % 2))
647 goto vm_error_kwargs_length_not_even
;
650 kw
= OBJECT_REF (idx
);
652 /* Switch NKW to be a negative index below SP. */
653 for (nkw
= -(sp
- (fp
- 1) - nkw
) + 1; nkw
< 0; nkw
++)
657 if (scm_is_keyword (sp
[nkw
]))
659 for (walk
= kw
; scm_is_pair (walk
); walk
= SCM_CDR (walk
))
661 if (scm_is_eq (SCM_CAAR (walk
), sp
[nkw
]))
663 SCM si
= SCM_CDAR (walk
);
664 LOCAL_SET (SCM_I_INUMP (si
) ? SCM_I_INUM (si
) : scm_to_long (si
),
669 if (!(kw_and_rest_flags
& F_ALLOW_OTHER_KEYS
) && !scm_is_pair (walk
))
670 goto vm_error_kwargs_unrecognized_keyword
;
674 else if (!(kw_and_rest_flags
& F_REST
))
675 goto vm_error_kwargs_invalid_keyword
;
681 #undef F_ALLOW_OTHER_KEYS
685 VM_DEFINE_INSTRUCTION (50, push_rest
, "push-rest", 2, -1, -1)
691 while (sp
- (fp
- 1) > n
)
692 /* No need to check for underflow. */
693 CONS (rest
, *sp
--, rest
);
698 VM_DEFINE_INSTRUCTION (51, bind_rest
, "bind-rest", 4, -1, -1)
707 while (sp
- (fp
- 1) > n
)
708 /* No need to check for underflow. */
709 CONS (rest
, *sp
--, rest
);
714 VM_DEFINE_INSTRUCTION (52, reserve_locals
, "reserve-locals", 2, -1, -1)
727 *++old_sp
= SCM_UNDEFINED
;
730 NULLSTACK (old_sp
- sp
);
735 VM_DEFINE_INSTRUCTION (53, new_frame
, "new-frame", 0, 0, 3)
737 /* NB: if you change this, see frames.c:vm-frame-num-locals */
738 /* and frames.h, vm-engine.c, etc of course */
739 PUSH ((SCM
)fp
); /* dynamic link */
745 VM_DEFINE_INSTRUCTION (54, call
, "call", 1, -1, 1)
753 VM_HANDLE_INTERRUPTS
;
758 if (SCM_PROGRAM_P (x
))
763 ASSERT (SCM_FRAME_RETURN_ADDRESS (fp
) == 0);
764 ASSERT (SCM_FRAME_MV_RETURN_ADDRESS (fp
) == 0);
765 SCM_FRAME_SET_RETURN_ADDRESS (fp
, ip
);
766 SCM_FRAME_SET_MV_RETURN_ADDRESS (fp
, 0);
767 ip
= SCM_C_OBJCODE_BASE (bp
);
772 if (SCM_STRUCTP (x
) && SCM_STRUCT_APPLICABLE_P (x
))
774 sp
[-nargs
] = SCM_STRUCT_PROCEDURE (x
);
778 * Other interpreted or compiled call
780 if (!scm_is_false (scm_procedure_p (x
)))
783 /* At this point, the stack contains the frame, the procedure and each one
786 ret
= apply_foreign (sp
[-nargs
],
789 vp
->stack_limit
- sp
+ 1);
790 NULLSTACK_FOR_NONLOCAL_EXIT ();
791 DROPN (nargs
+ 1); /* drop args and procedure */
794 if (SCM_UNLIKELY (SCM_VALUESP (ret
)))
796 /* truncate values */
797 ret
= scm_struct_ref (ret
, SCM_INUM0
);
798 if (scm_is_null (ret
))
799 goto vm_error_not_enough_values
;
800 PUSH (SCM_CAR (ret
));
808 goto vm_error_wrong_type_apply
;
811 VM_DEFINE_INSTRUCTION (55, goto_args
, "goto/args", 1, -1, 1)
818 VM_HANDLE_INTERRUPTS
;
823 if (SCM_PROGRAM_P (x
))
826 #ifdef VM_ENABLE_STACK_NULLING
833 /* switch programs */
836 /* shuffle down the program and the arguments */
837 for (i
= -1, sp
= sp
- nargs
+ 1; i
< nargs
; i
++)
838 SCM_FRAME_STACK_ADDRESS (fp
)[i
] = sp
[i
];
842 NULLSTACK (old_sp
- sp
);
844 ip
= SCM_C_OBJCODE_BASE (bp
);
850 if (SCM_STRUCTP (x
) && SCM_STRUCT_APPLICABLE_P (x
))
852 sp
[-nargs
] = SCM_STRUCT_PROCEDURE (x
);
856 * Other interpreted or compiled call
858 if (!scm_is_false (scm_procedure_p (x
)))
862 ret
= apply_foreign (sp
[-nargs
],
865 vp
->stack_limit
- sp
+ 1);
866 NULLSTACK_FOR_NONLOCAL_EXIT ();
867 DROPN (nargs
+ 1); /* drop args and procedure */
869 if (SCM_UNLIKELY (SCM_VALUESP (ret
)))
871 /* multiple values returned to continuation */
872 ret
= scm_struct_ref (ret
, SCM_INUM0
);
873 nvalues
= scm_ilength (ret
);
874 PUSH_LIST (ret
, scm_is_null
);
875 goto vm_return_values
;
886 goto vm_error_wrong_type_apply
;
889 VM_DEFINE_INSTRUCTION (56, goto_nargs
, "goto/nargs", 0, 0, 1)
893 nargs
= scm_to_int (x
);
894 /* FIXME: should truncate values? */
898 VM_DEFINE_INSTRUCTION (57, call_nargs
, "call/nargs", 0, 0, 1)
902 nargs
= scm_to_int (x
);
903 /* FIXME: should truncate values? */
907 VM_DEFINE_INSTRUCTION (58, mv_call
, "mv-call", 4, -1, 1)
914 FETCH_OFFSET (offset
);
923 if (SCM_PROGRAM_P (x
))
928 ASSERT (SCM_FRAME_RETURN_ADDRESS (fp
) == 0);
929 ASSERT (SCM_FRAME_MV_RETURN_ADDRESS (fp
) == 0);
930 SCM_FRAME_SET_RETURN_ADDRESS (fp
, ip
);
931 SCM_FRAME_SET_MV_RETURN_ADDRESS (fp
, mvra
);
932 ip
= SCM_C_OBJCODE_BASE (bp
);
937 if (SCM_STRUCTP (x
) && SCM_STRUCT_APPLICABLE_P (x
))
939 sp
[-nargs
] = SCM_STRUCT_PROCEDURE (x
);
943 * Other interpreted or compiled call
945 if (!scm_is_false (scm_procedure_p (x
)))
948 /* At this point, the stack contains the frame, the procedure and each one
951 ret
= apply_foreign (sp
[-nargs
],
954 vp
->stack_limit
- sp
+ 1);
955 NULLSTACK_FOR_NONLOCAL_EXIT ();
956 DROPN (nargs
+ 1); /* drop args and procedure */
959 if (SCM_VALUESP (ret
))
962 ret
= scm_struct_ref (ret
, SCM_INUM0
);
963 len
= scm_length (ret
);
964 PUSH_LIST (ret
, scm_is_null
);
974 goto vm_error_wrong_type_apply
;
977 VM_DEFINE_INSTRUCTION (59, apply
, "apply", 1, -1, 1)
986 len
= scm_ilength (ls
);
988 goto vm_error_wrong_type_arg
;
990 PUSH_LIST (ls
, SCM_NULL_OR_NIL_P
);
996 VM_DEFINE_INSTRUCTION (60, goto_apply
, "goto/apply", 1, -1, 1)
1003 ASSERT (nargs
>= 2);
1005 len
= scm_ilength (ls
);
1007 goto vm_error_wrong_type_arg
;
1009 PUSH_LIST (ls
, SCM_NULL_OR_NIL_P
);
1015 VM_DEFINE_INSTRUCTION (61, call_cc
, "call/cc", 0, 1, 1)
1021 cont
= scm_make_continuation (&first
);
1024 PUSH ((SCM
)fp
); /* dynamic link */
1025 PUSH (0); /* mvra */
1032 ASSERT (sp
== vp
->sp
);
1033 ASSERT (fp
== vp
->fp
);
1034 else if (SCM_VALUESP (cont
))
1036 /* multiple values returned to continuation */
1038 values
= scm_struct_ref (cont
, SCM_INUM0
);
1039 if (scm_is_null (values
))
1040 goto vm_error_no_values
;
1041 /* non-tail context does not accept multiple values? */
1042 PUSH (SCM_CAR (values
));
1052 VM_DEFINE_INSTRUCTION (62, goto_cc
, "goto/cc", 0, 1, 1)
1058 cont
= scm_make_continuation (&first
);
1059 ASSERT (sp
== vp
->sp
);
1060 ASSERT (fp
== vp
->fp
);
1068 else if (SCM_VALUESP (cont
))
1070 /* multiple values returned to continuation */
1072 values
= scm_struct_ref (cont
, SCM_INUM0
);
1073 nvalues
= scm_ilength (values
);
1074 PUSH_LIST (values
, scm_is_null
);
1075 goto vm_return_values
;
1084 VM_DEFINE_INSTRUCTION (63, return, "return", 0, 1, 1)
1090 VM_HANDLE_INTERRUPTS
;
1097 #ifdef VM_ENABLE_STACK_NULLING
1101 /* Restore registers */
1102 sp
= SCM_FRAME_LOWER_ADDRESS (fp
);
1103 ip
= SCM_FRAME_RETURN_ADDRESS (fp
);
1104 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
1106 #ifdef VM_ENABLE_STACK_NULLING
1107 NULLSTACK (old_sp
- sp
);
1110 /* Set return value (sp is already pushed) */
1114 /* Restore the last program */
1115 program
= SCM_FRAME_PROGRAM (fp
);
1121 VM_DEFINE_INSTRUCTION (64, return_values
, "return/values", 1, -1, -1)
1123 /* nvalues declared at top level, because for some reason gcc seems to think
1124 that perhaps it might be used without declaration. Fooey to that, I say. */
1130 if (nvalues
!= 1 && SCM_FRAME_MV_RETURN_ADDRESS (fp
))
1132 /* A multiply-valued continuation */
1133 SCM
*vals
= sp
- nvalues
;
1135 /* Restore registers */
1136 sp
= SCM_FRAME_LOWER_ADDRESS (fp
) - 1;
1137 ip
= SCM_FRAME_MV_RETURN_ADDRESS (fp
);
1138 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
1140 /* Push return values, and the number of values */
1141 for (i
= 0; i
< nvalues
; i
++)
1143 *++sp
= SCM_I_MAKINUM (nvalues
);
1145 /* Finally null the end of the stack */
1146 NULLSTACK (vals
+ nvalues
- sp
);
1148 else if (nvalues
>= 1)
1150 /* Multiple values for a single-valued continuation -- here's where I
1151 break with guile tradition and try and do something sensible. (Also,
1152 this block handles the single-valued return to an mv
1154 SCM
*vals
= sp
- nvalues
;
1155 /* Restore registers */
1156 sp
= SCM_FRAME_LOWER_ADDRESS (fp
) - 1;
1157 ip
= SCM_FRAME_RETURN_ADDRESS (fp
);
1158 fp
= SCM_FRAME_DYNAMIC_LINK (fp
);
1160 /* Push first value */
1163 /* Finally null the end of the stack */
1164 NULLSTACK (vals
+ nvalues
- sp
);
1167 goto vm_error_no_values
;
1169 /* Restore the last program */
1170 program
= SCM_FRAME_PROGRAM (fp
);
1176 VM_DEFINE_INSTRUCTION (65, return_values_star
, "return/values*", 1, -1, -1)
1181 ASSERT (nvalues
>= 1);
1185 while (scm_is_pair (l
))
1191 if (SCM_UNLIKELY (!SCM_NULL_OR_NIL_P (l
))) {
1192 finish_args
= scm_list_1 (l
);
1193 goto vm_error_improper_list
;
1196 goto vm_return_values
;
1199 VM_DEFINE_INSTRUCTION (66, truncate_values
, "truncate-values", 2, -1, -1)
1204 nvalues
= scm_to_int (x
);
1211 if (nvalues
< nbinds
)
1212 goto vm_error_not_enough_values
;
1215 POP_LIST (nvalues
- nbinds
);
1217 DROPN (nvalues
- nbinds
);
1222 VM_DEFINE_INSTRUCTION (67, box
, "box", 1, 1, 0)
1227 LOCAL_SET (FETCH (), scm_cell (scm_tc7_variable
, SCM_UNPACK (val
)));
1232 (let ((a *undef*) (b *undef*) ...)
1233 (set! a (lambda () (b ...)))
1236 VM_DEFINE_INSTRUCTION (68, empty_box
, "empty-box", 1, 0, 0)
1239 LOCAL_SET (FETCH (),
1240 scm_cell (scm_tc7_variable
, SCM_UNPACK (SCM_UNDEFINED
)));
1244 VM_DEFINE_INSTRUCTION (69, local_boxed_ref
, "local-boxed-ref", 1, 0, 1)
1246 SCM v
= LOCAL_REF (FETCH ());
1247 ASSERT_BOUND_VARIABLE (v
);
1248 PUSH (VARIABLE_REF (v
));
1252 VM_DEFINE_INSTRUCTION (70, local_boxed_set
, "local-boxed-set", 1, 1, 0)
1255 v
= LOCAL_REF (FETCH ());
1257 ASSERT_VARIABLE (v
);
1258 VARIABLE_SET (v
, val
);
1262 VM_DEFINE_INSTRUCTION (71, free_ref
, "free-ref", 1, 0, 1)
1264 scm_t_uint8 idx
= FETCH ();
1266 CHECK_FREE_VARIABLE (idx
);
1267 PUSH (FREE_VARIABLE_REF (idx
));
1271 /* no free-set -- if a var is assigned, it should be in a box */
1273 VM_DEFINE_INSTRUCTION (72, free_boxed_ref
, "free-boxed-ref", 1, 0, 1)
1276 scm_t_uint8 idx
= FETCH ();
1277 CHECK_FREE_VARIABLE (idx
);
1278 v
= FREE_VARIABLE_REF (idx
);
1279 ASSERT_BOUND_VARIABLE (v
);
1280 PUSH (VARIABLE_REF (v
));
1284 VM_DEFINE_INSTRUCTION (73, free_boxed_set
, "free-boxed-set", 1, 1, 0)
1287 scm_t_uint8 idx
= FETCH ();
1289 CHECK_FREE_VARIABLE (idx
);
1290 v
= FREE_VARIABLE_REF (idx
);
1291 ASSERT_BOUND_VARIABLE (v
);
1292 VARIABLE_SET (v
, val
);
1296 VM_DEFINE_INSTRUCTION (74, make_closure
, "make-closure", 0, 2, 1)
1301 /* fixme underflow */
1302 *sp
= scm_double_cell (scm_tc7_program
, (scm_t_bits
)SCM_PROGRAM_OBJCODE (*sp
),
1303 (scm_t_bits
)SCM_PROGRAM_OBJTABLE (*sp
), (scm_t_bits
)vect
);
1307 VM_DEFINE_INSTRUCTION (75, make_variable
, "make-variable", 0, 0, 1)
1310 /* fixme underflow */
1311 PUSH (scm_cell (scm_tc7_variable
, SCM_UNPACK (SCM_UNDEFINED
)));
1315 VM_DEFINE_INSTRUCTION (76, fix_closure
, "fix-closure", 2, 0, 1)
1318 unsigned int i
= FETCH ();
1322 /* FIXME CHECK_LOCAL (i) */
1324 /* FIXME ASSERT_PROGRAM (x); */
1325 SCM_SET_CELL_WORD_3 (x
, vect
);
1329 VM_DEFINE_INSTRUCTION (77, define
, "define", 0, 0, 2)
1335 VARIABLE_SET (scm_sym2var (sym
, scm_current_module_lookup_closure (),
1341 VM_DEFINE_INSTRUCTION (78, make_keyword
, "make-keyword", 0, 1, 1)
1345 *sp
= scm_symbol_to_keyword (*sp
);
1349 VM_DEFINE_INSTRUCTION (79, make_symbol
, "make-symbol", 0, 1, 1)
1353 *sp
= scm_string_to_symbol (*sp
);
1359 (defun renumber-ops ()
1360 "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
1363 (let ((counter -1)) (goto-char (point-min))
1364 (while (re-search-forward "^VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t)
1366 (number-to-string (setq counter (1+ counter)))