Ejemplo n.º 1
0
    public object VisitFunctionStatement(Statement.Function stmt)
    {
        var name         = stmt.Identifier;
        var parameters   = stmt.Parameters.Count;
        var returnValues = stmt.ReturnValue == null ? 0 : 1;

        current = new WASMFunction(parameters, returnValues, name);
        functions.Declare(name);

        // TODO too many nested envs?
        environment.EnterInner();
        passByVar.Add(name, new List <bool>());
        // TODO pass by
        foreach (var param in stmt.Parameters)
        {
            environment.Declare(param.Identifier);
            current.Locals++;
            passByVar[name].Add(param.IsRef);
        }

        stmt.Body.Accept(this);
        wasm.addFunction(current);

        environment.ExitInner();

        return(null);
    }
Ejemplo n.º 2
0
 public object VisitFunctionStatement(Statement.Function statement)
 {
     Declare(statement.name);
     Define(statement.name);
     ResolveFunction(statement);
     return(null);
 }
Ejemplo n.º 3
0
        public object VisitFunctionStatement(Statement.Function statement)
        {
            Function function = new Function(statement, environment);

            environment.Define(statement.name.lexeme, function);
            return(null);
        }
Ejemplo n.º 4
0
 public object VisitFunctionStatement(Statement.Function stmt)
 {
     // todo params?
     foreach (var param in stmt.Parameters)
     {
         param.Accept(this);
     }
     return(stmt.Body.Accept(this));
 }
Ejemplo n.º 5
0
 private void ResolveFunction(Statement.Function function)
 {
     BeginScope();
     foreach (Token parameter in function.parameters)
     {
         Define(parameter);
         Define(parameter);
     }
     Resolve(function.body);
     EndScope();
 }
Ejemplo n.º 6
0
        Expr IStatementVisitor <Expr> .Visit(Statement.Function statement)
        {
            // Rewrite AST to its desugared state
            // function a:b (params) body end -> function a.b (self, params) body end
            if (statement.Name.Table != null)
            {
                statement.Body.Parameters.Insert(0, "self");
                statement.Name.Identifiers.Add(statement.Name.Table);
                statement.Name.Table = null;
            }

            var bodyExpr = Visit(statement.Name.Identifiers.Last(), statement.Body);

            return(AssignToIdentifierList(statement.Name.Identifiers, bodyExpr));
        }
Ejemplo n.º 7
0
 public Function(Statement.Function declaration, Environment closure)
 {
     this.declaration = declaration;
     this.closure     = closure;
 }