Skip to content

Commit

Permalink
More polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNachoBIT committed Aug 14, 2023
1 parent ec2788c commit 5b14057
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
21 changes: 16 additions & 5 deletions Language/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ llvm::Value* GetInstNoCatch(AST::Expression* v, bool enable_phi = true)
{
if (CodeGen::NamedLoads[AST::CurrentIdentifier].second != nullptr)
{
return CodeGen::NamedLoads[AST::CurrentIdentifier].second;
if(!CodeGen::NamedLoads[AST::CurrentIdentifier].second->getType()->isPointerTy())
{
return CodeGen::NamedLoads[AST::CurrentIdentifier].second;
}
else
{
CodeGen::Error("Pointer found!");
}
}
}

Expand Down Expand Up @@ -242,8 +249,12 @@ llvm::Value* AST::Call::codegen()
for (unsigned i = 0, e = Args.size(); i != e; ++i) {
llvm::Value* argCG = GetInst(Args[i].get());

if(argCG == nullptr)
if(argCG == nullptr) {
argCG = Args[i]->codegen();
}
else if(isa<llvm::ArrayType>(argCG->getType())) {
argCG = Args[i]->codegen();
}

if(!argCG) { CodeGen::Error("One of the Arguments in " + Callee + " is nullptr in the codegen.\n"); }

Expand Down Expand Up @@ -501,7 +512,7 @@ llvm::Value* CreateAutoLoad(AST::Expression* v, llvm::Value* r)
else return getV;

auto L = CodeGen::Builder->CreateLoad(TV, getV, getV->getName());
CodeGen::NamedLoads[AST::CurrentIdentifier] = std::make_pair(L, nullptr);
CodeGen::NamedLoads[GetName(v)] = std::make_pair(L, nullptr);

return L;
}
Expand Down Expand Up @@ -1208,7 +1219,7 @@ llvm::Value* AST::GetElement::codegen()
AST::Type* T = nullptr;

if(all_array_ptrs.find(getName) == all_array_ptrs.end())
CodeGen::Error("'T' is not found or is nullptr.");
CodeGen::Error("'" + getName + "' is not found or is nullptr.");

T = all_array_ptrs[getName];

Expand Down Expand Up @@ -1350,7 +1361,7 @@ llvm::Value* AST::IntCast::codegen()
{
llvm::Value* target_cg = GetInst(target.get());

return CodeGen::Builder->CreateIntCast(target_cg, convert_to_type->codegen(), !convert_to_type->is_unsigned);
return CodeGen::Builder->CreateIntCast(target_cg, convert_to_type->codegen(), !convert_to_type->is_unsigned, "int_cast");
}

llvm::Value* AST::Data::codegen()
Expand Down
34 changes: 20 additions & 14 deletions Language/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ struct Parser
auto Expr = ParseExpression();
Expr->dont_share_history = true;

// AUTO-PURIFIER MY BELOVED <3
// AUTO-PURIFIER MY BELOVED <3+
// Update: Don't use this all the time, specially for heavy memory usage.

std::string title = "autoPure" + std::to_string(Parser::random_global_id);
Parser::random_global_id++;
Expand All @@ -549,8 +550,23 @@ struct Parser
}
}

inst_before_arg.push_back(std::make_unique<AST::Pure>(title, std::move(T), std::move(Expr)));
currentArgs.push_back(std::make_unique<AST::Variable>(nullptr, title));
if(VE)
{
auto new_variable = std::make_unique<AST::Variable>(nullptr, VE->Name);
currentArgs.push_back(std::move(new_variable));

if(check_if_is_in_array_list(VE->Name))
{
if(a->amount - 1 != -1)
inst_before_arg.push_back(std::make_unique<AST::Pure>(VE->Name + "_length", std::make_unique<AST::i32>(), std::make_unique<AST::Number>(std::to_string(a->amount - 1))));

currentArgs.push_back(std::make_unique<AST::Variable>(nullptr, VE->Name + "_length"));
}
}
else {
inst_before_arg.push_back(std::make_unique<AST::Pure>(title, std::move(T), std::move(Expr)));
currentArgs.push_back(std::make_unique<AST::Variable>(nullptr, title));
}

if(DE)
{
Expand All @@ -563,17 +579,6 @@ struct Parser
}
}

if(VE)
{
if(check_if_is_in_array_list(VE->Name))
{
if(a->amount - 1 != -1)
inst_before_arg.push_back(std::make_unique<AST::Pure>(VE->Name + "_length", std::make_unique<AST::i32>(), std::make_unique<AST::Number>(std::to_string(a->amount - 1))));

currentArgs.push_back(std::make_unique<AST::Variable>(nullptr, VE->Name + "_length"));
}
}

if(Lexer::CurrentToken != ',' && Lexer::CurrentToken != ')')
return AST::ExprError("Expected ',' or ')' after identifier.");

Expand All @@ -593,6 +598,7 @@ struct Parser
return std::make_unique<AST::Call>(IdName, std::move(currentArgs), std::move(inst_before_arg));
}

ResetTarget();
SetIdentToMainTarget(IdName);

return std::make_unique<AST::Variable>(nullptr, IdName);
Expand Down

0 comments on commit 5b14057

Please sign in to comment.