Ejemplo n.º 1
0
 public override void Visit(FunctionStmt n)
 {
     foreach (AST ast in n.param_list)
     {
         ast.accept(this);
     }
 }
Ejemplo n.º 2
0
        protected override void MatchFunctionStmt(FunctionStmt stmt)
        {
            Declare(stmt.Name);
            Define(stmt.Name);

            ResolveFunction(stmt, FunctionType.FUNCTION);
        }
Ejemplo n.º 3
0
        public object Visit(FunctionStmt stmt)
        {
            var arguments = new LLVMTypeRef[stmt.Arguments.Count];

            // Add argument types
            for (int i = 0; i < stmt.Arguments.Count; i++)
            {
                arguments[i] = stmt.Arguments[i].DataType.BaseType.ToLLVMType();
            }

            LLVMTypeRef  functionType = LLVM.FunctionType(stmt.ReturnType.BaseType.ToLLVMType(), arguments, LLVMBoolFalse);
            LLVMValueRef function     = LLVM.AddFunction(_module, stmt.Name.Lexeme, functionType);

            // Add names to arguments and allocate memory
            for (int k = 0; k < arguments.Length; k++)
            {
                string       argumentName = stmt.Arguments[k].Name.Lexeme;
                LLVMValueRef param        = LLVM.GetParam(function, (uint)k);
                LLVM.SetValueName(param, argumentName);

                _namedValues[argumentName] = new NamedValue(param);
            }

            _valueStack.Push(new Tuple <LLVMValueRef, BlockStmt>(function, stmt.Block));

            return(null);
        }
Ejemplo n.º 4
0
        public override void Visit(FunctionStmt n)
        {
            SymReferencing current = n.id as SymReferencing;

            InitiationTable[FindKey(current.id)] = 1;
            foreach (AST ast in n.param_list)
            {
                ast.accept(this);
            }
        }
Ejemplo n.º 5
0
        public override void Visit(FunctionStmt n)
        {
            SymReferencing current = n.id as SymReferencing;

            n.type = AST.SymbolTable[GetKeyVal(current.id)];
            foreach (AST ast in n.param_list)
            {
                ast.accept(this);
            }
            funcCalls.Add(n);
        }
Ejemplo n.º 6
0
        public object Visit(FunctionStmt stmt)
        {
            _currentFunctionType = stmt.ReturnType;

            for (int i = 0; i < stmt.Arguments.Count; i++)
            {
                Argument argument = stmt.Arguments[i];
                _scope.Define(argument.Name.Lexeme, argument.DataType, true);
            }

            stmt.Block.Accept(this);

            return(null);
        }
Ejemplo n.º 7
0
    private void resolve_function(FunctionStmt function, FunctionType type)
    {
        FunctionType enclosing_function = function_type;

        function_type = type;
        start_scope();
        foreach (Token param in function.paramaters)
        {
            declare(param);
            define(param);
        }
        resolve(function.body);
        end_scope();
        function_type = enclosing_function;
    }
Ejemplo n.º 8
0
        private void ResolveFunction(FunctionStmt function, FunctionType type)
        {
            var enclosingFunction = currentFunction;

            currentFunction = type;

            BeginScope();
            foreach (var param in function.Params)
            {
                Declare(param);
                Define(param);
            }
            Resolve(function.Body);
            EndScope();
            currentFunction = enclosingFunction;
        }
Ejemplo n.º 9
0
 public override void Visit(FunctionStmt n)
 {
     n.id.accept(this);
     emit($"(");
     if (n.param_list.Count > 0)
     {
         AST first = n.param_list[0];
         foreach (AST ast in n.param_list)
         {
             if (first != ast)
             {
                 emit(", ");
             }
             ast.accept(this);
         }
     }
     emit(");\n");
 }
Ejemplo n.º 10
0
    private TryCatchStmt trycatch()
    {
        consume(Token.Type.Try);
        Statement try_body = statement();

        consume(Token.Type.Catch, "Expected 'catch' keyword after 'try'");
        List <Token> paramaters = new List <Token>();

        if (expect(Token.Type.LeftParenthesis))
        {
            paramaters = get_paramaters();
        }
        List <Statement> function_body = new List <Statement>()
        {
            statement()
        };
        FunctionStmt catch_body = new FunctionStmt(new Token(Token.Type.Catch, "catch"), paramaters, function_body);

        return(new TryCatchStmt(try_body, catch_body));
    }
Ejemplo n.º 11
0
 public LoxFunction(FunctionStmt declaration, Environment closure, bool isInitializer)
 {
     Declaration   = declaration;
     Closure       = closure;
     IsInitializer = isInitializer;
 }
 public PlutoFunction(FunctionStmt function, Scope scope, bool is_constructor)
 {
     this.function       = function;
     this.scope          = scope;
     this.is_constructor = is_constructor;
 }
Ejemplo n.º 13
0
 public Function(FunctionStmt declaration, Env closure)
 {
     this.closure     = closure;
     this.declaration = declaration;
     Arity            = declaration.parameters.Count();
 }
Ejemplo n.º 14
0
 public TryCatchStmt(Statement try_body, FunctionStmt catch_body)
 {
     this.try_body   = try_body;
     this.catch_body = catch_body;
 }
Ejemplo n.º 15
0
    public void visit_function(FunctionStmt function_stmt)
    {
        PlutoFunction func = new PlutoFunction(function_stmt, this.local_scope, false);

        local_scope.define((string)function_stmt.name.value, func);
    }
Ejemplo n.º 16
0
 public void visit_function(FunctionStmt function_stmt)
 {
     declare(function_stmt.name);
     define(function_stmt.name);
     resolve_function(function_stmt, FunctionType.Function);
 }
Ejemplo n.º 17
0
Archivo: Matcher.cs Proyecto: sula0/Lox
 protected abstract void MatchFunctionStmt(FunctionStmt functionStmt);