#include "h.h" #include #include int od; // Number of primordial values uchar code[codesize]; // The compiled code static uchar false[] = {255, 0}; // (λx(λyy)) static uchar true [] = {255, 1}; // (λx(λyx)) static val increment(nis w){return (val){0, { .i = w+1}};} static val decrement(nis w){return (val){0, { .i = w-1}};} static val zeropred (nis w){return (val){1, { .f = {0, !w?true:false}}};} static val Putchar(nis w){putchar(w); return (val){0, { .i = w}};} static jmp_buf again; void Bye(char * d){loc(); printf("%s\n", d); tcflush(1, TCIFLUSH); longjmp(again, 42);} int main(){setjmp(again); init(); {env * prime_env = 0; cd=0; {void makeVal(uchar nm, val v){env * p = gw(); p->refcnt = 0; p->out = prime_env; if(prime_env) ++prime_env->refcnt; prime_env = p; p->v = v; symbols[cd++] = nm;} {void make_prim_fun(uchar nm, pf f){makeVal(nm, (val){2, { .p = f}});} make_prim_fun('i', increment); make_prim_fun('d', decrement); make_prim_fun('P', Putchar); make_prim_fun('z', zeropred);} {void make_first_fun(uchar nm, cp f) {makeVal(nm, (val){1, { .f = {0, f}}});} make_first_fun('H', false); make_first_fun('K', true);}} ++prime_env->refcnt; // pin the primal environ. while(1) {cx = code; od=cd; compile(); printf("code ="); {uchar * j; for(j = code; jrefcnt; // counter eval's decrement. {val v = eval(code, prime_env); if(v.tag) {printf("can't print function.\n"); if(v.tag==1 && v.u.f.e) dc(v.u.f.e);} else printf("val = %lld\n", v.u.i); pm();}}}}