示例#1
0
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);
}
示例#2
0
文件: math.c 项目: aryx/fork-kencc
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;
}
示例#3
0
文件: math.c 项目: toddhainsworth/hoc
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;
}
示例#4
0
void
xpop(void)	/* for when no value is wanted */
{
	if (stackp == stack)
		execerror("stack underflow", (char *)0);
	--stackp;
}
示例#5
0
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);
}
示例#6
0
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;
}
示例#8
0
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;
}
示例#9
0
void
push(Datum d)
{
	if (stackp >= &stack[NSTACK])
		execerror("stack too deep", 0);
	*stackp++ = d;
}
示例#10
0
文件: math.c 项目: aryx/fork-kencc
double
integer(double x)
{
	if(x<-2147483648.0 || x>2147483647.0)
		execerror("argument out of domain", 0);
	return (double)(long)x;
}
示例#11
0
void
procret(void) 	/* return from a procedure */
{
	if (fp->sp->type == FUNCTION)
		execerror(fp->sp->name,
			"(func) returns no value");
	ret();
}
示例#12
0
Datum
pop()
{
	if(stackp <= stack) {
		execerror("stack underflow", nil);
	}
	return *--stackp;
}
示例#13
0
void
push(Datum d)
{
	if(stackp >= &stack[NSTACK]) {
		execerror("stack overflow", nil);
	}
	*stackp++ = d;
}
示例#14
0
文件: code.c 项目: yogmk/prog
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;
}
示例#15
0
文件: code.c 项目: Jimmyzaurio/ESCOM
Inst * code(Inst f) {
	Inst *oprogp = progp;
	if(progp >= &prog[NPROG]) {
		execerror("program too big", nil);
	}
	*progp++ = f;
	return oprogp;
}
示例#16
0
文件: code.c 项目: Jimmyzaurio/ESCOM
void eval() {
	Datum d = pop();
	if(d.sym->type == UNDEF) {
		execerror("undefined variable", d.sym->name);
	}
	d.val = d.sym->u.val;
	push(d);
}
示例#17
0
文件: code.c 项目: yogmk/prog
void
push (Datum d)
{
	if (stackp >= &stack [NSTACK])
		execerror ("stack overflow", (char*)0);
	
	*stackp++ = d;
}
示例#18
0
文件: code.c 项目: yogmk/prog
Datum
pop (void)                  /* clear & return top element from stack */
{
	if (stackp <= stack)
		execerror ("stack underflow", (char*)0);
	//return *stackp--;
	return *--stackp;
}
示例#19
0
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;
}
示例#20
0
文件: code.c 项目: Jimmyzaurio/ESCOM
void division() {
	Datum d1, d2;
	d1 = pop();
	d2 = pop();
	if(d2.val == 0) {
		execerror("zero division error", nil);
	}
	d1.val /= d2.val;
	push(d1);
}
示例#21
0
文件: symbol.c 项目: shaiguitar/pcalc
char    *emalloc(unsigned n)

{
 char *p ;

   p = (char *) malloc( n) ;
   if (p == (char *)0)
      execerror("out of memory", (char *) 0) ;
   return p ;
}
示例#22
0
文件: code.c 项目: yogmk/prog
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);
}
示例#23
0
文件: code.c 项目: yogmk/prog
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);
}
示例#24
0
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);
}
示例#25
0
文件: code.c 项目: Jimmyzaurio/ESCOM
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);
}
示例#26
0
文件: code.c 项目: yogmk/prog
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);
}
示例#27
0
文件: CUPSETUP.C 项目: MegaGod/TW
/* -------------------------------------------------------------------- */
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 );
}
示例#28
0
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);
}
示例#29
0
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;
}
示例#30
0
文件: code.c 项目: yogmk/prog
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;
}