// Partially evaluate the programList with respect to the given static inputs, // producing a new ProgramLines object. public ProgramLines PEval(Value[] args, FullCellAddr[] residualInputs) { PEnv pEnv = new PEnv(); // Map static input cells to their constant values: for (int i = 0; i < args.Length; i++) { pEnv[inputCells[i]] = CGConst.Make(args[i]); } ProgramLines residual = new ProgramLines(outputCell, residualInputs); // PE-time environment PEnv maps each residual input cell address to the delegate argument: for (int i = 0; i < residualInputs.Length; i++) { FullCellAddr input = residualInputs[i]; pEnv[input] = new CGCellRef(input, residual.addressToVariable[input]); } // Process the given function's compute cells in dependency order, output last: foreach (ComputeCell ccell in programList) { ComputeCell rCcell = ccell.PEval(pEnv); if (rCcell != null) { residual.AddComputeCell(ccell.cellAddr, rCcell); } } residual = residual.PruneZeroUseCells(); return(residual); }
public override CGExpr PEval(PEnv pEnv, bool hasDynamicControl) { // When FunctionValue is known, reduce to a CGSdfCall node. // Don't actually call the function (even on constant arguments); could loop. CGExpr[] res = PEvalArgs(pEnv, hasDynamicControl); if (res[0] is CGValueConst) { FunctionValue fv = (res[0] as CGValueConst).Value as FunctionValue; if (fv != null) { CGExpr[] args = new CGExpr[fv.args.Length]; int j = 1; for (int i = 0; i < args.Length; i++) { if (fv.args[i] != ErrorValue.naError) { args[i] = CGConst.Make(fv.args[i]); } else { args[i] = res[j++]; } } return(new CGSdfCall(fv.sdfInfo, args)); } else { return(new CGError(ErrorValue.argCountError)); } } else { return(new CGApply(res)); } }
public override void EvalCond(PathCond evalCond, IDictionary <FullCellAddr, PathCond> evalConds, List <CGCachedExpr> caches) { if (es.Length >= 1) { CachedAtom atom = new CachedAtom(es[0], caches); CGCachedExpr cached = atom.cachedExpr; es[0].EvalCond(evalCond, evalConds, caches); es[0] = cached; for (int i = 1; i < es.Length; i++) { CGExpr iConst = CGConst.Make(i); CGExpr cond = new CGEqual(new CGExpr[] { cached, iConst }); es[i].EvalCond(evalCond.And(new CachedAtom(cond, caches)), evalConds, caches); } } }
public override CGExpr PEval(PEnv pEnv, bool hasDynamicControl) { CGExpr[] res = PEvalArgs(pEnv, hasDynamicControl); // If all args are constant then evaluate else residualize: if (AllConstant(res)) { Expr[] es = new Expr[res.Length]; for (int i = 0; i < res.Length; i++) { es[i] = Const.Make((res[i] as CGConst).Value); } // Use the interpretive implementation's applier on a fake sheet // and fake cell coordinates, but constant argument expressions: return(CGConst.Make(applier(null, es, -1, -1))); } else { return(Residualize(res)); } }