Codegen initial alloca and store

This commit is contained in:
Sofia 2026-04-09 15:37:51 +03:00
parent db60335507
commit cf94296877
2 changed files with 12 additions and 2 deletions

View File

@ -23,7 +23,18 @@ namespace AST {
} }
void InitializationStatement::codegen(codegen::Builder& builder) { void InitializationStatement::codegen(codegen::Builder& builder) {
if (!builder.block)
return; return;
builder.builder->SetInsertPoint(builder.block.get());
auto ty = this->m_type->codegen(builder);
auto ptr = builder.builder->CreateAlloca(ty);
if (this->m_expr.has_value()) {
auto value = this->m_expr->get()->codegen(builder);
builder.builder->CreateStore(value, ptr, false);
}
} }
void Function::codegen(codegen::Builder& builder) { void Function::codegen(codegen::Builder& builder) {

View File

@ -56,7 +56,6 @@ namespace parsing {
std::optional<std::unique_ptr<AST::Expression>> expr = {}; std::optional<std::unique_ptr<AST::Expression>> expr = {};
if (inner.peek().type == token::Type::Symbol && inner.peek().content == "=") { if (inner.peek().type == token::Type::Symbol && inner.peek().content == "=") {
std::cout << "hello" << std::endl;
inner.expect(token::Type::Symbol, "="); inner.expect(token::Type::Symbol, "=");
expr = parse_expression(inner).unwrap(); expr = parse_expression(inner).unwrap();
} }