public static void BuildRoutineDeclaration(Grammar g, string patternName, Pattern prefix, Pattern terminator) { g.AddPattern(patternName, seq( prefix, r(terminator, (Grammar gr) => { // descend into new subroutine-class Exec methodgen var c = gr.CodeGen; c.InvokeAssign(c["temp_typegen01"], c["GG"], "DescendIntoSub", c["AG"], c["current_typegen"], c["TG_top"], c["current_scope"], c["IN"], c["m"]["subName"], c["m"]["returnType"], c["m"]["subParams"]); c.InvokeAssign(c["cg"], c["GG"], "DescendIntoSub", c["cg"], c["current_typegen"], c["temp_typegen01"]); c.Assign(c["current_typegen"], c["temp_typegen01"]); c.Assign(c["current_scope"], c["current_typegen"].Field("FrameScope")); }), ows(), r(n("bodyStatements", p("statementListBlock")), (Grammar gr) => { var c = gr.CodeGen; c.If(c["cg"].Invoke("IsReachable")); { c.Increment(c["cg"].Field("InstructionCount")); c.Invoke(c["cg"], "Assign", c["cg"].Invoke("This").Invoke("Field", "Instruction"), c["cg"].Field("InstructionCount")); c.Invoke(c["cg"], "Label", "inst" + c["cg"].Field("InstructionCount").Invoke("ToString")); } c.End(); c.Invoke(c["cg"], "Goto", "csmeta_return_label"); c.Invoke(c["cg"], "Label", "inst0"); // at program-runtime, we've re-entered this frame from a child invocation (or // from a continuance of a continuation), so jump to the label (the CIL instruction) // corresponding to the saved instruction pointer (ends up JITted as a direct jump-table). c.Invoke(c["cg"], "Switch", c["cg"].Invoke("This").Invoke("Field", "Instruction"), c["GG"].Invoke("GetRoutineInstructionLabels", c["cg"])); //c.If(c["cg"].Invoke("IsReachable")); //{ c.Invoke(c["cg"], "Label", "csmeta_return_label"); c.Invoke(c["TG_top"].Field("FrameGen"), "RevertContextualsIn", c["current_scope"], c["cg"]); c.Invoke(c["cg"], "Return", c["cg"].Invoke("This").Invoke("Field", "Caller")); //} //c.End(); c.Assign(c["last_typegen"], c["current_typegen"]); c.Invoke(c["cg"], "Complete"); c.InvokeAssign(c["current_typegen"], c["GG"], "AscendOutofSub", c["last_typegen"]); c.InvokeAssign(c["cg"], c["GG"], "AscendOutofSub", 1); c.Assign(c["current_scope"], c["current_scope"].Field("Parent").Cast(typeof(FrameScope))); c.Invoke(c["cg"], "AssignNew", c["cg"].Invoke("This").Invoke("Field", c["last_typegen"].Field("NamedSubMangledName")), c["last_typegen"], c["cg"].Invoke("This")); c.Assign(c["m"].Field("Result"), c["cg"].Invoke("This").Invoke("Field", c["last_typegen"].Field("NamedSubMangledName"))); //c.WriteLine("finished declaring a sub"); }) )); }
public static Pattern finished(Pattern p) { return(new Finished(p)); }
public static Pattern final(Pattern p) { return(new Final(p)); }
public static Pattern opt(Pattern p) { return(Grammar.Alt(p, new Empty())); }
public static Pattern rep(Pattern p, int l, int h) { return(new Repetition(p, l, h)); }
public static Pattern n(string name, Pattern p) { return(new NamedGroup(name, p)); }
public static Pattern r(Pattern p, Action <Grammar> g) { return(new ReduceAction(p, g)); }
public override void ResolveSym(string symbol, Pattern parent, bool isRight) { L.ResolveSym(symbol, this, false); }
public UnaryPattern(Pattern l) : base() { L = l; }
public Either(Pattern l, Pattern r) : base(l, r) { }