From cf94296877fdae92e8105cef5699419bf01325f8 Mon Sep 17 00:00:00 2001 From: Sofia Date: Thu, 9 Apr 2026 15:37:51 +0300 Subject: [PATCH] Codegen initial alloca and store --- src/codegen.cpp | 13 ++++++++++++- src/parsing.cpp | 1 - 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 783c075..f101a43 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -23,7 +23,18 @@ namespace AST { } void InitializationStatement::codegen(codegen::Builder& builder) { - return; + if (!builder.block) + 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) { diff --git a/src/parsing.cpp b/src/parsing.cpp index b022d08..0322e01 100644 --- a/src/parsing.cpp +++ b/src/parsing.cpp @@ -56,7 +56,6 @@ namespace parsing { std::optional> expr = {}; if (inner.peek().type == token::Type::Symbol && inner.peek().content == "=") { - std::cout << "hello" << std::endl; inner.expect(token::Type::Symbol, "="); expr = parse_expression(inner).unwrap(); }