尝试UTF32String
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include <Ast/astBase.hpp>
|
||||
#include <Ast/functionParameters.hpp>
|
||||
#include <Evaluator/Context/context.hpp>
|
||||
#include <Core/fig_string.hpp>
|
||||
#include <Core/String.hpp>
|
||||
#include <Ast/AccessModifier.hpp>
|
||||
#include <Evaluator/Value/structType.hpp>
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
@@ -24,60 +24,60 @@ namespace Fig::Builtins
|
||||
{
|
||||
const TypeInfo &getErrorInterfaceTypeInfo()
|
||||
{
|
||||
static const TypeInfo ErrorInterfaceTypeInfo(u8"Error", true);
|
||||
static const TypeInfo ErrorInterfaceTypeInfo(U"Error", true);
|
||||
return ErrorInterfaceTypeInfo;
|
||||
}
|
||||
const TypeInfo &getTypeErrorStructTypeInfo()
|
||||
{
|
||||
static const TypeInfo TypeErrorStructTypeInfo(u8"TypeError", true);
|
||||
static const TypeInfo TypeErrorStructTypeInfo(U"TypeError", true);
|
||||
return TypeErrorStructTypeInfo;
|
||||
}
|
||||
const TypeInfo &getOperationInterfaceTypeInfo()
|
||||
{
|
||||
static const TypeInfo OperationInterfaceTypeInfo(u8"Operation", true);
|
||||
static const TypeInfo OperationInterfaceTypeInfo(U"Operation", true);
|
||||
return OperationInterfaceTypeInfo;
|
||||
}
|
||||
const std::unordered_map<FString, ObjectPtr> &getBuiltinValues()
|
||||
const std::unordered_map<String, ObjectPtr> &getBuiltinValues()
|
||||
{
|
||||
static const std::unordered_map<FString, ObjectPtr> builtinValues = {
|
||||
{u8"null", Object::getNullInstance()},
|
||||
{u8"true", Object::getTrueInstance()},
|
||||
{u8"false", Object::getFalseInstance()},
|
||||
{u8"Error",
|
||||
static const std::unordered_map<String, ObjectPtr> builtinValues = {
|
||||
{U"null", Object::getNullInstance()},
|
||||
{U"true", Object::getTrueInstance()},
|
||||
{U"false", Object::getFalseInstance()},
|
||||
{U"Error",
|
||||
std::make_shared<Object>(InterfaceType(getErrorInterfaceTypeInfo(),
|
||||
{Ast::InterfaceMethod(u8"toString",
|
||||
{Ast::InterfaceMethod(U"toString",
|
||||
Ast::FunctionParameters({}, {}),
|
||||
std::make_shared<Ast::VarExprAst>(u8"String"),
|
||||
std::make_shared<Ast::VarExprAst>(U"String"),
|
||||
nullptr),
|
||||
Ast::InterfaceMethod(u8"getErrorClass",
|
||||
Ast::InterfaceMethod(U"getErrorClass",
|
||||
Ast::FunctionParameters({}, {}),
|
||||
std::make_shared<Ast::VarExprAst>(u8"String"),
|
||||
std::make_shared<Ast::VarExprAst>(U"String"),
|
||||
nullptr),
|
||||
Ast::InterfaceMethod(u8"getErrorMessage",
|
||||
Ast::InterfaceMethod(U"getErrorMessage",
|
||||
Ast::FunctionParameters({}, {}),
|
||||
std::make_shared<Ast::VarExprAst>(u8"String"),
|
||||
std::make_shared<Ast::VarExprAst>(U"String"),
|
||||
nullptr)}))},
|
||||
{u8"TypeError", std::make_shared<Object>(StructType(
|
||||
{U"TypeError", std::make_shared<Object>(StructType(
|
||||
getTypeErrorStructTypeInfo(),
|
||||
std::make_shared<Context>(u8"<Built-in `TypeError`>"),
|
||||
{Field(AccessModifier::Public, u8"msg", ValueType::String, nullptr)}
|
||||
std::make_shared<Context>(U"<Built-in `TypeError`>"),
|
||||
{Field(AccessModifier::Public, U"msg", ValueType::String, nullptr)}
|
||||
))},
|
||||
{u8"Operation", std::make_shared<Object>(InterfaceType(getOperationInterfaceTypeInfo(), {}))},
|
||||
{U"Operation", std::make_shared<Object>(InterfaceType(getOperationInterfaceTypeInfo(), {}))},
|
||||
|
||||
{u8"Any", std::make_shared<Object>(StructType(ValueType::Any, nullptr, {}, true))},
|
||||
{u8"Int", std::make_shared<Object>(StructType(ValueType::Int, nullptr, {}, true))},
|
||||
{u8"Null", std::make_shared<Object>(StructType(ValueType::Null, nullptr, {}, true))},
|
||||
{u8"String", std::make_shared<Object>(StructType(ValueType::String, nullptr, {}, true))},
|
||||
{u8"Bool", std::make_shared<Object>(StructType(ValueType::Bool, nullptr, {}, true))},
|
||||
{u8"Double", std::make_shared<Object>(StructType(ValueType::Double, nullptr, {}, true))},
|
||||
{u8"Function", std::make_shared<Object>(StructType(ValueType::Function, nullptr, {}, true))},
|
||||
{u8"List", std::make_shared<Object>(StructType(ValueType::List, nullptr, {}, true))},
|
||||
{u8"Map", std::make_shared<Object>(StructType(ValueType::Map, nullptr, {}, true))},
|
||||
{U"Any", std::make_shared<Object>(StructType(ValueType::Any, nullptr, {}, true))},
|
||||
{U"Int", std::make_shared<Object>(StructType(ValueType::Int, nullptr, {}, true))},
|
||||
{U"Null", std::make_shared<Object>(StructType(ValueType::Null, nullptr, {}, true))},
|
||||
{U"String", std::make_shared<Object>(StructType(ValueType::String, nullptr, {}, true))},
|
||||
{U"Bool", std::make_shared<Object>(StructType(ValueType::Bool, nullptr, {}, true))},
|
||||
{U"Double", std::make_shared<Object>(StructType(ValueType::Double, nullptr, {}, true))},
|
||||
{U"Function", std::make_shared<Object>(StructType(ValueType::Function, nullptr, {}, true))},
|
||||
{U"List", std::make_shared<Object>(StructType(ValueType::List, nullptr, {}, true))},
|
||||
{U"Map", std::make_shared<Object>(StructType(ValueType::Map, nullptr, {}, true))},
|
||||
// Type `StructType` `StructInstance` `Module` `InterfaceType`
|
||||
// Not allowed to call constructor!
|
||||
|
||||
{u8"type", std::make_shared<Object>(Function(
|
||||
u8"type",
|
||||
{U"type", std::make_shared<Object>(Function(
|
||||
U"type",
|
||||
[](const std::vector<ObjectPtr> &_args) -> ObjectPtr
|
||||
{
|
||||
const ObjectPtr &arg = _args[0];
|
||||
@@ -88,86 +88,86 @@ namespace Fig::Builtins
|
||||
};
|
||||
return builtinValues;
|
||||
}
|
||||
const std::unordered_map<FString, int> &getBuiltinFunctionArgCounts()
|
||||
const std::unordered_map<String, int> &getBuiltinFunctionArgCounts()
|
||||
{
|
||||
static const std::unordered_map<FString, int> builtinFunctionArgCounts = {
|
||||
{u8"__fstdout_print", -1}, // variadic
|
||||
{u8"__fstdout_println", -1}, // variadic
|
||||
{u8"__fstdin_read", 0},
|
||||
{u8"__fstdin_readln", 0},
|
||||
{u8"__fvalue_type", 1},
|
||||
{u8"__fvalue_int_parse", 1},
|
||||
{u8"__fvalue_int_from", 1},
|
||||
{u8"__fvalue_double_parse", 1},
|
||||
{u8"__fvalue_double_from", 1},
|
||||
{u8"__fvalue_string_from", 1},
|
||||
{u8"__ftime_now_ns", 0},
|
||||
static const std::unordered_map<String, int> builtinFunctionArgCounts = {
|
||||
{U"__fstdout_print", -1}, // variadic
|
||||
{U"__fstdout_println", -1}, // variadic
|
||||
{U"__fstdin_read", 0},
|
||||
{U"__fstdin_readln", 0},
|
||||
{U"__fvalue_type", 1},
|
||||
{U"__fvalue_int_parse", 1},
|
||||
{U"__fvalue_int_from", 1},
|
||||
{U"__fvalue_double_parse", 1},
|
||||
{U"__fvalue_double_from", 1},
|
||||
{U"__fvalue_string_from", 1},
|
||||
{U"__ftime_now_ns", 0},
|
||||
/* math start */
|
||||
{u8"__fmath_acos", 1},
|
||||
{u8"__fmath_acosh", 1},
|
||||
{u8"__fmath_asin", 1},
|
||||
{u8"__fmath_asinh", 1},
|
||||
{u8"__fmath_atan", 1},
|
||||
{u8"__fmath_atan2", 2},
|
||||
{u8"__fmath_atanh", 1},
|
||||
{u8"__fmath_ceil", 1},
|
||||
{u8"__fmath_cos", 1},
|
||||
{u8"__fmath_cosh", 1},
|
||||
{u8"__fmath_exp", 1},
|
||||
{u8"__fmath_expm1", 1},
|
||||
{u8"__fmath_fabs", 1},
|
||||
{u8"__fmath_floor", 1},
|
||||
{u8"__fmath_fmod", 2},
|
||||
{u8"__fmath_frexp", 1},
|
||||
{u8"__fmath_gcd", 2},
|
||||
{u8"__fmath_hypot", 2},
|
||||
{u8"__fmath_isequal", 2},
|
||||
{u8"__fmath_log", 1},
|
||||
{u8"__fmath_log10", 1},
|
||||
{u8"__fmath_log1p", 1},
|
||||
{u8"__fmath_log2", 1},
|
||||
{u8"__fmath_sin", 1},
|
||||
{u8"__fmath_sinh", 1},
|
||||
{u8"__fmath_sqrt", 1},
|
||||
{u8"__fmath_tan", 1},
|
||||
{u8"__fmath_tanh", 1},
|
||||
{u8"__fmath_trunc", 1},
|
||||
{U"__fmath_acos", 1},
|
||||
{U"__fmath_acosh", 1},
|
||||
{U"__fmath_asin", 1},
|
||||
{U"__fmath_asinh", 1},
|
||||
{U"__fmath_atan", 1},
|
||||
{U"__fmath_atan2", 2},
|
||||
{U"__fmath_atanh", 1},
|
||||
{U"__fmath_ceil", 1},
|
||||
{U"__fmath_cos", 1},
|
||||
{U"__fmath_cosh", 1},
|
||||
{U"__fmath_exp", 1},
|
||||
{U"__fmath_expm1", 1},
|
||||
{U"__fmath_fabs", 1},
|
||||
{U"__fmath_floor", 1},
|
||||
{U"__fmath_fmod", 2},
|
||||
{U"__fmath_frexp", 1},
|
||||
{U"__fmath_gcd", 2},
|
||||
{U"__fmath_hypot", 2},
|
||||
{U"__fmath_isequal", 2},
|
||||
{U"__fmath_log", 1},
|
||||
{U"__fmath_log10", 1},
|
||||
{U"__fmath_log1p", 1},
|
||||
{U"__fmath_log2", 1},
|
||||
{U"__fmath_sin", 1},
|
||||
{U"__fmath_sinh", 1},
|
||||
{U"__fmath_sqrt", 1},
|
||||
{U"__fmath_tan", 1},
|
||||
{U"__fmath_tanh", 1},
|
||||
{U"__fmath_trunc", 1},
|
||||
};
|
||||
return builtinFunctionArgCounts;
|
||||
}
|
||||
const std::unordered_map<FString, BuiltinFunction> &getBuiltinFunctions()
|
||||
const std::unordered_map<String, BuiltinFunction> &getBuiltinFunctions()
|
||||
{
|
||||
static const std::unordered_map<FString, BuiltinFunction> builtinFunctions{
|
||||
{u8"__fstdout_print",
|
||||
static const std::unordered_map<String, BuiltinFunction> builtinFunctions{
|
||||
{U"__fstdout_print",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
for (auto arg : args) { std::print("{}", arg->toStringIO().toBasicString()); }
|
||||
return std::make_shared<Object>(ValueType::IntClass(args.size()));
|
||||
}},
|
||||
{u8"__fstdout_println",
|
||||
{U"__fstdout_println",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
for (auto arg : args) { std::print("{}", arg->toStringIO().toBasicString()); }
|
||||
std::print("\n");
|
||||
return std::make_shared<Object>(ValueType::IntClass(args.size()));
|
||||
}},
|
||||
{u8"__fstdin_read",
|
||||
{U"__fstdin_read",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
std::string input;
|
||||
std::cin >> input;
|
||||
return std::make_shared<Object>(FString::fromBasicString(input));
|
||||
return std::make_shared<Object>(String(input));
|
||||
}},
|
||||
{u8"__fstdin_readln",
|
||||
{U"__fstdin_readln",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
std::string line;
|
||||
std::getline(std::cin, line);
|
||||
return std::make_shared<Object>(FString::fromBasicString(line));
|
||||
return std::make_shared<Object>(String(line));
|
||||
}},
|
||||
{u8"__fvalue_type",
|
||||
{U"__fvalue_type",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
return std::make_shared<Object>(args[0]->getTypeInfo().toString());
|
||||
}},
|
||||
{u8"__fvalue_int_parse",
|
||||
{U"__fvalue_int_parse",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
FString str = args[0]->as<ValueType::StringClass>();
|
||||
String str = args[0]->as<ValueType::StringClass>();
|
||||
try
|
||||
{
|
||||
ValueType::IntClass val = std::stoi(str.toBasicString());
|
||||
@@ -175,10 +175,10 @@ namespace Fig::Builtins
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
throw RuntimeError(FString(std::format("Invalid int string for parsing", str.toBasicString())));
|
||||
throw RuntimeError(String(std::format("Invalid int string for parsing", str.toBasicString())));
|
||||
}
|
||||
}},
|
||||
{u8"__fvalue_int_from",
|
||||
{U"__fvalue_int_from",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
if (val->is<ValueType::DoubleClass>())
|
||||
@@ -193,13 +193,13 @@ namespace Fig::Builtins
|
||||
}
|
||||
else
|
||||
{
|
||||
throw RuntimeError(FString(std::format("Type '{}' cannot be converted to int",
|
||||
throw RuntimeError(String(std::format("Type '{}' cannot be converted to int",
|
||||
val->getTypeInfo().toString().toBasicString())));
|
||||
}
|
||||
}},
|
||||
{u8"__fvalue_double_parse",
|
||||
{U"__fvalue_double_parse",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
FString str = args[0]->as<ValueType::StringClass>();
|
||||
String str = args[0]->as<ValueType::StringClass>();
|
||||
try
|
||||
{
|
||||
ValueType::DoubleClass val = std::stod(str.toBasicString());
|
||||
@@ -207,10 +207,10 @@ namespace Fig::Builtins
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
throw RuntimeError(FString(std::format("Invalid double string for parsing", str.toBasicString())));
|
||||
throw RuntimeError(String(std::format("Invalid double string for parsing", str.toBasicString())));
|
||||
}
|
||||
}},
|
||||
{u8"__fvalue_double_from",
|
||||
{U"__fvalue_double_from",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
if (val->is<ValueType::IntClass>())
|
||||
@@ -225,16 +225,16 @@ namespace Fig::Builtins
|
||||
}
|
||||
else
|
||||
{
|
||||
throw RuntimeError(FString(std::format("Type '{}' cannot be converted to double",
|
||||
throw RuntimeError(String(std::format("Type '{}' cannot be converted to double",
|
||||
val->getTypeInfo().toString().toBasicString())));
|
||||
}
|
||||
}},
|
||||
{u8"__fvalue_string_from",
|
||||
{U"__fvalue_string_from",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
return std::make_shared<Object>(val->toStringIO());
|
||||
}},
|
||||
{u8"__ftime_now_ns",
|
||||
{U"__ftime_now_ns",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
// returns nanoseconds
|
||||
using namespace Fig::Time;
|
||||
@@ -244,97 +244,97 @@ namespace Fig::Builtins
|
||||
}},
|
||||
|
||||
/* math start */
|
||||
{u8"__fmath_acos",
|
||||
{U"__fmath_acos",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(acos(d));
|
||||
}},
|
||||
{u8"__fmath_acosh",
|
||||
{U"__fmath_acosh",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(acosh(d));
|
||||
}},
|
||||
{u8"__fmath_asin",
|
||||
{U"__fmath_asin",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(asin(d));
|
||||
}},
|
||||
{u8"__fmath_asinh",
|
||||
{U"__fmath_asinh",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(asinh(d));
|
||||
}},
|
||||
{u8"__fmath_atan",
|
||||
{U"__fmath_atan",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(atan(d));
|
||||
}},
|
||||
{u8"__fmath_atan2",
|
||||
{U"__fmath_atan2",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ValueType::DoubleClass y = args[0]->getNumericValue();
|
||||
ValueType::DoubleClass x = args[1]->getNumericValue();
|
||||
return std::make_shared<Object>(atan2(y, x));
|
||||
}},
|
||||
{u8"__fmath_atanh",
|
||||
{U"__fmath_atanh",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(atanh(d));
|
||||
}},
|
||||
{u8"__fmath_ceil",
|
||||
{U"__fmath_ceil",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(ceil(d));
|
||||
}},
|
||||
{u8"__fmath_cos",
|
||||
{U"__fmath_cos",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(cos(d));
|
||||
}},
|
||||
{u8"__fmath_cosh",
|
||||
{U"__fmath_cosh",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(cosh(d));
|
||||
}},
|
||||
{u8"__fmath_exp",
|
||||
{U"__fmath_exp",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(exp(d));
|
||||
}},
|
||||
{u8"__fmath_expm1",
|
||||
{U"__fmath_expm1",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(expm1(d));
|
||||
}},
|
||||
{u8"__fmath_fabs",
|
||||
{U"__fmath_fabs",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(fabs(d));
|
||||
}},
|
||||
{u8"__fmath_floor",
|
||||
{U"__fmath_floor",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(floor(d));
|
||||
}},
|
||||
{u8"__fmath_fmod",
|
||||
{U"__fmath_fmod",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ValueType::DoubleClass x = args[0]->getNumericValue();
|
||||
ValueType::DoubleClass y = args[1]->getNumericValue();
|
||||
return std::make_shared<Object>(fmod(x, y));
|
||||
}},
|
||||
{u8"__fmath_frexp",
|
||||
{U"__fmath_frexp",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
@@ -342,80 +342,80 @@ namespace Fig::Builtins
|
||||
return std::make_shared<Object>(List({std::make_shared<Object>(frexp(d, &e)),
|
||||
std::make_shared<Object>(static_cast<ValueType::IntClass>(e))}));
|
||||
}},
|
||||
{u8"__fmath_gcd",
|
||||
{U"__fmath_gcd",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ValueType::IntClass x = args[0]->as<ValueType::IntClass>();
|
||||
ValueType::IntClass y = args[1]->as<ValueType::IntClass>();
|
||||
return std::make_shared<Object>(std::gcd(x, y));
|
||||
}},
|
||||
{u8"__fmath_hypot",
|
||||
{U"__fmath_hypot",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ValueType::DoubleClass x = args[0]->getNumericValue();
|
||||
ValueType::DoubleClass y = args[1]->getNumericValue();
|
||||
return std::make_shared<Object>(hypot(x, y));
|
||||
}},
|
||||
{u8"__fmath_isequal",
|
||||
{U"__fmath_isequal",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ValueType::DoubleClass x = args[0]->getNumericValue();
|
||||
ValueType::DoubleClass y = args[1]->getNumericValue();
|
||||
static const double epsilon = 1e-9;
|
||||
return std::make_shared<Object>(fabs(x - y) < epsilon);
|
||||
}},
|
||||
{u8"__fmath_log",
|
||||
{U"__fmath_log",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(log(d));
|
||||
}},
|
||||
{u8"__fmath_log10",
|
||||
{U"__fmath_log10",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(log10(d));
|
||||
}},
|
||||
{u8"__fmath_log1p",
|
||||
{U"__fmath_log1p",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(log1p(d));
|
||||
}},
|
||||
{u8"__fmath_log2",
|
||||
{U"__fmath_log2",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(log2(d));
|
||||
}},
|
||||
{u8"__fmath_sin",
|
||||
{U"__fmath_sin",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(sin(d));
|
||||
}},
|
||||
{u8"__fmath_sinh",
|
||||
{U"__fmath_sinh",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(sinh(d));
|
||||
}},
|
||||
{u8"__fmath_sqrt",
|
||||
{U"__fmath_sqrt",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(sqrt(d));
|
||||
}},
|
||||
{u8"__fmath_tan",
|
||||
{U"__fmath_tan",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(tan(d));
|
||||
}},
|
||||
{u8"__fmath_tanh",
|
||||
{U"__fmath_tanh",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
return std::make_shared<Object>(tanh(d));
|
||||
}},
|
||||
{u8"__fmath_trunc",
|
||||
{U"__fmath_trunc",
|
||||
[](const std::vector<ObjectPtr> &args) -> ObjectPtr {
|
||||
ObjectPtr val = args[0];
|
||||
ValueType::DoubleClass d = val->getNumericValue();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <Ast/Expressions/VarExpr.hpp>
|
||||
|
||||
#include <Ast/functionParameters.hpp>
|
||||
#include <Core/fig_string.hpp>
|
||||
#include <Core/String.hpp>
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
#include <Core/runtimeTime.hpp>
|
||||
|
||||
@@ -34,39 +34,39 @@ namespace Fig
|
||||
{
|
||||
add(..., ...) -> ...;
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
const TypeInfo &getOperationInterfaceTypeInfo();
|
||||
|
||||
const std::unordered_map<FString, ObjectPtr> &getBuiltinValues();
|
||||
const std::unordered_map<String, ObjectPtr> &getBuiltinValues();
|
||||
|
||||
using BuiltinFunction = std::function<ObjectPtr(const std::vector<ObjectPtr> &)>;
|
||||
|
||||
const std::unordered_map<FString, int> &getBuiltinFunctionArgCounts();
|
||||
const std::unordered_map<FString, BuiltinFunction> &getBuiltinFunctions();
|
||||
const std::unordered_map<String, int> &getBuiltinFunctionArgCounts();
|
||||
const std::unordered_map<String, BuiltinFunction> &getBuiltinFunctions();
|
||||
|
||||
inline bool isBuiltinFunction(const FString &name)
|
||||
inline bool isBuiltinFunction(const String &name)
|
||||
{
|
||||
return getBuiltinFunctions().find(name) != getBuiltinFunctions().end();
|
||||
}
|
||||
|
||||
inline BuiltinFunction getBuiltinFunction(const FString &name)
|
||||
inline BuiltinFunction getBuiltinFunction(const String &name)
|
||||
{
|
||||
auto it = getBuiltinFunctions().find(name);
|
||||
if (it == getBuiltinFunctions().end())
|
||||
{
|
||||
throw RuntimeError(FString(std::format("Builtin function '{}' not found", name.toBasicString())));
|
||||
throw RuntimeError(String(std::format("Builtin function '{}' not found", name.toBasicString())));
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
inline int getBuiltinFunctionParamCount(const FString &name)
|
||||
inline int getBuiltinFunctionParamCount(const String &name)
|
||||
{
|
||||
auto it = getBuiltinFunctionArgCounts().find(name);
|
||||
if (it == getBuiltinFunctionArgCounts().end())
|
||||
{
|
||||
throw RuntimeError(FString(std::format("Builtin function '{}' not found", name.toBasicString())));
|
||||
throw RuntimeError(String(std::format("Builtin function '{}' not found", name.toBasicString())));
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user