#include #include #include "dat.h" #include "fns.h" Inst mkInst(char *op, int ne, ...) { int i; va_list arg; Inst inst; zero(inst); inst.op = op; inst.ne = ne; va_start(arg, ne); for(i=0; i= 8192) sysfatal("strdup big string"); if(nt < len){ t = malloc(8192); if(t == 0) sysfatal("out of memory"); nt = 8192; } r = t; t += len; nt -= len; strcpy(r, s); return r; } /* * Return a uniquely allocated copy of a string. * Don't free these -- they stay in the table for the * next caller who wants that particular string. * String comparison can be done with pointer comparison * if you know both strings are atoms. */ static Stringtab *stab[1024]; static uint hash(char *s) { uint h; uchar *p; h = 0; for(p=(uchar*)s; *p; p++) h = h*37 + *p; return h; } char* atom(char *str) { uint h; Stringtab *tab; h = hash(str) % nelem(stab); for(tab=stab[h]; tab; tab=tab->link) if(strcmp(str, tab->str) == 0) return tab->str; tab = taballoc(); tab->str = xstrdup(str); tab->link = stab[h]; stab[h] = tab; return tab->str; }