Skip to content

Commit

Permalink
Changed callable type to ASTNode in function call expression AST.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Sep 13, 2024
1 parent acaab9a commit 7d294f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions include/ast/expression/FunctionCallExpression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@

class FunctionCallExpression : public ASTNode {
private:
std::string functionName;
std::unique_ptr<ASTNode> callable;
std::vector<std::unique_ptr<ASTNode>> arguments;

public:
explicit FunctionCallExpression(
std::unique_ptr<Token> _address,
std::string _functionName,
std::unique_ptr<ASTNode> _callable,
std::vector<std::unique_ptr<ASTNode>> _arguments
) : functionName(std::move(_functionName)),
) : callable(std::move(_callable)),
arguments(std::move(_arguments)) {
this->address = std::move(_address);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ast/expression/FunctionCallExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
#include <ast/expression/FunctionCallExpression.hpp>

DynamicObject FunctionCallExpression::visit(SymbolTable& symbols) {
auto func = symbols.getSymbol(this->functionName);
auto func = this->callable->visit(symbols);
if(!func.isFunction())
throw std::runtime_error("Symbol '" + this->functionName + "' is not a function.");
throw std::runtime_error("Expression is not a function.");

auto callable = func.getCallable();
auto caller = func.getCallable();
std::vector<DynamicObject> args;

for(auto& arg : this->arguments)
args.push_back(arg->visit(symbols));

return callable->call(symbols, args);
return caller->call(symbols, args);
}

0 comments on commit 7d294f3

Please sign in to comment.