diff --git a/include/ast/declaration/FunctionNode.h b/include/ast/declaration/FunctionNode.h index 023254ae270bfa6b7b9fe1d469edbea7d87bf490..9711e82e59784c2517b361b6b32484ce5b589750 100644 --- a/include/ast/declaration/FunctionNode.h +++ b/include/ast/declaration/FunctionNode.h @@ -3,6 +3,7 @@ #include "ast/BlockNode.h" #include "ast/declaration/VariableNode.h" #include "ast/expression/ExpressionNode.h" +#include "parser/BuiltIn.h" #include "parser/Registry.h" #include "parser/Scope.h" #include "token/Token.h" diff --git a/source/ast/declaration/FunctionNode.cc b/source/ast/declaration/FunctionNode.cc index 240c375907d261ca2d2d25091267b269db24d3d4..61977bc86f45e5f3d6f072dc741e15fec6fa8716 100644 --- a/source/ast/declaration/FunctionNode.cc +++ b/source/ast/declaration/FunctionNode.cc @@ -28,6 +28,12 @@ FunctionNode::~FunctionNode() Node* FunctionNode::evaluate() const { + // Check if the function is built-in + if (BuiltIn::functions.find(identifier) != BuiltIn::functions.end()) + { + throw RuntimeError(get_location(), "Cannot overwrite built-in function: " + identifier); + } + // Register the function in the registry Registry::instance().add_function(const_cast<FunctionNode*>(this)); // Add the function to the current scope diff --git a/source/parser/Scope.cc b/source/parser/Scope.cc index 8299717505d5c833cff09776c7c8e63990d1c3e7..d771d5c74fcfd0c9663cb19a2698e4f7e2805a5a 100644 --- a/source/parser/Scope.cc +++ b/source/parser/Scope.cc @@ -4,7 +4,13 @@ namespace funk { Scope::Scope() {} -Scope::~Scope() {} +Scope::~Scope() +{ + for (auto& scope : scopes) + { + for (auto& [name, node] : scope) { delete node; } + } +} Scope& Scope::instance() {