loop wip
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "Parser/Statement/StatementVariable.h"
|
||||
#include "Parser/Statement/StatementReturn.h"
|
||||
#include "Parser/Statement/StatementExpression.h"
|
||||
#include "Parser/Statement/StatementLoop.h"
|
||||
#include "Parser/Statement/StatementMetaExternFunction.h"
|
||||
#include "Parser/Statement/StatementBlock.h"
|
||||
|
||||
@@ -49,6 +50,9 @@ void ModuleBuilder::buildStatement(shared_ptr<Statement> statement) {
|
||||
case StatementKind::RETURN:
|
||||
buildReturn(dynamic_pointer_cast<StatementReturn>(statement));
|
||||
break;
|
||||
case StatementKind::LOOP:
|
||||
buildLoop(dynamic_pointer_cast<StatementLoop>(statement));
|
||||
break;
|
||||
case StatementKind::META_EXTERN_FUNCTION:
|
||||
buildMetaExternFunction(dynamic_pointer_cast<StatementMetaExternFunction>(statement));
|
||||
break;
|
||||
@@ -121,6 +125,29 @@ void ModuleBuilder::buildReturn(shared_ptr<StatementReturn> statement) {
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleBuilder::buildLoop(shared_ptr<StatementLoop> statement) {
|
||||
shared_ptr<Statement> initStatement = statement->getInitStatement();
|
||||
shared_ptr<Expression> preExpression = statement->getPreConditionExpression();
|
||||
shared_ptr<Expression> postExpression = statement->getPostConditionExpression();
|
||||
shared_ptr<StatementBlock> bodyStatement= statement->getBodyBlockStatement();
|
||||
|
||||
llvm::BasicBlock *parentBlock = builder->GetInsertBlock();
|
||||
|
||||
|
||||
if (initStatement != nullptr)
|
||||
buildStatement(statement->getInitStatement());
|
||||
llvm::Function *fun = builder->GetInsertBlock()->getParent();
|
||||
|
||||
llvm::BasicBlock *bodyBlock = llvm::BasicBlock::Create(*context, "loopBody", fun);
|
||||
builder->SetInsertPoint(bodyBlock);
|
||||
buildBlock(bodyStatement);
|
||||
builder->CreateBr(bodyBlock);
|
||||
|
||||
//llvm::BasicBlock *loopEndBlock = builder->GetInsertBlock()
|
||||
|
||||
builder->SetInsertPoint(parentBlock);
|
||||
}
|
||||
|
||||
void ModuleBuilder::buildMetaExternFunction(shared_ptr<StatementMetaExternFunction> statement) {
|
||||
// get argument types
|
||||
vector<llvm::Type *> types;
|
||||
|
||||
@@ -26,6 +26,7 @@ class StatementFunction;
|
||||
class StatementVariable;
|
||||
class StatementReturn;
|
||||
class StatementExpression;
|
||||
class StatementLoop;
|
||||
class StatementMetaExternFunction;
|
||||
class StatementBlock;
|
||||
|
||||
@@ -54,6 +55,7 @@ private:
|
||||
void buildVarDeclaration(shared_ptr<StatementVariable> statement);
|
||||
void buildBlock(shared_ptr<StatementBlock> statement);
|
||||
void buildReturn(shared_ptr<StatementReturn> statement);
|
||||
void buildLoop(shared_ptr<StatementLoop> statement);
|
||||
void buildMetaExternFunction(shared_ptr<StatementMetaExternFunction> statement);
|
||||
void buildExpression(shared_ptr<StatementExpression> statement);
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ shared_ptr<Statement> Parser::matchStatementLoop() {
|
||||
|
||||
// pre condition
|
||||
shared_ptr<Expression> preConditionExpression = nextExpression();
|
||||
if (preConditionExpression == nullptr || !preConditionExpression->isValid())
|
||||
if (preConditionExpression != nullptr && !preConditionExpression->isValid())
|
||||
return matchStatementInvalid("Expected pre-condition expression");
|
||||
|
||||
// post condition
|
||||
|
||||
Reference in New Issue
Block a user