Exemplo n.º 1
0
        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()));
        }
Exemplo n.º 2
0
 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");
 }
Exemplo n.º 3
0
 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");
 }