diff --git a/src/language/BuiltinModule.cpp b/src/language/BuiltinModule.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2d2b1b556642353c53b93f7f54b75d96a074643f --- /dev/null +++ b/src/language/BuiltinModule.cpp @@ -0,0 +1,17 @@ +#include <BuiltinModule.hpp> + +#include <CFunctionEmbedder.hpp> + +#include <iostream> + +void +BuiltinModule::_addFunction(const std::string& name, std::shared_ptr<ICFunctionEmbedder> c_function_embedder) +{ + auto [i_function, success] = m_name_cfunction_map.insert(std::make_pair(name, c_function_embedder)); + // LCOV_EXCL_START + if (not success) { + std::cerr << "function " << name << " cannot be add!\n"; + std::exit(1); + } + // LCOV_EXCL_STOP +} diff --git a/src/language/BuiltinModule.hpp b/src/language/BuiltinModule.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2a076f511022c7aed15a25684865d9c7210b0b94 --- /dev/null +++ b/src/language/BuiltinModule.hpp @@ -0,0 +1,28 @@ +#ifndef BUILTIN_MODULE_HPP +#define BUILTIN_MODULE_HPP + +#include <PugsMacros.hpp> + +#include <IModule.hpp> + +class ICFunctionEmbedder; +class BuiltinModule : public IModule +{ + protected: + NameCFunctionMap m_name_cfunction_map; + + void _addFunction(const std::string& name, std::shared_ptr<ICFunctionEmbedder> c_function_embedder); + + public: + const NameCFunctionMap& + getNameCFunctionsMap() const final + { + return m_name_cfunction_map; + } + + BuiltinModule() = default; + + ~BuiltinModule() = default; +}; + +#endif // BUILTIN_MODULE_HPP diff --git a/src/language/CMakeLists.txt b/src/language/CMakeLists.txt index 8086dfbcae9b20581411be22699dece9ae16e21f..e901374f5167cdaa43750890f6e31d40fe2de91e 100644 --- a/src/language/CMakeLists.txt +++ b/src/language/CMakeLists.txt @@ -31,6 +31,7 @@ add_library( ASTPrinter.cpp ASTSymbolTableBuilder.cpp ASTSymbolInitializationChecker.cpp + BuiltinModule.cpp MathModule.cpp ModuleRepository.cpp PugsParser.cpp) diff --git a/src/language/MathModule.cpp b/src/language/MathModule.cpp index 934b55be831698dfaa8c06edad4b338d5101c7b9..440ad929041b6cb18baf3a8dff96994a6b0949c5 100644 --- a/src/language/MathModule.cpp +++ b/src/language/MathModule.cpp @@ -2,20 +2,6 @@ #include <CFunctionEmbedder.hpp> -#include <iostream> - -void -MathModule::_addFunction(const std::string& name, std::shared_ptr<ICFunctionEmbedder> c_function_embedder) -{ - auto [i_function, success] = m_name_cfunction_map.insert(std::make_pair(name, c_function_embedder)); - // LCOV_EXCL_START - if (not success) { - std::cerr << "function " << name << " cannot be add!\n"; - std::exit(1); - } - // LCOV_EXCL_STOP -} - MathModule::MathModule() { this->_addFunction("sqrt", std::make_shared<CFunctionEmbedder<double, double>>( diff --git a/src/language/MathModule.hpp b/src/language/MathModule.hpp index c3ca3ed0a46d8843e231d33fa270d661e191d588..8a897c8129e5d47403049f3906895b5c28b3ed59 100644 --- a/src/language/MathModule.hpp +++ b/src/language/MathModule.hpp @@ -1,15 +1,10 @@ #ifndef MATH_MODULE_HPP #define MATH_MODULE_HPP -#include <IModule.hpp> +#include <BuiltinModule.hpp> -class MathModule : public IModule +class MathModule : public BuiltinModule { - private: - NameCFunctionMap m_name_cfunction_map; - - void _addFunction(const std::string& name, std::shared_ptr<ICFunctionEmbedder> c_function_embedder); - public: std::string_view name() const final @@ -17,12 +12,6 @@ class MathModule : public IModule return "math"; } - const NameCFunctionMap& - getNameCFunctionsMap() const final - { - return m_name_cfunction_map; - } - MathModule(); ~MathModule() = default; diff --git a/src/language/ModuleRepository.cpp b/src/language/ModuleRepository.cpp index 4eb46c0ae204e58313f94d46b54e44fb1a2a2f98..1b3fee7d3878f66ed7c5120d542c107e0b2983d7 100644 --- a/src/language/ModuleRepository.cpp +++ b/src/language/ModuleRepository.cpp @@ -48,8 +48,6 @@ ModuleRepository::populateSymbolTable(const ASTNode& module_name_node, SymbolTab c_function_embedder_table.add(c_function); } - - std::cout << "populating ..."; } else { throw parse_error(std::string{"could not find module "} + module_name, std::vector{module_name_node.begin()}); }