Exemplo n.º 1
0
    protected void ResolveFunDeclStmt(AstFunDeclStmt stmt)
    {
        var scope = Scope();

        if (scope != null)  // TODO: Better global handling
        {
            if (scope.ContainsKey(stmt.m_identifier.m_identifier))
            {
                m_error = true;
                Lox.Error(stmt.m_startLine, "Redefinition of identifier \"" + stmt.m_identifier.m_identifier + "\"");
                return;
            }

            scope[stmt.m_identifier.m_identifier] = true;
        }

        scope = PushScope();
        foreach (string param in stmt.m_params)
        {
            scope[param] = true;
        }

        ResolveStmts(stmt.m_body);
        PopScope();
    }
Exemplo n.º 2
0
    protected Function ExecuteFunDeclStmt(AstFunDeclStmt stmt)
    {
        if (HadErrorOrReturn())
        {
            return(null);
        }

        Function fn = new Function(stmt, m_environment);

        bool success = m_environment.Define(stmt.m_identifier.m_identifier, fn);

        if (!success)
        {
            // @copypaste

            // TODO: Print the line that the first definition was on? To do that we would have to store
            //  line numbers in the environment. Also, it wouldn't really make sense for repl mode so we would
            //  have to have a way to check if we are in repl mode.

            m_runtimeError = true;
            Lox.Error(stmt.m_startLine, "Redifinition of identifier.m_identifier " + stmt.m_identifier.m_identifier);
            return(null);
        }

        return(fn);
    }
Exemplo n.º 3
0
 public Function(AstFunDeclStmt funDecl, Environment closure)
 {
     m_funDecl = funDecl;
     m_closure = closure;
 }