diff --git a/Swirl/include/parser/parser.h b/Swirl/include/parser/parser.h
index 30236fd..a42c2b4 100644
--- a/Swirl/include/parser/parser.h
+++ b/Swirl/include/parser/parser.h
@@ -185,7 +185,7 @@ struct Var: Node {
struct Function: Node {
std::string ident;
- std::string ret_type;
+ std::string ret_type = "none";
std::vector params{};
NodeType getType() const override {
@@ -199,6 +199,8 @@ struct Function: Node {
std::vector getParams() const override {
return params;
}
+
+ llvm::Value* codegen() override;
};
struct FuncCall: Node {
diff --git a/Swirl/src/parser/parser.cpp b/Swirl/src/parser/parser.cpp
index b379244..7df1924 100644
--- a/Swirl/src/parser/parser.cpp
+++ b/Swirl/src/parser/parser.cpp
@@ -11,7 +11,7 @@
std::stack ScopeTrack{};
-std::vector> Module{};
+std::vector> ParsedModule{};
extern std::unordered_map valid_expr_bin_ops;
@@ -34,10 +34,9 @@ std::unordered_map precedence_table = {
void pushToModule(std::unique_ptr node, bool isNotParent = true) {
if (!ScopeTrack.empty()) node->setParent(ScopeTrack.top());
- Module.emplace_back(std::move(node));
+ ParsedModule.emplace_back(std::move(node));
if (!isNotParent) {
- std::cout << "stack push: " << Module.back()->getType() << std::endl;
- ScopeTrack.push(Module.back().get());
+ ScopeTrack.push(ParsedModule.back().get());
}
}
@@ -89,8 +88,8 @@ void Parser::dispatch() {
m_Stream.next();
}
- for (const auto& nd : Module) {
- std::cout << nd->getType() << " -> " << nd->getParent() << std::endl;
+ for (const auto& nd : ParsedModule) {
+ nd->codegen();
}
}
@@ -148,7 +147,6 @@ void Parser::parseVar() {
parseExpr(&var_node.value);
}
-
pushToModule(std::make_unique(std::move(var_node)));
}
@@ -250,17 +248,16 @@ void Parser::parseExpr(std::variant*, Expression*> ptr,
ops.pop();
}
-
Expression expr{};
expr.expr.reserve(output.size());
- std::move(
- std::make_move_iterator(output.begin()),
- std::make_move_iterator(output.end()),
- std::back_inserter(expr.expr)
- );
+ for (auto& nd : output) {
+ auto n = std::make_unique();
+ n = std::move(nd);
+ expr.expr.push_back(std::move(n));
+ }
if (std::holds_alternative*>(ptr))
std::get*>(ptr)->push_back(std::move(expr));
else
- std::get(ptr)->expr = std::move(output);
+ std::get(ptr)->expr = std::move(expr.expr);
}