#include #include #include #include "paper.h" #include "y.tab.h" #include "impl.h" static int callhook(char *name) { Lsym *l; Node *n; l = look(name); if(l && l->proc) { n = an(ONAME, ZN, ZN); n->sym = l; n = an(OCALL, n, ZN); execute(n); return 0; } return -1; } static void die(void) { if(setjmp(err) == 0) callhook("dying"); exits(0); } void ppsetup(void) { fmtinstall('L', Lfmt); quotefmtinstall(); kinit(); installbuiltin(); /* used by ppcall */ /* Value *v; Lsym *s; s = mkvar("_result"); v = gmalloc(sizeof(Value)); memset(v, 0, sizeof(Value)); s->v = v; */ } void ppdestroy(void) { int i; Lsym *s, *next; unwind(); for(i = 0; i < Hashsize; i++){ for(s = hash[i]; s; s = next){ next = s->hash; free(s->name); free(s->v); free(s); } hash[i] = nil; } gc(1); } void ppinput(void) { for(;;) { if(setjmp(err)) unwind(); pushfile(0); if(yyparse() != 1){ die(); } restartio(); unwind(); } popio(); } void ppbind(char *name, void (*fn)(Node*, Node**, int)) { Lsym *s; s = look(name); if(s == 0) s = enter(name, Tid); s->builtin = fn; } void ppcheckarg(Node **av, int na, int i, int type, Node *res) { assert(av != nil); assert(res != nil); if(i < 0) pperror("negative argument index"); if(i > na) pperror("not enough arguments"); ppexpr(av[i], res); if(res->store.type != type) pperror("expected %s, got %s", pptypenames[type], pptypenames[res->store.type]); } void yyerror(char *fmt, ...) { char buf[128]; va_list arg; if(strcmp(fmt, "syntax error") == 0) { yyerror("syntax error, near symbol '%s'", symbol); return; } va_start(arg, fmt); vseprint(buf, buf+sizeof(buf), fmt, arg); va_end(arg); werrstr("%L: %s", buf); //fprint(2, "%L: %s", buf); }