Esempio n. 1
0
        static Expression CompileLocalAssignment(Ast.LocalAssignment assign, Expression Context)
        {
            var variable = Expression.Parameter(typeof(LuaArguments), "vars");
            var stats    = new List <Expression>();

            stats.Add(Expression.Assign(variable, Expression.New(LuaArguments_New_void)));
            foreach (IExpression expr in assign.Values)
            {
                var ret = CompileExpression(expr, Context);
                stats.Add(Expression.Call(variable, LuaArguments_Concat, ret));
            }
            int i = 0;

            foreach (string var in assign.Names)
            {
                var arg = GetArgument(variable, i);
                stats.Add(Expression.Call(Context, LuaContext_SetLocal, Expression.Constant(var), arg));
                i++;
            }

            return(Expression.Block(new[] { variable }, stats.ToArray()));
        }
Esempio n. 2
0
        Ast.LocalAssignment ParseLocalAssign(ParseTreeNode node)
        {
            if (node.Term.Name == "LocalAssignment")
            {
                Ast.LocalAssignment assign = new Ast.LocalAssignment();


                var child = node.ChildNodes[1];

                if (child.ChildNodes[0].Term.Name == "LocalFunction")
                {
                    child = child.ChildNodes[0];

                    var argsNode  = child.ChildNodes[2];
                    var blockNode = child.ChildNodes[3];

                    assign.Names.Add(child.ChildNodes[1].Token.ValueString);
                    var func = new Ast.FunctionDefinition();

                    if (argsNode.ChildNodes.Count > 0)
                    {
                        argsNode = argsNode.ChildNodes[0];
                        while (argsNode.ChildNodes.Count > 0)
                        {
                            string ident = argsNode.ChildNodes[0].Token.ValueString;
                            func.Arguments.Add(new Ast.Argument()
                            {
                                Name = ident
                            });
                            if (argsNode.ChildNodes.Count == 1)
                            {
                                break;
                            }
                            argsNode = argsNode.ChildNodes[1];
                        }
                    }

                    func.Body = ParseBlock(blockNode);

                    assign.Values.Add(func);
                    return(assign);
                }

                var left  = child.ChildNodes[0];
                var right = child.ChildNodes[1];

                assign.Names.Add(left.ChildNodes[0].Token.ValueString);

                left = left.ChildNodes[1];

                while (left.ChildNodes.Count > 0)
                {
                    left = left.ChildNodes[0];
                    assign.Names.Add(left.ChildNodes[0].Token.ValueString);
                    left = left.ChildNodes[1];
                }

                while (right.ChildNodes.Count > 0)
                {
                    right = right.ChildNodes[0];
                    assign.Values.Add(ParseExpression(right.ChildNodes[0]));
                    right = right.ChildNodes[1];
                }

                return(assign);
            }
            throw new Exception("Invalid LocalAssignment node");
        }
Esempio n. 3
0
        Ast.LocalAssignment ParseLocalAssign(ParseTreeNode node)
        {
            if (node.Term.Name == "LocalAssignment")
            {
                Ast.LocalAssignment assign = new Ast.LocalAssignment();


                var child = node.ChildNodes[1];

                if (child.ChildNodes[0].Term.Name == "LocalFunction")
                {
                    child = child.ChildNodes[0];

                    var argsNode = child.ChildNodes[2];
                    var blockNode = child.ChildNodes[3];

                    assign.Names.Add(child.ChildNodes[1].Token.ValueString);
                    var func = new Ast.FunctionDefinition();

                    if (argsNode.ChildNodes.Count > 0)
                    {
                        argsNode = argsNode.ChildNodes[0];
                        while (argsNode.ChildNodes.Count > 0)
                        {
                            string ident = argsNode.ChildNodes[0].Token.ValueString;
                            func.Arguments.Add(new Ast.Argument() { Name = ident });
                            if (argsNode.ChildNodes.Count == 1)
                                break;
                            argsNode = argsNode.ChildNodes[1];
                        }
                    }

                    func.Body = ParseBlock(blockNode);

                    assign.Values.Add(func);
                    return assign;
                }

                var left = child.ChildNodes[0];
                var right = child.ChildNodes[1];

                assign.Names.Add(left.ChildNodes[0].Token.ValueString);

                left = left.ChildNodes[1];

                while (left.ChildNodes.Count > 0)
                {
                    left = left.ChildNodes[0];
                    assign.Names.Add(left.ChildNodes[0].Token.ValueString);
                    left = left.ChildNodes[1];
                }

                while (right.ChildNodes.Count > 0)
                {
                    right = right.ChildNodes[0];
                    assign.Values.Add(ParseExpression(right.ChildNodes[0]));
                    right = right.ChildNodes[1];
                }

                return assign;
            }
            throw new Exception("Invalid LocalAssignment node");
        }