static Expression CompileFunctionCallStat(Ast.FunctionCall call, Expression Context) { var variable = Expression.Parameter(typeof(LuaArguments), "vars"); var stats = new List <Expression>(); stats.Add(Expression.Assign(variable, Expression.New(LuaArguments_New_void))); var expression = CompileSingleExpression(call.Function, Context); int i = 0; foreach (Ast.IExpression arg in call.Arguments) { if (i == call.Arguments.Count - 1) { var exp = CompileExpression(arg, Context); stats.Add(Expression.Call(variable, LuaArguments_Concat, exp)); } else { var exp = CompileSingleExpression(arg, Context); stats.Add(Expression.Call(variable, LuaArguments_Add, exp)); } i++; } stats.Add(Expression.Call(expression, LuaObject_Call, variable)); return(Expression.Block(new[] { variable }, stats.ToArray())); }
static Expression CompileFunctionCallExpr(Ast.FunctionCall expr, Expression Context) { var function = CompileSingleExpression(expr.Function, Context); var args = new List <Expression>(); Expression lastArg = null; int i = 0; foreach (IExpression e in expr.Arguments) { if (i == expr.Arguments.Count - 1) { lastArg = CompileExpression(e, Context); } else { args.Add(CompileSingleExpression(e, Context)); } i++; } var arg = Expression.NewArrayInit(LuaObject_Type, args.ToArray()); var luaarg = Expression.New(LuaArguments_New, arg); if (lastArg == null) { return(Expression.Call(function, LuaObject_Call, luaarg)); } else { return(Expression.Call(function, LuaObject_Call, Expression.Call(luaarg, LuaArguments_Concat, lastArg))); } }
Ast.FunctionCall ParseOopCall(ParseTreeNode node) { if (node.Term.Name == "OopCall") { Ast.IExpression expr = ParsePrefix(node.ChildNodes[0]); string name = node.ChildNodes[1].Token.ValueString; Ast.FunctionCall call = new Ast.FunctionCall(); call.Arguments.Add(expr); call.Function = new Ast.Variable() { Name = name, Prefix = expr }; var root = node.ChildNodes[2].ChildNodes[0]; if (root.ChildNodes.Count != 0) { root = root.ChildNodes[0]; while (true) { call.Arguments.Add(ParseExpression(root.ChildNodes[0])); if (root.ChildNodes.Count == 1) { break; } else { root = root.ChildNodes[1]; } } } return(call); } throw new Exception("Invalid OopCall node"); }
Ast.FunctionCall ParseFunctionCall(ParseTreeNode node) { if (node.Term.Name == "FunctionCall") { Ast.IExpression expr = ParsePrefix(node.ChildNodes[0]); Ast.FunctionCall call = new Ast.FunctionCall(); call.Arguments = new List <Ast.IExpression>(); call.Function = expr; var root = node.ChildNodes[1].ChildNodes[0]; if (root.ChildNodes.Count != 0) { root = root.ChildNodes[0]; while (true) { call.Arguments.Add(ParseExpression(root.ChildNodes[0])); if (root.ChildNodes.Count == 1) { break; } else { root = root.ChildNodes[1]; } } } return(call); } throw new Exception("Invalid FunctionCall node"); }
Ast.FunctionCall ParseOopCall(ParseTreeNode node) { if (node.Term.Name == "OopCall") { Ast.IExpression expr = ParsePrefix(node.ChildNodes[0]); string name = node.ChildNodes[1].Token.ValueString; Ast.FunctionCall call = new Ast.FunctionCall(); call.Arguments.Add(expr); call.Function = new Ast.Variable() { Name = name, Prefix = expr }; var root = node.ChildNodes[2].ChildNodes[0]; if (root.ChildNodes.Count != 0) { root = root.ChildNodes[0]; while (true) { call.Arguments.Add(ParseExpression(root.ChildNodes[0])); if (root.ChildNodes.Count == 1) break; else root = root.ChildNodes[1]; } } return call; } throw new Exception("Invalid OopCall node"); }
Ast.FunctionCall ParseFunctionCall(ParseTreeNode node) { if (node.Term.Name == "FunctionCall") { Ast.IExpression expr = ParsePrefix(node.ChildNodes[0]); Ast.FunctionCall call = new Ast.FunctionCall(); call.Arguments = new List<Ast.IExpression>(); call.Function = expr; var root = node.ChildNodes[1].ChildNodes[0]; if (root.ChildNodes.Count != 0) { root = root.ChildNodes[0]; while (true) { call.Arguments.Add(ParseExpression(root.ChildNodes[0])); if (root.ChildNodes.Count == 1) break; else root = root.ChildNodes[1]; } } return call; } throw new Exception("Invalid FunctionCall node"); }