diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-07-11 18:03:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-11 18:03:42 +0200 |
commit | e4871c661f0bfb979f1b235d7b6e59b70ed1aca6 (patch) | |
tree | 40542b06a966366e2e8a3a0118e756874a838ce6 /lib/math.c | |
parent | dad8f3aed4ca5f2f93e2be6f1243632439dec541 (diff) | |
parent | d5b25f942147b09511d77d5470cd38a1e1643fb9 (diff) |
Merge pull request #15 from jow-/c-api
C API wip
Diffstat (limited to 'lib/math.c')
-rw-r--r-- | lib/math.c | 52 |
1 files changed, 26 insertions, 26 deletions
@@ -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); } |