public virtual T VisitForNode(ForNode n) { T a = n.inList.Accept(this); T b = n.body.Accept(this); return(default(T)); }
public object VisitForNode(ForNode n) { WriteLine(n.kind + " - " + n.var); Indent(); Visit(n.inList); Visit(n.body); Dedent(); return(null); }
public override object VisitForNode(ForNode n) { Visit(n.inList); varTypes = varTypes.GoDown(); varTypes.PutInScope(n.var, n.inList.Type.ArrayType); Visit(n.body); varTypes = varTypes.GoUp(); return(null); }
public override object VisitForNode(ForNode n) { Visit(n.inList); semanticChecker.CheckAndReport(n.inList.Type.Kind == TypeSymbol.TypeKind.ARRAY, n.sourceLoc, "Array in for-loop is not an array"); varTypes = varTypes.GoDown(); varTypes.PutInScope(n.var, n.inList.Type.ArrayType); Visit(n.body); varTypes = varTypes.GoUp(); return(null); }
public override MIPSRegister VisitForNode(ForNode n) { var testlbl = emit.GetUniqueLabel(); var bodylbl = emit.GetUniqueLabel(); var incrlbl = emit.GetUniqueLabel(); var endlbl = emit.GetUniqueLabel(); /* * Gen(inlist) * it <- inlist[1] * idx <- 0 * test: * len <- inlist[0] * slt tmp, idx, len * blez tmp, end * body: * Gen(body) * incr: * idx <- idx + 1 * it <- inlist[idx] * j test * end: */ var list = Gen(n.inList); var it = GetMIPSRegister(); var idx = GetMIPSRegister(); vars = vars.GoDown(); vars.PutInScope(n.var, new Either <MIPSRegister, short>(it)); emit.EmitImmediate("addi", idx.Name, list.Name, 4); emit.EmitLoadStore("lw", it, 0, idx); emit.EmitLabel(testlbl); var tmp = GetMIPSRegister(); emit.EmitLoadStore("lw", tmp, 0, list); emit.Emit("slt", tmp, idx, tmp); emit.EmitLabelJump("blez", tmp, endlbl); emit.EmitLabel(bodylbl); Gen(n.body); emit.EmitLabel(incrlbl); emit.EmitImmediate("addi", idx.Name, 4); emit.EmitLoadStore("lw", it, 0, idx); emit.EmitJump("j", testlbl); emit.EmitLabel(endlbl); vars = vars.GoUp(); return(null); }
public override LData VisitForNode(ForNode n) { LData list = Visit(n.inList); var val = list.GetValue(); LData it = LDataMaker.GetDataFor(n.inList.Type.ArrayType); Vars = Vars.GoDown(); Vars.PutInScope(n.var, it); for (int i = 0; i < val.length; i++) { it.SetValue(val._arr[i].GetValue()); Visit(n.body); } Vars = Vars.GoUp(); return(null); }
public override LLVMRegister VisitForNode(ForNode n) { throw new NotImplementedException(); }