public override object VisitFunDefNode(FunDefNode n) { n.rettype = MakeTypeSymbolForString(n.rettype.Name); for (int i = 0; i < n.argtypes.Count; i++) { n.argtypes[i] = MakeTypeSymbolForString(n.argtypes[i].Name); } string functionType = ""; if (n.argtypes.Count > 0) { functionType = $"({n.argtypes.Select(t => t.Name).Aggregate((a, b) => $"{a},{b}")})->{n.rettype.Name}"; } else { functionType = $"()->{n.rettype.Name}"; } TypeSymbol funType = TypeSymbol.FUNCTION_SYMBOL(n.name, functionType, n.rettype, n.argtypes); n.funtype = funType; varTypes.PutInScope(funType.FunctionName, funType); varTypes = varTypes.GoDown(); varTypes.PutAllInScope(n.args, n.argtypes); Visit(n.body); varTypes = varTypes.GoUp(); return(null); }
public override bool VisitFunDefNode(FunDefNode n) { if (!n.rettype.Equals(TypeSymbol.VOID_SYMBOL)) { semanticChecker.CheckAndReport(Visit(n.body), n.sourceLoc, "Not all paths return a value"); } return(false); }
public override object VisitFunDefNode(FunDefNode n) { if (n.name == "main")// && n.rettype.Equals(TypeSymbol.VOID_SYMBOL)) { FoundMain = true; } return(null); }
public override LData VisitFunDefNode(FunDefNode n) { // This is our entry point Visit(n.body); // at the end, we have to call all the defered statements foreach (var defer in deferredExpressions) { Visit(defer); } return(null); }
public object VisitFunDefNode(FunDefNode n) { string args = ""; for (int i = 0; i < n.args.Count; i++) { args += n.args[i] + ":" + n.argtypes[i].Name + ","; } WriteLine(n.kind + " - " + n.name + "(" + (args.Length == 0 ? "" : args.Substring(0, args.Length - 1)) + ") -> " + n.rettype.Name); Indent(); Visit(n.body); Dedent(); return(null); }
public override object VisitFunDefNode(FunDefNode n) { string name = TypeSymbol.MakeFunctionName(n.name, n.funtype.ParameterTypes); semanticChecker.CheckAndReport(varTypes.PutInScope(name, n.funtype), n.sourceLoc, $"Function or function override with argtypes {n.name} already declared"); currentFunction = n.funtype; varTypes = varTypes.GoDown(); varTypes.PutAllInScope(n.args, n.argtypes); Visit(n.body); varTypes = varTypes.GoUp(); return(null); }
public override MIPSRegister VisitFunDefNode(FunDefNode n) { // @TODO emit.EmitLabel(n.name); int n_vars = new VarsInFunDefCounter().Visit(n); /* * allocate n_vars*4 bytes on the stack for local variables * store s0-s7 * store sp, fp, ra */ short offset = (short)(n_vars * 4); offset -= 4; emit.EmitLoadStore("sw", rm.SP, offset, rm.SP); offset -= 4; emit.EmitLoadStore("sw", rm.FP, offset, rm.SP); offset -= 4; emit.EmitLoadStore("sw", rm.RA, offset, rm.SP); offset -= 4; emit.EmitLoadStore("sw", "$s0", offset, rm.SP); offset -= 4; emit.EmitLoadStore("sw", "$s1", offset, rm.SP); offset -= 4; emit.EmitLoadStore("sw", "$s2", offset, rm.SP); offset -= 4; emit.EmitLoadStore("sw", "$s3", offset, rm.SP); offset -= 4; emit.EmitLoadStore("sw", "$s4", offset, rm.SP); offset -= 4; emit.EmitLoadStore("sw", "$s5", offset, rm.SP); offset -= 4; emit.EmitLoadStore("sw", "$s6", offset, rm.SP); offset -= 4; emit.EmitLoadStore("sw", "$s7", offset, rm.SP); emit.EmitImmediate("addi", rm.SP, rm.SP, offset); Visit(n.body); /* * restore s0-s7 * restore sp, fp, ra */ offset = 0; emit.EmitLoadStore("lw", "$s7", offset, rm.SP); offset += 4; emit.EmitLoadStore("lw", "$s6", offset, rm.SP); offset += 4; emit.EmitLoadStore("lw", "$s5", offset, rm.SP); offset += 4; emit.EmitLoadStore("lw", "$s4", offset, rm.SP); offset += 4; emit.EmitLoadStore("lw", "$s3", offset, rm.SP); offset += 4; emit.EmitLoadStore("lw", "$s2", offset, rm.SP); offset += 4; emit.EmitLoadStore("lw", "$s1", offset, rm.SP); offset += 4; emit.EmitLoadStore("lw", "$s0", offset, rm.SP); offset += 4; emit.EmitLoadStore("lw", rm.RA, offset, rm.SP); offset += 4; emit.EmitLoadStore("lw", rm.FP, offset, rm.SP); offset += 4; emit.EmitLoadStore("lw", rm.SP, offset, rm.SP); if (n.rettype == TypeSymbol.VOID_SYMBOL) { emit.Emit("ret"); } return(null); }
public override LLVMRegister VisitFunDefNode(FunDefNode n) { throw new NotImplementedException(); }
public override object VisitFunDefNode(FunDefNode n) { interp.Functions.Add(n.funtype.FunctionName, n); return(null); }
public override int VisitFunDefNode(FunDefNode n) { return(Visit(n.body)); }
public virtual T VisitFunDefNode(FunDefNode n) { T a = n.body.Accept(this); return(default(T)); }