Skip to content
Snippets Groups Projects

Refactor slightly BuiltinFunctionEmbedder and check types

Merged Stéphane Del Pino requested to merge feature/buitin-functions-improvements into develop
1 file
+ 1
1
Compare changes
  • Side-by-side
  • Inline
@@ -4,10 +4,17 @@
#include <language/modules/IModule.hpp>
#include <language/utils/ASTNodeDataType.hpp>
#include <utils/Exceptions.hpp>
#include <sstream>
class IBuiltinFunctionEmbedder;
class TypeDescriptor;
class ValueDescriptor;
template <typename FX, typename... Args>
class BuiltinFunctionEmbedder;
class BuiltinModule : public IModule
{
protected:
@@ -15,9 +22,27 @@ class BuiltinModule : public IModule
NameTypeMap m_name_type_map;
NameValueMap m_name_value_map;
template <typename FX, typename... Args>
void
_addBuiltinFunction(const std::string& name, std::function<FX(Args...)>&& f)
{
try {
this->_addBuiltinFunction(name, std::make_shared<BuiltinFunctionEmbedder<FX(Args...)>>(
std::forward<std::function<FX(Args...)>>(f)));
}
catch (std::invalid_argument& e) {
std::ostringstream os;
os << "while defining builtin function '" << rang::fgB::yellow << name << rang::fg::reset << "'\n";
os << e.what();
throw UnexpectedError(os.str());
}
}
private:
void _addBuiltinFunction(const std::string& name,
std::shared_ptr<IBuiltinFunctionEmbedder> builtin_function_embedder);
protected:
void _addTypeDescriptor(const ASTNodeDataType& type);
void _addNameValue(const std::string& name, const ASTNodeDataType& type, const DataVariant& data);
Loading