Ejemplo n.º 1
0
 static Expression GetVariable(Ast.Variable expr, Expression Context)
 {
     if (expr.Prefix == null)
     {
         return(Expression.Call(Context, LuaContext_Get, Expression.Constant(expr.Name)));
     }
     else
     {
         Expression p = CompileSingleExpression(expr.Prefix, Context);
         return(Expression.Property(p, "Item", Expression.Convert(Expression.Constant(expr.Name), LuaObject_Type)));
     }
 }
Ejemplo n.º 2
0
        Ast.Assignment ParseFunctionDecl(ParseTreeNode node)
        {
            if (node.Term.Name == "FunctionDecl")
            {
                Ast.IAssignable expr = ParseVariable(node.ChildNodes[1]);

                ParseTreeNode argsNode  = node.ChildNodes[3].ChildNodes[0];
                ParseTreeNode chunkNode = node.ChildNodes[4];

                Ast.Block block            = ParseBlock(chunkNode);
                Ast.FunctionDefinition def = new Ast.FunctionDefinition();
                def.Arguments = new List <Ast.Argument>();

                var nameNode = node.ChildNodes[2];
                if (nameNode.ChildNodes.Count > 0)
                {
                    def.Arguments.Add(new Ast.Argument()
                    {
                        Name = "self"
                    });
                    expr = new Ast.Variable()
                    {
                        Name   = nameNode.ChildNodes[0].Token.ValueString,
                        Prefix = expr
                    };
                }
                def.Body = block;
                if (argsNode.ChildNodes.Count > 0)
                {
                    argsNode = argsNode.ChildNodes[0];
                    while (argsNode.ChildNodes.Count > 0)
                    {
                        string ident = argsNode.ChildNodes[0].Token.ValueString;
                        def.Arguments.Add(new Ast.Argument()
                        {
                            Name = ident
                        });
                        if (argsNode.ChildNodes.Count == 1)
                        {
                            break;
                        }
                        argsNode = argsNode.ChildNodes[1];
                    }
                }
                Ast.Assignment assign = new Ast.Assignment();
                assign.Variables.Add(expr);
                assign.Expressions.Add(def);
                return(assign);
            }
            throw new Exception("Invalid FunctionDecl node");
        }
Ejemplo n.º 3
0
 static Expression SetVariable(Ast.Variable expr, Expression value, Expression Context)
 {
     if (expr.Prefix == null)
     {
         return(Expression.Call(Context, LuaContext_Set, Expression.Constant(expr.Name), value));
     }
     else
     {
         var prefix = CompileSingleExpression(expr.Prefix, Context);
         var index  = Expression.Constant((LuaObject)(expr.Name));
         var set    = Expression.Property(prefix, "Item", index);
         return(Expression.Assign(set, value));
     }
 }
Ejemplo n.º 4
0
        Ast.Assignment ParseFunctionDecl(ParseTreeNode node)
        {
            if (node.Term.Name == "FunctionDecl")
            {
                Ast.IAssignable expr = ParseVariable(node.ChildNodes[1]);

                ParseTreeNode argsNode = node.ChildNodes[3].ChildNodes[0];
                ParseTreeNode chunkNode = node.ChildNodes[4];

                Ast.Block block = ParseBlock(chunkNode);
                Ast.FunctionDefinition def = new Ast.FunctionDefinition();
                def.Arguments = new List<Ast.Argument>();

                var nameNode = node.ChildNodes[2];
                if (nameNode.ChildNodes.Count > 0)
                {
                    def.Arguments.Add(new Ast.Argument() { Name = "self" });
                    expr = new Ast.Variable()
                    {
                        Name = nameNode.ChildNodes[0].Token.ValueString,
                        Prefix = expr
                    };
                }
                def.Body = block;
                if (argsNode.ChildNodes.Count > 0)
                {
                    argsNode = argsNode.ChildNodes[0];
                    while (argsNode.ChildNodes.Count > 0)
                    {
                        string ident = argsNode.ChildNodes[0].Token.ValueString;
                        def.Arguments.Add(new Ast.Argument() { Name = ident });
                        if (argsNode.ChildNodes.Count == 1)
                            break;
                        argsNode = argsNode.ChildNodes[1];
                    }
                }
                Ast.Assignment assign = new Ast.Assignment();
                assign.Variables.Add(expr);
                assign.Expressions.Add(def);
                return assign;
            }
            throw new Exception("Invalid FunctionDecl node");
        }