Add forward declarations
This commit is contained in:
parent
07c0059c5c
commit
7cf752f67b
@ -85,12 +85,13 @@ namespace AST {
|
||||
|
||||
out << ") -> ";
|
||||
out << this->m_return_ty->formatted();
|
||||
if (this->m_statements) {
|
||||
out << " {\n";
|
||||
for (auto& statement : this->m_statements) {
|
||||
for (auto& statement : *this->m_statements) {
|
||||
out << " " << statement->formatted() << "\n";
|
||||
}
|
||||
|
||||
out << "}";
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
}
|
||||
@ -167,14 +167,14 @@ namespace AST {
|
||||
std::unique_ptr<types::Type> m_return_ty;
|
||||
std::vector<std::pair<std::string, std::unique_ptr<types::Type>>> m_params;
|
||||
std::string m_name;
|
||||
std::vector<std::unique_ptr<Statement>> m_statements;
|
||||
std::optional<std::vector<std::unique_ptr<Statement>>> m_statements;
|
||||
public:
|
||||
Function(
|
||||
token::Metadata meta,
|
||||
std::unique_ptr<types::Type> return_ty,
|
||||
std::vector<std::pair<std::string, std::unique_ptr<types::Type>>> params,
|
||||
std::string name,
|
||||
std::vector<std::unique_ptr<Statement>> statements)
|
||||
std::optional<std::vector<std::unique_ptr<Statement>>> statements)
|
||||
: TopLevelStatement{ meta }
|
||||
, m_return_ty{ std::move(return_ty) }
|
||||
, m_params{ std::move(params) }
|
||||
|
||||
@ -187,6 +187,7 @@ namespace AST {
|
||||
|
||||
scope.values[this->m_name] = codegen::StackValue{ function, fn_ty_ptr };
|
||||
|
||||
if (this->m_statements) {
|
||||
auto BB = llvm::BasicBlock::Create(*builder.context, "entry", function, nullptr);
|
||||
builder.block = BB;
|
||||
|
||||
@ -203,9 +204,10 @@ namespace AST {
|
||||
};
|
||||
}
|
||||
|
||||
for (auto& statement : this->m_statements) {
|
||||
for (auto& statement : *this->m_statements) {
|
||||
statement->codegen(builder, inner_scope);
|
||||
}
|
||||
}
|
||||
|
||||
llvm::verifyFunction(*function);
|
||||
|
||||
|
||||
@ -252,18 +252,25 @@ namespace parsing {
|
||||
}
|
||||
|
||||
inner.expect(token::Type::Symbol, ")");
|
||||
|
||||
std::optional<std::vector<std::unique_ptr<AST::Statement>>> statements{};
|
||||
if (inner.peek().content == "{") {
|
||||
inner.expect(token::Type::Symbol, "{");
|
||||
|
||||
std::vector<std::unique_ptr<AST::Statement>> statements{};
|
||||
std::vector<std::unique_ptr<AST::Statement>> statement_list{};
|
||||
|
||||
auto statement = parse_statement(inner);
|
||||
while (statement.ok()) {
|
||||
statements.push_back(statement.unwrap());
|
||||
statement_list.push_back(statement.unwrap());
|
||||
statement = parse_statement(inner);
|
||||
}
|
||||
|
||||
|
||||
statements = std::optional{ std::move(statement_list) };
|
||||
inner.expect(token::Type::Symbol, "}");
|
||||
}
|
||||
else {
|
||||
inner.expect(token::Type::Symbol, ";");
|
||||
}
|
||||
|
||||
stream.m_position = inner.m_position;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user