Variables can now be read from

This commit is contained in:
Pasha Bibko
2025-04-28 21:16:54 +01:00
parent cbc179411a
commit ce8f1619a4
4 changed files with 19 additions and 4 deletions

View File

@@ -92,6 +92,9 @@ namespace LX::AST
llvm::Value* VariableAccess::GenIR(InfoLLVM& LLVM)
{
return nullptr;
llvm::AllocaInst* var = LLVM.scope->GetVar(m_Name);
ThrowIf<Scope::VariableDoesntExist>(var == nullptr);
return LLVM.builder.CreateLoad(llvm::Type::getInt32Ty(LLVM.context), var, m_Name + "_val");
}
}

View File

@@ -42,6 +42,10 @@ namespace LX
case Token::NUMBER_LITERAL:
return std::make_unique<AST::NumberLiteral>(p.tokens[p.index++].GetContents());
// If an Identifier has got here it means a variable is being accessed //
case Token::IDENTIFIER:
return std::make_unique<AST::VariableAccess>(p.tokens[p.index++].GetContents());
// TODO: Fix this //
case Token::OPEN_BRACKET:
p.scopeDepth++;