public String Print(FuncNode fnode) { if (fnode.arguments.Count == 0) { return(fnode.identifier + "(" + ")"); } string str = Print(fnode.arguments[0]); for (int i = 1; i < fnode.arguments.Count; i++) { str += "," + Print(fnode.arguments[i]); } return(fnode.identifier + "(" + str + ")"); }
public type GetType(FuncNode fnode, Environment env) { FuncType funcType = (FuncType)env.GetType(fnode.identifier); List <ITreeNode> lexp = fnode.arguments; List <type> ltype = funcType.inputTypes; if (lexp.Count != ltype.Count) { throw new Exception("wrong number of arguments to function" + fnode.identifier); } for (int i = 0; i < ltype.Count; i++) { if (!ExpressionMatches(GetType(lexp[i], env), ltype[i])) { throw new Exception(lexp[i].ToString() + "is not of type " + ltype[i]); } } return(funcType.outputType); }
private string ConvertFuncNode(FuncNode fnode, Dictionary <string, int> variableIndex) { if (fnode.identifier.Equals("choice")) { return(ConvertChoice(fnode.arguments, variableIndex)); } List <ITreeNode> args = fnode.arguments; int size = args.Count; if (args.Count == 0) { return("call " + fnode.identifier); } string str = ""; for (int i = args.Count - 1; i >= 0; i--) { str += Convert(args[i], variableIndex) + skip + "push eax" + skip; } return(ConvertToCode(str, "call " + fnode.identifier, "sub esp, " + 4 * args.Count) + skip); }