ast.cpp
/* Note, you will not see ast_block_codegen generate ir_blocks.
 * To the AST and the IR, blocks are 2 different things.
 * In the AST it represents a block of code, usually enclosed in
 * curly braces {...}.
 * While in the IR it represents a block in terms of control-flow.
 */
Note, you will not see ast_block_codegen generate ir_blocks.
To the AST and the IR, blocks are 2 different things.
In the AST it represents a block of code, usually enclosed in
curly braces {...}.
While in the IR it represents a block in terms of control-flow.
Note you will not see ast_block_codegen generate ir_blocks . To the AST and the IR blocks are 2 different things . In the AST it represents a block of code usually enclosed in curly braces { ... } . While in the IR it represents a block in terms of control - flow .
bool ast_block::codegen(ast_function *func, bool lvalue, ir_value **out)
{
    if (lvalue) {
        compile_error(m_context, "not an l-value (code-block)");
        return false;
    }
    if (m_outr) {
        *out = m_outr;
        return true;
    }
    *out = nullptr;
    for (auto &it : m_locals) {
        if (!it->generateLocal(func->m_ir_func, false)) {
            if (OPTS_OPTION_BOOL(OPTION_DEBUG))
                compile_error(m_context, "failed to generate local `%s`", it->m_name);
            return false;
        }
    }
    for (auto &it : m_exprs) {
        if (func->m_curblock->m_final && !starts_a_label(it)) {
            if (compile_warning(it->m_context, WARN_UNREACHABLE_CODE, "unreachable statement"))
                return false;
            continue;
        }
        if (!it->codegen(func, false, out))
            return false;
    }
    m_outr = *out;
    return true;
}
bool ast_block :: codegen ( ast_function * func , bool lvalue , ir_value * * out ) { if ( lvalue ) { compile_error ( m_context , " " ) ; return false ; } if ( m_outr ) { * out = m_outr ; return true ; } * out = nullptr ; for ( auto & it : m_locals ) { if ( ! it -> generateLocal ( func -> m_ir_func , false ) ) { if ( OPTS_OPTION_BOOL ( OPTION_DEBUG ) ) compile_error ( m_context , " " , it -> m_name ) ; return false ; } } for ( auto & it : m_exprs ) { if ( func -> m_curblock -> m_final && ! starts_a_label ( it ) ) { if ( compile_warning ( it -> m_context , WARN_UNREACHABLE_CODE , " " ) ) return false ; continue ; } if ( ! it -> codegen ( func , false , out ) ) return false ; } m_outr = * out ; return true ; }
Note, you will not see ast_block_codegen generate ir_blocks.
Note you will not see ast_block_codegen generate ir_blocks .
/* We don't use this
     * Note: an ast-representation using the comma-operator
     * of the form: (a, b, c) = x should not assign to c...
     */ /* output is nullptr at first, we'll have each expression
     * assign to out output, thus, a comma-operator represention
     * using an ast_block will return the last generated value,
     * so: (b, c) + a  executed both b and c, and returns c,
     * which is then added to a.
     */ /* generate locals */