Node * mkimplstmt(Srcloc loc, Node *name, Type *t, Type **aux, size_t naux, Node **decls, size_t ndecls) { Node *n; size_t i; n = mknode(loc, Nimpl); n->impl.traitname = name; n->impl.type = t; n->impl.aux = aux; n->impl.naux = naux; n->impl.decls = decls; n->impl.ndecls = ndecls; lappend(&impltab, &nimpltab, n); if (hasparams(t)) { n->impl.env = mkenv(); bindtype(n->impl.env, t); } for (i = 0; i < naux; i++) if (hasparams(aux[i])) bindtype(n->impl.env, aux[i]); for (i = 0; i < ndecls; i++) { if (name->name.ns) setns(decls[i]->decl.name, name->name.ns); if (decls[i]->decl.env) decls[i]->decl.env->super = n->impl.env; } return n; }
Node * mkfunc(Srcloc loc, Node **args, size_t nargs, Type *ret, Node *body) { Node *n; Node *f; size_t i; Stab *st; f = mknode(loc, Nfunc); f->func.args = args; f->func.nargs = nargs; f->func.body = body; f->func.scope = mkstab(1); f->func.type = mktyfunc(loc, args, nargs, ret); f->func.env = mkenv(); bindtype(f->func.env, f->func.type); st = body->block.scope; for (i = 0; i < nargs; i++) putdcl(st, args[i]); n = mknode(loc, Nlit); n->lit.littype = Lfunc; n->lit.fnval = f; return n; }
//adds variables without overwriting values, and doesn't add the variable if it is already in the environment. void addVar(char var[8], int value, struct env *env) { while(env->next){ //checks that the next pointer is not null. if(strcmp(var, env->var)==0){ //if the variables have the same name, overwrite the variable value with the new one. return; } env = env->next; //if the next pointer is not null then move along the list. } //the last variable would have been reached at this point in the code. if(strcmp(var, env->var)==0){ //if the variables have the same name, overwrite the variable value with the new one. return; } else //otherwise add it to the end of the environment list. env->next = mkenv(var, value); }
Node * mkdecl(Srcloc loc, Node *name, Type *ty) { Node *n; n = mknode(loc, Ndecl); n->decl.did = ndecls; n->decl.name = name; n->decl.type = ty; lappend(&decls, &ndecls, n); if (ty && hasparams(ty)) { n->decl.env = mkenv(); bindtype(n->decl.env, ty); } return n; }
/* forkexec -- fork (if necessary) and exec */ extern List *forkexec(char *file, List *list, Boolean inchild) { int pid, status; Vector *env; gcdisable(); env = mkenv(); pid = efork(!inchild, FALSE); if (pid == 0) { execve(file, vectorize(list)->vector, env->vector); failexec(file, list); } gcenable(); status = ewaitfor(pid); if ((status & 0xff) == 0) { sigint_newline = FALSE; SIGCHK(); sigint_newline = TRUE; } else SIGCHK(); printstatus(0, status); return mklist(mkterm(mkstatus(status), NULL), NULL); }
int evalexp(struct exp *e){ envglb = mkenv("",0);//initialise an environment return evalexpenv(e, envglb); }