74 lines
2.1 KiB
C++
74 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <Ast/Expressions/VarExpr.hpp>
|
|
|
|
#include <Ast/functionParameters.hpp>
|
|
#include <Core/String.hpp>
|
|
#include <Evaluator/Value/value.hpp>
|
|
#include <Core/runtimeTime.hpp>
|
|
|
|
#include <unordered_map>
|
|
#include <functional>
|
|
#include <vector>
|
|
|
|
namespace Fig
|
|
{
|
|
namespace Builtins
|
|
{
|
|
|
|
/*
|
|
// error's interface like:
|
|
interface Error
|
|
{
|
|
toString() -> String;
|
|
getErrorClass() -> String;
|
|
getErrorMessage() -> String;
|
|
}
|
|
*/
|
|
|
|
const TypeInfo &getErrorInterfaceTypeInfo();
|
|
|
|
const TypeInfo &getTypeErrorStructTypeInfo();
|
|
/*
|
|
interface Operation
|
|
{
|
|
add(..., ...) -> ...;
|
|
}
|
|
|
|
*/
|
|
|
|
const TypeInfo &getOperationInterfaceTypeInfo();
|
|
|
|
const std::unordered_map<String, ObjectPtr> &getBuiltinValues();
|
|
|
|
using BuiltinFunction = std::function<ObjectPtr(const std::vector<ObjectPtr> &)>;
|
|
|
|
const std::unordered_map<String, int> &getBuiltinFunctionArgCounts();
|
|
const std::unordered_map<String, BuiltinFunction> &getBuiltinFunctions();
|
|
|
|
inline bool isBuiltinFunction(const String &name)
|
|
{
|
|
return getBuiltinFunctions().find(name) != getBuiltinFunctions().end();
|
|
}
|
|
|
|
inline BuiltinFunction getBuiltinFunction(const String &name)
|
|
{
|
|
auto it = getBuiltinFunctions().find(name);
|
|
if (it == getBuiltinFunctions().end())
|
|
{
|
|
throw RuntimeError(String(std::format("Builtin function '{}' not found", name.toBasicString())));
|
|
}
|
|
return it->second;
|
|
}
|
|
|
|
inline int getBuiltinFunctionParamCount(const String &name)
|
|
{
|
|
auto it = getBuiltinFunctionArgCounts().find(name);
|
|
if (it == getBuiltinFunctionArgCounts().end())
|
|
{
|
|
throw RuntimeError(String(std::format("Builtin function '{}' not found", name.toBasicString())));
|
|
}
|
|
return it->second;
|
|
}
|
|
}; // namespace Builtins
|
|
}; // namespace Fig.
|