void verify(Symbol* s) { if (s->type != VAR && s->type != UNDEF) execerror("attempt to evaluate non-variable", s->name); if (s->type == UNDEF) execerror("undefined variable", s->name); }
double errcheck(double d, char* s) /* check result of library call */ { if(isNaN(d)) execerror(s, "argument out of domain"); if(isInf(d, 0)) execerror(s, "result out of range"); return d; }
double errcheck(double d, char *s) { if (errno == EDOM) { errno = 0; execerror(s, "argument out of domain"); } else if (errno == ERANGE) { errno = 0; execerror(s, "result out of range"); } return d; }
void xpop(void) /* for when no value is wanted */ { if (stackp == stack) execerror("stack underflow", (char *)0); --stackp; }
void varread(void) /* read into variable */ { Datum d; extern Biobuf *bin; Symbol *var = (Symbol *) *pc++; int c; Again: do c = Bgetc(bin); while(c==' ' || c=='\t' || c=='\n'); if(c == Beof){ Iseof: if(moreinput()) goto Again; d.val = var->u.val = 0.0; goto Return; } if(strchr("+-.0123456789", c) == 0) execerror("non-number read into", var->name); Bungetc(bin); if(Bgetd(bin, &var->u.val) == Beof) goto Iseof; else d.val = 1.0; Return: var->type = VAR; push(d); }
Datum pop(void) { if (stackp == stack) execerror("stack underflow", 0); return *--stackp; }
char *emalloc(unsigned n) { char *p; p=malloc(n); if (p==0) execerror("\nFalta memoria\n",(char *)0); return p; }
int ExecveX(PCStr(where),PCStr(path),ConstV av,ConstV ev,int flag) { const char *nav[2]; /**/ char *nev[1024]; char **oev; int rcode; BeforeExec(); endhostent(); if( av[0] == NULL ) { nav[0] = nav[1] = NULL; av = nav; } oev = (char**)ev; if( flag & EXP_NOENV ) { filterDGENV(oev,nev,elnumof(nev)); ev = nev; } if( flag & EXP_NOFDS ) { closeFds(0); } if( flag & EXP_PATH ) { environ = (char**)ev; rcode = execvp(path,(char**)av); } else { rcode = execve(path,(char**)av,(char**)ev); } execerror(where,path,rcode); return -1; }
void push(Datum d) { if (stackp >= &stack[NSTACK]) execerror("stack too deep", 0); *stackp++ = d; }
double integer(double x) { if(x<-2147483648.0 || x>2147483647.0) execerror("argument out of domain", 0); return (double)(long)x; }
void procret(void) /* return from a procedure */ { if (fp->sp->type == FUNCTION) execerror(fp->sp->name, "(func) returns no value"); ret(); }
Datum pop() { if(stackp <= stack) { execerror("stack underflow", nil); } return *--stackp; }
void push(Datum d) { if(stackp >= &stack[NSTACK]) { execerror("stack overflow", nil); } *stackp++ = d; }
double* getarg(void) /* return pointer to argument */ { int nargs = (int) *pc++; if (nargs > fp->nargs) execerror(fp->sp->name, "not enough arguments"); return &fp->argn[nargs - fp->nargs].val; }
Inst * code(Inst f) { Inst *oprogp = progp; if(progp >= &prog[NPROG]) { execerror("program too big", nil); } *progp++ = f; return oprogp; }
void eval() { Datum d = pop(); if(d.sym->type == UNDEF) { execerror("undefined variable", d.sym->name); } d.val = d.sym->u.val; push(d); }
void push (Datum d) { if (stackp >= &stack [NSTACK]) execerror ("stack overflow", (char*)0); *stackp++ = d; }
Datum pop (void) /* clear & return top element from stack */ { if (stackp <= stack) execerror ("stack underflow", (char*)0); //return *stackp--; return *--stackp; }
Inst* code(Inst f) /* install one instruction or operand */ { Inst *oprogp = progp; if (progp >= &prog[NPROG]) execerror("program too big", (char *)0); *progp++ = f; return oprogp; }
void division() { Datum d1, d2; d1 = pop(); d2 = pop(); if(d2.val == 0) { execerror("zero division error", nil); } d1.val /= d2.val; push(d1); }
char *emalloc(unsigned n) { char *p ; p = (char *) malloc( n) ; if (p == (char *)0) execerror("out of memory", (char *) 0) ; return p ; }
eval () /* replace pointer by value */ { Datum d; d = pop (); if (d.sym->type == UNDEF) execerror ("undefined variable", (char*)0); d.val = d.sym->u.val; push (d); }
dvd () { Datum d1, d2; d2 = pop (); if (d2.val == 0.0) execerror ("division by zero", (char *)0); d1 = pop (); d1.val /= d2.val; push (d1); }
void funcret(void) /* return from a function */ { Datum d; if (fp->sp->type == PROCEDURE) execerror(fp->sp->name, "(proc) returns value"); d = pop(); /* preserve function return value */ ret(); push(d); }
void assign() { Datum d1, d2; d1 = pop(); d2 = pop(); if(d1.sym->type != VAR && d1.sym->type != UNDEF) { execerror("assignment to non-variable", d1.sym->name); } d1.sym->u.val = d2.val; d1.sym->type = VAR; push(d2); }
assign () /* store value in variable and pop pointer */ { Datum d1, d2; d1 = pop (); d2 = pop (); if (d1.sym->type != VAR && d1.sym->type != UNDEF) execerror ("assignment to non-variable", d1.sym->name); d1.sym->u.val = d2.val; d1.sym->type = VAR; push (d2); }
/* -------------------------------------------------------------------- */ void *cp_loadfont( char *fname, unsigned font_size ) { void *p; int handle; char fn[80]; p = ( void * ) malloc( font_size ); if ( p == NULL ) execerror( "Insufficient memory\n", "" ); if ( ( handle = open( fname, O_RDONLY | O_BINARY ) ) == -1 ) { sprintf( fn, "%s\\%s", cup_dir, fname ); handle = open( fn, O_RDONLY | O_BINARY ); } if ( handle != -1 ) { read( handle, p, font_size ); close( handle ); } else { execerror( "Printer font file not found : ", fname ); } return ( p ); }
void mod(void) { Datum d1, d2; d2 = pop(); if (d2.val == 0.0) execerror("division by zero", (char *)0); d1 = pop(); /* d1.val %= d2.val; */ d1.val = fmod(d1.val, d2.val); push(d1); }
void call(void) /* call a function */ { Formal *f; Datum *arg; Saveval *s; int i; Symbol *sp = (Symbol *)pc[0]; /* symbol table entry */ /* for function */ if (fp >= &frame[NFRAME-1]) execerror(sp->name, "call nested too deeply"); fp++; fp->sp = sp; fp->nargs = (int)(uintptr)pc[1]; fp->retpc = pc + 2; fp->argn = stackp - 1; /* last argument */ if(fp->nargs != sp->u.defn->nargs) execerror(sp->name, "called with wrong number of arguments"); /* bind formals */ f = sp->u.defn->formals; arg = stackp - fp->nargs; while(f){ s = emalloc(sizeof(Saveval)); s->val = f->sym->u; s->type = f->sym->type; s->next = f->save; f->save = s; f->sym->u.val = arg->val; f->sym->type = VAR; f = f->next; arg++; } for (i = 0; i < fp->nargs; i++) pop(); /* pop arguments; no longer needed */ execute(sp->u.defn->code); returning = 0; }
void call(void) /* call a function */ { Symbol *sp = (Symbol *)pc[0]; /* symbol table entry */ /* for function */ if (fp++ >= &frame[NFRAME-1]) execerror(sp->name, "call nested too deeply"); fp->sp = sp; fp->nargs = (int)pc[1]; fp->retpc = pc + 2; fp->argn = stackp - 1; /* last argument */ execute(sp->u.defn); returning = 0; }