* options.h, options.c: Options now have documentation strings.
[bpt/guile.git] / libguile / eval.c
CommitLineData
0f2d19dd
JB
1/* Copyright (C) 1995,1996 Free Software Foundation, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16 *
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
19 *
20 * The exception is that, if you link the GUILE library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking the GUILE library code into it.
25 *
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
28 *
29 * This exception applies only to the code released by the
30 * Free Software Foundation under the name GUILE. If you copy
31 * code from other Free Software Foundation releases into a copy of
32 * GUILE, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from them.
36 *
37 * If you write modifications of your own for GUILE, it is your choice
38 * whether to permit this exception to apply to your modifications.
39 * If you do not wish that, delete this exception notice.
40 */
41\f
42
6dbd0af5
MD
43/* This file is read twice in order to produce debugging versions of
44 * scm_ceval and scm_apply. These functions, scm_deval and
45 * scm_dapply, are produced when we define the preprocessor macro
46 * DEVAL. The file is divided into sections which are treated
47 * differently with respect to DEVAL. The heads of these sections are
48 * marked with the string "SECTION:".
49 */
50
51
52/* SECTION: This code is compiled once.
0f2d19dd
JB
53 */
54
55#ifndef DEVAL
56
57#include <stdio.h>
58#include "_scm.h"
59
60\f
61
6dbd0af5
MD
62/* The evaluator contains a plethora of EVAL symbols.
63 * This is an attempt at explanation.
64 *
65 * The following macros should be used in code which is read twice
66 * (where the choice of evaluator is hard soldered):
67 *
68 * SCM_CEVAL is the symbol used within one evaluator to call itself.
69 * Originally, it is defined to scm_ceval, but is redefined to
70 * scm_deval during the second pass.
71 *
72 * SIDEVAL corresponds to SCM_CEVAL, but is used in situations where
73 * only side effects of expressions matter. All immediates are
74 * ignored.
75 *
76 * EVALIM is used when it is known that the expression is an
77 * immediate. (This macro never calls an evaluator.)
78 *
79 * EVALCAR evaluates the car of an expression.
80 *
81 * EVALCELLCAR is like EVALCAR, but is used when it is known that the
82 * car is a lisp cell.
83 *
84 * The following macros should be used in code which is read once
85 * (where the choice of evaluator is dynamic):
86 *
87 * XEVAL takes care of immediates without calling an evaluator. It
88 * then calls scm_ceval *or* scm_deval, depending on the debugging
89 * mode.
90 *
91 * XEVALCAR corresponds to EVALCAR, but uses scm_ceval *or* scm_deval
92 * depending on the debugging mode.
93 *
94 * The main motivation for keeping this plethora is efficiency
95 * together with maintainability (=> locality of code).
96 */
97
0f2d19dd
JB
98#define EVALCELLCAR(x, env) (SCM_SYMBOLP (SCM_CAR(x)) \
99 ? *scm_lookupcar(x, env) \
100 : SCM_CEVAL(SCM_CAR(x), env))
101
102#ifdef MEMOIZE_LOCALS
6dbd0af5 103#define EVALIM(x, env) (SCM_ILOCP(x)?*scm_ilookup((x), env):x)
0f2d19dd 104#else
6dbd0af5 105#define EVALIM(x, env) x
0f2d19dd
JB
106#endif
107#define EVALCAR(x, env) (SCM_NCELLP(SCM_CAR(x))\
108 ? (SCM_IMP(SCM_CAR(x)) \
6dbd0af5 109 ? EVALIM(SCM_CAR(x), env) \
0f2d19dd
JB
110 : SCM_GLOC_VAL(SCM_CAR(x))) \
111 : EVALCELLCAR(x, env))
112#ifdef DEBUG_EXTENSIONS
113#define XEVALCAR(x, env) (SCM_NCELLP(SCM_CAR(x)) \
114 ? (SCM_IMP(SCM_CAR(x)) \
6dbd0af5 115 ? EVALIM(SCM_CAR(x), env) \
0f2d19dd
JB
116 : SCM_GLOC_VAL(SCM_CAR(x))) \
117 : (SCM_SYMBOLP(SCM_CAR(x)) \
118 ? *scm_lookupcar(x, env) \
119 : (*scm_ceval_ptr) (SCM_CAR(x), env)))
120#else
121#define XEVALCAR(x, env) EVALCAR(x, env)
122#endif
123
124#define EXTEND_SCM_ENV SCM_EXTEND_SCM_ENV
125
126#ifdef MEMOIZE_LOCALS
127#ifdef __STDC__
128SCM *
129scm_ilookup (SCM iloc, SCM env)
130#else
131SCM *
132scm_ilookup (iloc, env)
133 SCM iloc;
134 SCM env;
135#endif
136{
137 register int ir = SCM_IFRAME (iloc);
138 register SCM er = env;
139 for (; 0 != ir; --ir)
140 er = SCM_CDR (er);
141 er = SCM_CAR (er);
142 for (ir = SCM_IDIST (iloc); 0 != ir; --ir)
143 er = SCM_CDR (er);
144 if (SCM_ICDRP (iloc))
145 return &SCM_CDR (er);
146 return &SCM_CAR (SCM_CDR (er));
147}
148#endif
149
150#ifdef __STDC__
151SCM *
152scm_lookupcar (SCM vloc, SCM genv)
153#else
154SCM *
155scm_lookupcar (vloc, genv)
156 SCM vloc;
157 SCM genv;
158#endif
159{
160 SCM env = genv;
161 register SCM *al, fl, var = SCM_CAR (vloc);
162#ifdef MEMOIZE_LOCALS
163 register SCM iloc = SCM_ILOC00;
164#endif
165 for (; SCM_NIMP (env); env = SCM_CDR (env))
166 {
167 if (SCM_BOOL_T == scm_procedure_p (SCM_CAR (env)))
168 break;
169 al = &SCM_CAR (env);
170 for (fl = SCM_CAR (*al); SCM_NIMP (fl); fl = SCM_CDR (fl))
171 {
172 if (SCM_NCONSP (fl))
173 if (fl == var)
174 {
175#ifdef MEMOIZE_LOCALS
176 SCM_CAR (vloc) = iloc + SCM_ICDR;
177#endif
178 return &SCM_CDR (*al);
179 }
180 else
181 break;
182 al = &SCM_CDR (*al);
183 if (SCM_CAR (fl) == var)
184 {
185#ifdef MEMOIZE_LOCALS
186#ifndef RECKLESS /* letrec inits to SCM_UNDEFINED */
187 if (SCM_UNBNDP (SCM_CAR (*al)))
188 {
189 env = SCM_EOL;
190 goto errout;
191 }
192#endif
193 SCM_CAR (vloc) = iloc;
194#endif
195 return &SCM_CAR (*al);
196 }
197#ifdef MEMOIZE_LOCALS
198 iloc += SCM_IDINC;
199#endif
200 }
201#ifdef MEMOIZE_LOCALS
202 iloc = (~SCM_IDSTMSK) & (iloc + SCM_IFRINC);
203#endif
204 }
205 {
206 SCM top_thunk, vcell;
207 if (SCM_NIMP(env))
208 {
209 top_thunk = SCM_CAR(env); /* env now refers to a top level env thunk */
210 env = SCM_CDR (env);
211 }
212 else
213 top_thunk = SCM_BOOL_F;
214 vcell = scm_sym2vcell (var, top_thunk, SCM_BOOL_F);
215 if (vcell == SCM_BOOL_F)
216 goto errout;
217 else
218 var = vcell;
219 }
220#ifndef RECKLESS
221 if (SCM_NNULLP (env) || SCM_UNBNDP (SCM_CDR (var)))
222 {
223 var = SCM_CAR (var);
224 errout:
225 scm_everr (vloc, genv, var,
226 (SCM_NULLP (env)
227 ? "unbound variable: "
228 : "damaged environment"),
229 "");
230 }
231#endif
232 SCM_CAR (vloc) = var + 1;
233 /* Except wait...what if the var is not a vcell,
234 * but syntax or something....
235 */
236 return &SCM_CDR (var);
237}
238
239#define unmemocar scm_unmemocar
240#ifdef __STDC__
241SCM
242scm_unmemocar (SCM form, SCM env)
243#else
244SCM
245scm_unmemocar (form, env)
246 SCM form;
247 SCM env;
248#endif
249{
6dbd0af5 250#ifdef DEBUG_EXTENSIONS
0f2d19dd 251 register int ir;
6dbd0af5 252#endif
0f2d19dd
JB
253 SCM c;
254
255 if (SCM_IMP (form))
256 return form;
257 c = SCM_CAR (form);
258 if (1 == (c & 7))
259 SCM_CAR (form) = SCM_CAR (c - 1);
260#ifdef MEMOIZE_LOCALS
6dbd0af5 261#ifdef DEBUG_EXTENSIONS
0f2d19dd
JB
262 else if (SCM_ILOCP (c))
263 {
264 for (ir = SCM_IFRAME (c); ir != 0; --ir)
265 env = SCM_CDR (env);
266 env = SCM_CAR (SCM_CAR (env));
267 for (ir = SCM_IDIST (c); ir != 0; --ir)
268 env = SCM_CDR (env);
269 SCM_CAR (form) = SCM_ICDRP (c) ? env : SCM_CAR (env);
270 }
6dbd0af5 271#endif
0f2d19dd
JB
272#endif
273 return form;
274}
275
276#ifdef __STDC__
277SCM
278scm_eval_car (SCM pair, SCM env)
279#else
280SCM
281scm_eval_car (pair, env)
282 SCM pair;
283 SCM env;
284#endif
285{
6dbd0af5 286 return XEVALCAR (pair, env);
0f2d19dd
JB
287}
288
289\f
290/*
291 * The following rewrite expressions and
292 * some memoized forms have different syntax
293 */
294
295static char s_expression[] = "missing or extra expression";
296static char s_test[] = "bad test";
297static char s_body[] = "bad body";
298static char s_bindings[] = "bad bindings";
299static char s_variable[] = "bad variable";
300static char s_clauses[] = "bad or missing clauses";
301static char s_formals[] = "bad formals";
302#define ASSYNT(_cond, _arg, _pos, _subr) if(!(_cond))scm_wta(_arg, (char *)_pos, _subr);
303
304SCM scm_i_dot, scm_i_quote, scm_i_quasiquote, scm_i_lambda, scm_i_let,
305 scm_i_arrow, scm_i_else, scm_i_unquote, scm_i_uq_splicing, scm_i_apply;
306SCM scm_i_name;
6dbd0af5
MD
307SCM scm_i_define, scm_i_and, scm_i_begin, scm_i_case, scm_i_cond,
308 scm_i_do, scm_i_if, scm_i_let, scm_i_letrec, scm_i_letstar,
309 scm_i_or, scm_i_set, scm_i_atapply, scm_i_atcall_cc;
0f2d19dd
JB
310static char s_quasiquote[] = "quasiquote";
311static char s_delay[] = "delay";
6dbd0af5
MD
312static char s_undefine[] = "undefine";
313#ifdef DEBUG_EXTENSIONS
314SCM scm_i_enter_frame, scm_i_apply_frame, scm_i_exit_frame;
315SCM scm_i_trace;
316#endif
0f2d19dd
JB
317
318#define ASRTSYNTAX(cond_, msg_) if(!(cond_))scm_wta(xorig, (msg_), what);
319
320
321#ifdef __STDC__
322static void
323bodycheck (SCM xorig, SCM *bodyloc, char *what)
324#else
325static void
326bodycheck (xorig, bodyloc, what)
327 SCM xorig;
328 SCM *bodyloc;
329 char *what;
330#endif
331{
332 ASRTSYNTAX (scm_ilength (*bodyloc) >= 1, s_expression);
333}
334
335
336#ifdef __STDC__
337SCM
338scm_m_quote (SCM xorig, SCM env)
339#else
340SCM
341scm_m_quote (xorig, env)
342 SCM xorig;
343 SCM env;
344#endif
345{
346 ASSYNT (scm_ilength (SCM_CDR (xorig)) == 1, xorig, s_expression, "quote");
347 return scm_cons (SCM_IM_QUOTE, SCM_CDR (xorig));
348}
349
350
351#ifdef __STDC__
352SCM
353scm_m_begin (SCM xorig, SCM env)
354#else
355SCM
356scm_m_begin (xorig, env)
357 SCM xorig;
358 SCM env;
359#endif
360{
361 ASSYNT (scm_ilength (SCM_CDR (xorig)) >= 1, xorig, s_expression, "begin");
362 return scm_cons (SCM_IM_BEGIN, SCM_CDR (xorig));
363}
364
365
366#ifdef __STDC__
367SCM
368scm_m_if (SCM xorig, SCM env)
369#else
370SCM
371scm_m_if (xorig, env)
372 SCM xorig;
373 SCM env;
374#endif
375{
376 int len = scm_ilength (SCM_CDR (xorig));
377 ASSYNT (len >= 2 && len <= 3, xorig, s_expression, "if");
378 return scm_cons (SCM_IM_IF, SCM_CDR (xorig));
379}
380
381
382#ifdef __STDC__
383SCM
384scm_m_set (SCM xorig, SCM env)
385#else
386SCM
387scm_m_set (xorig, env)
388 SCM xorig;
389 SCM env;
390#endif
391{
6dbd0af5
MD
392 SCM x = SCM_CDR (xorig);
393 ASSYNT (2 == scm_ilength (x), xorig, s_expression, "set!");
394 ASSYNT (SCM_NIMP (SCM_CAR (x)) && SCM_SYMBOLP (SCM_CAR (x)),
395 xorig, s_variable, "set!");
0f2d19dd
JB
396 return scm_cons (SCM_IM_SET, x);
397}
398
399
400#if 0
401#ifdef __STDC__
402SCM
403scm_m_vref (SCM xorig, SCM env)
404#else
405SCM
406scm_m_vref (xorig, env)
407 SCM xorig;
408 SCM env;
409#endif
410{
411 SCM x = SCM_CDR (xorig);
412 ASSYNT (1 == scm_ilength (x), xorig, s_expression, s_vref);
413 if (SCM_NIMP(x) && UDSCM_VARIABLEP (SCM_CAR (x)))
414 {
415 scm_everr (SCM_UNDEFINED, env, SCM_CAR(SCM_CDR(x)), s_variable,
416 "global variable reference");
417 }
418 ASSYNT (SCM_NIMP(x) && DEFSCM_VARIABLEP (SCM_CAR (x)),
419 xorig, s_variable, s_vref);
420 return
421 return scm_cons (IM_VREF, x);
422}
423
424
425#ifdef __STDC__
426SCM
427scm_m_vset (SCM xorig, SCM env)
428#else
429SCM
430scm_m_vset (xorig, env)
431 SCM xorig;
432 SCM env;
433#endif
434{
435 SCM x = SCM_CDR (xorig);
436 ASSYNT (3 == scm_ilength (x), xorig, s_expression, s_vset);
437 ASSYNT (( DEFSCM_VARIABLEP (SCM_CAR (x))
438 || UDSCM_VARIABLEP (SCM_CAR (x))),
439 xorig, s_variable, s_vset);
440 return scm_cons (IM_VSET, x);
441}
442#endif
443
444
445#ifdef __STDC__
446SCM
447scm_m_and (SCM xorig, SCM env)
448#else
449SCM
450scm_m_and (xorig, env)
451 SCM xorig;
452 SCM env;
453#endif
454{
455 int len = scm_ilength (SCM_CDR (xorig));
456 ASSYNT (len >= 0, xorig, s_test, "and");
457 if (len >= 1)
458 return scm_cons (SCM_IM_AND, SCM_CDR (xorig));
459 else
460 return SCM_BOOL_T;
461}
462
463
464#ifdef __STDC__
465SCM
466scm_m_or (SCM xorig, SCM env)
467#else
468SCM
469scm_m_or (xorig, env)
470 SCM xorig;
471 SCM env;
472#endif
473{
474 int len = scm_ilength (SCM_CDR (xorig));
475 ASSYNT (len >= 0, xorig, s_test, "or");
476 if (len >= 1)
477 return scm_cons (SCM_IM_OR, SCM_CDR (xorig));
478 else
479 return SCM_BOOL_F;
480}
481
482
483#ifdef __STDC__
484SCM
485scm_m_case (SCM xorig, SCM env)
486#else
487SCM
488scm_m_case (xorig, env)
489 SCM xorig;
490 SCM env;
491#endif
492{
493 SCM proc, x = SCM_CDR (xorig);
494 ASSYNT (scm_ilength (x) >= 2, xorig, s_clauses, "case");
495 while (SCM_NIMP (x = SCM_CDR (x)))
496 {
497 proc = SCM_CAR (x);
498 ASSYNT (scm_ilength (proc) >= 2, xorig, s_clauses, "case");
499 ASSYNT (scm_ilength (SCM_CAR (proc)) >= 0 || scm_i_else == SCM_CAR (proc),
500 xorig, s_clauses, "case");
501 }
502 return scm_cons (SCM_IM_CASE, SCM_CDR (xorig));
503}
504
505
506#ifdef __STDC__
507SCM
508scm_m_cond (SCM xorig, SCM env)
509#else
510SCM
511scm_m_cond (xorig, env)
512 SCM xorig;
513 SCM env;
514#endif
515{
516 SCM arg1, x = SCM_CDR (xorig);
517 int len = scm_ilength (x);
518 ASSYNT (len >= 1, xorig, s_clauses, "cond");
519 while (SCM_NIMP (x))
520 {
521 arg1 = SCM_CAR (x);
522 len = scm_ilength (arg1);
523 ASSYNT (len >= 1, xorig, s_clauses, "cond");
524 if (scm_i_else == SCM_CAR (arg1))
525 {
526 ASSYNT (SCM_NULLP (SCM_CDR (x)) && len >= 2, xorig, "bad ELSE clause", "cond");
527 SCM_CAR (arg1) = SCM_BOOL_T;
528 }
529 if (len >= 2 && scm_i_arrow == SCM_CAR (SCM_CDR (arg1)))
530 ASSYNT (3 == len && SCM_NIMP (SCM_CAR (SCM_CDR (SCM_CDR (arg1)))),
531 xorig, "bad recipient", "cond");
532 x = SCM_CDR (x);
533 }
534 return scm_cons (SCM_IM_COND, SCM_CDR (xorig));
535}
536
537
538#ifdef __STDC__
539SCM
540scm_m_lambda (SCM xorig, SCM env)
541#else
542SCM
543scm_m_lambda (xorig, env)
544 SCM xorig;
545 SCM env;
546#endif
547{
548 SCM proc, x = SCM_CDR (xorig);
549 if (scm_ilength (x) < 2)
550 goto badforms;
551 proc = SCM_CAR (x);
552 if SCM_NULLP
553 (proc) goto memlambda;
554 if SCM_IMP
555 (proc) goto badforms;
556 if SCM_SYMBOLP
557 (proc) goto memlambda;
558 if SCM_NCONSP
559 (proc) goto badforms;
560 while SCM_NIMP
561 (proc)
562 {
563 if SCM_NCONSP
564 (proc)
565 if (!SCM_SYMBOLP (proc))
566 goto badforms;
567 else
568 goto memlambda;
569 if (!(SCM_NIMP (SCM_CAR (proc)) && SCM_SYMBOLP (SCM_CAR (proc))))
570 goto badforms;
571 proc = SCM_CDR (proc);
572 }
573 if SCM_NNULLP
574 (proc)
575 badforms:scm_wta (xorig, s_formals, "lambda");
576memlambda:
577 bodycheck (xorig, &SCM_CDR (x), "lambda");
578 return scm_cons (SCM_IM_LAMBDA, SCM_CDR (xorig));
579}
580
581
582#ifdef __STDC__
583SCM
584scm_m_letstar (SCM xorig, SCM env)
585#else
586SCM
587scm_m_letstar (xorig, env)
588 SCM xorig;
589 SCM env;
590#endif
591{
592 SCM x = SCM_CDR (xorig), arg1, proc, vars = SCM_EOL, *varloc = &vars;
593 int len = scm_ilength (x);
594 ASSYNT (len >= 2, xorig, s_body, "let*");
595 proc = SCM_CAR (x);
596 ASSYNT (scm_ilength (proc) >= 0, xorig, s_bindings, "let*");
6dbd0af5 597 while SCM_NIMP (proc)
0f2d19dd
JB
598 {
599 arg1 = SCM_CAR (proc);
600 ASSYNT (2 == scm_ilength (arg1), xorig, s_bindings, "let*");
601 ASSYNT (SCM_NIMP (SCM_CAR (arg1)) && SCM_SYMBOLP (SCM_CAR (arg1)), xorig, s_variable, "let*");
602 *varloc = scm_cons2 (SCM_CAR (arg1), SCM_CAR (SCM_CDR (arg1)), SCM_EOL);
603 varloc = &SCM_CDR (SCM_CDR (*varloc));
604 proc = SCM_CDR (proc);
605 }
606 x = scm_cons (vars, SCM_CDR (x));
607 bodycheck (xorig, &SCM_CDR (x), "let*");
608 return scm_cons (SCM_IM_LETSTAR, x);
609}
610
611/* DO gets the most radically altered syntax
612 (do ((<var1> <init1> <step1>)
613 (<var2> <init2>)
614 ... )
615 (<test> <return>)
616 <body>)
617 ;; becomes
618 (do_mem (varn ... var2 var1)
619 (<init1> <init2> ... <initn>)
620 (<test> <return>)
621 (<body>)
622 <step1> <step2> ... <stepn>) ;; missing steps replaced by var
623 */
624
625
626#ifdef __STDC__
627SCM
628scm_m_do (SCM xorig, SCM env)
629#else
630SCM
631scm_m_do (xorig, env)
632 SCM xorig;
633 SCM env;
634#endif
635{
636 SCM x = SCM_CDR (xorig), arg1, proc;
637 SCM vars = SCM_EOL, inits = SCM_EOL, steps = SCM_EOL;
638 SCM *initloc = &inits, *steploc = &steps;
639 int len = scm_ilength (x);
640 ASSYNT (len >= 2, xorig, s_test, "do");
641 proc = SCM_CAR (x);
642 ASSYNT (scm_ilength (proc) >= 0, xorig, s_bindings, "do");
643 while SCM_NIMP
644 (proc)
645 {
646 arg1 = SCM_CAR (proc);
647 len = scm_ilength (arg1);
648 ASSYNT (2 == len || 3 == len, xorig, s_bindings, "do");
649 ASSYNT (SCM_NIMP (SCM_CAR (arg1)) && SCM_SYMBOLP (SCM_CAR (arg1)), xorig, s_variable, "do");
650 /* vars reversed here, inits and steps reversed at evaluation */
651 vars = scm_cons (SCM_CAR (arg1), vars); /* variable */
652 arg1 = SCM_CDR (arg1);
653 *initloc = scm_cons (SCM_CAR (arg1), SCM_EOL); /* init */
654 initloc = &SCM_CDR (*initloc);
655 arg1 = SCM_CDR (arg1);
656 *steploc = scm_cons (SCM_IMP (arg1) ? SCM_CAR (vars) : SCM_CAR (arg1), SCM_EOL); /* step */
657 steploc = &SCM_CDR (*steploc);
658 proc = SCM_CDR (proc);
659 }
660 x = SCM_CDR (x);
661 ASSYNT (scm_ilength (SCM_CAR (x)) >= 1, xorig, s_test, "do");
662 x = scm_cons2 (SCM_CAR (x), SCM_CDR (x), steps);
663 x = scm_cons2 (vars, inits, x);
664 bodycheck (xorig, &SCM_CAR (SCM_CDR (SCM_CDR (x))), "do");
665 return scm_cons (SCM_IM_DO, x);
666}
667
6dbd0af5
MD
668/* evalcar is small version of inline EVALCAR when we don't care about
669 * speed
670 */
671#define evalcar scm_eval_car
0f2d19dd
JB
672
673#ifdef __STDC__
674static SCM
675iqq (SCM form, SCM env, int depth)
676#else
677static SCM
678iqq (form, env, depth)
679 SCM form;
680 SCM env;
681 int depth;
682#endif
683{
684 SCM tmp;
685 int edepth = depth;
686 if SCM_IMP
687 (form) return form;
688 if (SCM_VECTORP (form))
689 {
690 long i = SCM_LENGTH (form);
691 SCM *data = SCM_VELTS (form);
692 tmp = SCM_EOL;
693 for (; --i >= 0;)
694 tmp = scm_cons (data[i], tmp);
695 return scm_vector (iqq (tmp, env, depth));
696 }
697 if SCM_NCONSP
698 (form) return form;
699 tmp = SCM_CAR (form);
700 if (scm_i_quasiquote == tmp)
701 {
702 depth++;
703 goto label;
704 }
705 if (scm_i_unquote == tmp)
706 {
707 --depth;
708 label:
709 form = SCM_CDR (form);
710 /* !!! might need a check here to be sure that form isn't a struct. */
711 SCM_ASSERT (SCM_NIMP (form) && SCM_ECONSP (form) && SCM_NULLP (SCM_CDR (form)),
712 form, SCM_ARG1, s_quasiquote);
713 if (0 == depth)
714 return evalcar (form, env);
715 return scm_cons2 (tmp, iqq (SCM_CAR (form), env, depth), SCM_EOL);
716 }
717 if (SCM_NIMP (tmp) && (scm_i_uq_splicing == SCM_CAR (tmp)))
718 {
719 tmp = SCM_CDR (tmp);
720 if (0 == --edepth)
721 return scm_append (scm_cons2 (evalcar (tmp, env), iqq (SCM_CDR (form), env, depth), SCM_EOL));
722 }
723 return scm_cons (iqq (SCM_CAR (form), env, edepth), iqq (SCM_CDR (form), env, depth));
724}
725
726/* Here are acros which return values rather than code. */
727
728#ifdef __STDC__
729SCM
730scm_m_quasiquote (SCM xorig, SCM env)
731#else
732SCM
733scm_m_quasiquote (xorig, env)
734 SCM xorig;
735 SCM env;
736#endif
737{
738 SCM x = SCM_CDR (xorig);
739 ASSYNT (scm_ilength (x) == 1, xorig, s_expression, s_quasiquote);
740 return iqq (SCM_CAR (x), env, 1);
741}
742
743#ifdef __STDC__
744SCM
745scm_m_delay (SCM xorig, SCM env)
746#else
747SCM
748scm_m_delay (xorig, env)
749 SCM xorig;
750 SCM env;
751#endif
752{
753 ASSYNT (scm_ilength (xorig) == 2, xorig, s_expression, s_delay);
754 xorig = SCM_CDR (xorig);
755 return scm_makprom (scm_closure (scm_cons2 (SCM_EOL, SCM_CAR (xorig), SCM_CDR (xorig)),
756 env));
757}
758
759#ifdef __STDC__
760static SCM
761env_top_level (SCM env)
762#else
763static SCM
764env_top_level (env)
765 SCM env;
766#endif
767{
768 while (SCM_NIMP(env))
769 {
770 if (SCM_BOOL_T == scm_procedure_p (SCM_CAR(env)))
771 return SCM_CAR(env);
772 env = SCM_CDR (env);
773 }
774 return SCM_BOOL_F;
775}
776
777#ifdef __STDC__
778SCM
779scm_m_define (SCM x, SCM env)
780#else
781SCM
782scm_m_define (x, env)
783 SCM x;
784 SCM env;
785#endif
786{
787 SCM proc, arg1 = x;
788 x = SCM_CDR (x);
789 /* ASSYNT(SCM_NULLP(env), x, "bad placement", s_define);*/
790 ASSYNT (scm_ilength (x) >= 2, arg1, s_expression, "define");
791 proc = SCM_CAR (x);
792 x = SCM_CDR (x);
793 while (SCM_NIMP (proc) && SCM_CONSP (proc))
794 { /* nested define syntax */
795 x = scm_cons (scm_cons2 (scm_i_lambda, SCM_CDR (proc), x), SCM_EOL);
796 proc = SCM_CAR (proc);
797 }
798 ASSYNT (SCM_NIMP (proc) && SCM_SYMBOLP (proc), arg1, s_variable, "define");
799 ASSYNT (1 == scm_ilength (x), arg1, s_expression, "define");
800 if (SCM_TOP_LEVEL (env))
801 {
802 x = evalcar (x, env);
6dbd0af5
MD
803#ifdef DEBUG_EXTENSIONS
804 if (RECORD_PROCNAMES && SCM_NIMP (x) && SCM_CLOSUREP (x))
805 scm_set_procedure_property_x (x, scm_i_name, proc);
806#endif
0f2d19dd
JB
807 arg1 = scm_sym2vcell (proc, env_top_level (env), SCM_BOOL_T);
808#if 0
809#ifndef RECKLESS
810 if (SCM_NIMP (SCM_CDR (arg1)) && ((SCM) SCM_SNAME (SCM_CDR (arg1)) == proc)
811 && (SCM_CDR (arg1) != x))
812 scm_warn ("redefining built-in ", SCM_CHARS (proc));
813 else
814#endif
815 if (5 <= scm_verbose && SCM_UNDEFINED != SCM_CDR (arg1))
816 scm_warn ("redefining ", SCM_CHARS (proc));
0f2d19dd
JB
817#endif
818 SCM_CDR (arg1) = x;
819#ifdef SICP
820 return scm_cons2 (scm_i_quote, SCM_CAR (arg1), SCM_EOL);
821#else
822 return SCM_UNSPECIFIED;
823#endif
824 }
825 return scm_cons2 (SCM_IM_DEFINE, proc, x);
826}
6dbd0af5
MD
827
828SCM
829scm_m_undefine (x, env)
830 SCM x, env;
831{
832 SCM arg1 = x;
833 x = SCM_CDR (x);
834 ASSYNT (SCM_TOP_LEVEL (env), arg1, "bad placement ", s_undefine);
835 ASSYNT (SCM_NIMP (x) && SCM_CONSP (x) && SCM_CDR (x) == SCM_EOL,
836 arg1, s_expression, s_undefine);
837 x = SCM_CAR (x);
838 ASSYNT (SCM_NIMP (x) && SCM_SYMBOLP (x), arg1, s_variable, s_undefine);
839 arg1 = scm_sym2vcell (x, env_top_level (env), SCM_BOOL_F);
840 ASSYNT (SCM_NFALSEP (arg1) && !SCM_UNBNDP (SCM_CDR (arg1)),
841 x, "variable already unbound ", s_undefine);
842#if 0
843#ifndef RECKLESS
844 if (SCM_NIMP (SCM_CDR (arg1)) && ((SCM) SCM_SNAME (SCM_CDR (arg1)) == x))
845 scm_warn ("undefining built-in ", SCM_CHARS (x));
846 else
847#endif
848 if (5 <= scm_verbose && SCM_UNDEFINED != SCM_CDR (arg1))
849 scm_warn ("redefining ", SCM_CHARS (x));
850#endif
851 SCM_CDR (arg1) = SCM_UNDEFINED;
852#ifdef SICP
853 return SCM_CAR (arg1);
854#else
855 return SCM_UNSPECIFIED;
856#endif
857}
858
0f2d19dd
JB
859/* end of acros */
860
861#ifdef __STDC__
862SCM
863scm_m_letrec (SCM xorig, SCM env)
864#else
865SCM
866scm_m_letrec (xorig, env)
867 SCM xorig;
868 SCM env;
869#endif
870{
871 SCM cdrx = SCM_CDR (xorig); /* locally mutable version of form */
872 char *what = SCM_CHARS (SCM_CAR (xorig));
873 SCM x = cdrx, proc, arg1; /* structure traversers */
874 SCM vars = SCM_EOL, inits = SCM_EOL, *initloc = &inits;
875
876 ASRTSYNTAX (scm_ilength (x) >= 2, s_body);
877 proc = SCM_CAR (x);
878 if SCM_NULLP
879 (proc) return scm_m_letstar (xorig, env); /* null binding, let* faster */
880 ASRTSYNTAX (scm_ilength (proc) >= 1, s_bindings);
881 do
882 {
883 /* vars scm_list reversed here, inits reversed at evaluation */
884 arg1 = SCM_CAR (proc);
885 ASRTSYNTAX (2 == scm_ilength (arg1), s_bindings);
886 ASRTSYNTAX (SCM_NIMP (SCM_CAR (arg1)) && SCM_SYMBOLP (SCM_CAR (arg1)), s_variable);
887 vars = scm_cons (SCM_CAR (arg1), vars);
888 *initloc = scm_cons (SCM_CAR (SCM_CDR (arg1)), SCM_EOL);
889 initloc = &SCM_CDR (*initloc);
890 }
891 while SCM_NIMP
892 (proc = SCM_CDR (proc));
893 cdrx = scm_cons2 (vars, inits, SCM_CDR (x));
894 bodycheck (xorig, &SCM_CDR (SCM_CDR (cdrx)), what);
895 return scm_cons (SCM_IM_LETREC, cdrx);
896}
897
898#ifdef __STDC__
899SCM
900scm_m_let (SCM xorig, SCM env)
901#else
902SCM
903scm_m_let (xorig, env)
904 SCM xorig;
905 SCM env;
906#endif
907{
908 SCM cdrx = SCM_CDR (xorig); /* locally mutable version of form */
909 SCM x = cdrx, proc, arg1, name; /* structure traversers */
910 SCM vars = SCM_EOL, inits = SCM_EOL, *varloc = &vars, *initloc = &inits;
911
912 ASSYNT (scm_ilength (x) >= 2, xorig, s_body, "let");
913 proc = SCM_CAR (x);
914 if (SCM_NULLP (proc)
915 || (SCM_NIMP (proc) && SCM_CONSP (proc)
916 && SCM_NIMP (SCM_CAR (proc)) && SCM_CONSP (SCM_CAR (proc)) && SCM_NULLP (SCM_CDR (proc))))
917 return scm_m_letstar (xorig, env); /* null or single binding, let* is faster */
918 ASSYNT (SCM_NIMP (proc), xorig, s_bindings, "let");
919 if (SCM_CONSP (proc)) /* plain let, proc is <bindings> */
920 return scm_cons (SCM_IM_LET, SCM_CDR (scm_m_letrec (xorig, env)));
921 if (!SCM_SYMBOLP (proc))
922 scm_wta (xorig, s_bindings, "let"); /* bad let */
923 name = proc; /* named let, build equiv letrec */
924 x = SCM_CDR (x);
925 ASSYNT (scm_ilength (x) >= 2, xorig, s_body, "let");
926 proc = SCM_CAR (x); /* bindings scm_list */
927 ASSYNT (scm_ilength (proc) >= 0, xorig, s_bindings, "let");
928 while SCM_NIMP
929 (proc)
930 { /* vars and inits both in order */
931 arg1 = SCM_CAR (proc);
932 ASSYNT (2 == scm_ilength (arg1), xorig, s_bindings, "let");
933 ASSYNT (SCM_NIMP (SCM_CAR (arg1)) && SCM_SYMBOLP (SCM_CAR (arg1)), xorig, s_variable, "let");
934 *varloc = scm_cons (SCM_CAR (arg1), SCM_EOL);
935 varloc = &SCM_CDR (*varloc);
936 *initloc = scm_cons (SCM_CAR (SCM_CDR (arg1)), SCM_EOL);
937 initloc = &SCM_CDR (*initloc);
938 proc = SCM_CDR (proc);
939 }
940 return
941 scm_m_letrec (scm_cons2 (scm_i_let,
942 scm_cons (scm_cons2 (name, scm_cons2 (scm_i_lambda, vars, SCM_CDR (x)), SCM_EOL), SCM_EOL),
943 scm_acons (name, inits, SCM_EOL)), /* body */
944 env);
945}
946
947
948#ifdef __STDC__
949SCM
950scm_m_apply (SCM xorig, SCM env)
951#else
952SCM
953scm_m_apply (xorig, env)
954 SCM xorig;
955 SCM env;
956#endif
957{
958 ASSYNT (scm_ilength (SCM_CDR (xorig)) == 2, xorig, s_expression, "@apply");
959 return scm_cons (SCM_IM_APPLY, SCM_CDR (xorig));
960}
961
962#define s_atcall_cc (SCM_ISYMSCM_CHARS(SCM_IM_CONT)+1)
963
964#ifdef __STDC__
965SCM
966scm_m_cont (SCM xorig, SCM env)
967#else
968SCM
969scm_m_cont (xorig, env)
970 SCM xorig;
971 SCM env;
972#endif
973{
974 ASSYNT (scm_ilength (SCM_CDR (xorig)) == 1, xorig, s_expression, "@call-with-current-continuation");
975 return scm_cons (SCM_IM_CONT, SCM_CDR (xorig));
976}
977
6dbd0af5
MD
978/* scm_unmemocopy takes a memoized expression together with its
979 * environment and rewrites it to its original form. Thus, it is the
980 * inversion of the rewrite rules above. The procedure is not
981 * optimized for speed. It's used in scm_iprin1 when printing the
982 * code of a closure, in scm_procedure_source and in scm_expr_stack
983 * when generating the source for a stackframe.
984 */
985
986#ifdef __STDC__
987static SCM
988unmemocopy (SCM x, SCM env)
989#else
990static SCM
991unmemocopy (x, env)
992 SCM x;
993 SCM env;
994#endif
995{
996 SCM ls, z;
997#ifdef DEBUG_EXTENSIONS
998 SCM p;
999#endif
1000 if (SCM_NCELLP (x) || SCM_NECONSP (x))
1001 return x;
1002#ifdef DEBUG_EXTENSIONS
1003 p = scm_whash_lookup (scm_source_whash, x);
1004#endif
1005 switch (SCM_TYP7 (x))
1006 {
1007 case (127 & SCM_IM_AND):
1008 ls = z = scm_cons (scm_i_and, SCM_UNSPECIFIED);
1009 break;
1010 case (127 & SCM_IM_BEGIN):
1011 ls = z = scm_cons (scm_i_begin, SCM_UNSPECIFIED);
1012 break;
1013 case (127 & SCM_IM_CASE):
1014 ls = z = scm_cons (scm_i_case, SCM_UNSPECIFIED);
1015 break;
1016 case (127 & SCM_IM_COND):
1017 ls = z = scm_cons (scm_i_cond, SCM_UNSPECIFIED);
1018 break;
1019 case (127 & SCM_IM_DO):
1020 ls = scm_cons (scm_i_do, SCM_UNSPECIFIED);
1021 goto transform;
1022 case (127 & SCM_IM_IF):
1023 ls = z = scm_cons (scm_i_if, SCM_UNSPECIFIED);
1024 break;
1025 case (127 & SCM_IM_LET):
1026 ls = scm_cons (scm_i_let, SCM_UNSPECIFIED);
1027 goto transform;
1028 case (127 & SCM_IM_LETREC):
1029 {
1030 SCM f, v, e, s;
1031 ls = scm_cons (scm_i_letrec, SCM_UNSPECIFIED);
1032 transform:
1033 x = SCM_CDR (x);
1034 f = v = SCM_CAR (x);
1035 x = SCM_CDR (x);
1036 z = EXTEND_SCM_ENV (f, SCM_EOL, env);
1037 e = scm_reverse (unmemocopy (SCM_CAR (x),
1038 SCM_CAR (ls) == scm_i_letrec ? z : env));
1039 env = z;
1040 s = SCM_CAR (ls) == scm_i_do
1041 ? scm_reverse (unmemocopy (SCM_CDR (SCM_CDR (SCM_CDR (x))), env))
1042 : f;
1043 z = SCM_EOL;
1044 do
1045 {
1046 z = scm_acons (SCM_CAR (v),
1047 scm_cons (SCM_CAR (e),
1048 SCM_CAR (s) == SCM_CAR (v)
1049 ? SCM_EOL
1050 : scm_cons (SCM_CAR (s), SCM_EOL)),
1051 z);
1052 v = SCM_CDR (v);
1053 e = SCM_CDR (e);
1054 s = SCM_CDR (s);
1055 }
1056 while SCM_NIMP (v);
1057 SCM_CDR (ls) = z = scm_cons (z, SCM_UNSPECIFIED);
1058 if (SCM_CAR (ls) == scm_i_do)
1059 {
1060 x = SCM_CDR (x);
1061 z = (SCM_CDR (z) = scm_cons (unmemocopy (SCM_CAR (x), env),
1062 SCM_UNSPECIFIED));
1063 x = (SCM) (&SCM_CAR (SCM_CDR (x)) - 1);
1064 }
1065 break;
1066 }
1067 case (127 & SCM_IM_LETSTAR):
1068 {
1069 SCM b, y;
1070 x = SCM_CDR (x);
1071 b = SCM_CAR (x);
1072 y = SCM_EOL;
1073 if SCM_IMP (b)
1074 {
1075 env = EXTEND_SCM_ENV (SCM_EOL, SCM_EOL, env);
1076 goto letstar;
1077 }
1078 y = z = scm_acons (SCM_CAR (b),
1079 unmemocar (
1080 scm_cons (unmemocopy (SCM_CAR (SCM_CDR (b)), env), SCM_EOL), env),
1081 SCM_UNSPECIFIED);
1082 env = EXTEND_SCM_ENV (SCM_CAR (b), SCM_BOOL_F, env);
1083 b = SCM_CDR (SCM_CDR (b));
1084 if (SCM_IMP (b))
1085 {
1086 SCM_SETCDR (y, SCM_EOL);
1087 ls = scm_cons (scm_i_let, z = scm_cons (y, SCM_UNSPECIFIED));
1088 break;
1089 }
1090 do
1091 {
1092 z = (SCM_CDR (z) = scm_acons (SCM_CAR (b),
1093 unmemocar (
1094 scm_cons (unmemocopy (SCM_CAR (SCM_CDR (b)), env), SCM_EOL), env),
1095 SCM_UNSPECIFIED));
1096 env = EXTEND_SCM_ENV (SCM_CAR (b), SCM_BOOL_F, env);
1097 b = SCM_CDR (SCM_CDR (b));
1098 }
1099 while SCM_NIMP (b);
1100 SCM_CDR (z) = SCM_EOL;
1101 letstar:
1102 ls = scm_cons (scm_i_letstar, z = scm_cons (y, SCM_UNSPECIFIED));
1103 break;
1104 }
1105 case (127 & SCM_IM_OR):
1106 ls = z = scm_cons (scm_i_or, SCM_UNSPECIFIED);
1107 break;
1108 case (127 & SCM_IM_LAMBDA):
1109 x = SCM_CDR (x);
1110 ls = scm_cons (scm_i_lambda,
1111 z = scm_cons (SCM_CAR (x), SCM_UNSPECIFIED));
1112 env = EXTEND_SCM_ENV (SCM_CAR (x), SCM_EOL, env);
1113 break;
1114 case (127 & SCM_IM_QUOTE):
1115 ls = z = scm_cons (scm_i_quote, SCM_UNSPECIFIED);
1116 break;
1117 case (127 & SCM_IM_SET):
1118 ls = z = scm_cons (scm_i_set, SCM_UNSPECIFIED);
1119 break;
1120 case (127 & SCM_IM_DEFINE):
1121 {
1122 SCM n;
1123 x = SCM_CDR (x);
1124 ls = scm_cons (scm_i_define,
1125 z = scm_cons (n = SCM_CAR (x), SCM_UNSPECIFIED));
1126 if (SCM_NNULLP (env))
1127 SCM_CAR (SCM_CAR (env)) = scm_cons (n, SCM_CAR (SCM_CAR (env)));
1128 break;
1129 }
1130 case (127 & SCM_MAKISYM (0)):
1131 z = SCM_CAR (x);
1132 if (!SCM_ISYMP (z))
1133 goto unmemo;
1134 switch SCM_ISYMNUM (z)
1135 {
1136 case (SCM_ISYMNUM (SCM_IM_APPLY)):
1137 ls = z = scm_cons (scm_i_atapply, SCM_UNSPECIFIED);
1138 goto loop;
1139 case (SCM_ISYMNUM (SCM_IM_CONT)):
1140 ls = z = scm_cons (scm_i_atcall_cc, SCM_UNSPECIFIED);
1141 goto loop;
1142 default:
1143 }
1144 unmemo:
1145 default:
1146 ls = z = unmemocar (scm_cons (unmemocopy (SCM_CAR (x), env),
1147 SCM_UNSPECIFIED),
1148 env);
1149 }
1150loop:
1151 while (SCM_CELLP (x = SCM_CDR (x)) && SCM_ECONSP (x))
1152 z = (SCM_CDR (z) = unmemocar (scm_cons (unmemocopy (SCM_CAR (x), env),
1153 SCM_UNSPECIFIED),
1154 env));
1155 SCM_CDR (z) = x;
1156#ifdef DEBUG_EXTENSIONS
1157 if (SCM_NFALSEP (p))
1158 scm_whash_insert (scm_source_whash, ls, p);
1159#endif
1160 return ls;
1161}
1162
1163#ifdef __STDC__
1164SCM
1165scm_unmemocopy (SCM x, SCM env)
1166#else
1167SCM
1168scm_unmemocopy (x, env)
1169 SCM x;
1170 SCM env;
1171#endif
1172{
1173 if (SCM_NNULLP (env))
1174 /* Make a copy of the lowest frame to protect it from
1175 modifications by SCM_IM_DEFINE */
1176 return unmemocopy (x, scm_cons (SCM_CAR (env), SCM_CDR (env)));
1177 else
1178 return unmemocopy (x, env);
1179}
1180
0f2d19dd
JB
1181#ifndef RECKLESS
1182#ifdef __STDC__
1183int
1184scm_badargsp (SCM formals, SCM args)
1185#else
1186int
1187scm_badargsp (formals, args)
1188 SCM formals;
1189 SCM args;
1190#endif
1191{
1192 while SCM_NIMP
1193 (formals)
1194 {
1195 if SCM_NCONSP
1196 (formals) return 0;
1197 if SCM_IMP
1198 (args) return 1;
1199 formals = SCM_CDR (formals);
1200 args = SCM_CDR (args);
1201 }
1202 return SCM_NNULLP (args) ? 1 : 0;
1203}
1204#endif
1205
1206
1207\f
1208long scm_tc16_macro;
1209
6dbd0af5
MD
1210#ifdef __STDC__
1211SCM
1212scm_eval_args (SCM l, SCM env)
1213#else
1214SCM
1215scm_eval_args (l, env)
1216 SCM l;
1217 SCM env;
1218#endif
1219{
1220 SCM res = SCM_EOL, *lloc = &res;
1221 while (SCM_NIMP (l))
1222 {
1223 *lloc = scm_cons (EVALCAR (l, env), SCM_EOL);
1224 lloc = &SCM_CDR (*lloc);
1225 l = SCM_CDR (l);
1226 }
1227 return res;
1228}
0f2d19dd
JB
1229#endif /* !DEVAL */
1230
6dbd0af5
MD
1231
1232/* SECTION: This code is specific for the debugging support. One
1233 * branch is read when DEVAL isn't defined, the other when DEVAL is
1234 * defined.
1235 */
1236
1237#ifndef DEVAL
1238
1239#define SCM_APPLY scm_apply
1240#define PREP_APPLY(proc, args)
1241#define ENTER_APPLY
1242#define RETURN(x) return x;
1243#ifdef NO_CEVAL_STACK_CHECK
1244# ifdef STACK_CHECK
1245# undef STACK_CHECK
1246# endif
1247#endif
1248
1249#else /* !DEVAL */
1250
0f2d19dd
JB
1251#undef SCM_CEVAL
1252#define SCM_CEVAL scm_deval /* Substitute all uses of scm_ceval */
1253#undef SCM_APPLY
1254#define SCM_APPLY scm_dapply
6dbd0af5
MD
1255#undef PREP_APPLY
1256#define PREP_APPLY(p, l) \
1257{ ++debug.info; debug.info->a.proc = p; debug.info->a.args = l; }
1258#undef ENTER_APPLY
1259#define ENTER_APPLY \
1260{\
1261 SETARGSREADY (debug);\
1262 if (CHECK_APPLY)\
1263 if (APPLY_FRAME || (TRACE && PROCTRACEP (proc)))\
1264 {\
1265 SCM tmp, tail = TRACEDFRAMEP (debug) ? SCM_BOOL_T : SCM_BOOL_F;\
1266 SETTRACEDFRAME (debug);\
1267 if (CHEAPTRAPS)\
1268 {\
1269 tmp = scm_make_debugobj ((scm_debug_frame *) &debug);\
1270 scm_ithrow (scm_i_apply_frame, scm_cons2 (tmp, tail, SCM_EOL), 0);\
1271 }\
1272 else\
1273 {\
1274 scm_make_cont (&tmp);\
1275 if (!setjmp (SCM_JMPBUF (tmp)))\
1276 scm_ithrow (scm_i_apply_frame, scm_cons2 (tmp, tail, SCM_EOL), 0);\
1277 }\
1278 }\
1279}
0f2d19dd
JB
1280#undef RETURN
1281#define RETURN(e) {proc = (e); goto exit;}
6dbd0af5
MD
1282#ifdef STACK_LIMIT
1283# define STACK_CHECK
1284#endif
1285
1286/* scm_ceval_ptr points to the currently selected evaluator.
1287 * *fixme*: Although efficiency is important here, this state variable
1288 * should probably not be a global. It should be related to the
1289 * current repl.
1290 */
1291
1292#ifdef __STDC__
1293SCM (*scm_ceval_ptr) (SCM exp, SCM env);
0f2d19dd 1294#else
6dbd0af5 1295SCM (*scm_ceval_ptr) ();
0f2d19dd
JB
1296#endif
1297
6dbd0af5
MD
1298/* last_debug_info_frame contains a pointer to the last debugging
1299 * information stack frame. It is accessed very often from the
1300 * debugging evaluator, so it should probably not be indirectly
1301 * addressed. Better to save and restore it from the current root at
1302 * any stack swaps.
1303 */
1304
1305scm_debug_frame *last_debug_info_frame;
1306
1307/* scm_debug_eframe_size is the number of slots available for pseudo
1308 * stack frames at each real stack frame.
1309 */
1310
1311int scm_debug_eframe_size;
1312
1313int debug_mode, check_entry, check_apply, check_exit;
1314
1315scm_option scm_debug_opts[] = {
1316 { SCM_OPTION_BOOLEAN, "procnames", 1 },
1317 { SCM_OPTION_BOOLEAN, "deval", 0 },
1318 { SCM_OPTION_BOOLEAN, "breakpoints", 0 },
1319 { SCM_OPTION_BOOLEAN, "trace", 0 },
1320 { SCM_OPTION_BOOLEAN, "backtrace", 0 },
1321 { SCM_OPTION_INTEGER, "depth", 80 },
1322 { SCM_OPTION_INTEGER, "frames", 4 },
1323 { SCM_OPTION_BOOLEAN, "cheap", 1 }
1324};
1325
1326scm_option scm_evaluator_trap_table[] = {
1327 { SCM_OPTION_BOOLEAN, "enter-frame", 0 },
1328 { SCM_OPTION_BOOLEAN, "apply-frame", 0 },
1329 { SCM_OPTION_BOOLEAN, "exit-frame", 0 }
1330};
1331
1332SCM
1333scm_deval_args (l, env, lloc)
1334 SCM l, env, *lloc;
0f2d19dd 1335{
6dbd0af5 1336 SCM *res = lloc;
0f2d19dd
JB
1337 while (SCM_NIMP (l))
1338 {
1339 *lloc = scm_cons (EVALCAR (l, env), SCM_EOL);
1340 lloc = &SCM_CDR (*lloc);
1341 l = SCM_CDR (l);
1342 }
6dbd0af5 1343 return *res;
0f2d19dd
JB
1344}
1345
6dbd0af5
MD
1346#endif /* !DEVAL */
1347
1348
1349/* SECTION: Some local definitions for the evaluator.
1350 */
1351
1352#ifndef DEVAL
1353#ifdef SCM_FLOATS
1354#define CHECK_EQVISH(A,B) (((A) == (B)) || (SCM_NFALSEP (scm_eqv_p ((A), (B)))))
1355#else
1356#define CHECK_EQVISH(A,B) ((A) == (B))
1357#endif
1358#endif /* DEVAL */
1359
1360
1361/* SECTION: This is the evaluator. Like any real monster, it has
1362 * three heads. This code is compiled twice.
1363 */
1364
0f2d19dd
JB
1365#if 0
1366#ifdef __STDC__
1367SCM
1368scm_ceval (SCM x, SCM env)
1369#else
1370SCM
1371scm_ceval (x, env)
1372 SCM x;
1373 SCM env;
1374#endif
1375{}
1376#endif
1377#if 0
1378#ifdef __STDC__
1379SCM
1380scm_deval (SCM x, SCM env)
1381#else
1382SCM
1383scm_deval (x, env)
1384 SCM x;
1385 SCM env;
1386#endif
1387{}
1388#endif
1389
6dbd0af5
MD
1390#ifdef __STDC__
1391SCM
1392SCM_CEVAL (SCM x, SCM env)
0f2d19dd 1393#else
6dbd0af5 1394SCM
0f2d19dd
JB
1395SCM_CEVAL (x, env)
1396 SCM x;
1397 SCM env;
6dbd0af5 1398#endif
0f2d19dd
JB
1399{
1400 union
1401 {
1402 SCM *lloc;
1403 SCM arg1;
1404 } t;
6dbd0af5
MD
1405 SCM proc, arg2;
1406#ifdef DEVAL
1407 struct
1408 {
1409 scm_debug_frame *prev;
1410 long status;
1411 scm_debug_info vect[scm_debug_eframe_size];
1412 scm_debug_info *info;
1413 } debug;
1414 debug.prev = last_debug_info_frame;
1415 debug.status = scm_debug_eframe_size;
1416 debug.info = &debug.vect[0];
1417 last_debug_info_frame = (scm_debug_frame *) &debug;
1418#endif
1419#ifdef STACK_CHECK
1420 if (STACK_OVERFLOW_P ((STACKITEM *) &debug) && scm_check_stack_p)
1421 {
1422 debug.info->e.exp = x;
1423 debug.info->e.env = env;
1424 scm_report_stack_overflow ();
1425 }
1426#endif
1427#ifdef DEVAL
1428 goto start;
1429#endif
1430loopnoap:
1431 PREP_APPLY (SCM_UNDEFINED, SCM_EOL);
1432loop:
1433#ifdef DEVAL
1434#if 0 /* This will probably never have any practical use ... */
1435 if (CHECK_EXIT)
1436 {
1437 if (SINGLE_STEP || (TRACE && TRACEDFRAMEP (debug)))
1438 {
1439 SINGLE_STEP = 0;
1440 RESET_DEBUG_MODE;
1441 CLEARTRACEDFRAME (debug);
1442 scm_make_cont (&t.arg1);
1443 if (!setjmp (SCM_JMPBUF (t.arg1)))
1444 scm_ithrow (scm_i_exit_tail, scm_cons (t.arg1, SCM_EOL), 0);
1445 }
1446 }
1447nextframe:
1448#endif
1449 CLEARARGSREADY (debug);
1450 if (OVERFLOWP (debug))
1451 --debug.info;
1452 else if (++debug.info == (scm_debug_info *) &debug.info)
1453 {
1454 SETOVERFLOW (debug);
1455 debug.info -= 2;
1456 }
1457start:
1458 debug.info->e.exp = x;
1459 debug.info->e.env = env;
1460 if (CHECK_ENTRY)
1461 if (ENTER_FRAME || (BREAKPOINTS && SRCBRKP (x)))
1462 {
1463 SCM tail = TAILRECP (debug) ? SCM_BOOL_T : SCM_BOOL_F;
1464 SETTAILREC (debug);
1465 ENTER_FRAME = 0;
1466 RESET_DEBUG_MODE;
1467 if (CHEAPTRAPS)
1468 t.arg1 = scm_make_debugobj ((scm_debug_frame *) &debug);
1469 else
1470 {
1471 scm_make_cont (&t.arg1);
1472 if (setjmp (SCM_JMPBUF (t.arg1)))
1473 {
1474 x = SCM_THROW_VALUE (t.arg1);
1475 if (SCM_IMP (x))
1476 {
1477 RETURN (x);
1478 }
1479 else
1480 /* This gives the possibility for the debugger to
1481 modify the source expression before evaluation. */
1482 goto dispatch;
1483 }
1484 }
1485 scm_ithrow (scm_i_enter_frame,
1486 scm_cons2 (t.arg1, tail,
1487 scm_cons (scm_unmemocopy (x, env), SCM_EOL)),
1488 0);
1489 }
1490dispatch:
1491#endif
0f2d19dd 1492 SCM_ASYNC_TICK;
0f2d19dd
JB
1493 switch (SCM_TYP7 (x))
1494 {
1495 case scm_tcs_symbols:
1496 /* Only happens when called at top level.
1497 */
1498 x = scm_cons (x, SCM_UNDEFINED);
1499 goto retval;
1500
1501 case (127 & SCM_IM_AND):
1502 x = SCM_CDR (x);
1503 t.arg1 = x;
1504 while (SCM_NNULLP (t.arg1 = SCM_CDR (t.arg1)))
1505 if (SCM_FALSEP (EVALCAR (x, env)))
1506 {
1507 RETURN (SCM_BOOL_F);
1508 }
1509 else
1510 x = t.arg1;
6dbd0af5 1511 PREP_APPLY (SCM_UNDEFINED, SCM_EOL);
0f2d19dd
JB
1512 goto carloop;
1513
1514 case (127 & SCM_IM_BEGIN):
6dbd0af5
MD
1515 cdrxnoap:
1516 PREP_APPLY (SCM_UNDEFINED, SCM_EOL);
0f2d19dd
JB
1517 cdrxbegin:
1518 x = SCM_CDR (x);
1519
1520 begin:
1521 t.arg1 = x;
1522 while (SCM_NNULLP (t.arg1 = SCM_CDR (t.arg1)))
1523 {
1524 SIDEVAL (SCM_CAR (x), env);
1525 x = t.arg1;
1526 }
1527
1528 carloop: /* scm_eval car of last form in list */
1529 if (SCM_NCELLP (SCM_CAR (x)))
1530 {
1531 x = SCM_CAR (x);
6dbd0af5 1532 RETURN (SCM_IMP (x) ? EVALIM (x, env) : SCM_GLOC_VAL (x))
0f2d19dd
JB
1533 }
1534
1535 if (SCM_SYMBOLP (SCM_CAR (x)))
1536 {
1537 retval:
6dbd0af5 1538 RETURN (*scm_lookupcar (x, env))
0f2d19dd
JB
1539 }
1540
1541 x = SCM_CAR (x);
1542 goto loop; /* tail recurse */
1543
1544
1545 case (127 & SCM_IM_CASE):
1546 x = SCM_CDR (x);
1547 t.arg1 = EVALCAR (x, env);
1548 while (SCM_NIMP (x = SCM_CDR (x)))
1549 {
1550 proc = SCM_CAR (x);
1551 if (scm_i_else == SCM_CAR (proc))
1552 {
1553 x = SCM_CDR (proc);
6dbd0af5 1554 PREP_APPLY (SCM_UNDEFINED, SCM_EOL);
0f2d19dd
JB
1555 goto begin;
1556 }
1557 proc = SCM_CAR (proc);
1558 while (SCM_NIMP (proc))
1559 {
1560 if (CHECK_EQVISH (SCM_CAR (proc), t.arg1))
1561 {
1562 x = SCM_CDR (SCM_CAR (x));
6dbd0af5 1563 PREP_APPLY (SCM_UNDEFINED, SCM_EOL);
0f2d19dd
JB
1564 goto begin;
1565 }
1566 proc = SCM_CDR (proc);
1567 }
1568 }
6dbd0af5 1569 RETURN (SCM_UNSPECIFIED)
0f2d19dd
JB
1570
1571
1572 case (127 & SCM_IM_COND):
1573 while (SCM_NIMP (x = SCM_CDR (x)))
1574 {
1575 proc = SCM_CAR (x);
1576 t.arg1 = EVALCAR (proc, env);
1577 if (SCM_NFALSEP (t.arg1))
1578 {
1579 x = SCM_CDR (proc);
6dbd0af5 1580 if SCM_NULLP (x)
0f2d19dd 1581 {
6dbd0af5 1582 RETURN (t.arg1)
0f2d19dd
JB
1583 }
1584 if (scm_i_arrow != SCM_CAR (x))
6dbd0af5
MD
1585 {
1586 PREP_APPLY (SCM_UNDEFINED, SCM_EOL);
1587 goto begin;
1588 }
0f2d19dd
JB
1589 proc = SCM_CDR (x);
1590 proc = EVALCAR (proc, env);
1591 SCM_ASRTGO (SCM_NIMP (proc), badfun);
6dbd0af5
MD
1592 PREP_APPLY (proc, scm_cons (t.arg1, SCM_EOL));
1593 ENTER_APPLY;
0f2d19dd
JB
1594 goto evap1;
1595 }
1596 }
6dbd0af5 1597 RETURN (SCM_UNSPECIFIED)
0f2d19dd
JB
1598
1599
1600 case (127 & SCM_IM_DO):
1601 x = SCM_CDR (x);
1602 proc = SCM_CAR (SCM_CDR (x)); /* inits */
1603 t.arg1 = SCM_EOL; /* values */
1604 while (SCM_NIMP (proc))
1605 {
1606 t.arg1 = scm_cons (EVALCAR (proc, env), t.arg1);
1607 proc = SCM_CDR (proc);
1608 }
1609 env = EXTEND_SCM_ENV (SCM_CAR (x), t.arg1, env);
1610 x = SCM_CDR (SCM_CDR (x));
1611 while (proc = SCM_CAR (x), SCM_FALSEP (EVALCAR (proc, env)))
1612 {
1613 for (proc = SCM_CAR (SCM_CDR (x)); SCM_NIMP (proc); proc = SCM_CDR (proc))
1614 {
1615 t.arg1 = SCM_CAR (proc); /* body */
1616 SIDEVAL (t.arg1, env);
1617 }
1618 for (t.arg1 = SCM_EOL, proc = SCM_CDR (SCM_CDR (x)); SCM_NIMP (proc); proc = SCM_CDR (proc))
1619 t.arg1 = scm_cons (EVALCAR (proc, env), t.arg1); /* steps */
1620 env = EXTEND_SCM_ENV (SCM_CAR (SCM_CAR (env)), t.arg1, SCM_CDR (env));
1621 }
1622 x = SCM_CDR (proc);
1623 if (SCM_NULLP (x))
6dbd0af5
MD
1624 RETURN (SCM_UNSPECIFIED);
1625 PREP_APPLY (SCM_UNDEFINED, SCM_EOL);
0f2d19dd
JB
1626 goto begin;
1627
1628
1629 case (127 & SCM_IM_IF):
1630 x = SCM_CDR (x);
1631 if (SCM_NFALSEP (EVALCAR (x, env)))
1632 x = SCM_CDR (x);
1633 else if (SCM_IMP (x = SCM_CDR (SCM_CDR (x))))
1634 {
1635 RETURN (SCM_UNSPECIFIED);
1636 }
6dbd0af5 1637 PREP_APPLY (SCM_UNDEFINED, SCM_EOL);
0f2d19dd
JB
1638 goto carloop;
1639
1640
1641 case (127 & SCM_IM_LET):
1642 x = SCM_CDR (x);
1643 proc = SCM_CAR (SCM_CDR (x));
1644 t.arg1 = SCM_EOL;
1645 do
1646 {
1647 t.arg1 = scm_cons (EVALCAR (proc, env), t.arg1);
1648 }
1649 while (SCM_NIMP (proc = SCM_CDR (proc)));
1650 env = EXTEND_SCM_ENV (SCM_CAR (x), t.arg1, env);
1651 x = SCM_CDR (x);
6dbd0af5 1652 goto cdrxnoap;
0f2d19dd
JB
1653
1654
1655 case (127 & SCM_IM_LETREC):
1656 x = SCM_CDR (x);
1657 env = EXTEND_SCM_ENV (SCM_CAR (x), scm_undefineds, env);
1658 x = SCM_CDR (x);
1659 proc = SCM_CAR (x);
1660 t.arg1 = SCM_EOL;
1661 do
1662 {
1663 t.arg1 = scm_cons (EVALCAR (proc, env), t.arg1);
1664 }
1665 while (SCM_NIMP (proc = SCM_CDR (proc)));
1666 SCM_CDR (SCM_CAR (env)) = t.arg1;
6dbd0af5 1667 goto cdrxnoap;
0f2d19dd
JB
1668
1669
1670 case (127 & SCM_IM_LETSTAR):
1671 x = SCM_CDR (x);
1672 proc = SCM_CAR (x);
1673 if (SCM_IMP (proc))
1674 {
1675 env = EXTEND_SCM_ENV (SCM_EOL, SCM_EOL, env);
6dbd0af5 1676 goto cdrxnoap;
0f2d19dd
JB
1677 }
1678 do
1679 {
1680 t.arg1 = SCM_CAR (proc);
1681 proc = SCM_CDR (proc);
1682 env = EXTEND_SCM_ENV (t.arg1, EVALCAR (proc, env), env);
1683 }
1684 while (SCM_NIMP (proc = SCM_CDR (proc)));
6dbd0af5 1685 goto cdrxnoap;
0f2d19dd
JB
1686
1687 case (127 & SCM_IM_OR):
1688 x = SCM_CDR (x);
1689 t.arg1 = x;
1690 while (SCM_NNULLP (t.arg1 = SCM_CDR (t.arg1)))
1691 {
1692 x = EVALCAR (x, env);
1693 if (SCM_NFALSEP (x))
1694 {
1695 RETURN (x);
1696 }
1697 x = t.arg1;
1698 }
6dbd0af5 1699 PREP_APPLY (SCM_UNDEFINED, SCM_EOL);
0f2d19dd
JB
1700 goto carloop;
1701
1702
1703 case (127 & SCM_IM_LAMBDA):
1704 RETURN (scm_closure (SCM_CDR (x), env));
1705
1706
1707 case (127 & SCM_IM_QUOTE):
1708 RETURN (SCM_CAR (SCM_CDR (x)));
1709
1710
1711 case (127 & SCM_IM_SET):
0f2d19dd
JB
1712 x = SCM_CDR (x);
1713 proc = SCM_CAR (x);
6dbd0af5 1714 switch (7 & (int) proc)
0f2d19dd
JB
1715 {
1716 case 0:
1717 t.lloc = scm_lookupcar (x, env);
1718 break;
1719 case 1:
1720 t.lloc = &SCM_GLOC_VAL (proc);
1721 break;
1722#ifdef MEMOIZE_LOCALS
1723 case 4:
1724 t.lloc = scm_ilookup (proc, env);
1725 break;
1726#endif
1727 }
1728 x = SCM_CDR (x);
1729 *t.lloc = EVALCAR (x, env);
0f2d19dd
JB
1730#ifdef SICP
1731 RETURN (*t.lloc);
1732#else
1733 RETURN (SCM_UNSPECIFIED);
1734#endif
1735
1736
1737 case (127 & SCM_IM_DEFINE): /* only for internal defines */
1738 x = SCM_CDR (x);
1739 proc = SCM_CAR (x);
1740 x = SCM_CDR (x);
1741 x = evalcar (x, env);
6dbd0af5
MD
1742#ifdef DEBUG_EXTENSIONS
1743 if (RECORD_PROCNAMES && SCM_NIMP (x) && SCM_CLOSUREP (x))
1744 scm_set_procedure_property_x (x, scm_i_name, proc);
1745#endif
0f2d19dd
JB
1746 env = SCM_CAR (env);
1747 SCM_DEFER_INTS;
1748 SCM_CAR (env) = scm_cons (proc, SCM_CAR (env));
1749 SCM_CDR (env) = scm_cons (x, SCM_CDR (env));
1750 SCM_ALLOW_INTS;
1751 RETURN (SCM_UNSPECIFIED);
1752
1753
1754
1755 /* new syntactic forms go here. */
1756 case (127 & SCM_MAKISYM (0)):
1757 proc = SCM_CAR (x);
1758 SCM_ASRTGO (SCM_ISYMP (proc), badfun);
1759 switch SCM_ISYMNUM (proc)
1760 {
1761#if 0
1762 case (SCM_ISYMNUM (IM_VREF)):
1763 {
1764 SCM var;
1765 var = SCM_CAR (SCM_CDR (x));
1766 RETURN (SCM_CDR(var));
1767 }
1768 case (SCM_ISYMNUM (IM_VSET)):
1769 SCM_CDR (SCM_CAR ( SCM_CDR (x))) = EVALCAR( SCM_CDR ( SCM_CDR (x)), env);
1770 SCM_CAR (SCM_CAR ( SCM_CDR (x))) = scm_tc16_variable;
6dbd0af5 1771 RETURN (SCM_UNSPECIFIED)
0f2d19dd
JB
1772#endif
1773
1774 case (SCM_ISYMNUM (SCM_IM_APPLY)):
1775 proc = SCM_CDR (x);
1776 proc = EVALCAR (proc, env);
1777 SCM_ASRTGO (SCM_NIMP (proc), badfun);
1778 if (SCM_CLOSUREP (proc))
1779 {
6dbd0af5 1780 PREP_APPLY (proc, SCM_EOL);
0f2d19dd
JB
1781 t.arg1 = SCM_CDR (SCM_CDR (x));
1782 t.arg1 = EVALCAR (t.arg1, env);
6dbd0af5
MD
1783#ifdef DEVAL
1784 debug.info->a.args = t.arg1;
1785#endif
0f2d19dd
JB
1786#ifndef RECKLESS
1787 if (scm_badargsp (SCM_CAR (SCM_CODE (proc)), t.arg1))
1788 goto wrongnumargs;
1789#endif
1790 env = EXTEND_SCM_ENV (SCM_CAR (SCM_CODE (proc)), t.arg1, SCM_ENV (proc));
1791 x = SCM_CODE (proc);
1792 goto cdrxbegin;
1793 }
1794 proc = scm_i_apply;
1795 goto evapply;
1796
1797 case (SCM_ISYMNUM (SCM_IM_CONT)):
1798 scm_make_cont (&t.arg1);
1799 if (setjmp (SCM_JMPBUF (t.arg1)))
1800 {
1801 SCM val;
1802 val = SCM_THROW_VALUE (t.arg1);
6dbd0af5 1803 RETURN (val);
0f2d19dd
JB
1804 }
1805 proc = SCM_CDR (x);
1806 proc = evalcar (proc, env);
1807 SCM_ASRTGO (SCM_NIMP (proc), badfun);
6dbd0af5
MD
1808 PREP_APPLY (proc, scm_cons (t.arg1, SCM_EOL));
1809 ENTER_APPLY;
0f2d19dd
JB
1810 goto evap1;
1811
1812 default:
1813 goto badfun;
1814 }
1815
1816 default:
1817 proc = x;
1818 badfun:
1819 scm_everr (x, env, proc, "Wrong type to apply: ", "");
1820
1821 case scm_tc7_vector:
1822 case scm_tc7_wvect:
1823 case scm_tc7_bvect:
1824 case scm_tc7_byvect:
1825 case scm_tc7_svect:
1826 case scm_tc7_ivect:
1827 case scm_tc7_uvect:
1828 case scm_tc7_fvect:
1829 case scm_tc7_dvect:
1830 case scm_tc7_cvect:
1831#ifdef LONGLONGS
1832 case scm_tc7_llvect:
1833#endif
1834 case scm_tc7_string:
1835 case scm_tc7_mb_string:
1836 case scm_tc7_substring:
1837 case scm_tc7_mb_substring:
1838 case scm_tc7_smob:
1839 case scm_tcs_closures:
1840 case scm_tcs_subrs:
1841 RETURN (x);
1842
1843#ifdef MEMOIZE_LOCALS
1844 case (127 & SCM_ILOC00):
1845 proc = *scm_ilookup (SCM_CAR (x), env);
1846 SCM_ASRTGO (SCM_NIMP (proc), badfun);
1847#ifndef RECKLESS
1848#ifdef CAUTIOUS
1849 goto checkargs;
1850#endif
1851#endif
1852 break;
1853#endif /* ifdef MEMOIZE_LOCALS */
1854
1855
1856 case scm_tcs_cons_gloc:
1857 proc = SCM_GLOC_VAL (SCM_CAR (x));
1858 SCM_ASRTGO (SCM_NIMP (proc), badfun);
1859#ifndef RECKLESS
1860#ifdef CAUTIOUS
1861 goto checkargs;
1862#endif
1863#endif
1864 break;
1865
1866
1867 case scm_tcs_cons_nimcar:
1868 if (SCM_SYMBOLP (SCM_CAR (x)))
1869 {
1870 proc = *scm_lookupcar (x, env);
1871 if (SCM_IMP (proc))
1872 {
1873 unmemocar (x, env);
1874 goto badfun;
1875 }
1876 if (scm_tc16_macro == SCM_TYP16 (proc))
1877 {
1878 unmemocar (x, env);
1879
1880 handle_a_macro:
1881 t.arg1 = SCM_APPLY (SCM_CDR (proc), x, scm_cons (env, scm_listofnull));
1882 switch ((int) (SCM_CAR (proc) >> 16))
1883 {
1884 case 2:
1885 if (scm_ilength (t.arg1) <= 0)
1886 t.arg1 = scm_cons2 (SCM_IM_BEGIN, t.arg1, SCM_EOL);
6dbd0af5
MD
1887#ifdef DEVAL
1888 if (!SCM_CLOSUREP (SCM_CDR (proc)))
1889 {
1890#if 0 /* Top-level defines doesn't very often occur in backtraces */
1891 if (scm_m_define == SCM_SUBRF (SCM_CDR (proc)) && SCM_TOP_LEVEL (env))
1892 /* Prevent memoizing result of define macro */
1893 {
1894 debug.info->e.exp = scm_cons (SCM_CAR (x), SCM_CDR (x));
1895 scm_set_source_properties_x (debug.info->e.exp,
1896 scm_source_properties (x));
1897 }
1898#endif
1899 SCM_DEFER_INTS;
1900 SCM_CAR (x) = SCM_CAR (t.arg1);
1901 SCM_CDR (x) = SCM_CDR (t.arg1);
1902 SCM_ALLOW_INTS;
1903 goto dispatch;
1904 }
1905 /* Prevent memoizing of debug info expression. */
1906 debug.info->e.exp = scm_cons (SCM_CAR (x), SCM_CDR (x));
1907 scm_set_source_properties_x (debug.info->e.exp,
1908 scm_source_properties (x));
1909#endif
0f2d19dd
JB
1910 SCM_DEFER_INTS;
1911 SCM_CAR (x) = SCM_CAR (t.arg1);
1912 SCM_CDR (x) = SCM_CDR (t.arg1);
1913 SCM_ALLOW_INTS;
6dbd0af5 1914 goto loopnoap;
0f2d19dd
JB
1915 case 1:
1916 if (SCM_NIMP (x = t.arg1))
6dbd0af5 1917 goto loopnoap;
0f2d19dd
JB
1918 case 0:
1919 RETURN (t.arg1);
1920 }
1921 }
1922 }
1923 else
1924 proc = SCM_CEVAL (SCM_CAR (x), env);
1925 SCM_ASRTGO (SCM_NIMP (proc), badfun);
1926#ifndef RECKLESS
1927#ifdef CAUTIOUS
1928 checkargs:
1929#endif
1930 if (SCM_CLOSUREP (proc))
1931 {
1932 arg2 = SCM_CAR (SCM_CODE (proc));
1933 t.arg1 = SCM_CDR (x);
1934 while (SCM_NIMP (arg2))
1935 {
1936 if (SCM_NCONSP (arg2))
1937 goto evapply;
1938 if (SCM_IMP (t.arg1))
1939 goto umwrongnumargs;
1940 arg2 = SCM_CDR (arg2);
1941 t.arg1 = SCM_CDR (t.arg1);
1942 }
1943 if (SCM_NNULLP (t.arg1))
1944 goto umwrongnumargs;
1945 }
1946 else if (scm_tc16_macro == SCM_TYP16 (proc))
1947 goto handle_a_macro;
1948#endif
1949 }
1950
1951
6dbd0af5
MD
1952evapply:
1953 PREP_APPLY (proc, SCM_EOL);
1954 if (SCM_NULLP (SCM_CDR (x))) {
1955 ENTER_APPLY;
0f2d19dd
JB
1956 switch (SCM_TYP7 (proc))
1957 { /* no arguments given */
1958 case scm_tc7_subr_0:
1959 RETURN (SCM_SUBRF (proc) ());
1960 case scm_tc7_subr_1o:
1961 RETURN (SCM_SUBRF (proc) (SCM_UNDEFINED));
1962 case scm_tc7_lsubr:
1963 RETURN (SCM_SUBRF (proc) (SCM_EOL));
1964 case scm_tc7_rpsubr:
1965 RETURN (SCM_BOOL_T);
1966 case scm_tc7_asubr:
1967 RETURN (SCM_SUBRF (proc) (SCM_UNDEFINED, SCM_UNDEFINED));
6dbd0af5 1968#ifdef CCLO
0f2d19dd
JB
1969 case scm_tc7_cclo:
1970 t.arg1 = proc;
1971 proc = SCM_CCLO_SUBR (proc);
6dbd0af5
MD
1972#ifdef DEVAL
1973 debug.info->a.proc = proc;
1974 debug.info->a.args = scm_cons (t.arg1, SCM_EOL);
1975#endif
0f2d19dd 1976 goto evap1;
6dbd0af5 1977#endif
0f2d19dd
JB
1978 case scm_tcs_closures:
1979 x = SCM_CODE (proc);
1980 env = EXTEND_SCM_ENV (SCM_CAR (x), SCM_EOL, SCM_ENV (proc));
1981 goto cdrxbegin;
1982 case scm_tc7_contin:
1983 case scm_tc7_subr_1:
1984 case scm_tc7_subr_2:
1985 case scm_tc7_subr_2o:
1986 case scm_tc7_cxr:
1987 case scm_tc7_subr_3:
1988 case scm_tc7_lsubr_2:
1989 umwrongnumargs:
1990 unmemocar (x, env);
1991 wrongnumargs:
1992 scm_everr (x, env, proc, (char *) SCM_WNA, "");
1993 default:
1994 /* handle macros here */
1995 goto badfun;
1996 }
6dbd0af5 1997 }
0f2d19dd
JB
1998
1999 /* must handle macros by here */
2000 x = SCM_CDR (x);
2001#ifdef CAUTIOUS
2002 if (SCM_IMP (x))
2003 goto wrongnumargs;
2004#endif
2005 t.arg1 = EVALCAR (x, env);
6dbd0af5
MD
2006#ifdef DEVAL
2007 debug.info->a.args = scm_cons (t.arg1, SCM_EOL);
2008#endif
0f2d19dd
JB
2009 x = SCM_CDR (x);
2010 if (SCM_NULLP (x))
2011 {
6dbd0af5 2012 ENTER_APPLY;
0f2d19dd
JB
2013 evap1:
2014 switch (SCM_TYP7 (proc))
6dbd0af5 2015 { /* have one argument in t.arg1 */
0f2d19dd
JB
2016 case scm_tc7_subr_2o:
2017 RETURN (SCM_SUBRF (proc) (t.arg1, SCM_UNDEFINED));
2018 case scm_tc7_subr_1:
2019 case scm_tc7_subr_1o:
2020 RETURN (SCM_SUBRF (proc) (t.arg1));
2021 case scm_tc7_cxr:
2022#ifdef SCM_FLOATS
2023 if (SCM_SUBRF (proc))
2024 {
2025 if (SCM_INUMP (t.arg1))
2026 {
2027 RETURN (scm_makdbl (SCM_DSUBRF (proc) ((double) SCM_INUM (t.arg1)),
2028 0.0));
2029 }
2030 SCM_ASRTGO (SCM_NIMP (t.arg1), floerr);
2031 if (SCM_REALP (t.arg1))
2032 {
2033 RETURN (scm_makdbl (SCM_DSUBRF (proc) (SCM_REALPART (t.arg1)), 0.0));
2034 }
2035#ifdef SCM_BIGDIG
2036 if (SCM_BIGP (t.arg1))
2037 {
2038 RETURN (scm_makdbl (SCM_DSUBRF (proc) (scm_big2dbl (t.arg1)), 0.0));
2039 }
2040#endif
2041 floerr:
2042 scm_wta (t.arg1, (char *) SCM_ARG1, SCM_CHARS (SCM_SNAME (proc)));
2043 }
2044#endif
2045 proc = (SCM) SCM_SNAME (proc);
2046 {
2047 char *chrs = SCM_CHARS (proc) + SCM_LENGTH (proc) - 1;
2048 while ('c' != *--chrs)
2049 {
2050 SCM_ASSERT (SCM_NIMP (t.arg1) && SCM_CONSP (t.arg1),
2051 t.arg1, SCM_ARG1, SCM_CHARS (proc));
2052 t.arg1 = ('a' == *chrs) ? SCM_CAR (t.arg1) : SCM_CDR (t.arg1);
2053 }
2054 RETURN (t.arg1);
2055 }
2056 case scm_tc7_rpsubr:
2057 RETURN (SCM_BOOL_T);
2058 case scm_tc7_asubr:
2059 RETURN (SCM_SUBRF (proc) (t.arg1, SCM_UNDEFINED));
2060 case scm_tc7_lsubr:
2061#ifdef DEVAL
6dbd0af5 2062 RETURN (SCM_SUBRF (proc) (debug.info->a.args))
0f2d19dd
JB
2063#else
2064 RETURN (SCM_SUBRF (proc) (scm_cons (t.arg1, SCM_EOL)));
2065#endif
6dbd0af5 2066#ifdef CCLO
0f2d19dd
JB
2067 case scm_tc7_cclo:
2068 arg2 = t.arg1;
2069 t.arg1 = proc;
2070 proc = SCM_CCLO_SUBR (proc);
6dbd0af5
MD
2071#ifdef DEVAL
2072 debug.info->a.args = scm_cons (t.arg1, debug.info->a.args);
2073 debug.info->a.proc = proc;
2074#endif
0f2d19dd 2075 goto evap2;
6dbd0af5 2076#endif
0f2d19dd
JB
2077 case scm_tcs_closures:
2078 x = SCM_CODE (proc);
2079#ifdef DEVAL
6dbd0af5 2080 env = EXTEND_SCM_ENV (SCM_CAR (x), debug.info->a.args, SCM_ENV (proc));
0f2d19dd
JB
2081#else
2082 env = EXTEND_SCM_ENV (SCM_CAR (x), scm_cons (t.arg1, SCM_EOL), SCM_ENV (proc));
2083#endif
2084 goto cdrxbegin;
2085 case scm_tc7_contin:
2086 scm_call_continuation (proc, t.arg1);
2087 case scm_tc7_subr_2:
2088 case scm_tc7_subr_0:
2089 case scm_tc7_subr_3:
2090 case scm_tc7_lsubr_2:
2091 goto wrongnumargs;
2092 default:
2093 goto badfun;
2094 }
2095 }
2096#ifdef CAUTIOUS
2097 if (SCM_IMP (x))
2098 goto wrongnumargs;
2099#endif
2100 { /* have two or more arguments */
2101 arg2 = EVALCAR (x, env);
6dbd0af5
MD
2102#ifdef DEVAL
2103 debug.info->a.args = scm_cons2 (t.arg1, arg2, SCM_EOL);
2104#endif
0f2d19dd
JB
2105 x = SCM_CDR (x);
2106 if (SCM_NULLP (x)) {
6dbd0af5 2107 ENTER_APPLY;
0f2d19dd
JB
2108#ifdef CCLO
2109 evap2:
2110#endif
6dbd0af5
MD
2111 switch (SCM_TYP7 (proc))
2112 { /* have two arguments */
2113 case scm_tc7_subr_2:
2114 case scm_tc7_subr_2o:
2115 RETURN (SCM_SUBRF (proc) (t.arg1, arg2));
2116 case scm_tc7_lsubr:
0f2d19dd 2117#ifdef DEVAL
6dbd0af5
MD
2118 RETURN (SCM_SUBRF (proc) (debug.info->a.args))
2119#else
2120 RETURN (SCM_SUBRF (proc) (scm_cons2 (t.arg1, arg2, SCM_EOL)));
0f2d19dd 2121#endif
6dbd0af5
MD
2122 case scm_tc7_lsubr_2:
2123 RETURN (SCM_SUBRF (proc) (t.arg1, arg2, SCM_EOL));
2124 case scm_tc7_rpsubr:
2125 case scm_tc7_asubr:
2126 RETURN (SCM_SUBRF (proc) (t.arg1, arg2));
2127#ifdef CCLO
2128 cclon:
2129 case scm_tc7_cclo:
0f2d19dd 2130#ifdef DEVAL
6dbd0af5
MD
2131 RETURN (SCM_APPLY (SCM_CCLO_SUBR (proc), proc,
2132 scm_cons (debug.info->a.args, SCM_EOL)));
0f2d19dd 2133#else
6dbd0af5
MD
2134 RETURN (SCM_APPLY (SCM_CCLO_SUBR (proc), proc,
2135 scm_cons2 (t.arg1, arg2,
2136 scm_cons (scm_eval_args (x, env), SCM_EOL))));
0f2d19dd 2137#endif
6dbd0af5
MD
2138 /* case scm_tc7_cclo:
2139 x = scm_cons(arg2, scm_eval_args(x, env));
2140 arg2 = t.arg1;
2141 t.arg1 = proc;
2142 proc = SCM_CCLO_SUBR(proc);
2143 goto evap3; */
2144#endif
2145 case scm_tc7_subr_0:
2146 case scm_tc7_cxr:
2147 case scm_tc7_subr_1o:
2148 case scm_tc7_subr_1:
2149 case scm_tc7_subr_3:
2150 case scm_tc7_contin:
2151 goto wrongnumargs;
2152 default:
2153 goto badfun;
2154 case scm_tcs_closures:
0f2d19dd 2155#ifdef DEVAL
6dbd0af5 2156 env = EXTEND_SCM_ENV (SCM_CAR (SCM_CODE (proc)), debug.info->a.args, SCM_ENV (proc));
0f2d19dd 2157#else
6dbd0af5 2158 env = EXTEND_SCM_ENV (SCM_CAR (SCM_CODE (proc)), scm_cons2 (t.arg1, arg2, SCM_EOL), SCM_ENV (proc));
0f2d19dd 2159#endif
6dbd0af5
MD
2160 x = SCM_CODE (proc);
2161 goto cdrxbegin;
2162 }
0f2d19dd
JB
2163 }
2164#ifdef DEVAL
6dbd0af5
MD
2165 debug.info->a.args = scm_cons2 (t.arg1, arg2,
2166 scm_deval_args (x, env, &SCM_CDR (SCM_CDR (debug.info->a.args))));
0f2d19dd 2167#endif
6dbd0af5
MD
2168 ENTER_APPLY;
2169 switch (SCM_TYP7 (proc))
2170 { /* have 3 or more arguments */
0f2d19dd 2171#ifdef DEVAL
6dbd0af5
MD
2172 case scm_tc7_subr_3:
2173 SCM_ASRTGO (SCM_NULLP (SCM_CDR (x)), wrongnumargs);
2174 RETURN (SCM_SUBRF (proc) (t.arg1, arg2, SCM_CAR (SCM_CDR (SCM_CDR (debug.info->a.args)))));
2175 case scm_tc7_asubr:
2176 /* t.arg1 = SCM_SUBRF(proc)(t.arg1, arg2);
2177 while SCM_NIMP(x) {
2178 t.arg1 = SCM_SUBRF(proc)(t.arg1, EVALCAR(x, env));
2179 x = SCM_CDR(x);
2180 }
2181 RETURN (t.arg1) */
2182 case scm_tc7_rpsubr:
2183 RETURN (SCM_APPLY (proc, t.arg1, scm_acons (arg2, SCM_CDR (SCM_CDR (debug.info->a.args)), SCM_EOL)))
2184 case scm_tc7_lsubr_2:
2185 RETURN (SCM_SUBRF (proc) (t.arg1, arg2, SCM_CDR (SCM_CDR (debug.info->a.args))))
2186 case scm_tc7_lsubr:
2187 RETURN (SCM_SUBRF (proc) (debug.info->a.args))
0f2d19dd 2188#ifdef CCLO
6dbd0af5
MD
2189 case scm_tc7_cclo:
2190 goto cclon;
0f2d19dd 2191#endif
6dbd0af5
MD
2192 case scm_tcs_closures:
2193 SETARGSREADY (debug);
2194 env = EXTEND_SCM_ENV (SCM_CAR (SCM_CODE (proc)),
2195 debug.info->a.args,
2196 SCM_ENV (proc));
2197 x = SCM_CODE (proc);
2198 goto cdrxbegin;
2199#else /* DEVAL */
2200 case scm_tc7_subr_3:
2201 SCM_ASRTGO (SCM_NULLP (SCM_CDR (x)), wrongnumargs);
2202 RETURN (SCM_SUBRF (proc) (t.arg1, arg2, EVALCAR (x, env)));
2203 case scm_tc7_asubr:
2204 /* t.arg1 = SCM_SUBRF(proc)(t.arg1, arg2);
2205 while SCM_NIMP(x) {
2206 t.arg1 = SCM_SUBRF(proc)(t.arg1, EVALCAR(x, env));
2207 x = SCM_CDR(x);
2208 }
2209 RETURN (t.arg1) */
2210 case scm_tc7_rpsubr:
2211 RETURN (SCM_APPLY (proc, t.arg1, scm_acons (arg2, scm_eval_args (x, env), SCM_EOL)));
2212 case scm_tc7_lsubr_2:
2213 RETURN (SCM_SUBRF (proc) (t.arg1, arg2, scm_eval_args (x, env)));
2214 case scm_tc7_lsubr:
2215 RETURN (SCM_SUBRF (proc) (scm_cons2 (t.arg1, arg2, scm_eval_args (x, env))));
0f2d19dd 2216#ifdef CCLO
6dbd0af5
MD
2217 case scm_tc7_cclo:
2218 goto cclon;
0f2d19dd 2219#endif
6dbd0af5
MD
2220 case scm_tcs_closures:
2221#ifdef DEVAL
2222 SETARGSREADY (debug);
2223#endif
2224 env = EXTEND_SCM_ENV (SCM_CAR (SCM_CODE (proc)),
2225 scm_cons2 (t.arg1, arg2, scm_eval_args (x, env)),
2226 SCM_ENV (proc));
2227 x = SCM_CODE (proc);
2228 goto cdrxbegin;
0f2d19dd 2229#endif /* DEVAL */
6dbd0af5
MD
2230 case scm_tc7_subr_2:
2231 case scm_tc7_subr_1o:
2232 case scm_tc7_subr_2o:
2233 case scm_tc7_subr_0:
2234 case scm_tc7_cxr:
2235 case scm_tc7_subr_1:
2236 case scm_tc7_contin:
2237 goto wrongnumargs;
2238 default:
2239 goto badfun;
2240 }
0f2d19dd
JB
2241 }
2242#ifdef DEVAL
6dbd0af5
MD
2243exit:
2244 if (CHECK_EXIT)
2245 if (EXIT_FRAME || (TRACE && TRACEDFRAMEP (debug)))
2246 {
2247 EXIT_FRAME = 0;
2248 RESET_DEBUG_MODE;
2249 CLEARTRACEDFRAME (debug);
2250 if (CHEAPTRAPS)
2251 t.arg1 = scm_make_debugobj ((scm_debug_frame *) &debug);
2252 else
2253 {
2254 scm_make_cont (&t.arg1);
2255 if (setjmp (SCM_JMPBUF (t.arg1)))
2256 {
2257 proc = SCM_THROW_VALUE (t.arg1);
2258 goto ret;
2259 }
2260 }
2261 scm_ithrow (scm_i_exit_frame, scm_cons2 (t.arg1, proc, SCM_EOL), 0);
2262 }
2263ret:
2264 last_debug_info_frame = debug.prev;
0f2d19dd
JB
2265 return proc;
2266#endif
2267}
2268
6dbd0af5
MD
2269
2270/* SECTION: This code is compiled once.
2271 */
2272
0f2d19dd
JB
2273#ifndef DEVAL
2274
2275SCM_PROC(s_procedure_documentation, "procedure-documentation", 1, 0, 0, scm_procedure_documentation);
2276#ifdef __STDC__
2277SCM
2278scm_procedure_documentation (SCM proc)
2279#else
2280SCM
2281scm_procedure_documentation (proc)
2282 SCM proc;
2283#endif
2284{
2285 SCM code;
2286 SCM_ASSERT (SCM_BOOL_T == scm_procedure_p (proc) && SCM_NIMP (proc) && SCM_TYP7 (proc) != scm_tc7_contin,
2287 proc, SCM_ARG1, s_procedure_documentation);
2288 switch (SCM_TYP7 (proc))
2289 {
2290 case scm_tcs_closures:
2291 code = SCM_CDR (SCM_CODE (proc));
2292 if (SCM_IMP (SCM_CDR (code)))
2293 return SCM_BOOL_F;
2294 code = SCM_CAR (code);
2295 if (SCM_IMP (code))
2296 return SCM_BOOL_F;
2297 if (SCM_STRINGP (code))
2298 return code;
2299 default:
2300 return SCM_BOOL_F;
2301/*
2302 case scm_tcs_subrs:
2303#ifdef CCLO
2304 case scm_tc7_cclo:
2305#endif
2306*/
2307 }
2308}
2309
2310/* This code is for scm_apply. it is destructive on multiple args.
2311 * This will only screw you if you do (scm_apply scm_apply '( ... ))
2312 */
2313SCM_PROC(s_nconc2last, "apply:nconc2last", 1, 0, 0, scm_nconc2last);
2314#ifdef __STDC__
2315SCM
2316scm_nconc2last (SCM lst)
2317#else
2318SCM
2319scm_nconc2last (lst)
2320 SCM lst;
2321#endif
2322{
2323 SCM *lloc;
2324 if (SCM_EOL == lst)
2325 return lst;
2326 SCM_ASSERT (SCM_NIMP (lst) && SCM_CONSP (lst), lst, SCM_ARG1, s_nconc2last);
2327 lloc = &lst;
2328 while (SCM_NNULLP (SCM_CDR (*lloc)))
2329 {
2330 lloc = &SCM_CDR (*lloc);
2331 SCM_ASSERT (SCM_NIMP (*lloc) && SCM_CONSP (*lloc), lst, SCM_ARG1, s_nconc2last);
2332 }
2333 *lloc = SCM_CAR (*lloc);
2334 return lst;
2335}
2336
2337#endif /* !DEVAL */
2338
6dbd0af5
MD
2339
2340/* SECTION: When DEVAL is defined this code yields scm_dapply.
2341 * It is compiled twice.
2342 */
2343
0f2d19dd
JB
2344#if 0
2345#ifdef __STDC__
2346SCM
2347scm_apply (SCM proc, SCM arg1, SCM args)
2348#else
2349SCM
2350scm_apply (proc, arg1, args)
2351 SCM proc;
2352 SCM arg1;
2353 SCM args;
2354#endif
2355{}
2356#endif
2357
2358#if 0
2359#ifdef __STDC__
2360SCM
2361scm_dapply (SCM proc, SCM arg1, SCM args)
2362#else
2363SCM
2364scm_dapply (proc, arg1, args)
2365 SCM proc;
2366 SCM arg1;
2367 SCM args;
2368#endif
2369{}
2370#endif
2371
0f2d19dd
JB
2372#ifdef __STDC__
2373SCM
2374SCM_APPLY (SCM proc, SCM arg1, SCM args)
2375#else
2376SCM
2377SCM_APPLY (proc, arg1, args)
2378 SCM proc;
2379 SCM arg1;
2380 SCM args;
2381#endif
2382{
2383#ifdef DEBUG_EXTENSIONS
2384#ifdef DEVAL
6dbd0af5
MD
2385 scm_debug_frame debug;
2386 debug.prev = last_debug_info_frame;
2387 debug.status = APPLYFRAME;
2388 debug.vect[0].a.proc = proc;
2389 debug.vect[0].a.args = SCM_EOL;
2390 last_debug_info_frame = &debug;
0f2d19dd
JB
2391#else
2392 if (DEBUGGINGP)
2393 return scm_dapply (proc, arg1, args);
2394#endif
2395#endif
2396
2397 SCM_ASRTGO (SCM_NIMP (proc), badproc);
2398 if (SCM_NULLP (args))
2399 {
2400 if (SCM_NULLP (arg1))
2401 arg1 = SCM_UNDEFINED;
2402 else
2403 {
2404 args = SCM_CDR (arg1);
2405 arg1 = SCM_CAR (arg1);
2406 }
2407 }
2408 else
2409 {
2410 /* SCM_ASRTGO(SCM_NIMP(args) && SCM_CONSP(args), wrongnumargs); */
2411 args = scm_nconc2last (args);
2412 }
0f2d19dd 2413#ifdef DEVAL
6dbd0af5
MD
2414 debug.vect[0].a.args = scm_cons (arg1, args);
2415 if (ENTER_FRAME)
2416 {
2417 SCM tmp;
2418 ENTER_FRAME = 0;
2419 RESET_DEBUG_MODE;
2420 if (CHEAPTRAPS)
2421 tmp = scm_make_debugobj ((scm_debug_frame *) &debug);
2422 else
2423 {
2424 scm_make_cont (&tmp);
2425 if (setjmp (SCM_JMPBUF (tmp)))
2426 goto entap;
2427 }
2428 scm_ithrow (scm_i_enter_frame, scm_cons (tmp, SCM_EOL), 0);
2429 }
2430entap:
2431 ENTER_APPLY;
2432#endif
2433#ifdef CCLO
2434tail:
0f2d19dd
JB
2435#endif
2436 switch (SCM_TYP7 (proc))
2437 {
2438 case scm_tc7_subr_2o:
2439 args = SCM_NULLP (args) ? SCM_UNDEFINED : SCM_CAR (args);
2440 RETURN (SCM_SUBRF (proc) (arg1, args))
2441 case scm_tc7_subr_2:
2442 SCM_ASRTGO (SCM_NULLP (SCM_CDR (args)), wrongnumargs);
2443 args = SCM_CAR (args);
2444 RETURN (SCM_SUBRF (proc) (arg1, args))
2445 case scm_tc7_subr_0:
2446 SCM_ASRTGO (SCM_UNBNDP (arg1), wrongnumargs);
2447 RETURN (SCM_SUBRF (proc) ())
2448 case scm_tc7_subr_1:
2449 case scm_tc7_subr_1o:
2450 SCM_ASRTGO (SCM_NULLP (args), wrongnumargs);
2451 RETURN (SCM_SUBRF (proc) (arg1))
2452 case scm_tc7_cxr:
2453 SCM_ASRTGO (SCM_NULLP (args), wrongnumargs);
2454#ifdef SCM_FLOATS
2455 if (SCM_SUBRF (proc))
2456 {
6dbd0af5
MD
2457 if (SCM_INUMP (arg1))
2458 {
2459 RETURN (scm_makdbl (SCM_DSUBRF (proc) ((double) SCM_INUM (arg1)), 0.0));
2460 }
0f2d19dd 2461 SCM_ASRTGO (SCM_NIMP (arg1), floerr);
6dbd0af5
MD
2462 if (SCM_REALP (arg1))
2463 {
2464 RETURN (scm_makdbl (SCM_DSUBRF (proc) (SCM_REALPART (arg1)), 0.0));
2465 }
0f2d19dd
JB
2466#ifdef SCM_BIGDIG
2467 if SCM_BIGP
2468 (arg1)
2469 RETURN (scm_makdbl (SCM_DSUBRF (proc) (scm_big2dbl (arg1)), 0.0))
2470#endif
2471 floerr:
2472 scm_wta (arg1, (char *) SCM_ARG1, SCM_CHARS (SCM_SNAME (proc)));
2473 }
2474#endif
2475 proc = (SCM) SCM_SNAME (proc);
2476 {
2477 char *chrs = SCM_CHARS (proc) + SCM_LENGTH (proc) - 1;
2478 while ('c' != *--chrs)
2479 {
2480 SCM_ASSERT (SCM_NIMP (arg1) && SCM_CONSP (arg1),
2481 arg1, SCM_ARG1, SCM_CHARS (proc));
2482 arg1 = ('a' == *chrs) ? SCM_CAR (arg1) : SCM_CDR (arg1);
2483 }
2484 RETURN (arg1)
2485 }
2486 case scm_tc7_subr_3:
2487 RETURN (SCM_SUBRF (proc) (arg1, SCM_CAR (args), SCM_CAR (SCM_CDR (args))))
2488 case scm_tc7_lsubr:
2489#ifdef DEVAL
6dbd0af5 2490 RETURN (SCM_SUBRF (proc) (SCM_UNBNDP (arg1) ? SCM_EOL : debug.vect[0].a.args))
0f2d19dd
JB
2491#else
2492 RETURN (SCM_SUBRF (proc) (SCM_UNBNDP (arg1) ? SCM_EOL : scm_cons (arg1, args)))
2493#endif
2494 case scm_tc7_lsubr_2:
2495 SCM_ASRTGO (SCM_NIMP (args) && SCM_CONSP (args), wrongnumargs);
2496 RETURN (SCM_SUBRF (proc) (arg1, SCM_CAR (args), SCM_CDR (args)))
2497 case scm_tc7_asubr:
2498 if (SCM_NULLP (args))
2499 RETURN (SCM_SUBRF (proc) (arg1, SCM_UNDEFINED))
2500 while (SCM_NIMP (args))
2501 {
2502 SCM_ASSERT (SCM_CONSP (args), args, SCM_ARG2, "apply");
2503 arg1 = SCM_SUBRF (proc) (arg1, SCM_CAR (args));
2504 args = SCM_CDR (args);
2505 }
2506 RETURN (arg1);
2507 case scm_tc7_rpsubr:
2508 if (SCM_NULLP (args))
2509 RETURN (SCM_BOOL_T);
2510 while (SCM_NIMP (args))
2511 {
2512 SCM_ASSERT (SCM_CONSP (args), args, SCM_ARG2, "apply");
2513 if (SCM_FALSEP (SCM_SUBRF (proc) (arg1, SCM_CAR (args))))
2514 RETURN (SCM_BOOL_F);
2515 arg1 = SCM_CAR (args);
2516 args = SCM_CDR (args);
2517 }
2518 RETURN (SCM_BOOL_T);
2519 case scm_tcs_closures:
2520#ifdef DEVAL
6dbd0af5 2521 arg1 = (SCM_UNBNDP (arg1) ? SCM_EOL : debug.vect[0].a.args);
0f2d19dd
JB
2522#else
2523 arg1 = (SCM_UNBNDP (arg1) ? SCM_EOL : scm_cons (arg1, args));
2524#endif
2525#ifndef RECKLESS
2526 if (scm_badargsp (SCM_CAR (SCM_CODE (proc)), arg1))
2527 goto wrongnumargs;
2528#endif
2529 args = EXTEND_SCM_ENV (SCM_CAR (SCM_CODE (proc)), arg1, SCM_ENV (proc));
2530 proc = SCM_CODE (proc);
2531 while (SCM_NNULLP (proc = SCM_CDR (proc)))
2532 arg1 = EVALCAR (proc, args);
2533 RETURN (arg1);
2534 case scm_tc7_contin:
2535 SCM_ASRTGO (SCM_NULLP (args), wrongnumargs);
2536 scm_call_continuation (proc, arg1);
2537#ifdef CCLO
2538 case scm_tc7_cclo:
2539#ifdef DEVAL
6dbd0af5
MD
2540 args = (SCM_UNBNDP(arg1) ? SCM_EOL : debug.vect[0].a.args);
2541 arg1 = proc;
2542 proc = SCM_CCLO_SUBR (proc);
2543 debug.vect[0].a.proc = proc;
2544 debug.vect[0].a.args = scm_cons (arg1, args);
0f2d19dd
JB
2545#else
2546 args = (SCM_UNBNDP(arg1) ? SCM_EOL : scm_cons (arg1, args));
0f2d19dd
JB
2547 arg1 = proc;
2548 proc = SCM_CCLO_SUBR (proc);
6dbd0af5 2549#endif
0f2d19dd
JB
2550 goto tail;
2551#endif
2552 wrongnumargs:
2553 scm_wta (proc, (char *) SCM_WNA, "apply");
2554 default:
2555 badproc:
2556 scm_wta (proc, (char *) SCM_ARG1, "apply");
2557 RETURN (arg1);
2558 }
2559#ifdef DEVAL
6dbd0af5
MD
2560exit:
2561 if (CHECK_EXIT)
2562 if (EXIT_FRAME || (TRACE && TRACEDFRAMEP (debug)))
2563 {
2564 EXIT_FRAME = 0;
2565 RESET_DEBUG_MODE;
2566 CLEARTRACEDFRAME (debug);
2567 if (CHEAPTRAPS)
2568 arg1 = scm_make_debugobj ((scm_debug_frame *) &debug);
2569 else
2570 {
2571 scm_make_cont (&arg1);
2572 if (setjmp (SCM_JMPBUF (arg1)))
2573 {
2574 proc = SCM_THROW_VALUE (arg1);
2575 goto ret;
2576 }
2577 }
2578 scm_ithrow (scm_i_exit_frame, scm_cons2 (arg1, proc, SCM_EOL), 0);
2579 }
2580ret:
2581 last_debug_info_frame = debug.prev;
0f2d19dd
JB
2582 return proc;
2583#endif
2584}
2585
6dbd0af5
MD
2586
2587/* SECTION: The rest of this file is only read once.
2588 */
2589
0f2d19dd
JB
2590#ifndef DEVAL
2591
2592SCM_PROC(s_map, "map", 2, 0, 1, scm_map);
2593#ifdef __STDC__
2594SCM
2595scm_map (SCM proc, SCM arg1, SCM args)
2596#else
2597SCM
2598scm_map (proc, arg1, args)
2599 SCM proc;
2600 SCM arg1;
2601 SCM args;
2602#endif
2603{
2604 long i;
2605 SCM res = SCM_EOL;
2606 SCM *pres = &res;
2607 SCM *ve = &args; /* Keep args from being optimized away. */
2608
2609 if (SCM_NULLP (arg1))
2610 return res;
2611 SCM_ASSERT (SCM_NIMP (arg1), arg1, SCM_ARG2, s_map);
2612 if (SCM_NULLP (args))
2613 {
2614 while (SCM_NIMP (arg1))
2615 {
2616 SCM_ASSERT (SCM_CONSP (arg1), arg1, SCM_ARG2, s_map);
2617 *pres = scm_cons (scm_apply (proc, SCM_CAR (arg1), scm_listofnull), SCM_EOL);
2618 pres = &SCM_CDR (*pres);
2619 arg1 = SCM_CDR (arg1);
2620 }
2621 return res;
2622 }
2623 args = scm_vector (scm_cons (arg1, args));
2624 ve = SCM_VELTS (args);
2625#ifndef RECKLESS
2626 for (i = SCM_LENGTH (args) - 1; i >= 0; i--)
2627 SCM_ASSERT (SCM_NIMP (ve[i]) && SCM_CONSP (ve[i]), args, SCM_ARG2, s_map);
2628#endif
2629 while (1)
2630 {
2631 arg1 = SCM_EOL;
2632 for (i = SCM_LENGTH (args) - 1; i >= 0; i--)
2633 {
2634 if SCM_IMP
2635 (ve[i]) return res;
2636 arg1 = scm_cons (SCM_CAR (ve[i]), arg1);
2637 ve[i] = SCM_CDR (ve[i]);
2638 }
2639 *pres = scm_cons (scm_apply (proc, arg1, SCM_EOL), SCM_EOL);
2640 pres = &SCM_CDR (*pres);
2641 }
2642}
2643
2644
2645SCM_PROC(s_for_each, "for-each", 2, 0, 1, scm_for_each);
2646#ifdef __STDC__
2647SCM
2648scm_for_each (SCM proc, SCM arg1, SCM args)
2649#else
2650SCM
2651scm_for_each (proc, arg1, args)
2652 SCM proc;
2653 SCM arg1;
2654 SCM args;
2655#endif
2656{
2657 SCM *ve = &args; /* Keep args from being optimized away. */
2658 long i;
2659 if SCM_NULLP (arg1)
2660 return SCM_UNSPECIFIED;
2661 SCM_ASSERT (SCM_NIMP (arg1), arg1, SCM_ARG2, s_for_each);
2662 if SCM_NULLP (args)
2663 {
2664 while SCM_NIMP (arg1)
2665 {
2666 SCM_ASSERT (SCM_CONSP (arg1), arg1, SCM_ARG2, s_for_each);
2667 scm_apply (proc, SCM_CAR (arg1), scm_listofnull);
2668 arg1 = SCM_CDR (arg1);
2669 }
2670 return SCM_UNSPECIFIED;
2671 }
2672 args = scm_vector (scm_cons (arg1, args));
2673 ve = SCM_VELTS (args);
2674#ifndef RECKLESS
2675 for (i = SCM_LENGTH (args) - 1; i >= 0; i--)
2676 SCM_ASSERT (SCM_NIMP (ve[i]) && SCM_CONSP (ve[i]), args, SCM_ARG2, s_for_each);
2677#endif
2678 while (1)
2679 {
2680 arg1 = SCM_EOL;
2681 for (i = SCM_LENGTH (args) - 1; i >= 0; i--)
2682 {
2683 if SCM_IMP
2684 (ve[i]) return SCM_UNSPECIFIED;
2685 arg1 = scm_cons (SCM_CAR (ve[i]), arg1);
2686 ve[i] = SCM_CDR (ve[i]);
2687 }
2688 scm_apply (proc, arg1, SCM_EOL);
2689 }
2690}
2691
2692
2693#ifdef __STDC__
2694SCM
2695scm_closure (SCM code, SCM env)
2696#else
2697SCM
2698scm_closure (code, env)
2699 SCM code;
2700 SCM env;
2701#endif
2702{
2703 register SCM z;
2704 SCM_NEWCELL (z);
2705 SCM_SETCODE (z, code);
2706 SCM_ENV (z) = env;
2707 return z;
2708}
2709
2710
2711long scm_tc16_promise;
2712#ifdef __STDC__
2713SCM
2714scm_makprom (SCM code)
2715#else
2716SCM
2717scm_makprom (code)
2718 SCM code;
2719#endif
2720{
2721 register SCM z;
2722 SCM_NEWCELL (z);
2723 SCM_CDR (z) = code;
2724 SCM_CAR (z) = scm_tc16_promise;
2725 return z;
2726}
2727
2728
2729#ifdef __STDC__
2730static int
2731prinprom (SCM exp, SCM port, int writing)
2732#else
2733static int
2734prinprom (exp, port, writing)
2735 SCM exp;
2736 SCM port;
2737 int writing;
2738#endif
2739{
2740 scm_gen_puts (scm_regular_string, "#<promise ", port);
2741 scm_iprin1 (SCM_CDR (exp), port, writing);
2742 scm_gen_putc ('>', port);
2743 return !0;
2744}
2745
2746
2747SCM_PROC(s_makacro, "procedure->syntax", 1, 0, 0, scm_makacro);
2748#ifdef __STDC__
2749SCM
2750scm_makacro (SCM code)
2751#else
2752SCM
2753scm_makacro (code)
2754 SCM code;
2755#endif
2756{
2757 register SCM z;
2758 SCM_NEWCELL (z);
2759 SCM_CDR (z) = code;
2760 SCM_CAR (z) = scm_tc16_macro;
2761 return z;
2762}
2763
2764
2765SCM_PROC(s_makmacro, "procedure->macro", 1, 0, 0, scm_makmacro);
2766#ifdef __STDC__
2767SCM
2768scm_makmacro (SCM code)
2769#else
2770SCM
2771scm_makmacro (code)
2772 SCM code;
2773#endif
2774{
2775 register SCM z;
2776 SCM_NEWCELL (z);
2777 SCM_CDR (z) = code;
2778 SCM_CAR (z) = scm_tc16_macro | (1L << 16);
2779 return z;
2780}
2781
2782
2783SCM_PROC(s_makmmacro, "procedure->memoizing-macro", 1, 0, 0, scm_makmmacro);
2784#ifdef __STDC__
2785SCM
2786scm_makmmacro (SCM code)
2787#else
2788SCM
2789scm_makmmacro (code)
2790 SCM code;
2791#endif
2792{
2793 register SCM z;
2794 SCM_NEWCELL (z);
2795 SCM_CDR (z) = code;
2796 SCM_CAR (z) = scm_tc16_macro | (2L << 16);
2797 return z;
2798}
2799
2800
2801#ifdef __STDC__
2802static int
2803prinmacro (SCM exp, SCM port, int writing)
2804#else
2805static int
2806prinmacro (exp, port, writing)
2807 SCM exp;
2808 SCM port;
2809 int writing;
2810#endif
2811{
2812 if (SCM_CAR (exp) & (3L << 16))
2813 scm_gen_puts (scm_regular_string, "#<macro", port);
2814 else
2815 scm_gen_puts (scm_regular_string, "#<syntax", port);
2816 if (SCM_CAR (exp) & (2L << 16))
2817 scm_gen_putc ('!', port);
2818 scm_gen_putc (' ', port);
2819 scm_iprin1 (SCM_CDR (exp), port, writing);
2820 scm_gen_putc ('>', port);
2821 return !0;
2822}
2823
2824SCM_PROC(s_force, "force", 1, 0, 0, scm_force);
2825#ifdef __STDC__
2826SCM
2827scm_force (SCM x)
2828#else
2829SCM
2830scm_force (x)
2831 SCM x;
2832#endif
2833{
2834 SCM_ASSERT ((SCM_TYP16 (x) == scm_tc16_promise), x, SCM_ARG1, s_force);
2835 if (!((1L << 16) & SCM_CAR (x)))
2836 {
2837 SCM ans = scm_apply (SCM_CDR (x), SCM_EOL, SCM_EOL);
2838 if (!((1L << 16) & SCM_CAR (x)))
2839 {
2840 SCM_DEFER_INTS;
2841 SCM_CDR (x) = ans;
2842 SCM_CAR (x) |= (1L << 16);
2843 SCM_ALLOW_INTS;
2844 }
2845 }
2846 return SCM_CDR (x);
2847}
2848
2849SCM_PROC (s_promise_p, "promise?", 1, 0, 0, scm_promise_p);
2850#ifdef __STDC__
2851SCM
2852scm_promise_p (SCM x)
2853#else
2854SCM
2855scm_promise_p (x)
2856 SCM x;
2857#endif
2858{
2859 return ((SCM_NIMP (x) && (SCM_TYP16 (x) == scm_tc16_promise))
2860 ? SCM_BOOL_T
2861 : SCM_BOOL_F);
2862}
2863
2864SCM_PROC(s_copy_tree, "copy-tree", 1, 0, 0, scm_copy_tree);
2865#ifdef __STDC__
2866SCM
2867scm_copy_tree (SCM obj)
2868#else
2869SCM
2870scm_copy_tree (obj)
2871 SCM obj;
2872#endif
2873{
2874 SCM ans, tl;
2875 if SCM_IMP
2876 (obj) return obj;
2877 if (SCM_VECTORP (obj))
2878 {
2879 scm_sizet i = SCM_LENGTH (obj);
2880 ans = scm_make_vector (SCM_MAKINUM (i), SCM_UNSPECIFIED, SCM_UNDEFINED);
2881 while (i--)
2882 SCM_VELTS (ans)[i] = scm_copy_tree (SCM_VELTS (obj)[i]);
2883 return ans;
2884 }
2885 if SCM_NCONSP (obj)
2886 return obj;
2887/* return scm_cons(scm_copy_tree(SCM_CAR(obj)), scm_copy_tree(SCM_CDR(obj))); */
2888 ans = tl = scm_cons (scm_copy_tree (SCM_CAR (obj)), SCM_UNSPECIFIED);
2889 while (SCM_NIMP (obj = SCM_CDR (obj)) && SCM_CONSP (obj))
2890 tl = (SCM_CDR (tl) = scm_cons (scm_copy_tree (SCM_CAR (obj)), SCM_UNSPECIFIED));
2891 SCM_CDR (tl) = obj;
2892 return ans;
2893}
2894
2895#ifdef __STDC__
2896SCM
2897scm_eval_3 (SCM obj, int copyp, SCM env)
2898#else
2899SCM
2900scm_eval_3 (obj, copyp, env)
2901 SCM obj;
2902 int copyp;
2903 SCM env;
2904#endif
2905{
2906 if (SCM_NIMP (SCM_CDR (scm_system_transformer)))
2907 obj = scm_apply (SCM_CDR (scm_system_transformer), obj, scm_listofnull);
2908 else if (copyp)
2909 obj = scm_copy_tree (obj);
6dbd0af5 2910 return XEVAL (obj, env);
0f2d19dd
JB
2911}
2912
2913#ifdef __STDC__
2914SCM
2915scm_top_level_env (SCM thunk)
2916#else
2917SCM
2918scm_top_level_env (thunk)
2919 SCM thunk;
2920#endif
2921{
2922 if (SCM_IMP(thunk))
2923 return SCM_EOL;
2924 else
2925 return scm_cons(thunk, (SCM)SCM_EOL);
2926}
2927
2928SCM_PROC(s_eval2, "eval2", 2, 0, 0, scm_eval2);
2929#ifdef __STDC__
2930SCM
2931scm_eval2 (SCM obj, SCM env_thunk)
2932#else
2933SCM
2934scm_eval2 (obj, env_thunk)
2935 SCM obj;
2936 SCM env_thunk;
2937#endif
2938{
2939 return scm_eval_3 (obj, 1, scm_top_level_env(env_thunk));
2940}
2941
2942SCM_PROC(s_eval, "eval", 1, 0, 0, scm_eval);
2943#ifdef __STDC__
2944SCM
2945scm_eval (SCM obj)
2946#else
2947SCM
2948scm_eval (obj)
2949 SCM obj;
2950#endif
2951{
2952 return
2953 scm_eval_3(obj, 1, scm_top_level_env(SCM_CDR(scm_top_level_lookup_thunk_var)));
2954}
2955
2956SCM_PROC(s_eval_x, "eval!", 1, 0, 0, scm_eval_x);
2957#ifdef __STDC__
2958SCM
2959scm_eval_x (SCM obj)
2960#else
2961SCM
2962scm_eval_x (obj)
2963 SCM obj;
2964#endif
2965{
2966 return
2967 scm_eval_3(obj,
2968 0,
2969 scm_top_level_env (SCM_CDR (scm_top_level_lookup_thunk_var)));
2970}
2971
2972SCM_PROC (s_macro_eval_x, "macro-eval!", 2, 0, 0, scm_macro_eval_x);
2973#ifdef __STDC__
2974SCM
2975scm_macro_eval_x (SCM exp, SCM env)
2976#else
2977SCM
2978scm_macro_eval_x (exp, env)
2979 SCM exp;
2980 SCM env;
2981#endif
2982{
2983 return scm_eval_3 (exp, 0, env);
2984}
2985
2986#ifdef __STDC__
2987SCM
2988scm_definedp (SCM x, SCM env)
2989#else
2990SCM
2991scm_definedp (x, env)
2992 SCM x;
2993 SCM env;
2994#endif
2995{
2996 SCM proc = SCM_CAR (x = SCM_CDR (x));
2997 if (SCM_ISYMP (proc))
2998 return SCM_BOOL_T;
2999 else if(SCM_IMP(proc) || !SCM_SYMBOLP(proc))
3000 return SCM_BOOL_F;
3001 else
3002 {
3003 SCM vcell = scm_sym2vcell(proc, env_top_level(env), SCM_BOOL_F);
3004 return (vcell == SCM_BOOL_F || SCM_UNBNDP(SCM_CDR(vcell))) ? SCM_BOOL_F : SCM_BOOL_T;
3005 }
3006}
3007
3008static scm_smobfuns promsmob =
3009{scm_markcdr, scm_free0, prinprom};
3010
3011static scm_smobfuns macrosmob =
3012{scm_markcdr, scm_free0, prinmacro};
3013
3014#ifdef __STDC__
3015SCM
3016scm_make_synt (char *name, SCM (*macroizer) (), SCM (*fcn) ())
3017#else
3018SCM
3019scm_make_synt (name, macroizer, fcn)
3020 char *name;
3021 SCM (*macroizer) ();
3022 SCM (*fcn) ();
3023#endif
3024{
3025 SCM symcell = scm_sysintern (name, SCM_UNDEFINED);
3026 long tmp = ((((SCM_CELLPTR) (SCM_CAR (symcell))) - scm_heap_org) << 8);
3027 register SCM z;
3028 if ((tmp >> 8) != ((SCM_CELLPTR) (SCM_CAR (symcell)) - scm_heap_org))
3029 tmp = 0;
3030 SCM_NEWCELL (z);
3031 SCM_SUBRF (z) = fcn;
3032 SCM_CAR (z) = tmp + scm_tc7_subr_2;
3033 SCM_CDR (symcell) = macroizer (z);
3034 return SCM_CAR (symcell);
3035}
3036
6dbd0af5
MD
3037
3038/* At this point, scm_deval and scm_dapply are generated.
3039 */
3040
0f2d19dd 3041#ifdef DEBUG_EXTENSIONS
6dbd0af5
MD
3042# define DEVAL
3043# include "eval.c"
0f2d19dd
JB
3044#endif
3045
3046
3047#ifdef __STDC__
3048void
3049scm_init_eval (void)
3050#else
3051void
3052scm_init_eval ()
3053#endif
3054{
0f2d19dd
JB
3055 scm_tc16_promise = scm_newsmob (&promsmob);
3056 scm_tc16_macro = scm_newsmob (&macrosmob);
3057 scm_i_apply = scm_make_subr ("apply", scm_tc7_lsubr_2, scm_apply);
3058 scm_system_transformer = scm_sysintern ("scm:eval-transformer", SCM_UNDEFINED);
3059 scm_i_dot = SCM_CAR (scm_sysintern (".", SCM_UNDEFINED));
3060 scm_i_arrow = SCM_CAR (scm_sysintern ("=>", SCM_UNDEFINED));
3061 scm_i_else = SCM_CAR (scm_sysintern ("else", SCM_UNDEFINED));
3062 scm_i_unquote = SCM_CAR (scm_sysintern ("unquote", SCM_UNDEFINED));
3063 scm_i_uq_splicing = SCM_CAR (scm_sysintern ("unquote-splicing", SCM_UNDEFINED));
3064
3065 /* acros */
3066 scm_i_quasiquote = scm_make_synt (s_quasiquote, scm_makacro, scm_m_quasiquote);
6dbd0af5 3067 scm_make_synt (s_undefine, scm_makacro, scm_m_undefine);
0f2d19dd
JB
3068 scm_make_synt (s_delay, scm_makacro, scm_m_delay);
3069 /* end of acros */
3070
3071 scm_top_level_lookup_thunk_var =
3072 scm_sysintern("*top-level-lookup-thunk*", SCM_BOOL_F);
3073
6dbd0af5
MD
3074 scm_i_and = scm_make_synt ("and", scm_makmmacro, scm_m_and);
3075 scm_i_begin = scm_make_synt ("begin", scm_makmmacro, scm_m_begin);
3076 scm_i_case = scm_make_synt ("case", scm_makmmacro, scm_m_case);
3077 scm_i_cond = scm_make_synt ("cond", scm_makmmacro, scm_m_cond);
3078 scm_i_define = scm_make_synt ("define", scm_makmmacro, scm_m_define);
3079 scm_i_do = scm_make_synt ("do", scm_makmmacro, scm_m_do);
3080 scm_i_if = scm_make_synt ("if", scm_makmmacro, scm_m_if);
0f2d19dd
JB
3081 scm_i_lambda = scm_make_synt ("lambda", scm_makmmacro, scm_m_lambda);
3082 scm_i_let = scm_make_synt ("let", scm_makmmacro, scm_m_let);
6dbd0af5
MD
3083 scm_i_letrec = scm_make_synt ("letrec", scm_makmmacro, scm_m_letrec);
3084 scm_i_letstar = scm_make_synt ("let*", scm_makmmacro, scm_m_letstar);
3085 scm_i_or = scm_make_synt ("or", scm_makmmacro, scm_m_or);
0f2d19dd 3086 scm_i_quote = scm_make_synt ("quote", scm_makmmacro, scm_m_quote);
6dbd0af5
MD
3087 scm_i_set = scm_make_synt ("set!", scm_makmmacro, scm_m_set);
3088 scm_i_atapply = scm_make_synt ("@apply", scm_makmmacro, scm_m_apply);
3089 scm_i_atcall_cc = scm_make_synt ("@call-with-current-continuation",
3090 scm_makmmacro, scm_m_cont);
3091
0f2d19dd
JB
3092 scm_make_synt ("defined?", scm_makmmacro, scm_definedp);
3093 scm_i_name = SCM_CAR (scm_sysintern ("name", SCM_UNDEFINED));
3094 scm_permanent_object (scm_i_name);
6dbd0af5
MD
3095
3096#ifdef DEBUG_EXTENSIONS
3097 scm_i_enter_frame = SCM_CAR (scm_sysintern ("enter-frame", SCM_UNDEFINED));
3098 scm_i_apply_frame = SCM_CAR (scm_sysintern ("apply-frame", SCM_UNDEFINED));
3099 scm_i_exit_frame = SCM_CAR (scm_sysintern ("exit-frame", SCM_UNDEFINED));
3100 scm_i_trace = SCM_CAR (scm_sysintern ("trace", SCM_UNDEFINED));
3101#endif
3102
0f2d19dd
JB
3103#include "eval.x"
3104}
0f2d19dd 3105
6dbd0af5 3106#endif /* !DEVAL */