#include "h.h" #include static env work[worksize]; static int wp = worksize; env * gw(int z){if(!wp) {wp=worksize; Bye("Exhausted!");} return &work[--wp];} void crsh(char* d, cp c){exit(printf("%s: compiler bug at %d!", d, c-code));} val eval(cp x, env * e){ // Use the stack at first uchar op = *x; if(op < 253) {while(op--) if (e) e = e->out; else crsh("bad sym\n", x); return e->v;} if(op == 254) { val f = eval(x+3, e); // function to apply val a = eval(3+x+*(us *)(x+1), e); // argument to apply it to if(f.tag == 2) { if(a.tag) Bye("Numeric operator applied to function"); return f.u.p(a.u.i);} if (f.tag) {env * e2 = gw(0); *e2 = (env){a, f.u.f.e}; // extended environ return eval(f.u.f.c, e2);} Bye("number as function");} if(op == 255) return (val){1, {.f = {e, x+1}}}; {nis y = 0; do y = y<<7 | (*++x & 0x7f); while(*x < 0x80); return (val){0, { .i = y }};}}