// This code has a bug that is explained in ../gc.html #include "h.h" #include 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) {cp argE = 3+x+*(us *)(x+1); // Where exp for argument is at. val f = eval(x+3, e); // function to apply val a = eval(argE, 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);} {env * e2 = alloca(sizeof(env)); *e2 = (env){a, f.u.f.e}; if (f.tag) return eval(f.u.f.c, e2); Bye("number as function");}} if(op == 255) return (val){1, {.f = {e, x+1}}}; {nis y = 0; ++x; do y = y<<7 | (*x & 0x7f); while(*(x++) < 0x80) ; return (val){0, { .i = y }};}} /* 172% ./replr2 (K 4 6) code = fe 06 00 fe 01 00 00 fd 84 fd 86 val = 32658931318788 ^C 172% ./repl2 (K 4 6) code = fe 06 00 fe 01 00 00 fd 84 fd 86 val = 4 */