summaryrefslogtreecommitdiffhomepage
path: root/lib/math.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/math.c')
-rw-r--r--lib/math.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/lib/math.c b/lib/math.c
index 8f8466e..c4a08e3 100644
--- a/lib/math.c
+++ b/lib/math.c
@@ -17,14 +17,14 @@
#include <math.h>
#include <sys/time.h>
-#include "../module.h"
+#include "ucode/module.h"
static bool srand_called = false;
static uc_value_t *
-uc_abs(uc_vm *vm, size_t nargs)
+uc_abs(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *v = uc_get_arg(0);
+ uc_value_t *v = uc_fn_arg(0);
uc_type_t t;
int64_t n;
double d;
@@ -32,7 +32,7 @@ uc_abs(uc_vm *vm, size_t nargs)
if (ucv_type(v) == UC_NULL)
return ucv_double_new(NAN);
- t = uc_to_number(v, &n, &d);
+ t = ucv_cast_number(v, &n, &d);
if (t == UC_DOUBLE)
return (isnan(d) || d < 0) ? ucv_double_new(-d) : ucv_get(v);
@@ -41,10 +41,10 @@ uc_abs(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_atan2(uc_vm *vm, size_t nargs)
+uc_atan2(uc_vm_t *vm, size_t nargs)
{
- double d1 = uc_to_double(uc_get_arg(0));
- double d2 = uc_to_double(uc_get_arg(1));
+ double d1 = ucv_to_double(uc_fn_arg(0));
+ double d2 = ucv_to_double(uc_fn_arg(1));
if (isnan(d1) || isnan(d2))
return ucv_double_new(NAN);
@@ -53,9 +53,9 @@ uc_atan2(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_cos(uc_vm *vm, size_t nargs)
+uc_cos(uc_vm_t *vm, size_t nargs)
{
- double d = uc_to_double(uc_get_arg(0));
+ double d = ucv_to_double(uc_fn_arg(0));
if (isnan(d))
return ucv_double_new(NAN);
@@ -64,9 +64,9 @@ uc_cos(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_exp(uc_vm *vm, size_t nargs)
+uc_exp(uc_vm_t *vm, size_t nargs)
{
- double d = uc_to_double(uc_get_arg(0));
+ double d = ucv_to_double(uc_fn_arg(0));
if (isnan(d))
return ucv_double_new(NAN);
@@ -75,9 +75,9 @@ uc_exp(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_log(uc_vm *vm, size_t nargs)
+uc_log(uc_vm_t *vm, size_t nargs)
{
- double d = uc_to_double(uc_get_arg(0));
+ double d = ucv_to_double(uc_fn_arg(0));
if (isnan(d))
return ucv_double_new(NAN);
@@ -86,9 +86,9 @@ uc_log(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_sin(uc_vm *vm, size_t nargs)
+uc_sin(uc_vm_t *vm, size_t nargs)
{
- double d = uc_to_double(uc_get_arg(0));
+ double d = ucv_to_double(uc_fn_arg(0));
if (isnan(d))
return ucv_double_new(NAN);
@@ -97,9 +97,9 @@ uc_sin(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_sqrt(uc_vm *vm, size_t nargs)
+uc_sqrt(uc_vm_t *vm, size_t nargs)
{
- double d = uc_to_double(uc_get_arg(0));
+ double d = ucv_to_double(uc_fn_arg(0));
if (isnan(d))
return ucv_double_new(NAN);
@@ -108,10 +108,10 @@ uc_sqrt(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_pow(uc_vm *vm, size_t nargs)
+uc_pow(uc_vm_t *vm, size_t nargs)
{
- double x = uc_to_double(uc_get_arg(0));
- double y = uc_to_double(uc_get_arg(1));
+ double x = ucv_to_double(uc_fn_arg(0));
+ double y = ucv_to_double(uc_fn_arg(1));
if (isnan(x) || isnan(y))
return ucv_double_new(NAN);
@@ -120,7 +120,7 @@ uc_pow(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_rand(uc_vm *vm, size_t nargs)
+uc_rand(uc_vm_t *vm, size_t nargs)
{
struct timeval tv;
@@ -135,9 +135,9 @@ uc_rand(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_srand(uc_vm *vm, size_t nargs)
+uc_srand(uc_vm_t *vm, size_t nargs)
{
- int64_t n = uc_to_int64(uc_get_arg(0));
+ int64_t n = ucv_to_integer(uc_fn_arg(0));
srand((unsigned int)n);
srand_called = true;
@@ -145,7 +145,7 @@ uc_srand(uc_vm *vm, size_t nargs)
return NULL;
}
-static const uc_cfunction_list math_fns[] = {
+static const uc_function_list_t math_fns[] = {
{ "abs", uc_abs },
{ "atan2", uc_atan2 },
{ "cos", uc_cos },
@@ -158,7 +158,7 @@ static const uc_cfunction_list math_fns[] = {
{ "srand", uc_srand },
};
-void uc_module_init(uc_value_t *scope)
+void uc_module_init(uc_vm_t *vm, uc_value_t *scope)
{
- uc_add_proto_functions(scope, math_fns);
+ uc_function_list_register(scope, math_fns);
}