Initial commit, 3-52-19 alpha
[cls.git] / src / include / xlbcode.h
blob1dc1be5d8c004453f2ac782e997b16398ecc9035
1 #define DONE NIL
2 #define NO_VALUE -1
4 #define bcode_literals(fun) getbclits(getbcccode(fun))
5 #define get_one_result() xlresults[0]
6 #define get_nth_result(n) (((n) < xlnumresults) ? xlresults[n] : NIL)
7 #define set_nth_result(n,v) (xlresults[n] = (v))
8 #define set_no_results() (xlnumresults = 0, xlresults[0] = NIL)
9 #define set_one_result(v) (xlnumresults = 1, xlresults[0] = (v))
10 #define getlitval(n) (getelement(literals,n))
12 #define getlitfun(n, fun) { \
13 (fun) = getlitval(n); \
14 while (! fboundp(fun)) xlfunbound(fun); \
15 (fun) = getfunction(fun); \
18 #define getregval(i) (vsbase[i])
19 #define setregval(i,v) (vsbase[i] = (v))
21 #define RETURN(c) { \
22 LVAL __c__ = (getregval(c)); \
23 if (__c__ == DONE) { vsbase[-1] = NIL; return; } \
24 xlcstop = xlcontinuation_stack + getfixnum(__c__); \
25 vsbase = xlcstop->base; \
26 vstop = xlcstop->top; \
27 if (xlcstop->vreg != NO_VALUE) setregval(xlcstop->vreg,get_one_result()); \
28 if (xlcstop < FVcont) return; \
29 else { entry = xlcstop->pe.entry; goto Entry; } \
32 #define cmp_check_required_only_argcount(n) { \
33 int argc = vstop - vsbase; \
34 if (argc != (n)) { \
35 if (argc < (n)) xltoofew(); \
36 else xltoomany(); \
37 } \
40 #define cmp_push_space(n) { \
41 int __n__ = (n); \
42 if (xlsp + __n__ > xlargstktop) xlargstkoverflow(); \
43 while (__n__ -- > 0) *xlsp++ = NIL; \
46 extern LVAL cmpAREF1 _((LVAL xl, LVAL il));
48 #define cmpCAR(x) \
49 (tmp = (x), (null(tmp)) ? NIL : (consp(tmp)) ? car(tmp) : xlbadtype(tmp))
50 #define cmpCDR(x) \
51 (tmp = (x), (null(tmp)) ? NIL : (consp(tmp)) ? cdr(tmp) : xlbadtype(tmp))
53 #define cmp_save_current_continuation(Entry, vr) { \
54 if (xlcstop >= xlcsend) xlabort("continuation stack overflow"); \
55 xlcstop->base = vsbase; \
56 xlcstop->top = vstop; \
57 xlcstop->pe.entry = (Entry); \
58 xlcstop->vreg = (vr); \
59 xlcstop++; \
62 extern VOID cmp_call_setup _((LVAL fun, int vi, int entry, int argc,
63 LVAL cont, int tailp));
65 #define cmp_shift_tail_frame(base) { \
66 if (xlcstop[-1].base != base) { \
67 int n = vstop - vsbase; \
68 MEMMOVE(base - 1, vsbase - 1, sizeof(LVAL) * (n + 1)); \
69 vstop = base + n; \
70 vsbase = base; \
71 } \
74 #define cmp_do_call(fun, argc) { \
75 if (bcclosurep(fun)) return; \
76 else xlapply(argc); \
79 #define cmp_do_call_set(fun, argc, vreg) { \
80 if (bcclosurep(fun)) return; \
81 else setregval(vreg, xlapply(argc)); \
84 #define cmp_do_tail_call(fun,base,argc,creg) { \
85 if (bcclosurep(fun)) { \
86 cmp_shift_tail_frame(base); \
87 return; \
88 } \
89 else { \
90 xlapply(argc); \
91 RETURN(creg); \
92 } \
95 #define cmp_do_lcall(f) goto f;
97 #define cmp_do_tail_lcall(f,base) {\
98 cmp_shift_tail_frame(base); \
99 goto f; \
102 #define cmp_tail_lcall_setup(argc, cont) { \
103 LVAL Cont = (cont); \
104 pusharg(vsbase[-1]); \
105 vsbase = vstop; \
106 pusharg(Cont); \
107 if (xlsp + argc > xlargstktop) xlargstkoverflow(); \
110 #define cmp_lcall_setup(vi, entry, argc) { \
111 LVAL Cont; \
112 Cont = cvfixnum((FIXTYPE) (xlcstop - xlcontinuation_stack)); \
113 cmp_save_current_continuation(entry, vi); \
114 pusharg(vsbase[-1]); \
115 vsbase = vstop; \
116 pusharg(Cont); \
117 if (xlsp + argc > xlargstktop) xlargstkoverflow(); \