mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-03 17:39:02 +00:00
Variables can now be read from
This commit is contained in:
@@ -92,6 +92,9 @@ namespace LX::AST
|
|||||||
|
|
||||||
llvm::Value* VariableAccess::GenIR(InfoLLVM& LLVM)
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ namespace LX
|
|||||||
case Token::NUMBER_LITERAL:
|
case Token::NUMBER_LITERAL:
|
||||||
return std::make_unique<AST::NumberLiteral>(p.tokens[p.index++].GetContents());
|
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 //
|
// TODO: Fix this //
|
||||||
case Token::OPEN_BRACKET:
|
case Token::OPEN_BRACKET:
|
||||||
p.scopeDepth++;
|
p.scopeDepth++;
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
This is my custom compiled language written in C++ based off of the LLVM toolchain. Do not use the language in it's current state unless you are insane.
|
This is my custom compiled language written in C++ based off of the LLVM toolchain. Do not use the language in it's current state unless you are insane.
|
||||||
|
|
||||||
### Planned features
|
### Planned features
|
||||||
- Variables
|
|
||||||
- Operations (Maths + BinOp)
|
- Operations (Maths + BinOp)
|
||||||
- Functions
|
- Functions
|
||||||
- More than just int as a type
|
- More than just int as a type
|
||||||
|
- References / Pointers
|
||||||
- Structs / Classes (Polymorphism + vtables)
|
- Structs / Classes (Polymorphism + vtables)
|
||||||
|
|
||||||
### Stuff I want to do later
|
### Stuff I want to do later
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
func main()
|
func main()
|
||||||
{
|
{
|
||||||
int result
|
int a
|
||||||
result = 4
|
a = 4
|
||||||
|
|
||||||
|
int b
|
||||||
|
b = 7
|
||||||
|
|
||||||
|
int c
|
||||||
|
c = a + b
|
||||||
|
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user