static Expression CompileReturnStat(Ast.ReturnStat ret, LabelTarget returnTarget, Expression Context) { var variable = Expression.Parameter(LuaArguments_Type); var body = new List <Expression>(); var ctor = Expression.New(LuaArguments_New_void); body.Add(Expression.Assign(variable, ctor)); int i = 0; foreach (IExpression expr in ret.Expressions) { if (i == ret.Expressions.Count - 1) { var exp = CompileExpression(expr, Context); body.Add(Expression.Call(variable, LuaArguments_Concat, exp)); } else { var exp = CompileSingleExpression(expr, Context); body.Add(Expression.Call(variable, LuaArguments_Add, exp)); } } body.Add(Expression.Return(returnTarget, variable)); return(Expression.Block(new[] { variable }, body.ToArray())); }
Ast.ReturnStat ParseReturnStat(ParseTreeNode node) { if (node.Term.Name == "ReturnStat") { Ast.ReturnStat ret = new Ast.ReturnStat(); var child = node.ChildNodes[1]; while (child.ChildNodes.Count > 0) { child = child.ChildNodes[0]; ret.Expressions.Add(ParseExpression(child.ChildNodes[0])); child = child.ChildNodes[1]; } return(ret); } throw new Exception("Invalid ReturnStat node"); }
Ast.ReturnStat ParseReturnStat(ParseTreeNode node) { if (node.Term.Name == "ReturnStat") { Ast.ReturnStat ret = new Ast.ReturnStat(); var child = node.ChildNodes[1]; while (child.ChildNodes.Count > 0) { child = child.ChildNodes[0]; ret.Expressions.Add(ParseExpression(child.ChildNodes[0])); child = child.ChildNodes[1]; } return ret; } throw new Exception("Invalid ReturnStat node"); }