|
|
@@ -46,14 +46,14 @@ inline CodeObject_ VM::compile(Str source, Str filename, CompileMode mode, bool
|
|
|
_vm->bind_method<1>("int", #name, [](VM* vm, ArgsView args){ \
|
|
|
if(is_int(args[1])) return VAR(_CAST(i64, args[0]) op _CAST(i64, args[1])); \
|
|
|
if(is_float(args[1])) return VAR(vm->num_to_float(args[0]) op _CAST(f64, args[1])); \
|
|
|
- if constexpr(is_eq) return VAR(args[0] op args[1]); \
|
|
|
+ if constexpr(is_eq) return VAR(args[0] op args[1]); \
|
|
|
vm->TypeError("unsupported operand type(s) for " #op ); \
|
|
|
return vm->None; \
|
|
|
}); \
|
|
|
_vm->bind_method<1>("float", #name, [](VM* vm, ArgsView args){ \
|
|
|
if(is_float(args[1])) return VAR(_CAST(f64, args[0]) op _CAST(f64, args[1])); \
|
|
|
if(is_int(args[1])) return VAR(_CAST(f64, args[0]) op _CAST(i64, args[1])); \
|
|
|
- if constexpr(is_eq) return VAR(args[0] op args[1]); \
|
|
|
+ if constexpr(is_eq) return VAR(args[0] op args[1]); \
|
|
|
vm->TypeError("unsupported operand type(s) for " #op ); \
|
|
|
return vm->None; \
|
|
|
});
|
|
|
@@ -228,13 +228,13 @@ inline void init_builtins(VM* _vm) {
|
|
|
_vm->bind_method<0>("NoneType", "__json__", CPP_LAMBDA(VAR("null")));
|
|
|
|
|
|
_vm->bind_method<1>("int", "__truediv__", [](VM* vm, ArgsView args) {
|
|
|
- f64 rhs = vm->num_to_float(args[1]);
|
|
|
+ f64 rhs = VAR_F(args[1]);
|
|
|
if (rhs == 0) vm->ZeroDivisionError();
|
|
|
return VAR(_CAST(i64, args[0]) / rhs);
|
|
|
});
|
|
|
|
|
|
_vm->bind_method<1>("float", "__truediv__", [](VM* vm, ArgsView args) {
|
|
|
- f64 rhs = vm->num_to_float(args[1]);
|
|
|
+ f64 rhs = VAR_F(args[1]);
|
|
|
if (rhs == 0) vm->ZeroDivisionError();
|
|
|
return VAR(_CAST(f64, args[0]) / rhs);
|
|
|
});
|
|
|
@@ -254,7 +254,7 @@ inline void init_builtins(VM* _vm) {
|
|
|
if(flag) return VAR((f64)(1.0 / ret));
|
|
|
return VAR(ret);
|
|
|
}else{
|
|
|
- return VAR((f64)std::pow(vm->num_to_float(args[0]), vm->num_to_float(args[1])));
|
|
|
+ return VAR((f64)std::pow(VAR_F(args[0]), VAR_F(args[1])));
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -799,7 +799,7 @@ inline void add_module_time(VM* vm){
|
|
|
});
|
|
|
|
|
|
vm->bind_func<1>(mod, "sleep", [](VM* vm, ArgsView args) {
|
|
|
- f64 seconds = FLOAT(args[0]);
|
|
|
+ f64 seconds = VAR_F(args[0]);
|
|
|
auto begin = std::chrono::high_resolution_clock::now();
|
|
|
while(true){
|
|
|
auto now = std::chrono::high_resolution_clock::now();
|
|
|
@@ -850,15 +850,15 @@ inline void add_module_math(VM* vm){
|
|
|
mod->attr().set("inf", VAR(std::numeric_limits<double>::infinity()));
|
|
|
mod->attr().set("nan", VAR(std::numeric_limits<double>::quiet_NaN()));
|
|
|
|
|
|
- vm->bind_func<1>(mod, "ceil", CPP_LAMBDA(VAR((i64)std::ceil(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "fabs", CPP_LAMBDA(VAR(std::fabs(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "floor", CPP_LAMBDA(VAR((i64)std::floor(vm->num_to_float(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "ceil", CPP_LAMBDA(VAR((i64)std::ceil(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "fabs", CPP_LAMBDA(VAR(std::fabs(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "floor", CPP_LAMBDA(VAR((i64)std::floor(VAR_F(args[0])))));
|
|
|
vm->bind_func<1>(mod, "fsum", [](VM* vm, ArgsView args) {
|
|
|
List& list = CAST(List&, args[0]);
|
|
|
double sum = 0;
|
|
|
double c = 0;
|
|
|
for(PyObject* arg : list){
|
|
|
- double x = vm->num_to_float(arg);
|
|
|
+ double x = VAR_F(arg);
|
|
|
double y = x - c;
|
|
|
double t = sum + y;
|
|
|
c = (t - sum) - y;
|
|
|
@@ -879,29 +879,29 @@ inline void add_module_math(VM* vm){
|
|
|
return VAR(a);
|
|
|
});
|
|
|
|
|
|
- vm->bind_func<1>(mod, "isfinite", CPP_LAMBDA(VAR(std::isfinite(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "isinf", CPP_LAMBDA(VAR(std::isinf(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "isnan", CPP_LAMBDA(VAR(std::isnan(vm->num_to_float(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "isfinite", CPP_LAMBDA(VAR(std::isfinite(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "isinf", CPP_LAMBDA(VAR(std::isinf(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "isnan", CPP_LAMBDA(VAR(std::isnan(VAR_F(args[0])))));
|
|
|
|
|
|
- vm->bind_func<1>(mod, "exp", CPP_LAMBDA(VAR(std::exp(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "log", CPP_LAMBDA(VAR(std::log(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "log2", CPP_LAMBDA(VAR(std::log2(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "log10", CPP_LAMBDA(VAR(std::log10(vm->num_to_float(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "exp", CPP_LAMBDA(VAR(std::exp(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "log", CPP_LAMBDA(VAR(std::log(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "log2", CPP_LAMBDA(VAR(std::log2(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "log10", CPP_LAMBDA(VAR(std::log10(VAR_F(args[0])))));
|
|
|
|
|
|
- vm->bind_func<2>(mod, "pow", CPP_LAMBDA(VAR(std::pow(vm->num_to_float(args[0]), vm->num_to_float(args[1])))));
|
|
|
- vm->bind_func<1>(mod, "sqrt", CPP_LAMBDA(VAR(std::sqrt(vm->num_to_float(args[0])))));
|
|
|
+ vm->bind_func<2>(mod, "pow", CPP_LAMBDA(VAR(std::pow(VAR_F(args[0]), VAR_F(args[1])))));
|
|
|
+ vm->bind_func<1>(mod, "sqrt", CPP_LAMBDA(VAR(std::sqrt(VAR_F(args[0])))));
|
|
|
|
|
|
- vm->bind_func<1>(mod, "acos", CPP_LAMBDA(VAR(std::acos(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "asin", CPP_LAMBDA(VAR(std::asin(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "atan", CPP_LAMBDA(VAR(std::atan(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<2>(mod, "atan2", CPP_LAMBDA(VAR(std::atan2(vm->num_to_float(args[0]), vm->num_to_float(args[1])))));
|
|
|
+ vm->bind_func<1>(mod, "acos", CPP_LAMBDA(VAR(std::acos(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "asin", CPP_LAMBDA(VAR(std::asin(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "atan", CPP_LAMBDA(VAR(std::atan(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<2>(mod, "atan2", CPP_LAMBDA(VAR(std::atan2(VAR_F(args[0]), VAR_F(args[1])))));
|
|
|
|
|
|
- vm->bind_func<1>(mod, "cos", CPP_LAMBDA(VAR(std::cos(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "sin", CPP_LAMBDA(VAR(std::sin(vm->num_to_float(args[0])))));
|
|
|
- vm->bind_func<1>(mod, "tan", CPP_LAMBDA(VAR(std::tan(vm->num_to_float(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "cos", CPP_LAMBDA(VAR(std::cos(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "sin", CPP_LAMBDA(VAR(std::sin(VAR_F(args[0])))));
|
|
|
+ vm->bind_func<1>(mod, "tan", CPP_LAMBDA(VAR(std::tan(VAR_F(args[0])))));
|
|
|
|
|
|
- vm->bind_func<1>(mod, "degrees", CPP_LAMBDA(VAR(vm->num_to_float(args[0]) * 180 / 3.1415926535897932384)));
|
|
|
- vm->bind_func<1>(mod, "radians", CPP_LAMBDA(VAR(vm->num_to_float(args[0]) * 3.1415926535897932384 / 180)));
|
|
|
+ vm->bind_func<1>(mod, "degrees", CPP_LAMBDA(VAR(VAR_F(args[0]) * 180 / 3.1415926535897932384)));
|
|
|
+ vm->bind_func<1>(mod, "radians", CPP_LAMBDA(VAR(VAR_F(args[0]) * 3.1415926535897932384 / 180)));
|
|
|
}
|
|
|
|
|
|
inline void add_module_dis(VM* vm){
|