Example #1
0
void
compile(Node *n)	/* called from parser only */
{
	extern long autooffset;
	Errjmp x;
	n=constants(n);
	if(cflag){
		fprint(2, "%z:constants:\n");
		dump(n, 0);
	}
	errsave(x);
	if(errmark()){
		autooffset=0;
		resultloc=0;
		breakloc=-1;
		continueloc=-1;
		didbecome=0;
		freenode(n);
		errrest(x);
		errjmp();
	}
	istart();
	gen(n, 0);
	freenode(n);
	errrest(x);
}
Example #2
0
void
execute(void)
{
	extern int xflag;
	Errjmp s;
	interpreter.fp=0;
	interpreter.sp=interpreter.stack;
	interpreter.pc=prog+1;
	phead=&interpreter;
	ptail=&interpreter;
	interpreter.next=0;
	errsave(s);
	if(errmark()){
		istart();
		errrest(s);
		libgflush();
		errjmp();
	}
    loop:
	if(xflag)
		xxec();
	else
		xec();
	phead=0;
	while(moreio()){
		schedio(1);
		if(phead)
			goto loop;
	}

	if(interpreter.pc[-1]!=idone)
		error("interpreter process blocked");
	errrest(s);
	istart();
	libgflush();
}
Example #3
0
void
proggen(Node *t, Node *n)
{
	int or;
	Node *of;
	Errjmp s;
	Store *p;
	long len, loc;
	long nauto, oao;
	int osp, odb;
	extern int (**prog)(Proc*);
	extern int storeprog;
	odb=didbecome;
	oao=autooffset;
	or=returnloc;
	of=formals;
	osp=storeprog;
	autooffset=0;
	returnloc=0;
	formals=t->l;
	errsave(s);
	if(errmark()){
		didbecome=odb;
		returnloc=or;
		formals=of;
		autooffset=oao;
		storeprog=osp;
		errrest(s);
		errjmp();
	}
	loc=here();
	emitconst(0);	/* space for locals pointer */
	pushscope();
	dclformals(t->l);
	autooffset=0;
	emit(Ipushfp);
	nauto=here();
	storeprog=here();
	emitconst(0L);
	gen(n, 0);
	trlrgen();
	patch((int)nauto, autooffset);
	popscope();
	errrest(s);
	if(!didbecome && n && t->r->o.t!=TUnit)
		lerror(n, "prog has no become");
	didbecome=odb;
	autooffset=oao;
	returnloc=or;
	formals=of;
	storeprog=osp;
	len=here()-loc+1;
	p=emalloc(SHSZ+len*WS);
	memcpy(p->data, prog+loc, len*WS);
	p->ref=1;
	p->len=len;
	p->type=Sprog;
	setprog(loc);
	emit(Ipushdata);
	emitconst((long)p);
	emitstore(p);
}