Add if statement

Signed-off-by: CHatingPython <chatingpython@gmail.com>
This commit is contained in:
CHatingPython
2026-05-31 17:29:17 +02:00
committed by CHatingPython
parent 646d185d40
commit 91ef7f01a4
12 changed files with 170 additions and 44 deletions
+9 -5
View File
@@ -17,13 +17,14 @@ public:
ir_generator(ir_generator&&) = default;
ir_generator& operator=(ir_generator&&) = default;
ir_generator(const ir_generator&) = default;
ir_generator& operator=(const ir_generator&) = default;
ir_generator(const ir_generator&) = delete;
ir_generator& operator=(const ir_generator&) = delete;
public:
furlang::ir::module&& move_module() { return std::move(m_module); }
public:
void visit_function_definition_node(const ast::function_definition_node& funcDef) override;
void visit_return_statement_node(const ast::return_statement_node& returnStmt) override;
void visit_if_statement_node(const ast::if_statement_node& node) override;
void visit_string_literal_node(const ast::string_literal_node& node) override;
void visit_integer_literal_node(const ast::integer_literal_node& node) override;
void visit_var_read_expression_node(const ast::var_read_expression_node& node) override;
@@ -31,9 +32,12 @@ public:
void visit_binop_expression_node(const ast::binop_expression_node& node) override;
void visit_var_assign_expression_node(const ast::var_assign_expression_node& node) override;
private:
furlang::ir::module m_module;
std::shared_ptr<furlang::ir::block> m_currentBlock;
std::uint32_t m_registerCounter = 0;
furlang::ir::block_index push_block();
private:
furlang::ir::module m_module;
std::unique_ptr<furlang::ir::function> m_currentFunction;
std::shared_ptr<furlang::ir::block> m_currentBlock;
std::uint32_t m_registerCounter = 0;
std::unordered_map<std::string_view, std::uint32_t> m_variableMap;
};
+1 -1
View File
@@ -36,7 +36,7 @@ private:
ast::expression_node_h parse_expression_unary(std::uint32_t precedence);
ast::expression_node_h parse_expression_rhs(ast::expression_node_h&& init, std::uint32_t precedence);
ast::function_body_h parse_body();
ast::body_h parse_body();
private:
token_handle<> next_token();
const token_handle<>& peek_token();
+8
View File
@@ -134,6 +134,8 @@ enum class keyword_token {
None,
Func,
Return,
If,
Else,
};
static inline std::ostream& operator<<(std::ostream& os, keyword_token keyword) {
@@ -141,7 +143,10 @@ static inline std::ostream& operator<<(std::ostream& os, keyword_token keyword)
case keyword_token::None: return os << "none";
case keyword_token::Func: return os << "func";
case keyword_token::Return: return os << "return";
case keyword_token::If: return os << "if";
case keyword_token::Else: return os << "else";
}
return os;
}
static inline std::string operator+(const std::string& str, keyword_token keyword) {
@@ -149,7 +154,10 @@ static inline std::string operator+(const std::string& str, keyword_token keywor
case keyword_token::None: return str + "none";
case keyword_token::Func: return str + "func";
case keyword_token::Return: return str + "return";
case keyword_token::If: return str + "if";
case keyword_token::Else: return str + "else";
}
return str;
}
using integer_token = std::uint64_t;