Debian Codegraph @

src/c/interpreter.d

raw
1 /* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */
3
4 /*
5 * interpreter.d - bytecode interpreter
6 *
7 * Copyright (c) 2001 Juan Jose Garcia Ripoll
8 *
9 * See file 'LICENSE' for the copyright details.
10 *
11 */
12
13 #include <ecl/ecl.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <stdio.h>
17 #include <ecl/ecl-inl.h>
18 #include <ecl/bytecodes.h>
19 #include <ecl/internal.h>
20 #include <ecl/stack-resize.h>
21
22 /* -- Errors signaled by the interpreter. ----------------------------------- */
23
24 static void
25 VEbad_lambda_too_many_args(cl_object bytecodes, cl_object frame)
26 {
27 FEprogram_error("Too many arguments passed to "
28 "function ~A~&Argument list: ~S",
29 2, bytecodes, cl_apply(2, @'list', frame));
30 }
31
32 static void
33 VEbad_lambda_unknown_keyword(cl_object bytecodes, cl_object frame)
34 {
35 FEprogram_error("Unknown keyword argument passed to function ~S.~&"
36 "Argument list: ~S", 2, bytecodes,
37 cl_apply(2, @'list', frame));
38 }
39
40 static void
41 VEbad_lambda_odd_keys(cl_object bytecodes, cl_object frame)
42 {
43 FEprogram_error("Function ~A called with odd number "
44 "of keyword arguments.",
45 1, bytecodes);
46 }
47
48 static void
49 VEwrong_arg_type_endp(cl_object reg0)
50 {
51 FEwrong_type_only_arg(@[endp], reg0, @[list]);
52 }
53
54 static void
55 VEwrong_arg_type_car(cl_object reg0)
56 {
57 FEwrong_type_only_arg(@[car], reg0, @[cons]);
58 }
59
60 static void
61 VEwrong_arg_type_cdr(cl_object reg0)
62 {
63 FEwrong_type_only_arg(@[cdr], reg0, @[cons]);
64 }
65
66 static void
67 VEwrong_arg_type_nth_val(cl_fixnum n)
68 {
69 FEerror("Wrong index passed to NTH-VAL", 1, ecl_make_fixnum(n));
70 }
71
72 static void
73 VEassignment_to_constant(cl_object var)
74 {
75 FEassignment_to_constant(var);
76 }
77
78 static void
79 VEunbound_variable(cl_object var)
80 {
81 FEunbound_variable(var);
82 }
83
84 static void
85 VEwrong_num_arguments(cl_object fname)
86 {
87 FEwrong_num_arguments(fname);
88 }
89
90 static void
91 VEundefined_function(cl_object fun)
92 {
93 FEundefined_function(fun);
94 }
95
96 static void
97 VEinvalid_function(cl_object fun)
98 {
99 FEinvalid_function(fun);
100 }
101
102 static void
103 VEclose_around_arg_type()
104 {
105 FEerror("Internal error: ecl_close_around should be called on t_bytecodes or t_bclosure.", 0);
106 }
107
108 /* ------------------------------ LEXICAL ENV. ------------------------------ */
109 /*
110 * A lexical environment is a list of entries, each containing either a variable
111 * definition, a tagbody or block tag, or a local function or macro definition.
112 *
113 * lex_env ---> ( { record }* )
114 * record = variable | function | block | tagbody | macro | sym_macro
115 *
116 * variable = ( var_name[symbol] . value )
117 * function = function[bytecodes]
118 * block = ( tag[fixnum] . block_name[symbol] )
119 * tagbody = ( tag[fixnum] . 0 )
120 * macro = ( si::macro macro_function[bytecodes] . macro_name )
121 * sym_macro = ( si::symbol-macro macro_function[bytecodes] . macro_name )
122 */
123
124 #define bind_lcl(env, entry) push_lcl(env, entry)
125
126 #define bind_var(env, var, val) bind_lcl(env, CONS(var, val))
127 #define bind_function(env, fun) bind_lcl(env, fun)
128 #define bind_frame(env, id, name) bind_lcl(env, CONS(id, name))
129
130 #define unbind_lcl(env, n) drop_lcl(env, n)
131 #define tangle_lcl(stack) ecl_make_fixnum(stack->frame.sp)
132 #define unwind_lcl(stack, where) (stack->frame.sp = ecl_fixnum(where))
133
134 static void
135 push_lcl(cl_object stack, cl_object new)
136 {
137 *ECL_STACK_FRAME_TOP(stack) = new;
138 stack->frame.sp++;
139 }
140
141 static void
142 drop_lcl(cl_object stack, cl_fixnum n)
143 {
144 cl_index i;
145 for(i=0; i<n; i++) {
146 stack->frame.sp--;
147 *ECL_STACK_FRAME_TOP(stack) = ECL_NIL;
148 }
149 }
150
151 static cl_object
152 ecl_lcl_env_get_record(cl_object env, cl_fixnum n)
153 {
154 return ECL_STACK_FRAME_REF(env,n);
155 }
156
157 static cl_object
158 ecl_lex_env_get_record(cl_object env, int s)
159 {
160 return env->vector.self.t[s];
161 }
162
163 #define ecl_lcl_env_get_fun(env,x) ecl_lcl_env_get_record(env,x)
164 #define ecl_lcl_env_get_blk(env,x) ecl_lcl_env_get_record(env,x)
165 #define ecl_lcl_env_get_tag(env,x) ecl_lcl_env_get_record(env,x)
166 #define ecl_lcl_env_get_var(env,x) ECL_CONS_CDR(ecl_lcl_env_get_record(env,x))
167 #define ecl_lcl_env_set_var(env,x,v) ECL_RPLACD(ecl_lcl_env_get_record(env,x),(v))
168
169 #define ecl_lex_env_get_fun(env,x) ecl_lex_env_get_record(env,x)
170 #define ecl_lex_env_get_blk(env,x) ecl_lex_env_get_record(env,x)
171 #define ecl_lex_env_get_tag(env,x) ecl_lex_env_get_record(env,x)
172 #define ecl_lex_env_get_var(env,x) ECL_CONS_CDR(ecl_lex_env_get_record(env,x))
173 #define ecl_lex_env_set_var(env,x,v) ECL_RPLACD(ecl_lex_env_get_record(env,x),(v))
174
175 /* -- Lexical and local env operators ------------------------------------------ */
176
177 static cl_object
178 make_lex(cl_index n)
179 {
180 return si_make_vector(ECL_T, ecl_make_fixnum(n), ECL_NIL,
181 ecl_make_fixnum(0), ECL_NIL, ECL_NIL);
182 }
183
184 static void
185 push_lex(cl_object stack, cl_object new)
186 {
187 cl_vector_push(new, stack);
188 }
189
190 /* -------------------- AIDS TO THE INTERPRETER -------------------- */
191
192 cl_object
193 _ecl_bytecodes_dispatch_vararg(cl_narg narg, ...)
194 {
195 cl_object output;
196 ECL_STACK_FRAME_VARARGS_BEGIN(narg, narg, frame) {
197 output = ecl_interpret(frame, ECL_NIL, frame->frame.env->function);
198 } ECL_STACK_FRAME_VARARGS_END(frame);
199 return output;
200 }
201
202 cl_object
203 _ecl_bclosure_dispatch_vararg(cl_narg narg, ...)
204 {
205 cl_object output;
206 ECL_STACK_FRAME_VARARGS_BEGIN(narg, narg, frame) {
207 cl_object fun = frame->frame.env->function;
208 output = ecl_interpret(frame, fun->bclosure.lex, fun->bclosure.code);
209 } ECL_STACK_FRAME_VARARGS_END(frame);
210 return output;
211 }
212
213 /* Find the global function definition associated with a name. This function is
214 similar to ecl_fdefinition except thta it does not check for lambdas and
215 assumes that the name is either SYMBOL or (SETF SYMBOL). -- jd 2024-12-12 */
216 static cl_object
217 _ecl_global_function_definition(cl_object name)
218 {
219 cl_object fun = ECL_NIL, sym, pair;
220 switch (ecl_t_of(name)) {
221 case t_symbol:
222 unlikely_if (!ECL_FBOUNDP(name)
223 || name->symbol.stype & (ecl_stp_macro | ecl_stp_special_form))
224 VEundefined_function(name);
225 fun = ECL_SYM_FUN(name);
226 break;
227 case t_list:
228 unlikely_if (Null(name))
229 VEundefined_function(name);
230 /* (setf fname) */
231 sym = ECL_CONS_CAR(ECL_CONS_CDR(name));
232 pair = sym->symbol.sfdef;
233 unlikely_if (Null(pair) || Null(ECL_CONS_CDR(pair))) {
234 VEundefined_function(name);
235 }
236 fun = ECL_CONS_CAR(pair);
237 break;
238 default:
239 VEinvalid_function(name);
240 }
241 return fun;
242 }
243
244 /* Functions close_around_self and close_around_self_fixup are defined to first
245 create a closure (so that it can be bound in locals) and then they modify
246 these closures in place to enable self references. -- jd 2025-01-07 */
247 static cl_object
248 close_around_self(cl_object fun) {
249 cl_object v, template;
250 if(ecl_t_of(fun) != t_bytecodes)
251 VEclose_around_arg_type();
252 template = fun->bytecodes.flex;
253 if(Null(template)) return fun;
254 /* Make a closure */
255 v = ecl_alloc_object(t_bclosure);
256 v->bclosure.entry = _ecl_bclosure_dispatch_vararg;
257 v->bclosure.code = fun;
258 v->bclosure.lex = ECL_NIL;
259 return v;
260 }
261
262 static void
263 close_around_self_fixup(cl_object fun, cl_object lcl_env, cl_object lex_env) {
264 cl_object new_lex, template, entry;
265 cl_fixnum nlex, idx, ndx;
266 switch(ecl_t_of(fun)) {
267 case t_bytecodes:
268 break;
269 case t_bclosure:
270 template = fun->bclosure.code->bytecodes.flex;
271 /* Close around */
272 nlex = template->vector.dim;
273 new_lex = make_lex(nlex);
274 for (idx = 0; idx<nlex; idx++) {
275 entry = template->vector.self.t[idx];
276 if(!ECL_FIXNUMP(entry)) {
277 push_lex(new_lex, entry);
278 continue;
279 }
280 ndx = ecl_fixnum(template->vector.self.t[idx]);
281 ndx < 0
282 ? push_lex(new_lex, ecl_lcl_env_get_record(lcl_env, -ndx-1))
283 : push_lex(new_lex, ecl_lex_env_get_record(lex_env, ndx));
284 }
285 /* Fixup the closure */
286 fun->bclosure.lex = new_lex;
287 break;
288 default:
289 VEclose_around_arg_type();
290 }
291 }
292
293
294 cl_object
295 ecl_close_around(cl_object fun, cl_object lcl_env, cl_object lex_env) {
296 cl_object v, new_lex, template, entry;
297 cl_fixnum nlex, idx, ndx;
298 if(ecl_t_of(fun) != t_bytecodes)
299 VEclose_around_arg_type();
300 template = fun->bytecodes.flex;
301 if(Null(template)) return fun;
302 /* Close around */
303 nlex = template->vector.dim;
304 new_lex = make_lex(nlex);
305 for (idx = 0; idx<nlex; idx++) {
306 entry = template->vector.self.t[idx];
307 if(!ECL_FIXNUMP(entry)) {
308 push_lex(new_lex, entry);
309 continue;
310 }
311 ndx = ecl_fixnum(template->vector.self.t[idx]);
312 ndx < 0
313 ? push_lex(new_lex, ecl_lcl_env_get_record(lcl_env, -ndx-1))
314 : push_lex(new_lex, ecl_lex_env_get_record(lex_env, ndx));
315 }
316 /* Make a closure */
317 v = ecl_alloc_object(t_bclosure);
318 v->bclosure.entry = _ecl_bclosure_dispatch_vararg;
319 v->bclosure.code = fun;
320 v->bclosure.lex = new_lex;
321 /* Profit */
322 return v;
323 }
324
325 static inline cl_object
326 call_stepper(cl_env_ptr the_env, cl_object form, cl_object delta)
327 {
328 return _ecl_funcall3(the_env->stepper, form, delta);
329 }
330
331 #define SETUP_ENV(the_env) { ihs.lex_env = closure; }
332
333 /*
334 * INTERPRET-FUNCALL is one of the few ways to "exit" the interpreted
335 * environment and get into the C/lisp world. Since almost all data
336 * from the interpreter is kept in local variables, and frame stacks,
337 * binding stacks, etc, are already handled by the C core, only the
338 * lexical environment needs to be saved.
339 */
340
341 #define INTERPRET_FUNCALL(reg0, the_env, frame, narg, fun) { \
342 cl_index __n = narg; \
343 cl_index __b = ECL_STACK_INDEX(the_env) - __n; \
344 SETUP_ENV(the_env); \
345 frame.opened = 1; \
346 frame.base = __b; \
347 frame.size = __n; \
348 frame.sp = __b; \
349 reg0 = ecl_apply_from_stack_frame((cl_object)&frame, fun); \
350 ecl_stack_frame_close((cl_object)&frame); }
351
352 /* -------------------- THE INTERPRETER -------------------- */
353
354 cl_object
355 ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes)
356 {
357 ECL_OFFSET_TABLE;
358 const cl_env_ptr the_env = frame->frame.env;
359 volatile cl_index frame_index = 0;
360 cl_opcode *vector = (cl_opcode*)bytecodes->bytecodes.code;
361 cl_object lex_env = closure, lcl_env = ECL_NIL;
362 cl_object dat_env = bytecodes->bytecodes.data;
363 cl_object *data = Null(dat_env) ? NULL : dat_env->vector.self.t;
364 cl_object reg0 = ECL_NIL, reg1 = ECL_NIL;
365 cl_index narg = 0;
366 cl_index nlcl = ecl_fixnum(bytecodes->bytecodes.nlcl);
367 struct ecl_stack_frame frame_aux;
368 struct ecl_stack_frame frame_lcl;
369 volatile struct ecl_ihs_frame ihs;
370
371 /* INV: bytecodes is of type t_bytecodes */
372 lcl_env = ecl_cast_ptr(cl_object, &frame_lcl);
373 ecl_cs_check(the_env, ihs);
374 ecl_ihs_push(the_env, &ihs, bytecodes, closure);
375 ecl_stack_frame_open(the_env, lcl_env, nlcl);
376 frame_aux.t = t_frame;
377 frame_aux.opened = 0;
378 frame_aux.base = 0;
379 frame_aux.size = 0;
380 frame_aux.sp = 0;
381 frame_aux.env = the_env;
382 BEGIN_SWITCH {
383 CASE(OP_NOP); {
384 reg0 = ECL_NIL;
385 the_env->nvalues = 0;
386 THREAD_NEXT;
387 }
388 /* OP_QUOTE
389 Sets REG0 to an immediate value.
390 */
391 CASE(OP_QUOTE); {
392 GET_DATA(reg0, vector, data);
393 THREAD_NEXT;
394 }
395 /* OP_VAR n{lcl}
396 OP_VARC n{lex}
397 OP_VARS n{dat}
398 Sets REG0 to the value of the n-th variable's value.
399 */
400 CASE(OP_VAR); {
401 cl_fixnum ndx;
402 GET_OPARG(ndx, vector);
403 reg0 = ecl_lcl_env_get_var(lcl_env, ndx);
404 THREAD_NEXT;
405 }
406 CASE(OP_VARC); {
407 cl_fixnum ndx;
408 GET_OPARG(ndx, vector);
409 reg0 = ecl_lex_env_get_var(lex_env, ndx);
410 THREAD_NEXT;
411 }
412 CASE(OP_VARS); {
413 cl_object var_name;
414 GET_DATA(var_name, vector, data);
415 reg0 = ECL_SYM_VAL(the_env, var_name);
416 if (ecl_unlikely(reg0 == OBJNULL))
417 VEunbound_variable(var_name);
418 THREAD_NEXT;
419 }
420
421 /* OP_CONS, OP_CAR, OP_CDR, etc
422 Inlined forms for some functions which act on reg0 and stack.
423 */
424 CASE(OP_CONS); {
425 cl_object car = ECL_STACK_POP_UNSAFE(the_env);
426 reg0 = CONS(car, reg0);
427 THREAD_NEXT;
428 }
429
430 CASE(OP_CAR); {
431 if (ecl_unlikely(!LISTP(reg0)))
432 VEwrong_arg_type_car(reg0);
433 reg0 = CAR(reg0);
434 THREAD_NEXT;
435 }
436
437 CASE(OP_CDR); {
438 if (ecl_unlikely(!LISTP(reg0)))
439 VEwrong_arg_type_cdr(reg0);
440 reg0 = CDR(reg0);
441 THREAD_NEXT;
442 }
443
444 CASE(OP_LIST);
445 reg0 = ecl_list1(reg0);
446
447 CASE(OP_LISTA); {
448 cl_index n;
449 GET_OPARG(n, vector);
450 while (--n) {
451 reg0 = CONS(ECL_STACK_POP_UNSAFE(the_env), reg0);
452 }
453 THREAD_NEXT;
454 }
455
456 /* OP_CONS_CAR and OP_CONS_CDR
457 (Unsafe) primops that act on reg0 and stack.
458 */
459 CASE(OP_CONS_CAR); {
460 reg0 = ECL_CONS_CAR(reg0);
461 THREAD_NEXT;
462 }
463
464 CASE(OP_CONS_CDR); {
465 reg0 = ECL_CONS_CDR(reg0);
466 THREAD_NEXT;
467 }
468
469 CASE(OP_INT); {
470 cl_fixnum n;
471 GET_OPARG(n, vector);
472 reg0 = ecl_make_fixnum(n);
473 THREAD_NEXT;
474 }
475
476 CASE(OP_PINT); {
477 cl_fixnum n;
478 GET_OPARG(n, vector);
479 ECL_STACK_PUSH(the_env, ecl_make_fixnum(n));
480 THREAD_NEXT;
481 }
482
483 /* OP_PUSH
484 Pushes the object in REG0.
485 */
486 CASE(OP_PUSH); {
487 ECL_STACK_PUSH(the_env, reg0);
488 THREAD_NEXT;
489 }
490 /* OP_PUSHV n{lcl}
491 OP_PUSHVC n{lex}
492 OP_PUSHVS n{dat}
493 Pushes the value of the n-th variable onto the stack.
494 */
495 CASE(OP_PUSHV); {
496 int ndx;
497 GET_OPARG(ndx, vector);
498 ECL_STACK_PUSH(the_env, ecl_lcl_env_get_var(lcl_env, ndx));
499 THREAD_NEXT;
500 }
501 CASE(OP_PUSHVC); {
502 int ndx;
503 GET_OPARG(ndx, vector);
504 ECL_STACK_PUSH(the_env, ecl_lex_env_get_var(lex_env, ndx));
505 THREAD_NEXT;
506 }
507 CASE(OP_PUSHVS); {
508 cl_object var_name, value;
509 GET_DATA(var_name, vector, data);
510 value = ECL_SYM_VAL(the_env, var_name);
511 if (ecl_unlikely(value == OBJNULL))
512 VEunbound_variable(var_name);
513 ECL_STACK_PUSH(the_env, value);
514 THREAD_NEXT;
515 }
516 /* OP_PUSHQ n{arg}
517 Pushes n-th constant onto the stack.
518 */
519 CASE(OP_PUSHQ); {
520 cl_object aux;
521 GET_DATA(aux, vector, data);
522 ECL_STACK_PUSH(the_env, aux);
523 THREAD_NEXT;
524 }
525
526 CASE(OP_CALLG1); {
527 cl_object s;
528 cl_objectfn f;
529 GET_DATA(s, vector, data);
530 the_env->function = ECL_SYM_FUN(s);
531 f = ECL_SYM_FUN(s)->cfun.entry;
532 SETUP_ENV(the_env);
533 reg0 = f(1, reg0);
534 THREAD_NEXT;
535 }
536
537 CASE(OP_CALLG2); {
538 cl_object s;
539 cl_objectfn f;
540 GET_DATA(s, vector, data);
541 the_env->function = ECL_SYM_FUN(s);
542 f = ECL_SYM_FUN(s)->cfun.entry;
543 SETUP_ENV(the_env);
544 reg0 = f(2, ECL_STACK_POP_UNSAFE(the_env), reg0);
545 THREAD_NEXT;
546 }
547
548 /* OP_CALL n{arg}
549 Calls the function in REG0 with N arguments which
550 have been deposited in the stack. The first output value
551 is pushed on the stack.
552 */
553 CASE(OP_CALL); {
554 GET_OPARG(narg, vector);
555 INTERPRET_FUNCALL(reg0, the_env, frame_aux, narg, reg0);
556 THREAD_NEXT;
557 }
558
559 /* OP_CALLG n{arg}, name{arg}
560 Calls the function NAME with N arguments which have been
561 deposited in the stack. The first output value is pushed on
562 the stack.
563 */
564 CASE(OP_CALLG); {
565 GET_OPARG(narg, vector);
566 GET_DATA(reg0, vector, data);
567 INTERPRET_FUNCALL(reg0, the_env, frame_aux, narg, reg0);
568 THREAD_NEXT;
569 }
570
571 /* OP_FCALL n{arg}
572 Calls a function in the stack with N arguments which
573 have been also deposited in the stack. The output values
574 are left in VALUES(...)
575 */
576 CASE(OP_FCALL); {
577 GET_OPARG(narg, vector);
578 reg0 = ECL_STACK_REF(the_env,-narg-1);
579 INTERPRET_FUNCALL(reg0, the_env, frame_aux, narg, reg0);
580 THREAD_NEXT;
581 }
582
583 /* OP_MCALL
584 Similar to FCALL, but gets the number of arguments from
585 the stack (They all have been deposited by OP_PUSHVALUES)
586 */
587 CASE(OP_MCALL); {
588 narg = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env));
589 reg0 = ECL_STACK_REF(the_env,-narg-1);
590 INTERPRET_FUNCALL(reg0, the_env, frame_aux, narg, reg0);
591 THREAD_NEXT;
592 }
593
594 /* OP_POP
595 Pops a single value pushed by a OP_PUSH* operator.
596 */
597 CASE(OP_POP); {
598 reg0 = ECL_STACK_POP_UNSAFE(the_env);
599 THREAD_NEXT;
600 }
601 /* OP_POP1
602 Pops a single value pushed by a OP_PUSH* operator, ignoring it.
603 */
604 CASE(OP_POP1); {
605 (void)ECL_STACK_POP_UNSAFE(the_env);
606 THREAD_NEXT;
607 }
608 /* OP_POPREQ
609 Checks the arguments list.
610 If there are remaining arguments, REG0 = ARG, otherwise signal an error.
611 */
612 CASE(OP_POPREQ); {
613 if (ecl_unlikely(frame_index >= frame->frame.size)) {
614 VEwrong_num_arguments(bytecodes->bytecodes.name);
615 }
616 reg0 = ECL_STACK_FRAME_REF(frame, frame_index++);
617 THREAD_NEXT;
618 }
619 /* OP_POPOPT
620 Checks the arguments list.
621 If there are remaining arguments, REG0 = T and the value is on the stack,
622 otherwise REG0 = NIL.
623 */
624 CASE(OP_POPOPT); {
625 if (frame_index >= frame->frame.size) {
626 reg0 = ECL_NIL;
627 } else {
628 ECL_STACK_PUSH(the_env, ECL_STACK_FRAME_REF(frame, frame_index++));
629 reg0 = ECL_T;
630 }
631 THREAD_NEXT;
632 }
633 /* OP_NOMORE
634 Asserts that there are no more arguments in the frame.
635 */
636 CASE(OP_NOMORE); {
637 if (ecl_unlikely(frame_index < frame->frame.size))
638 VEbad_lambda_too_many_args(bytecodes, frame);
639 THREAD_NEXT;
640 }
641 /* OP_POPREST
642 Makes a list out of the remaining arguments.
643 */
644 CASE(OP_POPREST); {
645 cl_object *first = ECL_STACK_FRAME_PTR(frame) + frame_index;
646 cl_object *last = ECL_STACK_FRAME_PTR(frame) + frame->frame.size;
647 for (reg0 = ECL_NIL; last > first; ) {
648 reg0 = CONS(*(--last), reg0);
649 }
650 THREAD_NEXT;
651 }
652 /* OP_PUSHKEYS {names-list}
653 Checks the stack frame for keyword arguments.
654 */
655 CASE(OP_PUSHKEYS); {
656 cl_object keys_list, aok, *ptr, *end;
657 cl_index count, limit;
658 GET_DATA(keys_list, vector, data);
659 limit = count = frame->frame.size - frame_index;
660 if (ecl_unlikely(count & 1)) {
661 VEbad_lambda_odd_keys(bytecodes, frame);
662 }
663 aok = ECL_CONS_CAR(keys_list);
664 for (; (keys_list = ECL_CONS_CDR(keys_list), !Null(keys_list)); ) {
665 cl_object name = ECL_CONS_CAR(keys_list);
666 cl_object flag = ECL_NIL;
667 cl_object value = ECL_NIL;
668 ptr = ECL_STACK_FRAME_PTR(frame) + frame_index;
669 end = ptr + limit;
670 for (; ptr != end; ptr++) {
671 if (*(ptr++) == name) {
672 count -= 2;
673 if (flag == ECL_NIL) {
674 flag = ECL_T;
675 value = *ptr;
676 }
677 }
678 }
679 /* Pushing to the stack may resize it, so be careful to reinitialize
680 pointers using the new value of ECL_STACK_FRAME_PTR. */
681 if (flag != ECL_NIL) ECL_STACK_PUSH(the_env, value);
682 ECL_STACK_PUSH(the_env, flag);
683 }
684 if (count && Null(aok)) {
685 ptr = ECL_STACK_FRAME_PTR(frame) + frame_index;
686 end = ptr + limit;
687 for (; ptr != end; ptr++) {
688 if (*(ptr++) == @':allow-other-keys') {
689 aok = *ptr;
690 count -= 2;
691 /* only the first :allow-other-keys argument is considered */
692 for (ptr++; ptr != end; ptr++) {
693 if (*(ptr++) != @':allow-other-keys')
694 break;
695 count -= 2;
696 }
697 break;
698 }
699 }
700 if (ecl_likely(count && Null(aok))) {
701 VEbad_lambda_unknown_keyword(bytecodes, frame);
702 }
703 }
704 THREAD_NEXT;
705 }
706 /* OP_EXIT
707 Marks the end of a high level construct (BLOCK, CATCH...)
708 or a function.
709 */
710 CASE(OP_EXIT); {
711 ecl_ihs_pop(the_env);
712 ecl_stack_frame_close(lcl_env);
713 return reg0;
714 }
715 /* OP_FLET nfun{arg}, fun1{object}
716 ...
717 OP_UNBIND nfun
718
719 Executes the enclosed code in a lexical enviroment extended with
720 the functions "fun1" ... "funn". Note that we only record the
721 index of the first function: the others are after this one.
722 Note that nfun > 0.
723 */
724 CASE(OP_FLET); {
725 int idx, nfun;
726 cl_object fun;
727 GET_OPARG(nfun, vector);
728 /* Create closures. */
729 for(idx = 0; idx<nfun; idx++) {
730 GET_DATA(fun, vector, data);
731 fun = ecl_close_around(fun, lcl_env, lex_env);
732 push_lcl(lcl_env, fun);
733 }
734 THREAD_NEXT;
735 }
736 /* OP_LABELS nfun{arg}
737 fun1{object}
738 ...
739 funn{object}
740 ...
741 OP_UNBIND n
742
743 Executes the enclosed code in a lexical enviroment extended with
744 the functions "fun1" ... "funn".
745 */
746 CASE(OP_LABELS); {
747 cl_index idx, nfun;
748 cl_object fun;
749 cl_object *sp = ECL_STACK_FRAME_TOP(lcl_env);
750 GET_OPARG(nfun, vector);
751 /* Create closures. */
752 for(idx = 0; idx<nfun; idx++) {
753 GET_DATA(fun, vector, data);
754 fun = close_around_self(fun);
755 push_lcl(lcl_env, fun);
756 }
757 for(idx = 0; idx<nfun; idx++) {
758 fun = *sp++;
759 close_around_self_fixup(fun, lcl_env, lex_env);
760 }
761 THREAD_NEXT;
762 }
763 /* OP_LFUNCTION index{fixnum} ; local
764 OP_CFUNCTION index{fixnum} ; cfb
765
766 Extracts a local function denoted by the index from the environment.
767 */
768 CASE(OP_LFUNCTION); {
769 int ndx;
770 GET_OPARG(ndx, vector);
771 reg0 = ecl_lcl_env_get_fun(lcl_env, ndx);
772 THREAD_NEXT;
773 }
774 CASE(OP_CFUNCTION); {
775 int ndx;
776 GET_OPARG(ndx, vector);
777 reg0 = ecl_lex_env_get_fun(lex_env, ndx);
778 THREAD_NEXT;
779 }
780
781 /* OP_FUNCTION name{function-name}
782
783 Extracts a function associated with the name. The function is defined in
784 the global environment. Local function are handled by OP_LFUNCTION and
785 lambdas are handled by OP_QUOTE and OP_CLOSE.
786 */
787 CASE(OP_FUNCTION); {
788 GET_DATA(reg0, vector, data);
789 reg0 = _ecl_global_function_definition(reg0);
790 THREAD_NEXT;
791 }
792
793 /* OP_CLOSE fun{object}
794
795 Creates a closure around objects referenced in the current lexical
796 environment. Objects may be part of parent locals or its closure.
797 */
798 CASE(OP_CLOSE); {
799 cl_object fun;
800 GET_DATA(fun, vector, data);
801 reg0 = ecl_close_around(fun, lcl_env, lex_env);
802 THREAD_NEXT;
803 }
804
805 /* OP_GO n{arg}, tag-ndx{arg}
806 OP_GO_CFB n{lex}, tag-ndx{arg}
807
808 Jumps to the tag which is defined for the tagbody
809 frame registered at the n-th position in the lexical
810 environment. TAG-NDX is the number of tag in the list.
811 */
812 CASE(OP_GO); {
813 cl_index ndx;
814 cl_fixnum tag_ndx;
815 cl_object record;
816 GET_OPARG(ndx, vector);
817 GET_OPARG(tag_ndx, vector);
818 record = ecl_lcl_env_get_tag(lcl_env, ndx);
819 /* record = (id . ???) */
820 cl_go(ECL_CONS_CAR(record), ecl_make_fixnum(tag_ndx));
821 THREAD_NEXT;
822 }
823 CASE(OP_GO_CFB); {
824 cl_fixnum ndx, tag_ndx;
825 cl_object record;
826 GET_OPARG(ndx, vector);
827 GET_OPARG(tag_ndx, vector);
828 record = ecl_lex_env_get_tag(lex_env, ndx);
829 /* record = (id . ???) */
830 cl_go(ECL_CONS_CAR(record), ecl_make_fixnum(tag_ndx));
831 THREAD_NEXT;
832 }
833 /* OP_RETURN n{arg}
834 OP_RETURN_CFB n{lex}
835
836 Returns from the block whose record in the environment occuppies the n-th
837 position.
838 */
839 CASE(OP_RETURN); {
840 int ndx;
841 cl_object record;
842 GET_OPARG(ndx, vector);
843 /* record = (id . name) */
844 record = ecl_lcl_env_get_blk(lcl_env, ndx);
845 the_env->values[0] = reg0;
846 cl_return_from(ECL_CONS_CAR(record), ECL_CONS_CDR(record));
847 THREAD_NEXT;
848 }
849 CASE(OP_RETURN_CFB); {
850 int ndx;
851 cl_object record;
852 GET_OPARG(ndx, vector);
853 /* record = (id . name) */
854 record = ecl_lex_env_get_blk(lex_env, ndx);
855 the_env->values[0] = reg0;
856 cl_return_from(ECL_CONS_CAR(record), ECL_CONS_CDR(record));
857 THREAD_NEXT;
858 }
859 /* OP_THROW
860 Jumps to an enclosing CATCH form whose tag matches the one
861 of the THROW. The tag is taken from the stack, while the
862 output values are left in VALUES(...).
863 */
864 CASE(OP_THROW); {
865 cl_object tag_name = ECL_STACK_POP_UNSAFE(the_env);
866 the_env->values[0] = reg0;
867 cl_throw(tag_name);
868 THREAD_NEXT;
869 }
870 /* OP_JMP label{arg}
871 OP_JNIL label{arg}
872 OP_JT label{arg}
873 OP_JEQ value{object}, label{arg}
874 OP_JNEQ value{object}, label{arg}
875 Direct or conditional jumps. The conditional jumps are made
876 comparing with the value of REG0.
877 */
878 CASE(OP_JMP); {
879 cl_oparg jump;
880 GET_OPARG(jump, vector);
881 vector += jump - OPARG_SIZE;
882 THREAD_NEXT;
883 }
884 CASE(OP_JNIL); {
885 cl_oparg jump;
886 GET_OPARG(jump, vector);
887 if (Null(reg0))
888 vector += jump - OPARG_SIZE;
889 THREAD_NEXT;
890 }
891 CASE(OP_JT); {
892 cl_oparg jump;
893 GET_OPARG(jump, vector);
894 if (!Null(reg0))
895 vector += jump - OPARG_SIZE;
896 THREAD_NEXT;
897 }
898 CASE(OP_JEQL); {
899 cl_oparg value, jump;
900 GET_OPARG(value, vector);
901 GET_OPARG(jump, vector);
902 if (ecl_eql(reg0, data[value]))
903 vector += jump - OPARG_SIZE;
904 THREAD_NEXT;
905 }
906 CASE(OP_JNEQL); {
907 cl_oparg value, jump;
908 GET_OPARG(value, vector);
909 GET_OPARG(jump, vector);
910 if (!ecl_eql(reg0, data[value]))
911 vector += jump - OPARG_SIZE;
912 THREAD_NEXT;
913 }
914
915 CASE(OP_ENDP);
916 if (ecl_unlikely(!LISTP(reg0)))
917 VEwrong_arg_type_endp(reg0);
918 CASE(OP_NOT); {
919 reg0 = (reg0 == ECL_NIL)? ECL_T : ECL_NIL;
920 THREAD_NEXT;
921 }
922
923 /* OP_UNBIND n{arg}
924 Undo "n" local bindings.
925 */
926 CASE(OP_UNBIND); {
927 cl_oparg n;
928 GET_OPARG(n, vector);
929 unbind_lcl(lcl_env, n);
930 THREAD_NEXT;
931 }
932 /* OP_UNBINDS n{arg}
933 Undo "n" bindings of special variables.
934 */
935 CASE(OP_UNBINDS); {
936 cl_oparg n;
937 GET_OPARG(n, vector);
938 ecl_bds_unwind_n(the_env, n);
939 THREAD_NEXT;
940 }
941 /* OP_BIND name{symbol}
942 OP_PBIND name{symbol}
943 OP_VBIND nvalue{arg}, name{symbol}
944 OP_BINDS name{symbol}
945 OP_PBINDS name{symbol}
946 OP_VBINDS nvalue{arg}, name{symbol}
947 Binds a lexical or special variable to the the
948 value of REG0, the first value of the stack (PBIND) or
949 to a given value in the values array.
950 */
951 CASE(OP_BIND); {
952 cl_object var_name;
953 GET_DATA(var_name, vector, data);
954 bind_var(lcl_env, var_name, reg0);
955 THREAD_NEXT;
956 }
957 CASE(OP_PBIND); {
958 cl_object var_name;
959 GET_DATA(var_name, vector, data);
960 bind_var(lcl_env, var_name, ECL_STACK_POP_UNSAFE(the_env));
961 THREAD_NEXT;
962 }
963 CASE(OP_VBIND); {
964 cl_index n;
965 cl_object var_name;
966 GET_OPARG(n, vector);
967 GET_DATA(var_name, vector, data);
968 bind_var(lcl_env, var_name,
969 (n < the_env->nvalues) ? the_env->values[n] : ECL_NIL);
970 THREAD_NEXT;
971 }
972 CASE(OP_BINDS); {
973 cl_object var_name;
974 GET_DATA(var_name, vector, data);
975 ecl_bds_bind(the_env, var_name, reg0);
976 THREAD_NEXT;
977 }
978 CASE(OP_PBINDS); {
979 cl_object var_name;
980 GET_DATA(var_name, vector, data);
981 ecl_bds_bind(the_env, var_name, ECL_STACK_POP_UNSAFE(the_env));
982 THREAD_NEXT;
983 }
984 CASE(OP_VBINDS); {
985 cl_index n;
986 cl_object var_name;
987 GET_OPARG(n, vector);
988 GET_DATA(var_name, vector, data);
989 ecl_bds_bind(the_env, var_name,
990 (n < the_env->nvalues) ? the_env->values[n] : ECL_NIL);
991 THREAD_NEXT;
992 }
993 /* OP_SETQ n{lcl}
994 OP_SETQC n{lex}
995 OP_SETQS n{dat}
996
997 OP_PSETQ n{lcl}
998 OP_PSETQC n{lex}
999 OP_PSETQS n{dat}
1000
1001 OP_VSETQ n{lcl}, nvalue{arg}
1002 OP_VSETQC n{lex}, nvalue{arg}
1003 OP_VSETQS n{dat}, nvalue{arg}
1004
1005 Sets either the n-th variable to either the value in REG0 (OP_SETQ[CS])
1006 or to the first value on the stack (OP_PSETQ[CS]), or to a given value
1007 from the multiple values array (OP_VSETQ[CS]). Note NVALUE > 0 strictly.
1008 */
1009 CASE(OP_SETQ); {
1010 int ndx;
1011 GET_OPARG(ndx, vector);
1012 ecl_lcl_env_set_var(lcl_env, ndx, reg0);
1013 THREAD_NEXT;
1014 }
1015 CASE(OP_SETQC); {
1016 int ndx;
1017 GET_OPARG(ndx, vector);
1018 ecl_lex_env_set_var(lex_env, ndx, reg0);
1019 THREAD_NEXT;
1020 }
1021 CASE(OP_SETQS); {
1022 cl_object var;
1023 GET_DATA(var, vector, data);
1024 /* INV: Not NIL, and of type t_symbol */
1025 if (ecl_unlikely(var->symbol.stype & ecl_stp_constant))
1026 VEassignment_to_constant(var);
1027 ECL_SETQ(the_env, var, reg0);
1028 THREAD_NEXT;
1029 }
1030 CASE(OP_PSETQ); {
1031 int ndx;
1032 GET_OPARG(ndx, vector);
1033 ecl_lcl_env_set_var(lcl_env, ndx, ECL_STACK_POP_UNSAFE(the_env));
1034 THREAD_NEXT;
1035 }
1036 CASE(OP_PSETQC); {
1037 int ndx;
1038 GET_OPARG(ndx, vector);
1039 ecl_lex_env_set_var(lex_env, ndx, ECL_STACK_POP_UNSAFE(the_env));
1040 THREAD_NEXT;
1041 }
1042 CASE(OP_PSETQS); {
1043 cl_object var;
1044 GET_DATA(var, vector, data);
1045 /* INV: Not NIL, and of type t_symbol */
1046 ECL_SETQ(the_env, var, ECL_STACK_POP_UNSAFE(the_env));
1047 THREAD_NEXT;
1048 }
1049 CASE(OP_VSETQ); {
1050 cl_index ndx;
1051 cl_oparg index;
1052 cl_object value;
1053 GET_OPARG(ndx, vector);
1054 GET_OPARG(index, vector);
1055 value = (index >= the_env->nvalues)
1056 ? ECL_NIL
1057 : the_env->values[index];
1058 ecl_lcl_env_set_var(lcl_env, ndx, value);
1059 THREAD_NEXT;
1060 }
1061 CASE(OP_VSETQC); {
1062 cl_index ndx;
1063 cl_oparg index;
1064 cl_object value;
1065 GET_OPARG(ndx, vector);
1066 GET_OPARG(index, vector);
1067 value = (index >= the_env->nvalues)
1068 ? ECL_NIL
1069 : the_env->values[index];
1070 ecl_lex_env_set_var(lex_env, ndx, value);
1071 THREAD_NEXT;
1072 }
1073 CASE(OP_VSETQS); {
1074 cl_object var, v;
1075 cl_oparg index;
1076 GET_DATA(var, vector, data);
1077 GET_OPARG(index, vector);
1078 v = (index >= the_env->nvalues)? ECL_NIL : the_env->values[index];
1079 ECL_SETQ(the_env, var, v);
1080 THREAD_NEXT;
1081 }
1082
1083 /* OP_BLOCK constant
1084 OP_DO
1085 OP_CATCH
1086
1087 OP_FRAME label{arg}
1088 ...
1089 OP_EXIT_FRAME
1090 label:
1091 */
1092
1093 CASE(OP_BLOCK); {
1094 GET_DATA(reg0, vector, data);
1095 reg1 = ecl_make_fixnum(the_env->frs_stack.frame_id++);
1096 bind_frame(lcl_env, reg1, reg0);
1097 THREAD_NEXT;
1098 }
1099 CASE(OP_DO); {
1100 reg0 = ECL_NIL;
1101 reg1 = ecl_make_fixnum(the_env->frs_stack.frame_id++);
1102 bind_frame(lcl_env, reg1, reg0);
1103 THREAD_NEXT;
1104 }
1105 CASE(OP_CATCH); {
1106 reg1 = reg0;
1107 bind_frame(lcl_env, reg1, reg0);
1108 THREAD_NEXT;
1109 }
1110 CASE(OP_FRAME); {
1111 cl_opcode *exit;
1112 GET_LABEL(exit, vector);
1113 ECL_STACK_PUSH(the_env, tangle_lcl(lcl_env));
1114 ECL_STACK_PUSH(the_env, (cl_object)exit);
1115 ecl_frs_push(the_env,reg1);
1116 if (__ecl_frs_push_result != 0) {
1117 reg0 = the_env->values[0];
1118 vector = (cl_opcode *)ECL_STACK_REF(the_env,-1); /* FIXME! */
1119 /* Unbind locals including the frame, we are leaving the frame. */
1120 unwind_lcl(lcl_env, ECL_STACK_REF(the_env, -2));
1121 unbind_lcl(lcl_env, 1); /* unbind the frame */
1122 goto DO_EXIT_FRAME;
1123 }
1124 THREAD_NEXT;
1125 }
1126 /* OP_FRAMEID 0
1127 OP_TAGBODY n{arg}
1128 label1
1129 ...
1130 labeln
1131 label1:
1132 ...
1133 labeln:
1134 ...
1135 OP_EXIT_TAGBODY
1136
1137 High level construct for the TAGBODY form.
1138 */
1139 CASE(OP_TAGBODY); {
1140 int n;
1141 GET_OPARG(n, vector);
1142 ECL_STACK_PUSH(the_env, tangle_lcl(lcl_env));
1143 ECL_STACK_PUSH(the_env, (cl_object)vector); /* FIXME! */
1144 vector += n * OPARG_SIZE;
1145 ecl_frs_push(the_env,reg1);
1146 if (__ecl_frs_push_result != 0) {
1147 /* Wait here for gotos. Each goto sets VALUES(0) to an integer which
1148 ranges from 0 to ntags-1, depending on the tag. These numbers are
1149 indices into the jump table and are computed at compile time. */
1150 cl_opcode *table = (cl_opcode *)ECL_STACK_REF(the_env,-1);
1151 /* Unbind locals but leave the frame, we are still inside the frame. */
1152 unwind_lcl(lcl_env, ECL_STACK_REF(the_env,-2));
1153 table = table + ecl_fixnum(the_env->values[0]) * OPARG_SIZE;
1154 vector = table + *(cl_oparg *)table;
1155 }
1156 THREAD_NEXT;
1157 }
1158 CASE(OP_EXIT_TAGBODY); {
1159 reg0 = ECL_NIL;
1160 }
1161 CASE(OP_EXIT_FRAME); {
1162 DO_EXIT_FRAME:
1163 ecl_frs_pop(the_env);
1164 ECL_STACK_POP_N_UNSAFE(the_env, 2);
1165 THREAD_NEXT;
1166 }
1167 CASE(OP_NIL); {
1168 reg0 = ECL_NIL;
1169 THREAD_NEXT;
1170 }
1171 CASE(OP_PUSHNIL); {
1172 ECL_STACK_PUSH(the_env, ECL_NIL);
1173 THREAD_NEXT;
1174 }
1175 CASE(OP_VALUEREG0); {
1176 the_env->nvalues = 1;
1177 THREAD_NEXT;
1178 }
1179
1180 /* OP_PUSHVALUES
1181 Pushes the values output by the last form, plus the number
1182 of values.
1183 */
1184 PUSH_VALUES:
1185 CASE(OP_PUSHVALUES); {
1186 cl_index i = the_env->nvalues;
1187 ECL_STACK_PUSH_N(the_env, i+1);
1188 the_env->values[0] = reg0;
1189 memcpy(&ECL_STACK_REF(the_env, -(i+1)), the_env->values, i * sizeof(cl_object));
1190 ECL_STACK_REF(the_env, -1) = ecl_make_fixnum(the_env->nvalues);
1191 THREAD_NEXT;
1192 }
1193 /* OP_PUSHMOREVALUES
1194 Adds more values to the ones pushed by OP_PUSHVALUES.
1195 */
1196 CASE(OP_PUSHMOREVALUES); {
1197 cl_index n = ecl_fixnum(ECL_STACK_REF(the_env,-1));
1198 cl_index i = the_env->nvalues;
1199 ECL_STACK_PUSH_N(the_env, i);
1200 the_env->values[0] = reg0;
1201 memcpy(&ECL_STACK_REF(the_env, -(i+1)), the_env->values, i * sizeof(cl_object));
1202 ECL_STACK_REF(the_env, -1) = ecl_make_fixnum(n + i);
1203 THREAD_NEXT;
1204 }
1205 /* OP_POPVALUES
1206 Pops all values pushed by a OP_PUSHVALUES operator.
1207 */
1208 CASE(OP_POPVALUES); {
1209 cl_object *dest = the_env->values;
1210 int n = the_env->nvalues = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env));
1211 if (n == 0) {
1212 *dest = reg0 = ECL_NIL;
1213 THREAD_NEXT;
1214 } else if (n == 1) {
1215 *dest = reg0 = ECL_STACK_POP_UNSAFE(the_env);
1216 THREAD_NEXT;
1217 } else {
1218 ECL_STACK_POP_N_UNSAFE(the_env,n);
1219 memcpy(dest, &ECL_STACK_REF(the_env,0), n * sizeof(cl_object));
1220 reg0 = *dest;
1221 THREAD_NEXT;
1222 }
1223 }
1224 /* OP_VALUES n{arg}
1225 Pop N values from the stack and store them in VALUES(...)
1226 Note that N is strictly > 0.
1227 */
1228 CASE(OP_VALUES); {
1229 cl_fixnum n;
1230 GET_OPARG(n, vector);
1231 the_env->nvalues = n;
1232 ECL_STACK_POP_N_UNSAFE(the_env, n);
1233 memcpy(the_env->values, &ECL_STACK_REF(the_env, 0), n * sizeof(cl_object));
1234 reg0 = the_env->values[0];
1235 THREAD_NEXT;
1236 }
1237 /* OP_NTHVAL
1238 Set VALUES(0) to the N-th value of the VALUES(...) list.
1239 The index N-th is extracted from the top of the stack.
1240 */
1241 CASE(OP_NTHVAL); {
1242 cl_fixnum n = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env));
1243 if (ecl_unlikely(n < 0)) {
1244 VEwrong_arg_type_nth_val(n);
1245 } else if ((cl_index)n >= the_env->nvalues) {
1246 reg0 = ECL_NIL;
1247 } else if (n) {
1248 reg0 = the_env->values[n];
1249 }
1250 THREAD_NEXT;
1251 }
1252 /* OP_PROTECT label
1253 ... ; code to be protected and whose value is output
1254 OP_PROTECT_NORMAL
1255 label:
1256 ... ; code executed at exit
1257 OP_PROTECT_EXIT
1258
1259 High level construct for UNWIND-PROTECT. The first piece of code is
1260 executed and its output value is saved. Then the second piece of code
1261 is executed and the output values restored. The second piece of code
1262 is always executed, even if a THROW, RETURN or GO happen within the
1263 first piece of code.
1264 */
1265 CASE(OP_PROTECT); {
1266 cl_opcode *exit;
1267 GET_LABEL(exit, vector);
1268 ECL_STACK_PUSH(the_env, tangle_lcl(lcl_env));
1269 ECL_STACK_PUSH(the_env, (cl_object)exit);
1270 ecl_frs_push(the_env,ECL_PROTECT_TAG);
1271 if (__ecl_frs_push_result != 0) {
1272 ecl_frs_pop(the_env);
1273 vector = (cl_opcode *)ECL_STACK_POP_UNSAFE(the_env);
1274 unwind_lcl(lcl_env, ECL_STACK_POP_UNSAFE(the_env));
1275 reg0 = the_env->values[0];
1276 ECL_STACK_PUSH(the_env, ecl_make_fixnum(the_env->frs_stack.nlj_fr - the_env->frs_stack.top));
1277 goto PUSH_VALUES;
1278 }
1279 THREAD_NEXT;
1280 }
1281 CASE(OP_PROTECT_NORMAL); {
1282 ecl_bds_unwind(the_env, the_env->frs_stack.top->frs_bds_ndx);
1283 ecl_frs_pop(the_env);
1284 (void)ECL_STACK_POP_UNSAFE(the_env);
1285 unwind_lcl(lcl_env, ECL_STACK_POP_UNSAFE(the_env));
1286 ECL_STACK_PUSH(the_env, ecl_make_fixnum(1));
1287 goto PUSH_VALUES;
1288 }
1289 CASE(OP_PROTECT_EXIT); {
1290 volatile cl_fixnum n = the_env->nvalues = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env));
1291 while (n--)
1292 the_env->values[n] = ECL_STACK_POP_UNSAFE(the_env);
1293 reg0 = the_env->values[0];
1294 n = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env));
1295 if (n <= 0)
1296 ecl_unwind(the_env, the_env->frs_stack.top + n);
1297 THREAD_NEXT;
1298 }
1299
1300 /* OP_PROGV bindings{list}
1301 ...
1302 OP_EXIT
1303 Execute the code enclosed with the special variables in BINDINGS
1304 set to the values in the list which was passed in VALUES(0).
1305 */
1306 CASE(OP_PROGV); {
1307 cl_object values = reg0;
1308 cl_object vars = ECL_STACK_POP_UNSAFE(the_env);
1309 cl_index n = ecl_progv(the_env, vars, values);
1310 ECL_STACK_PUSH(the_env, ecl_make_fixnum(n));
1311 THREAD_NEXT;
1312 }
1313 CASE(OP_EXIT_PROGV); {
1314 cl_index n = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env));
1315 ecl_bds_unwind(the_env, n);
1316 THREAD_NEXT;
1317 }
1318 CASE(OP_CSET); {
1319 cl_object *p;
1320 GET_DATA_PTR(p, vector, data);
1321 *p = reg0;
1322 THREAD_NEXT;
1323 }
1324
1325 CASE(OP_STEPIN); {
1326 cl_object form;
1327 cl_index n;
1328 GET_DATA(form, vector, data);
1329 SETUP_ENV(the_env);
1330 the_env->values[0] = reg0;
1331 n = ecl_data_stack_push_values(the_env);
1332 call_stepper(the_env, form, ecl_make_fixnum(1));
1333 ecl_data_stack_pop_values(the_env, n);
1334 reg0 = the_env->values[0];
1335 THREAD_NEXT;
1336 }
1337 CASE(OP_STEPCALL); {
1338 /* We are going to call a function. However, we would
1339 * like to step _in_ the function. STEPPER takes care of
1340 * that. */
1341 cl_fixnum n;
1342 GET_OPARG(n, vector);
1343 SETUP_ENV(the_env);
1344 reg0 = call_stepper(the_env, reg0, ecl_make_fixnum(0));
1345 INTERPRET_FUNCALL(reg0, the_env, frame_aux, n, reg0);
1346 }
1347 CASE(OP_STEPOUT); {
1348 cl_index n;
1349 SETUP_ENV(the_env);
1350 the_env->values[0] = reg0;
1351 n = ecl_data_stack_push_values(the_env);
1352 call_stepper(the_env, ECL_NIL, ecl_make_fixnum(-1));
1353 ecl_data_stack_pop_values(the_env, n);
1354 reg0 = the_env->values[0];
1355 THREAD_NEXT;
1356 }
1357 }
1358 }
1359
1360 cl_object
1361 si_interpreter_stack ()
1362 {
1363 cl_env_ptr env = ecl_process_env();
1364 ecl_return1(env, ECL_NIL);
1365 }