/* walk -- walk through a tree, evaluating nodes */ extern List *walk(Tree *tree0, Binding *binding0, int flags) { Tree *volatile tree = tree0; Binding *volatile binding = binding0; SIGCHK(); top: if (tree == NULL) return true; switch (tree->kind) { case nConcat: case nList: case nQword: case nVar: case nVarsub: case nWord: case nThunk: case nLambda: case nCall: case nPrim: { List *list; Ref(Binding *, bp, binding); list = glom(tree, binding, TRUE); binding = bp; RefEnd(bp); return eval(list, binding, flags); } case nAssign: return assign(tree->u[0].p, tree->u[1].p, binding); case nLet: case nClosure: Ref(Tree *, body, tree->u[1].p); binding = letbindings(tree->u[0].p, binding, binding, flags); tree = body; RefEnd(body); goto top; case nLocal: return local(tree->u[0].p, tree->u[1].p, binding, flags); case nFor: return forloop(tree->u[0].p, tree->u[1].p, binding, flags); case nMatch: return matchpattern(tree->u[0].p, tree->u[1].p, binding); case nExtract: return extractpattern(tree->u[0].p, tree->u[1].p, binding); default: panic("walk: bad node kind %d", tree->kind); } NOTREACHED; }
ex_take() { int takezr(); int i, k, o, fill[MRANK], fflg; /* While TANSTAAFL, in APL there is a close approximation. It * is possible to perform a "take" of more elements than an * array actually contains (to be padded with zeros or blanks). * If "td1()" detects that a dimension exceeds what the array * actually contains it will return 1. Special code is then * required to force the extra elements in the new array to * zero or blank. This code is supposed to work for null items * also, but it doesn't. */ o = 0; fflg = td1(0); for(i=0; i<idx.rank; i++) { fill[i] = 0; k = idx.idx[i]; if(k < 0) { k = -k; if (k > idx.dim[i]) fill[i] = idx.dim[i] - k; o += idx.del[i] * (idx.dim[i] - k); } else { if (k > idx.dim[i]) fill[i] = idx.dim[i]; } idx.dim[i] = k; } map(o); if (fflg){ bidx(sp[-1]); forloop(takezr, fill); } }
void op_forloops() { forloop(TRUE); }
void op_forloop() { forloop(FALSE); }
static void udelay(unsigned us) { while (us--) forloop(100); }