diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-07-11 07:18:37 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-07-11 15:49:14 +0200 |
commit | d5b25f942147b09511d77d5470cd38a1e1643fb9 (patch) | |
tree | 40542b06a966366e2e8a3a0118e756874a838ce6 | |
parent | cc4ce8dfd13e833702c949e56049443cd01c0dfb (diff) |
treewide: harmonize function naming
- Ensure that most functions follow the subject_verb naming schema
- Move type related function from value.c to types.c
- Rename value.c to vallist.c
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | compiler.c | 6 | ||||
-rw-r--r-- | examples/exception-handler.c | 2 | ||||
-rw-r--r-- | examples/execute-file.c | 2 | ||||
-rw-r--r-- | examples/execute-string.c | 2 | ||||
-rw-r--r-- | examples/native-function.c | 12 | ||||
-rw-r--r-- | examples/state-reset.c | 2 | ||||
-rw-r--r-- | examples/state-reuse.c | 2 | ||||
-rw-r--r-- | include/ucode/chunk.h | 2 | ||||
-rw-r--r-- | include/ucode/lexer.h | 2 | ||||
-rw-r--r-- | include/ucode/lib.h | 70 | ||||
-rw-r--r-- | include/ucode/types.h | 33 | ||||
-rw-r--r-- | include/ucode/vallist.h (renamed from include/ucode/value.h) | 9 | ||||
-rw-r--r-- | lexer.c | 2 | ||||
-rw-r--r-- | lib.c | 198 | ||||
-rw-r--r-- | lib/fs.c | 102 | ||||
-rw-r--r-- | lib/math.c | 28 | ||||
-rw-r--r-- | lib/ubus.c | 28 | ||||
-rw-r--r-- | lib/uci.c | 108 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | types.c | 294 | ||||
-rw-r--r-- | vallist.c (renamed from value.c) | 285 | ||||
-rw-r--r-- | vm.c | 44 |
23 files changed, 618 insertions, 619 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c77ecec..7f8171d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ IF(JSONC_FOUND) INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS}) ENDIF() -SET(UCODE_SOURCES lexer.c lib.c vm.c chunk.c value.c compiler.c source.c types.c) +SET(UCODE_SOURCES lexer.c lib.c vm.c chunk.c vallist.c compiler.c source.c types.c) ADD_LIBRARY(libucode SHARED ${UCODE_SOURCES}) SET(SOVERSION 0 CACHE STRING "Override ucode library version") SET_TARGET_PROPERTIES(libucode PROPERTIES OUTPUT_NAME ucode SOVERSION ${SOVERSION}) @@ -20,7 +20,7 @@ #include "ucode/chunk.h" #include "ucode/vm.h" /* I_* */ #include "ucode/source.h" -#include "ucode/lib.h" /* format_error_context() */ +#include "ucode/lib.h" /* uc_error_context_format() */ static void uc_compiler_compile_unary(uc_compiler_t *compiler, bool assignable); static void uc_compiler_compile_binary(uc_compiler_t *compiler, bool assignable); @@ -181,7 +181,7 @@ uc_compiler_syntax_error(uc_compiler_t *compiler, size_t off, const char *fmt, . if (line) ucv_stringbuf_printf(buf, "In line %zu, byte %zu:\n", line, byte); - if (format_error_context(buf, uc_compiler_current_source(compiler), NULL, off)) + if (uc_error_context_format(buf, uc_compiler_current_source(compiler), NULL, off)) ucv_stringbuf_append(buf, "\n\n"); } @@ -229,7 +229,7 @@ uc_compiler_parse_consume(uc_compiler_t *compiler, uc_tokentype_t type) } uc_compiler_syntax_error(compiler, compiler->parser->curr.pos, - "Unexpected token\nExpecting %s", uc_get_tokenname(type)); + "Unexpected token\nExpecting %s", uc_tokenname(type)); } static bool diff --git a/examples/exception-handler.c b/examples/exception-handler.c index e2b1058..1e722ec 100644 --- a/examples/exception-handler.c +++ b/examples/exception-handler.c @@ -79,7 +79,7 @@ int main(int argc, char **argv) uc_vm_init(&vm, &config); /* load standard library into global VM scope */ - uc_load_stdlib(uc_vm_scope_get(&vm)); + uc_stdlib_load(uc_vm_scope_get(&vm)); /* register custom exception handler */ uc_vm_exception_handler_set(&vm, log_exception); diff --git a/examples/execute-file.c b/examples/execute-file.c index 2e86f7d..12910e3 100644 --- a/examples/execute-file.c +++ b/examples/execute-file.c @@ -66,7 +66,7 @@ int main(int argc, char **argv) uc_vm_init(&vm, &config); /* load standard library into global VM scope */ - uc_load_stdlib(uc_vm_scope_get(&vm)); + uc_stdlib_load(uc_vm_scope_get(&vm)); /* add global variables x and y to VM scope */ ucv_object_add(uc_vm_scope_get(&vm), "x", ucv_int64_new(123)); diff --git a/examples/execute-string.c b/examples/execute-string.c index c51a600..1fcc966 100644 --- a/examples/execute-string.c +++ b/examples/execute-string.c @@ -76,7 +76,7 @@ int main(int argc, char **argv) uc_vm_init(&vm, &config); /* load standard library into global VM scope */ - uc_load_stdlib(uc_vm_scope_get(&vm)); + uc_stdlib_load(uc_vm_scope_get(&vm)); /* add global variables x and y to VM scope */ ucv_object_add(uc_vm_scope_get(&vm), "x", ucv_int64_new(123)); diff --git a/examples/native-function.c b/examples/native-function.c index 89b3d15..9c643ec 100644 --- a/examples/native-function.c +++ b/examples/native-function.c @@ -39,8 +39,8 @@ static uc_parse_config_t config = { static uc_value_t * multiply_two_numbers(uc_vm_t *vm, size_t nargs) { - uc_value_t *x = uc_get_arg(0); - uc_value_t *y = uc_get_arg(1); + uc_value_t *x = uc_fn_arg(0); + uc_value_t *y = uc_fn_arg(1); return ucv_double_new(ucv_to_double(x) * ucv_to_double(y)); } @@ -51,7 +51,7 @@ add_all_numbers(uc_vm_t *vm, size_t nargs) double res = 0.0; for (size_t n = 0; n < nargs; n++) - res += ucv_to_double(uc_get_arg(n)); + res += ucv_to_double(uc_fn_arg(n)); return ucv_double_new(res); } @@ -82,11 +82,11 @@ int main(int argc, char **argv) uc_vm_init(&vm, &config); /* load standard library into global VM scope */ - uc_load_stdlib(uc_vm_scope_get(&vm)); + uc_stdlib_load(uc_vm_scope_get(&vm)); /* register our native functions as "add" and "multiply" */ - uc_add_function(uc_vm_scope_get(&vm), "add", add_all_numbers); - uc_add_function(uc_vm_scope_get(&vm), "multiply", multiply_two_numbers); + uc_function_register(uc_vm_scope_get(&vm), "add", add_all_numbers); + uc_function_register(uc_vm_scope_get(&vm), "multiply", multiply_two_numbers); /* execute program function */ int return_code = uc_vm_execute(&vm, progfunc, NULL); diff --git a/examples/state-reset.c b/examples/state-reset.c index 893ea26..692aa76 100644 --- a/examples/state-reset.c +++ b/examples/state-reset.c @@ -66,7 +66,7 @@ int main(int argc, char **argv) uc_vm_init(&vm, &config); /* load standard library into global VM scope */ - uc_load_stdlib(uc_vm_scope_get(&vm)); + uc_stdlib_load(uc_vm_scope_get(&vm)); printf("Iteration %d: ", i + 1); diff --git a/examples/state-reuse.c b/examples/state-reuse.c index 4ebf556..7e2c44f 100644 --- a/examples/state-reuse.c +++ b/examples/state-reuse.c @@ -65,7 +65,7 @@ int main(int argc, char **argv) uc_vm_init(&vm, &config); /* load standard library into global VM scope */ - uc_load_stdlib(uc_vm_scope_get(&vm)); + uc_stdlib_load(uc_vm_scope_get(&vm)); /* execute compiled program function five times */ for (int i = 0; i < 5; i++) { diff --git a/include/ucode/chunk.h b/include/ucode/chunk.h index 458af1f..0005e3c 100644 --- a/include/ucode/chunk.h +++ b/include/ucode/chunk.h @@ -20,7 +20,7 @@ #include <stdint.h> #include <stddef.h> -#include "value.h" +#include "vallist.h" #include "util.h" #include "types.h" diff --git a/include/ucode/lexer.h b/include/ucode/lexer.h index 1b19b60..ee8a0a5 100644 --- a/include/ucode/lexer.h +++ b/include/ucode/lexer.h @@ -170,6 +170,6 @@ uc_token_t *uc_lexer_next_token(uc_lexer_t *lex); bool utf8enc(char **out, int *rem, int code); const char * -uc_get_tokenname(unsigned type); +uc_tokenname(unsigned type); #endif /* __LEXER_H_ */ diff --git a/include/ucode/lib.h b/include/ucode/lib.h index 7eeae9f..1f30cba 100644 --- a/include/ucode/lib.h +++ b/include/ucode/lib.h @@ -20,31 +20,32 @@ #include "vm.h" #include "lexer.h" + typedef struct { const char *name; uc_cfn_ptr_t func; -} uc_cfunction_list_t; +} uc_function_list_t; -extern const uc_cfunction_list_t uc_stdlib_functions[]; +extern const uc_function_list_t uc_stdlib_functions[]; -void uc_load_stdlib(uc_value_t *scope); +void uc_stdlib_load(uc_value_t *scope); -bool format_source_context(uc_stringbuf_t *buf, uc_source_t *src, size_t off, bool compact); -bool format_error_context(uc_stringbuf_t *buf, uc_source_t *src, uc_value_t *stacktrace, size_t off); +bool uc_source_context_format(uc_stringbuf_t *buf, uc_source_t *src, size_t off, bool compact); +bool uc_error_context_format(uc_stringbuf_t *buf, uc_source_t *src, uc_value_t *stacktrace, size_t off); /* vm helper */ static inline void * -_uc_get_self(uc_vm_t *vm, const char *expected_type) +_uc_fn_this(uc_vm_t *vm, const char *expected_type) { return ucv_ressource_dataptr(vm->callframes.entries[vm->callframes.count - 1].ctx, expected_type); } -#define uc_get_self(...) _uc_get_self(vm, __VA_ARGS__) +#define uc_fn_this(...) _uc_fn_this(vm, __VA_ARGS__) static inline uc_value_t * -_uc_get_arg(uc_vm_t *vm, size_t nargs, size_t n) +_uc_fn_arg(uc_vm_t *vm, size_t nargs, size_t n) { if (n >= nargs) return NULL; @@ -52,50 +53,23 @@ _uc_get_arg(uc_vm_t *vm, size_t nargs, size_t n) return uc_vm_stack_peek(vm, nargs - n - 1); } -#define uc_get_arg(...) _uc_get_arg(vm, nargs, __VA_ARGS__) +#define uc_fn_arg(...) _uc_fn_arg(vm, nargs, __VA_ARGS__) #define uc_call(nargs) uc_vm_call(vm, false, nargs) -#define uc_push_val(val) uc_vm_stack_push(vm, val) -#define uc_pop_val() uc_vm_stack_pop(vm) +#define uc_value_push(val) uc_vm_stack_push(vm, val) +#define uc_value_pop() uc_vm_stack_pop(vm) -/* value helper */ +/* ressource type helper */ static inline uc_value_t * -uc_alloc_ressource(uc_ressource_type_t *type, void *data) +uc_ressource_new(uc_ressource_type_t *type, void *data) { return ucv_ressource_new(type, data); } -static inline uc_type_t -uc_to_number(uc_value_t *v, int64_t *n, double *d) -{ - return uc_cast_number(v, n, d); -} - -static inline double -uc_to_double(uc_value_t *v) -{ - int64_t n; - double d; - - return (uc_cast_number(v, &n, &d) == UC_DOUBLE) ? d : (double)n; -} - -static inline int64_t -uc_to_int64(uc_value_t *v) -{ - int64_t n; - double d; - - return (uc_cast_number(v, &n, &d) == UC_DOUBLE) ? (int64_t)d : n; -} - - -/* ressource type helper */ - static inline uc_ressource_type_t * -_uc_declare_type(uc_vm_t *vm, const char *name, const uc_cfunction_list_t *list, size_t len, void (*freefn)(void *)) +_uc_type_declare(uc_vm_t *vm, const char *name, const uc_function_list_t *list, size_t len, void (*freefn)(void *)) { uc_value_t *proto = ucv_object_new(NULL); @@ -106,27 +80,27 @@ _uc_declare_type(uc_vm_t *vm, const char *name, const uc_cfunction_list_t *list, return ucv_ressource_type_add(vm, name, proto, freefn); } -#define uc_declare_type(vm, name, functions, freefn) \ - _uc_declare_type(vm, name, functions, ARRAY_SIZE(functions), freefn) +#define uc_type_declare(vm, name, functions, freefn) \ + _uc_type_declare(vm, name, functions, ARRAY_SIZE(functions), freefn) /* function helper */ -#define uc_add_function(object, name, function) \ +#define uc_function_register(object, name, function) \ ucv_object_add(object, name, ucv_cfunction_new(name, function)) static inline bool -_uc_add_functions(uc_value_t *object, const uc_cfunction_list_t *list, size_t len) +_uc_function_list_register(uc_value_t *object, const uc_function_list_t *list, size_t len) { bool rv = true; while (len-- > 0) - rv &= uc_add_function(object, list[len].name, list[len].func); + rv &= uc_function_register(object, list[len].name, list[len].func); return rv; } -#define uc_add_functions(object, functions) \ - _uc_add_functions(object, functions, ARRAY_SIZE(functions)) +#define uc_function_list_register(object, functions) \ + _uc_function_list_register(object, functions, ARRAY_SIZE(functions)) #endif /* __LIB_H_ */ diff --git a/include/ucode/types.h b/include/ucode/types.h index da19f9b..7473f22 100644 --- a/include/ucode/types.h +++ b/include/ucode/types.h @@ -369,6 +369,27 @@ void ucv_to_stringbuf_formatted(uc_vm_t *, uc_stringbuf_t *, uc_value_t *, size_ #define ucv_to_jsonstring(vm, val) ucv_to_jsonstring_formatted(vm, val, '\1', 0) #define ucv_to_stringbuf(vm, buf, val, json) ucv_to_stringbuf_formatted(vm, buf, val, 0, json ? '\1' : '\0', 0) +uc_type_t ucv_cast_number(uc_value_t *, int64_t *, double *); + +static inline double +ucv_to_double(uc_value_t *v) +{ + int64_t n; + double d; + + return (ucv_cast_number(v, &n, &d) == UC_DOUBLE) ? d : (double)n; +} + +static inline int64_t +ucv_to_integer(uc_value_t *v) +{ + int64_t n; + double d; + + return (ucv_cast_number(v, &n, &d) == UC_DOUBLE) ? (int64_t)d : n; +} + + static inline bool ucv_is_callable(uc_value_t *uv) { @@ -412,6 +433,16 @@ ucv_is_scalar(uc_value_t *uv) } } +bool ucv_is_equal(uc_value_t *, uc_value_t *); +bool ucv_is_truish(uc_value_t *); + +bool ucv_compare(int, uc_value_t *, uc_value_t *); + +uc_value_t *ucv_key_get(uc_vm_t *, uc_value_t *, uc_value_t *); +uc_value_t *ucv_key_set(uc_vm_t *, uc_value_t *, uc_value_t *, uc_value_t *); +bool ucv_key_delete(uc_vm_t *, uc_value_t *, uc_value_t *); + + static inline bool ucv_is_marked(uc_value_t *uv) { @@ -432,8 +463,6 @@ ucv_clear_mark(uc_value_t *uv) uv->mark = false; } -bool ucv_equal(uc_value_t *, uc_value_t *); - void ucv_gc(uc_vm_t *); void ucv_freeall(uc_vm_t *); diff --git a/include/ucode/value.h b/include/ucode/vallist.h index 04d37a9..a3d94e8 100644 --- a/include/ucode/value.h +++ b/include/ucode/vallist.h @@ -41,15 +41,6 @@ typedef enum { TAG_PTR = 6 } uc_value_type_t; -bool uc_cmp(int how, uc_value_t *v1, uc_value_t *v2); -bool uc_val_is_truish(uc_value_t *val); - -uc_type_t uc_cast_number(uc_value_t *v, int64_t *n, double *d); - -uc_value_t *uc_getval(uc_vm_t *, uc_value_t *scope, uc_value_t *key); -uc_value_t *uc_setval(uc_vm_t *, uc_value_t *scope, uc_value_t *key, uc_value_t *val); -bool uc_delval(uc_vm_t *, uc_value_t *scope, uc_value_t *key); - void uc_vallist_init(uc_value_list_t *list); void uc_vallist_free(uc_value_list_t *list); @@ -1236,7 +1236,7 @@ uc_lexer_next_token(uc_lexer_t *lex) } const char * -uc_get_tokenname(unsigned type) +uc_tokenname(unsigned type) { static char buf[sizeof("'endfunction'")]; size_t i; @@ -109,7 +109,7 @@ source_filename(uc_source_t *src, uint32_t line) } bool -format_source_context(uc_stringbuf_t *buf, uc_source_t *src, size_t off, bool compact) +uc_source_context_format(uc_stringbuf_t *buf, uc_source_t *src, size_t off, bool compact) { size_t len, rlen; bool truncated; @@ -155,7 +155,7 @@ format_source_context(uc_stringbuf_t *buf, uc_source_t *src, size_t off, bool co } bool -format_error_context(uc_stringbuf_t *buf, uc_source_t *src, uc_value_t *stacktrace, size_t off) +uc_error_context_format(uc_stringbuf_t *buf, uc_source_t *src, uc_value_t *stacktrace, size_t off) { uc_value_t *e, *fn, *file, *line, *byte; const char *path; @@ -201,7 +201,7 @@ format_error_context(uc_stringbuf_t *buf, uc_source_t *src, uc_value_t *stacktra } } - return format_source_context(buf, src, off, false); + return uc_source_context_format(buf, src, off, false); } static char *uc_cast_string(uc_vm_t *vm, uc_value_t **v, bool *freeable) { @@ -223,7 +223,7 @@ uc_cast_double(uc_value_t *v) int64_t n; double d; - t = uc_cast_number(v, &n, &d); + t = ucv_cast_number(v, &n, &d); errno = 0; if (t == UC_DOUBLE) { @@ -245,7 +245,7 @@ uc_cast_int64(uc_value_t *v) int64_t n; double d; - t = uc_cast_number(v, &n, &d); + t = ucv_cast_number(v, &n, &d); errno = 0; if (t == UC_DOUBLE) { @@ -283,7 +283,7 @@ uc_print_common(uc_vm_t *vm, size_t nargs, FILE *fh) char *p; for (arridx = 0; arridx < nargs; arridx++) { - item = uc_get_arg(arridx); + item = uc_fn_arg(arridx); if (ucv_type(item) == UC_STRING) { len = ucv_string_length(item); @@ -310,7 +310,7 @@ uc_print(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_length(uc_vm_t *vm, size_t nargs) { - uc_value_t *arg = uc_get_arg(0); + uc_value_t *arg = uc_fn_arg(0); switch (ucv_type(arg)) { case UC_OBJECT: @@ -330,8 +330,8 @@ uc_length(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_index(uc_vm_t *vm, size_t nargs, bool right) { - uc_value_t *stack = uc_get_arg(0); - uc_value_t *needle = uc_get_arg(1); + uc_value_t *stack = uc_fn_arg(0); + uc_value_t *needle = uc_fn_arg(1); const char *sstr, *nstr, *p; size_t arridx, len; ssize_t ret = -1; @@ -339,7 +339,7 @@ uc_index(uc_vm_t *vm, size_t nargs, bool right) switch (ucv_type(stack)) { case UC_ARRAY: for (arridx = 0, len = ucv_array_length(stack); arridx < len; arridx++) { - if (uc_cmp(I_EQ, ucv_array_get(stack, arridx), needle)) { + if (ucv_compare(I_EQ, ucv_array_get(stack, arridx), needle)) { ret = (ssize_t)arridx; if (!right) @@ -385,7 +385,7 @@ uc_rindex(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_push(uc_vm_t *vm, size_t nargs) { - uc_value_t *arr = uc_get_arg(0); + uc_value_t *arr = uc_fn_arg(0); uc_value_t *item = NULL; size_t arridx; @@ -393,7 +393,7 @@ uc_push(uc_vm_t *vm, size_t nargs) return NULL; for (arridx = 1; arridx < nargs; arridx++) { - item = uc_get_arg(arridx); + item = uc_fn_arg(arridx); ucv_array_push(arr, ucv_get(item)); } @@ -403,7 +403,7 @@ uc_push(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_pop(uc_vm_t *vm, size_t nargs) { - uc_value_t *arr = uc_get_arg(0); + uc_value_t *arr = uc_fn_arg(0); return ucv_array_pop(arr); } @@ -411,7 +411,7 @@ uc_pop(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_shift(uc_vm_t *vm, size_t nargs) { - uc_value_t *arr = uc_get_arg(0); + uc_value_t *arr = uc_fn_arg(0); return ucv_array_shift(arr); } @@ -419,7 +419,7 @@ uc_shift(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_unshift(uc_vm_t *vm, size_t nargs) { - uc_value_t *arr = uc_get_arg(0); + uc_value_t *arr = uc_fn_arg(0); uc_value_t *item = NULL; size_t i; @@ -427,7 +427,7 @@ uc_unshift(uc_vm_t *vm, size_t nargs) return NULL; for (i = 1; i < nargs; i++) { - item = uc_get_arg(i); + item = uc_fn_arg(i); ucv_array_unshift(arr, ucv_get(item)); } @@ -448,7 +448,7 @@ uc_chr(uc_vm_t *vm, size_t nargs) str = xalloc(nargs); for (idx = 0; idx < nargs; idx++) { - n = uc_cast_int64(uc_get_arg(idx)); + n = uc_cast_int64(uc_fn_arg(idx)); if (n < 0) n = 0; @@ -467,7 +467,7 @@ uc_chr(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_die(uc_vm_t *vm, size_t nargs) { - uc_value_t *msg = uc_get_arg(0); + uc_value_t *msg = uc_fn_arg(0); bool freeable = false; char *s; @@ -484,8 +484,8 @@ uc_die(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_exists(uc_vm_t *vm, size_t nargs) { - uc_value_t *obj = uc_get_arg(0); - uc_value_t *key = uc_get_arg(1); + uc_value_t *obj = uc_fn_arg(0); + uc_value_t *key = uc_fn_arg(1); bool found, freeable; char *k; @@ -505,7 +505,7 @@ uc_exists(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_exit(uc_vm_t *vm, size_t nargs) { - int64_t n = uc_cast_int64(uc_get_arg(0)); + int64_t n = uc_cast_int64(uc_fn_arg(0)); vm->arg.s32 = (int32_t)n; uc_vm_raise_exception(vm, EXCEPTION_EXIT, "Terminated"); @@ -516,7 +516,7 @@ uc_exit(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_getenv(uc_vm_t *vm, size_t nargs) { - uc_value_t *key = uc_get_arg(0); + uc_value_t *key = uc_fn_arg(0); char *k = ucv_string_get(key); char *val = k ? getenv(k) : NULL; @@ -526,8 +526,8 @@ uc_getenv(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_filter(uc_vm_t *vm, size_t nargs) { - uc_value_t *obj = uc_get_arg(0); - uc_value_t *func = uc_get_arg(1); + uc_value_t *obj = uc_fn_arg(0); + uc_value_t *func = uc_fn_arg(1); uc_value_t *rv, *arr; size_t arridx, arrlen; @@ -551,7 +551,7 @@ uc_filter(uc_vm_t *vm, size_t nargs) rv = uc_vm_stack_pop(vm); - if (uc_val_is_truish(rv)) + if (ucv_is_truish(rv)) ucv_array_push(arr, ucv_get(ucv_array_get(obj, arridx))); ucv_put(rv); @@ -563,7 +563,7 @@ uc_filter(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_hex(uc_vm_t *vm, size_t nargs) { - uc_value_t *val = uc_get_arg(0); + uc_value_t *val = uc_fn_arg(0); char *e, *v; int64_t n; @@ -583,7 +583,7 @@ uc_hex(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_int(uc_vm_t *vm, size_t nargs) { - int64_t n = uc_cast_int64(uc_get_arg(0)); + int64_t n = uc_cast_int64(uc_fn_arg(0)); if (errno == EINVAL || errno == EOVERFLOW) return ucv_double_new(NAN); @@ -594,8 +594,8 @@ uc_int(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_join(uc_vm_t *vm, size_t nargs) { - uc_value_t *sep = uc_get_arg(0); - uc_value_t *arr = uc_get_arg(1); + uc_value_t *sep = uc_fn_arg(0); + uc_value_t *arr = uc_fn_arg(1); size_t arrlen, arridx; uc_stringbuf_t *buf; @@ -617,7 +617,7 @@ uc_join(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_keys(uc_vm_t *vm, size_t nargs) { - uc_value_t *obj = uc_get_arg(0); + uc_value_t *obj = uc_fn_arg(0); uc_value_t *arr = NULL; if (ucv_type(obj) != UC_OBJECT) @@ -636,7 +636,7 @@ uc_keys(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_lc(uc_vm_t *vm, size_t nargs) { - char *str = ucv_to_string(vm, uc_get_arg(0)); + char *str = ucv_to_string(vm, uc_fn_arg(0)); uc_value_t *rv = NULL; char *p; @@ -657,8 +657,8 @@ uc_lc(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_map(uc_vm_t *vm, size_t nargs) { - uc_value_t *obj = uc_get_arg(0); - uc_value_t *func = uc_get_arg(1); + uc_value_t *obj = uc_fn_arg(0); + uc_value_t *func = uc_fn_arg(1); uc_value_t *arr, *rv; size_t arridx, arrlen; @@ -691,7 +691,7 @@ uc_map(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_ord(uc_vm_t *vm, size_t nargs) { - uc_value_t *obj = uc_get_arg(0); + uc_value_t *obj = uc_fn_arg(0); uc_value_t *rv, *pos; const char *str; size_t i, len; @@ -709,7 +709,7 @@ uc_ord(uc_vm_t *vm, size_t nargs) rv = ucv_array_new(vm); for (i = 1; i < nargs; i++) { - pos = uc_get_arg(i); + pos = uc_fn_arg(i); if (ucv_type(pos) == UC_INTEGER) { n = ucv_int64_get(pos); @@ -732,7 +732,7 @@ uc_ord(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_type(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 = ucv_type(v); switch (t) { @@ -758,7 +758,7 @@ uc_type(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_reverse(uc_vm_t *vm, size_t nargs) { - uc_value_t *obj = uc_get_arg(0); + uc_value_t *obj = uc_fn_arg(0); uc_value_t *rv = NULL; size_t len, arridx; const char *str; @@ -804,8 +804,8 @@ default_cmp(uc_value_t *v1, uc_value_t *v2) if (ucv_type(v1) == UC_INTEGER || ucv_type(v1) == UC_DOUBLE || ucv_type(v2) == UC_INTEGER || ucv_type(v2) == UC_DOUBLE) { - t1 = uc_cast_number(v1, &n1, &d1); - t2 = uc_cast_number(v2, &n2, &d2); + t1 = ucv_cast_number(v1, &n1, &d1); + t2 = ucv_cast_number(v2, &n2, &d2); if (t1 == UC_DOUBLE || t2 == UC_DOUBLE) { d1 = (t1 == UC_DOUBLE) ? d1 : (double)n1; @@ -868,7 +868,7 @@ sort_fn(const void *k1, const void *k2) } rv = uc_vm_stack_pop(sort_ctx.vm); - t = uc_cast_number(rv, &n, &d); + t = ucv_cast_number(rv, &n, &d); if (t == UC_DOUBLE) { if (d < 0) @@ -893,8 +893,8 @@ sort_fn(const void *k1, const void *k2) static uc_value_t * uc_sort(uc_vm_t *vm, size_t nargs) { - uc_value_t *arr = uc_get_arg(0); - uc_value_t *fn = uc_get_arg(1); + uc_value_t *arr = uc_fn_arg(0); + uc_value_t *fn = uc_fn_arg(1); if (ucv_type(arr) != UC_ARRAY) return NULL; @@ -910,9 +910,9 @@ uc_sort(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_splice(uc_vm_t *vm, size_t nargs) { - uc_value_t *arr = uc_get_arg(0); - int64_t ofs = uc_cast_int64(uc_get_arg(1)); - int64_t remlen = uc_cast_int64(uc_get_arg(2)); + uc_value_t *arr = uc_fn_arg(0); + int64_t ofs = uc_cast_int64(uc_fn_arg(1)); + int64_t remlen = uc_cast_int64(uc_fn_arg(2)); size_t arrlen, addlen, idx; if (ucv_type(arr) != UC_ARRAY) @@ -975,7 +975,7 @@ uc_splice(uc_vm_t *vm, size_t nargs) for (idx = 0; idx < addlen; idx++) ucv_array_set(arr, ofs + idx, - ucv_get(uc_get_arg(3 + idx))); + ucv_get(uc_fn_arg(3 + idx))); return ucv_get(arr); } @@ -983,8 +983,8 @@ uc_splice(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_split(uc_vm_t *vm, size_t nargs) { - uc_value_t *str = uc_get_arg(0); - uc_value_t *sep = uc_get_arg(1); + uc_value_t *str = uc_fn_arg(0); + uc_value_t *sep = uc_fn_arg(1); uc_value_t *arr = NULL; const char *p, *sepstr, *splitstr; int eflags = 0, res; @@ -1042,9 +1042,9 @@ uc_split(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_substr(uc_vm_t *vm, size_t nargs) { - uc_value_t *str = uc_get_arg(0); - int64_t ofs = uc_cast_int64(uc_get_arg(1)); - int64_t sublen = uc_cast_int64(uc_get_arg(2)); + uc_value_t *str = uc_fn_arg(0); + int64_t ofs = uc_cast_int64(uc_fn_arg(1)); + int64_t sublen = uc_cast_int64(uc_fn_arg(2)); const char *p; size_t len; @@ -1114,7 +1114,7 @@ uc_time(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uc(uc_vm_t *vm, size_t nargs) { - char *str = ucv_to_string(vm, uc_get_arg(0)); + char *str = ucv_to_string(vm, uc_fn_arg(0)); uc_value_t *rv = NULL; char *p; @@ -1142,7 +1142,7 @@ uc_uchr(uc_vm_t *vm, size_t nargs) int rem; for (idx = 0, ulen = 0; idx < nargs; idx++) { - n = uc_cast_int64(uc_get_arg(idx)); + n = uc_cast_int64(uc_fn_arg(idx)); if (errno == EINVAL || errno == EOVERFLOW || n < 0 || n > 0x10FFFF) ulen += 3; @@ -1159,7 +1159,7 @@ uc_uchr(uc_vm_t *vm, size_t nargs) str = xalloc(ulen); for (idx = 0, p = str, rem = ulen; idx < nargs; idx++) { - n = uc_cast_int64(uc_get_arg(idx)); + n = uc_cast_int64(uc_fn_arg(idx)); if (errno == EINVAL || errno == EOVERFLOW || n < 0 || n > 0x10FFFF) n = 0xFFFD; @@ -1178,7 +1178,7 @@ uc_uchr(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_values(uc_vm_t *vm, size_t nargs) { - uc_value_t *obj = uc_get_arg(0); + uc_value_t *obj = uc_fn_arg(0); uc_value_t *arr; if (ucv_type(obj) != UC_OBJECT) @@ -1197,8 +1197,8 @@ uc_values(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_trim_common(uc_vm_t *vm, size_t nargs, bool start, bool end) { - uc_value_t *str = uc_get_arg(0); - uc_value_t *chr = uc_get_arg(1); + uc_value_t *str = uc_fn_arg(0); + uc_value_t *chr = uc_fn_arg(1); const char *p, *c; size_t len; @@ -1255,7 +1255,7 @@ uc_rtrim(uc_vm_t *vm, size_t nargs) static void uc_printf_common(uc_vm_t *vm, size_t nargs, uc_stringbuf_t *buf) { - uc_value_t *fmt = uc_get_arg(0); + uc_value_t *fmt = uc_fn_arg(0); char *fp, sfmt[sizeof("%0- 123456789.123456789%")]; union { char *s; int64_t n; double d; } arg; const char *fstr, *last, *p; @@ -1345,7 +1345,7 @@ uc_printf_common(uc_vm_t *vm, size_t nargs, uc_stringbuf_t *buf) t = UC_INTEGER; if (argidx < nargs) - arg.n = uc_cast_int64(uc_get_arg(argidx++)); + arg.n = uc_cast_int64(uc_fn_arg(argidx++)); else arg.n = 0; @@ -1360,7 +1360,7 @@ uc_printf_common(uc_vm_t *vm, size_t nargs, uc_stringbuf_t *buf) t = UC_DOUBLE; if (argidx < nargs) - arg.d = uc_cast_double(uc_get_arg(argidx++)); + arg.d = uc_cast_double(uc_fn_arg(argidx++)); else arg.d = 0; @@ -1370,7 +1370,7 @@ uc_printf_common(uc_vm_t *vm, size_t nargs, uc_stringbuf_t *buf) t = UC_INTEGER; if (argidx < nargs) - arg.n = uc_cast_int64(uc_get_arg(argidx++)) & 0xff; + arg.n = uc_cast_int64(uc_fn_arg(argidx++)) & 0xff; else arg.n = 0; @@ -1380,7 +1380,7 @@ uc_printf_common(uc_vm_t *vm, size_t nargs, uc_stringbuf_t *buf) t = UC_STRING; if (argidx < nargs) - arg.s = ucv_to_string(vm, uc_get_arg(argidx++)); + arg.s = ucv_to_string(vm, uc_fn_arg(argidx++)); else arg.s = NULL; @@ -1403,7 +1403,7 @@ uc_printf_common(uc_vm_t *vm, size_t nargs, uc_stringbuf_t *buf) if (argidx < nargs) { arg.s = ucv_to_jsonstring_formatted(vm, - uc_get_arg(argidx++), + uc_fn_arg(argidx++), pad_size > 0 ? (pad_size > 1 ? ' ' : '\t') : '\0', pad_size > 0 ? (pad_size > 1 ? pad_size - 1 : 1) : 0); } @@ -1643,7 +1643,7 @@ out: static uc_value_t * uc_require(uc_vm_t *vm, size_t nargs) { - uc_value_t *val = uc_get_arg(0); + uc_value_t *val = uc_fn_arg(0); uc_value_t *search, *se, *res; size_t arridx, arrlen; const char *name; @@ -1680,7 +1680,7 @@ uc_require(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_iptoarr(uc_vm_t *vm, size_t nargs) { - uc_value_t *ip = uc_get_arg(0); + uc_value_t *ip = uc_fn_arg(0); uc_value_t *res; union { uint8_t u8[4]; @@ -1733,7 +1733,7 @@ check_byte(uc_value_t *v) static uc_value_t * uc_arrtoip(uc_vm_t *vm, size_t nargs) { - uc_value_t *arr = uc_get_arg(0); + uc_value_t *arr = uc_fn_arg(0); union { uint8_t u8[4]; struct in6_addr in6; @@ -1781,8 +1781,8 @@ uc_arrtoip(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_match(uc_vm_t *vm, size_t nargs) { - uc_value_t *subject = uc_get_arg(0); - uc_value_t *pattern = uc_get_arg(1); + uc_value_t *subject = uc_fn_arg(0); + uc_value_t *pattern = uc_fn_arg(1); uc_value_t *rv = NULL, *m; regmatch_t pmatch[10]; int eflags = 0, res; @@ -1939,9 +1939,9 @@ static uc_value_t * uc_replace(uc_vm_t *vm, size_t nargs) { char *sb = NULL, *pt = NULL, *p, *l; - uc_value_t *subject = uc_get_arg(0); - uc_value_t *pattern = uc_get_arg(1); - uc_value_t *replace = uc_get_arg(2); + uc_value_t *subject = uc_fn_arg(0); + uc_value_t *pattern = uc_fn_arg(1); + uc_value_t *replace = uc_fn_arg(2); bool sb_freeable, pt_freeable; uc_value_t *rv = NULL; uc_stringbuf_t *resbuf; @@ -2040,7 +2040,7 @@ uc_replace(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_json(uc_vm_t *vm, size_t nargs) { - uc_value_t *rv, *src = uc_get_arg(0); + uc_value_t *rv, *src = uc_fn_arg(0); struct json_tokener *tok = NULL; enum json_tokener_error err; json_object *jso; @@ -2132,8 +2132,8 @@ include_path(const char *curpath, const char *incpath) static uc_value_t * uc_include(uc_vm_t *vm, size_t nargs) { - uc_value_t *path = uc_get_arg(0); - uc_value_t *scope = uc_get_arg(1); + uc_value_t *path = uc_fn_arg(0); + uc_value_t *scope = uc_fn_arg(1); uc_value_t *rv = NULL, *sc = NULL; uc_closure_t *closure = NULL; size_t i; @@ -2253,8 +2253,8 @@ uc_warn(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_system(uc_vm_t *vm, size_t nargs) { - uc_value_t *cmdline = uc_get_arg(0); - uc_value_t *timeout = uc_get_arg(1); + uc_value_t *cmdline = uc_fn_arg(0); + uc_value_t *timeout = uc_fn_arg(1); const char **arglist, *fn; sigset_t sigmask, sigomask; struct timespec ts; @@ -2393,7 +2393,7 @@ fail: static uc_value_t * uc_trace(uc_vm_t *vm, size_t nargs) { - uc_value_t *level = uc_get_arg(0); + uc_value_t *level = uc_fn_arg(0); uint8_t prev_level; if (ucv_type(level) != UC_INTEGER) { @@ -2411,13 +2411,13 @@ uc_trace(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_proto(uc_vm_t *vm, size_t nargs) { - uc_value_t *val = uc_get_arg(0); + uc_value_t *val = uc_fn_arg(0); uc_value_t *proto = NULL; if (nargs < 2) return ucv_get(ucv_prototype_get(val)); - proto = uc_get_arg(1); + proto = uc_fn_arg(1); if (!ucv_prototype_set(val, proto)) uc_vm_raise_exception(vm, EXCEPTION_TYPE, "Passed value is neither a prototype, ressource or object"); @@ -2430,7 +2430,7 @@ uc_proto(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_sleep(uc_vm_t *vm, size_t nargs) { - uc_value_t *duration = uc_get_arg(0); + uc_value_t *duration = uc_fn_arg(0); struct timeval tv; int64_t ms; @@ -2450,12 +2450,12 @@ uc_sleep(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_assert(uc_vm_t *vm, size_t nargs) { - uc_value_t *cond = uc_get_arg(0); - uc_value_t *msg = uc_get_arg(1); + uc_value_t *cond = uc_fn_arg(0); + uc_value_t *msg = uc_fn_arg(1); bool freeable = false; char *s; - if (!uc_val_is_truish(cond)) { + if (!ucv_is_truish(cond)) { s = msg ? uc_cast_string(vm, &msg, &freeable) : "Assertion failed"; uc_vm_raise_exception(vm, EXCEPTION_USER, "%s", s); @@ -2473,8 +2473,8 @@ static uc_value_t * uc_regexp(uc_vm_t *vm, size_t nargs) { bool icase = false, newline = false, global = false, freeable; - uc_value_t *source = uc_get_arg(0); - uc_value_t *flags = uc_get_arg(1); + uc_value_t *source = uc_fn_arg(0); + uc_value_t *flags = uc_fn_arg(1); uc_value_t *regex = NULL; char *p, *err = NULL; @@ -2527,9 +2527,9 @@ uc_regexp(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_wildcard(uc_vm_t *vm, size_t nargs) { - uc_value_t *subject = uc_get_arg(0); - uc_value_t *pattern = uc_get_arg(1); - uc_value_t *icase = uc_get_arg(2); + uc_value_t *subject = uc_fn_arg(0); + uc_value_t *pattern = uc_fn_arg(1); + uc_value_t *icase = uc_fn_arg(2); int flags = 0, rv; bool freeable; char *s; @@ -2537,7 +2537,7 @@ uc_wildcard(uc_vm_t *vm, size_t nargs) if (!subject || ucv_type(pattern) != UC_STRING) return NULL; - if (uc_val_is_truish(icase)) + if (ucv_is_truish(icase)) flags |= FNM_CASEFOLD; s = uc_cast_string(vm, &subject, &freeable); @@ -2552,8 +2552,8 @@ uc_wildcard(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_sourcepath(uc_vm_t *vm, size_t nargs) { - uc_value_t *calldepth = uc_get_arg(0); - uc_value_t *dironly = uc_get_arg(1); + uc_value_t *calldepth = uc_fn_arg(0); + uc_value_t *dironly = uc_fn_arg(1); uc_value_t *rv = NULL; uc_callframe_t *frame; char *path = NULL; @@ -2581,7 +2581,7 @@ uc_sourcepath(uc_vm_t *vm, size_t nargs) } if (path) { - if (uc_val_is_truish(dironly)) + if (ucv_is_truish(dironly)) rv = ucv_string_new(dirname(path)); else rv = ucv_string_new(path); @@ -2600,9 +2600,9 @@ uc_min_max(uc_vm_t *vm, size_t nargs, int cmp) size_t i; for (i = 0; i < nargs; i++) { - val = uc_get_arg(i); + val = uc_fn_arg(i); - if (!set || uc_cmp(cmp, val, rv)) { + if (!set || ucv_compare(cmp, val, rv)) { set = true; rv = val; } @@ -2704,7 +2704,7 @@ static uc_value_t * uc_b64dec(uc_vm_t *vm, size_t nargs) { enum { BYTE1, BYTE2, BYTE3, BYTE4 } state; - uc_value_t *str = uc_get_arg(0); + uc_value_t *str = uc_fn_arg(0); uc_stringbuf_t *buf; const char *src; unsigned int ch; @@ -2836,7 +2836,7 @@ static const char Base64[] = static uc_value_t * uc_b64enc(uc_vm_t *vm, size_t nargs) { - uc_value_t *str = uc_get_arg(0); + uc_value_t *str = uc_fn_arg(0); unsigned char input[3] = {0}; uc_stringbuf_t *buf; const char *src; @@ -2887,7 +2887,7 @@ uc_b64enc(uc_vm_t *vm, size_t nargs) */ -const uc_cfunction_list_t uc_stdlib_functions[] = { +const uc_function_list_t uc_stdlib_functions[] = { { "chr", uc_chr }, { "die", uc_die }, { "exists", uc_exists }, @@ -2949,7 +2949,7 @@ const uc_cfunction_list_t uc_stdlib_functions[] = { void -uc_load_stdlib(uc_value_t *scope) +uc_stdlib_load(uc_value_t *scope) { - uc_add_functions(scope, uc_stdlib_functions); + uc_function_list_register(scope, uc_stdlib_functions); } @@ -52,14 +52,14 @@ uc_fs_error(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_read_common(uc_vm_t *vm, size_t nargs, const char *type) { - uc_value_t *limit = uc_get_arg(0); + uc_value_t *limit = uc_fn_arg(0); uc_value_t *rv = NULL; char buf[128], *p = NULL, *tmp; size_t rlen, len = 0; const char *lstr; int64_t lsize; - FILE **fp = uc_get_self(type); + FILE **fp = uc_fn_this(type); if (!fp || !*fp) err_return(EBADF); @@ -144,11 +144,11 @@ uc_fs_read_common(uc_vm_t *vm, size_t nargs, const char *type) static uc_value_t * uc_fs_write_common(uc_vm_t *vm, size_t nargs, const char *type) { - uc_value_t *data = uc_get_arg(0); + uc_value_t *data = uc_fn_arg(0); size_t len, wsize; char *str; - FILE **fp = uc_get_self(type); + FILE **fp = uc_fn_this(type); if (!fp || !*fp) err_return(EBADF); @@ -174,7 +174,7 @@ uc_fs_write_common(uc_vm_t *vm, size_t nargs, const char *type) static uc_value_t * uc_fs_pclose(uc_vm_t *vm, size_t nargs) { - FILE **fp = uc_get_self("fs.proc"); + FILE **fp = uc_fn_this("fs.proc"); int rc; if (!fp || !*fp) @@ -210,8 +210,8 @@ uc_fs_pwrite(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_popen(uc_vm_t *vm, size_t nargs) { - uc_value_t *comm = uc_get_arg(0); - uc_value_t *mode = uc_get_arg(1); + uc_value_t *comm = uc_fn_arg(0); + uc_value_t *mode = uc_fn_arg(1); FILE *fp; if (ucv_type(comm) != UC_STRING) @@ -223,14 +223,14 @@ uc_fs_popen(uc_vm_t *vm, size_t nargs) if (!fp) err_return(errno); - return uc_alloc_ressource(proc_type, fp); + return uc_ressource_new(proc_type, fp); } static uc_value_t * uc_fs_close(uc_vm_t *vm, size_t nargs) { - FILE **fp = uc_get_self("fs.file"); + FILE **fp = uc_fn_this("fs.file"); if (!fp || !*fp) err_return(EBADF); @@ -256,12 +256,12 @@ uc_fs_write(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_seek(uc_vm_t *vm, size_t nargs) { - uc_value_t *ofs = uc_get_arg(0); - uc_value_t *how = uc_get_arg(1); + uc_value_t *ofs = uc_fn_arg(0); + uc_value_t *how = uc_fn_arg(1); int whence, res; long offset; - FILE **fp = uc_get_self("fs.file"); + FILE **fp = uc_fn_this("fs.file"); if (!fp || !*fp) err_return(EBADF); @@ -293,7 +293,7 @@ uc_fs_tell(uc_vm_t *vm, size_t nargs) { long offset; - FILE **fp = uc_get_self("fs.file"); + FILE **fp = uc_fn_this("fs.file"); if (!fp || !*fp) err_return(EBADF); @@ -309,8 +309,8 @@ uc_fs_tell(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_open(uc_vm_t *vm, size_t nargs) { - uc_value_t *path = uc_get_arg(0); - uc_value_t *mode = uc_get_arg(1); + uc_value_t *path = uc_fn_arg(0); + uc_value_t *mode = uc_fn_arg(1); FILE *fp; if (ucv_type(path) != UC_STRING) @@ -322,14 +322,14 @@ uc_fs_open(uc_vm_t *vm, size_t nargs) if (!fp) err_return(errno); - return uc_alloc_ressource(file_type, fp); + return uc_ressource_new(file_type, fp); } static uc_value_t * uc_fs_readdir(uc_vm_t *vm, size_t nargs) { - DIR **dp = uc_get_self("fs.dir"); + DIR **dp = uc_fn_this("fs.dir"); struct dirent *e; if (!dp || !*dp) @@ -347,7 +347,7 @@ uc_fs_readdir(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_telldir(uc_vm_t *vm, size_t nargs) { - DIR **dp = uc_get_self("fs.dir"); + DIR **dp = uc_fn_this("fs.dir"); long position; if (!dp || !*dp) @@ -364,8 +364,8 @@ uc_fs_telldir(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_seekdir(uc_vm_t *vm, size_t nargs) { - uc_value_t *ofs = uc_get_arg(0); - DIR **dp = uc_get_self("fs.dir"); + uc_value_t *ofs = uc_fn_arg(0); + DIR **dp = uc_fn_this("fs.dir"); long position; if (ucv_type(ofs) != UC_INTEGER) @@ -384,7 +384,7 @@ uc_fs_seekdir(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_closedir(uc_vm_t *vm, size_t nargs) { - DIR **dp = uc_get_self("fs.dir"); + DIR **dp = uc_fn_this("fs.dir"); if (!dp || !*dp) err_return(EBADF); @@ -398,7 +398,7 @@ uc_fs_closedir(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_opendir(uc_vm_t *vm, size_t nargs) { - uc_value_t *path = uc_get_arg(0); + uc_value_t *path = uc_fn_arg(0); DIR *dp; if (ucv_type(path) != UC_STRING) @@ -409,13 +409,13 @@ uc_fs_opendir(uc_vm_t *vm, size_t nargs) if (!dp) err_return(errno); - return uc_alloc_ressource(dir_type, dp); + return uc_ressource_new(dir_type, dp); } static uc_value_t * uc_fs_readlink(uc_vm_t *vm, size_t nargs) { - uc_value_t *path = uc_get_arg(0); + uc_value_t *path = uc_fn_arg(0); uc_value_t *res; ssize_t buflen = 0, rv; char *buf = NULL, *tmp; @@ -455,7 +455,7 @@ uc_fs_readlink(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_stat_common(uc_vm_t *vm, size_t nargs, bool use_lstat) { - uc_value_t *path = uc_get_arg(0); + uc_value_t *path = uc_fn_arg(0); uc_value_t *res, *o; struct stat st; int rv; @@ -551,8 +551,8 @@ uc_fs_lstat(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_mkdir(uc_vm_t *vm, size_t nargs) { - uc_value_t *path = uc_get_arg(0); - uc_value_t *mode = uc_get_arg(1); + uc_value_t *path = uc_fn_arg(0); + uc_value_t *mode = uc_fn_arg(1); if (ucv_type(path) != UC_STRING || (mode && ucv_type(mode) != UC_INTEGER)) @@ -567,7 +567,7 @@ uc_fs_mkdir(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_rmdir(uc_vm_t *vm, size_t nargs) { - uc_value_t *path = uc_get_arg(0); + uc_value_t *path = uc_fn_arg(0); if (ucv_type(path) != UC_STRING) err_return(EINVAL); @@ -581,8 +581,8 @@ uc_fs_rmdir(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_symlink(uc_vm_t *vm, size_t nargs) { - uc_value_t *dest = uc_get_arg(0); - uc_value_t *path = uc_get_arg(1); + uc_value_t *dest = uc_fn_arg(0); + uc_value_t *path = uc_fn_arg(1); if (ucv_type(dest) != UC_STRING || ucv_type(path) != UC_STRING) @@ -597,7 +597,7 @@ uc_fs_symlink(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_unlink(uc_vm_t *vm, size_t nargs) { - uc_value_t *path = uc_get_arg(0); + uc_value_t *path = uc_fn_arg(0); if (ucv_type(path) != UC_STRING) err_return(EINVAL); @@ -647,7 +647,7 @@ uc_fs_getcwd(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_chdir(uc_vm_t *vm, size_t nargs) { - uc_value_t *path = uc_get_arg(0); + uc_value_t *path = uc_fn_arg(0); if (ucv_type(path) != UC_STRING) err_return(EINVAL); @@ -661,8 +661,8 @@ uc_fs_chdir(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_chmod(uc_vm_t *vm, size_t nargs) { - uc_value_t *path = uc_get_arg(0); - uc_value_t *mode = uc_get_arg(1); + uc_value_t *path = uc_fn_arg(0); + uc_value_t *mode = uc_fn_arg(1); if (ucv_type(path) != UC_STRING || ucv_type(mode) != UC_INTEGER) @@ -771,9 +771,9 @@ uc_fs_resolve_group(uc_value_t *v, gid_t *gid) static uc_value_t * uc_fs_chown(uc_vm_t *vm, size_t nargs) { - uc_value_t *path = uc_get_arg(0); - uc_value_t *user = uc_get_arg(1); - uc_value_t *group = uc_get_arg(2); + uc_value_t *path = uc_fn_arg(0); + uc_value_t *user = uc_fn_arg(1); + uc_value_t *group = uc_fn_arg(2); uid_t uid; gid_t gid; @@ -793,8 +793,8 @@ uc_fs_chown(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_fs_rename(uc_vm_t *vm, size_t nargs) { - uc_value_t *oldpath = uc_get_arg(0); - uc_value_t *newpath = uc_get_arg(1); + uc_value_t *oldpath = uc_fn_arg(0); + uc_value_t *newpath = uc_fn_arg(1); if (ucv_type(oldpath) != UC_STRING || ucv_type(newpath) != UC_STRING) @@ -814,7 +814,7 @@ uc_fs_glob(uc_vm_t *vm, size_t nargs) size_t i; for (i = 0; i < nargs; i++) { - pat = uc_get_arg(i); + pat = uc_fn_arg(i); if (ucv_type(pat) != UC_STRING) { globfree(&gl); @@ -835,14 +835,14 @@ uc_fs_glob(uc_vm_t *vm, size_t nargs) } -static const uc_cfunction_list_t proc_fns[] = { +static const uc_function_list_t proc_fns[] = { { "read", uc_fs_pread }, { "write", uc_fs_pwrite }, { "close", uc_fs_pclose }, { "error", uc_fs_error }, }; -static const uc_cfunction_list_t file_fns[] = { +static const uc_function_list_t file_fns[] = { { "read", uc_fs_read }, { "write", uc_fs_write }, { "seek", uc_fs_seek }, @@ -851,7 +851,7 @@ static const uc_cfunction_list_t file_fns[] = { { "error", uc_fs_error }, }; -static const uc_cfunction_list_t dir_fns[] = { +static const uc_function_list_t dir_fns[] = { { "read", uc_fs_readdir }, { "seek", uc_fs_seekdir }, { "tell", uc_fs_telldir }, @@ -859,7 +859,7 @@ static const uc_cfunction_list_t dir_fns[] = { { "error", uc_fs_error }, }; -static const uc_cfunction_list_t global_fns[] = { +static const uc_function_list_t global_fns[] = { { "error", uc_fs_error }, { "open", uc_fs_open }, { "opendir", uc_fs_opendir }, @@ -906,13 +906,13 @@ static void close_dir(void *ud) void uc_module_init(uc_vm_t *vm, uc_value_t *scope) { - uc_add_functions(scope, global_fns); + uc_function_list_register(scope, global_fns); - proc_type = uc_declare_type(vm, "fs.proc", proc_fns, close_proc); - file_type = uc_declare_type(vm, "fs.file", file_fns, close_file); - dir_type = uc_declare_type(vm, "fs.dir", dir_fns, close_dir); + proc_type = uc_type_declare(vm, "fs.proc", proc_fns, close_proc); + file_type = uc_type_declare(vm, "fs.file", file_fns, close_file); + dir_type = uc_type_declare(vm, "fs.dir", dir_fns, close_dir); - ucv_object_add(scope, "stdin", uc_alloc_ressource(file_type, stdin)); - ucv_object_add(scope, "stdout", uc_alloc_ressource(file_type, stdout)); - ucv_object_add(scope, "stderr", uc_alloc_ressource(file_type, stderr)); + ucv_object_add(scope, "stdin", uc_ressource_new(file_type, stdin)); + ucv_object_add(scope, "stdout", uc_ressource_new(file_type, stdout)); + ucv_object_add(scope, "stderr", uc_ressource_new(file_type, stderr)); } @@ -24,7 +24,7 @@ static bool srand_called = false; static uc_value_t * 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_t *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); @@ -43,8 +43,8 @@ uc_abs(uc_vm_t *vm, size_t nargs) static uc_value_t * 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); @@ -55,7 +55,7 @@ uc_atan2(uc_vm_t *vm, size_t nargs) static uc_value_t * 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); @@ -66,7 +66,7 @@ uc_cos(uc_vm_t *vm, size_t nargs) static uc_value_t * 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); @@ -77,7 +77,7 @@ uc_exp(uc_vm_t *vm, size_t nargs) static uc_value_t * 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); @@ -88,7 +88,7 @@ uc_log(uc_vm_t *vm, size_t nargs) static uc_value_t * 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); @@ -99,7 +99,7 @@ uc_sin(uc_vm_t *vm, size_t nargs) static uc_value_t * 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); @@ -110,8 +110,8 @@ uc_sqrt(uc_vm_t *vm, size_t nargs) static uc_value_t * 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); @@ -137,7 +137,7 @@ uc_rand(uc_vm_t *vm, size_t nargs) static uc_value_t * 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_t *vm, size_t nargs) return NULL; } -static const uc_cfunction_list_t math_fns[] = { +static const uc_function_list_t math_fns[] = { { "abs", uc_abs }, { "atan2", uc_atan2 }, { "cos", uc_cos }, @@ -160,5 +160,5 @@ static const uc_cfunction_list_t math_fns[] = { void uc_module_init(uc_vm_t *vm, uc_value_t *scope) { - uc_add_functions(scope, math_fns); + uc_function_list_register(scope, math_fns); } @@ -133,8 +133,8 @@ uc_blob_to_json(uc_vm_t *vm, struct blob_attr *attr, bool table, const char **na static uc_value_t * uc_ubus_connect(uc_vm_t *vm, size_t nargs) { - uc_value_t *socket = uc_get_arg(0); - uc_value_t *timeout = uc_get_arg(1); + uc_value_t *socket = uc_fn_arg(0); + uc_value_t *timeout = uc_fn_arg(1); uc_value_t *co; ubus_connection *c; @@ -168,7 +168,7 @@ uc_ubus_connect(uc_vm_t *vm, size_t nargs) ubus_add_uloop(c->ctx); - return uc_alloc_ressource(conn_type, c); + return uc_ressource_new(conn_type, c); } static void @@ -201,8 +201,8 @@ uc_ubus_objects_cb(struct ubus_context *c, struct ubus_object_data *o, void *p) static uc_value_t * uc_ubus_list(uc_vm_t *vm, size_t nargs) { - ubus_connection **c = uc_get_self("ubus.connection"); - uc_value_t *objname = uc_get_arg(0); + ubus_connection **c = uc_fn_this("ubus.connection"); + uc_value_t *objname = uc_fn_arg(0); uc_value_t *res = NULL; enum ubus_msg_status rv; @@ -239,10 +239,10 @@ uc_ubus_call_cb(struct ubus_request *req, int type, struct blob_attr *msg) static uc_value_t * uc_ubus_call(uc_vm_t *vm, size_t nargs) { - ubus_connection **c = uc_get_self("ubus.connection"); - uc_value_t *objname = uc_get_arg(0); - uc_value_t *funname = uc_get_arg(1); - uc_value_t *funargs = uc_get_arg(2); + ubus_connection **c = uc_fn_this("ubus.connection"); + uc_value_t *objname = uc_fn_arg(0); + uc_value_t *funname = uc_fn_arg(1); + uc_value_t *funargs = uc_fn_arg(2); uc_value_t *res = NULL; json_object *o; enum ubus_msg_status rv; @@ -284,7 +284,7 @@ uc_ubus_call(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_ubus_disconnect(uc_vm_t *vm, size_t nargs) { - ubus_connection **c = uc_get_self("ubus.connection"); + ubus_connection **c = uc_fn_this("ubus.connection"); if (!c || !*c || !(*c)->ctx) err_return(UBUS_STATUS_CONNECTION_FAILED); @@ -296,12 +296,12 @@ uc_ubus_disconnect(uc_vm_t *vm, size_t nargs) } -static const uc_cfunction_list_t global_fns[] = { +static const uc_function_list_t global_fns[] = { { "error", uc_ubus_error }, { "connect", uc_ubus_connect }, }; -static const uc_cfunction_list_t conn_fns[] = { +static const uc_function_list_t conn_fns[] = { { "list", uc_ubus_list }, { "call", uc_ubus_call }, { "error", uc_ubus_error }, @@ -322,7 +322,7 @@ static void close_connection(void *ud) { void uc_module_init(uc_vm_t *vm, uc_value_t *scope) { - uc_add_functions(scope, global_fns); + uc_function_list_register(scope, global_fns); - conn_type = uc_declare_type(vm, "ubus.connection", conn_fns, close_connection); + conn_type = uc_type_declare(vm, "ubus.connection", conn_fns, close_connection); } @@ -66,8 +66,8 @@ uc_uci_error(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uci_cursor(uc_vm_t *vm, size_t nargs) { - uc_value_t *cdir = uc_get_arg(0); - uc_value_t *sdir = uc_get_arg(1); + uc_value_t *cdir = uc_fn_arg(0); + uc_value_t *sdir = uc_fn_arg(1); struct uci_context *c; int rv; @@ -94,15 +94,15 @@ uc_uci_cursor(uc_vm_t *vm, size_t nargs) err_return(rv); } - return uc_alloc_ressource(cursor_type, c); + return uc_ressource_new(cursor_type, c); } static uc_value_t * uc_uci_load(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); struct uci_element *e; char *s; @@ -130,8 +130,8 @@ uc_uci_load(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uci_unload(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); struct uci_element *e; if (!c || !*c) @@ -251,10 +251,10 @@ package_to_uval(uc_vm_t *vm, struct uci_package *p) static uc_value_t * uc_uci_get_any(uc_vm_t *vm, size_t nargs, bool all) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); - uc_value_t *sect = uc_get_arg(1); - uc_value_t *opt = uc_get_arg(2); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); + uc_value_t *sect = uc_fn_arg(1); + uc_value_t *opt = uc_fn_arg(2); struct uci_ptr ptr = { 0 }; int rv; @@ -323,10 +323,10 @@ uc_uci_get_all(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uci_get_first(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); - uc_value_t *type = uc_get_arg(1); - uc_value_t *opt = uc_get_arg(2); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); + uc_value_t *type = uc_fn_arg(1); + uc_value_t *opt = uc_fn_arg(2); struct uci_package *p = NULL; struct uci_section *sc; struct uci_element *e; @@ -381,9 +381,9 @@ uc_uci_get_first(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uci_add(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); - uc_value_t *type = uc_get_arg(1); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); + uc_value_t *type = uc_fn_arg(1); struct uci_element *e = NULL; struct uci_package *p = NULL; struct uci_section *sc = NULL; @@ -461,9 +461,9 @@ uval_to_uci(uc_vm_t *vm, uc_value_t *val, const char **p, bool *is_list) static uc_value_t * uc_uci_set(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); - uc_value_t *sect = uc_get_arg(1); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); + uc_value_t *sect = uc_fn_arg(1); uc_value_t *opt = NULL, *val = NULL; struct uci_ptr ptr = { 0 }; bool is_list = false; @@ -477,8 +477,8 @@ uc_uci_set(uc_vm_t *vm, size_t nargs) switch (nargs) { /* conf, sect, opt, val */ case 4: - opt = uc_get_arg(2); - val = uc_get_arg(3); + opt = uc_fn_arg(2); + val = uc_fn_arg(3); if (ucv_type(opt) != UC_STRING) err_return(UCI_ERR_INVAL); @@ -487,7 +487,7 @@ uc_uci_set(uc_vm_t *vm, size_t nargs) /* conf, sect, type */ case 3: - val = uc_get_arg(2); + val = uc_fn_arg(2); if (ucv_type(val) != UC_STRING) err_return(UCI_ERR_INVAL); @@ -566,10 +566,10 @@ uc_uci_set(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uci_delete(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); - uc_value_t *sect = uc_get_arg(1); - uc_value_t *opt = uc_get_arg(2); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); + uc_value_t *sect = uc_fn_arg(1); + uc_value_t *opt = uc_fn_arg(2); struct uci_ptr ptr = { 0 }; int rv; @@ -601,9 +601,9 @@ uc_uci_delete(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uci_rename(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); - uc_value_t *sect = uc_get_arg(1); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); + uc_value_t *sect = uc_fn_arg(1); uc_value_t *opt = NULL, *val = NULL; struct uci_ptr ptr = { 0 }; int rv; @@ -615,8 +615,8 @@ uc_uci_rename(uc_vm_t *vm, size_t nargs) switch (nargs) { /* conf, sect, opt, val */ case 4: - opt = uc_get_arg(2); - val = uc_get_arg(3); + opt = uc_fn_arg(2); + val = uc_fn_arg(3); if (ucv_type(opt) != UC_STRING || ucv_type(val) != UC_STRING) @@ -626,7 +626,7 @@ uc_uci_rename(uc_vm_t *vm, size_t nargs) /* conf, sect, type */ case 3: - val = uc_get_arg(2); + val = uc_fn_arg(2); if (ucv_type(val) != UC_STRING) err_return(UCI_ERR_INVAL); @@ -661,10 +661,10 @@ uc_uci_rename(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uci_reorder(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); - uc_value_t *sect = uc_get_arg(1); - uc_value_t *val = uc_get_arg(2); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); + uc_value_t *sect = uc_fn_arg(1); + uc_value_t *val = uc_fn_arg(2); struct uci_ptr ptr = { 0 }; int64_t n; int rv; @@ -701,8 +701,8 @@ uc_uci_reorder(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uci_pkg_command(uc_vm_t *vm, size_t nargs, enum pkg_cmd cmd) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); struct uci_element *e, *tmp; struct uci_package *p; struct uci_ptr ptr = { 0 }; @@ -858,8 +858,8 @@ changes_to_uval(uc_vm_t *vm, struct uci_context *ctx, const char *package) static uc_value_t * uc_uci_changes(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); uc_value_t *res, *chg; char **configs; int rv, i; @@ -892,10 +892,10 @@ uc_uci_changes(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uci_foreach(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); - uc_value_t *conf = uc_get_arg(0); - uc_value_t *type = uc_get_arg(1); - uc_value_t *func = uc_get_arg(2); + struct uci_context **c = uc_fn_this("uci.cursor"); + uc_value_t *conf = uc_fn_arg(0); + uc_value_t *type = uc_fn_arg(1); + uc_value_t *func = uc_fn_arg(2); uc_value_t *rv = NULL; struct uci_package *p = NULL; struct uci_element *e, *tmp; @@ -927,8 +927,8 @@ uc_uci_foreach(uc_vm_t *vm, size_t nargs) if (type && strcmp(sc->type, ucv_string_get(type))) continue; - uc_push_val(ucv_get(func)); - uc_push_val(section_to_uval(vm, sc, i - 1)); + uc_value_push(ucv_get(func)); + uc_value_push(section_to_uval(vm, sc, i - 1)); ex = uc_call(1); @@ -937,7 +937,7 @@ uc_uci_foreach(uc_vm_t *vm, size_t nargs) break; ret = true; - rv = uc_pop_val(); + rv = uc_value_pop(); stop = (ucv_type(rv) == UC_BOOLEAN && !ucv_boolean_get(rv)); ucv_put(rv); @@ -954,7 +954,7 @@ uc_uci_foreach(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_uci_configs(uc_vm_t *vm, size_t nargs) { - struct uci_context **c = uc_get_self("uci.cursor"); + struct uci_context **c = uc_fn_this("uci.cursor"); uc_value_t *a; char **configs; int i, rv; @@ -975,7 +975,7 @@ uc_uci_configs(uc_vm_t *vm, size_t nargs) } -static const uc_cfunction_list_t cursor_fns[] = { +static const uc_function_list_t cursor_fns[] = { { "load", uc_uci_load }, { "unload", uc_uci_unload }, { "get", uc_uci_get }, @@ -995,7 +995,7 @@ static const uc_cfunction_list_t cursor_fns[] = { { "error", uc_uci_error }, }; -static const uc_cfunction_list_t global_fns[] = { +static const uc_function_list_t global_fns[] = { { "error", uc_uci_error }, { "cursor", uc_uci_cursor }, }; @@ -1007,7 +1007,7 @@ static void close_uci(void *ud) { void uc_module_init(uc_vm_t *vm, uc_value_t *scope) { - uc_add_functions(scope, global_fns); + uc_function_list_register(scope, global_fns); - cursor_type = uc_declare_type(vm, "uci.cursor", cursor_fns, close_uci); + cursor_type = uc_type_declare(vm, "uci.cursor", cursor_fns, close_uci); } @@ -208,7 +208,7 @@ main(int argc, char **argv) uc_vm_init(&vm, &config); /* load std functions into global scope */ - uc_load_stdlib(uc_vm_scope_get(&vm)); + uc_stdlib_load(uc_vm_scope_get(&vm)); /* register ARGV array */ o = ucv_array_new_length(&vm, argc); @@ -20,6 +20,7 @@ #include <endian.h> #include <errno.h> #include <math.h> +#include <ctype.h> #include "ucode/types.h" #include "ucode/util.h" @@ -1658,8 +1659,80 @@ ucv_to_jsonstring_formatted(uc_vm_t *vm, uc_value_t *uv, char pad_char, size_t p return ucv_to_string_any(vm, uv, pad_char ? pad_char : '\1', pad_size); } +uc_type_t +ucv_cast_number(uc_value_t *v, int64_t *n, double *d) +{ + bool is_double = false; + const char *s; + char *e; + + *d = 0.0; + *n = 0; + + switch (ucv_type(v)) { + case UC_INTEGER: + *n = ucv_int64_get(v); + + return UC_INTEGER; + + case UC_DOUBLE: + *d = ucv_double_get(v); + + return UC_DOUBLE; + + case UC_NULL: + return UC_INTEGER; + + case UC_BOOLEAN: + *n = ucv_boolean_get(v); + + return UC_INTEGER; + + case UC_STRING: + s = ucv_string_get(v); + + while (isspace(*s)) + s++; + + if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X') && isxdigit(s[2])) { + *n = strtoll(s, &e, 16); + } + else if (s[0] == '0' && isdigit(s[2])) { + *n = strtoll(s, &e, 8); + } + else { + *n = strtoll(s, &e, 10); + + if (*e == '.') { + *d = strtod(s, &e); + is_double = (e > s); + } + } + + while (isspace(*e)) + e++; + + if (*e) { + *d = NAN; + + return UC_DOUBLE; + } + + if (is_double) + return UC_DOUBLE; + + return UC_INTEGER; + + default: + *d = NAN; + + return UC_DOUBLE; + } +} + + bool -ucv_equal(uc_value_t *uv1, uc_value_t *uv2) +ucv_is_equal(uc_value_t *uv1, uc_value_t *uv2) { uc_type_t t1 = ucv_type(uv1); uc_type_t t2 = ucv_type(uv2); @@ -1724,7 +1797,7 @@ ucv_equal(uc_value_t *uv1, uc_value_t *uv2) return false; for (u1 = 0; u1 < u2; u1++) - if (!ucv_equal(ucv_array_get(uv1, u1), ucv_array_get(uv2, u1))) + if (!ucv_is_equal(ucv_array_get(uv1, u1), ucv_array_get(uv2, u1))) return false; return true; @@ -1737,7 +1810,7 @@ ucv_equal(uc_value_t *uv1, uc_value_t *uv2) return false; ucv_object_foreach(uv1, key, val) { - if (!ucv_equal(val, ucv_object_get(uv2, key, NULL))) + if (!ucv_is_equal(val, ucv_object_get(uv2, key, NULL))) return false; } @@ -1756,6 +1829,221 @@ ucv_equal(uc_value_t *uv1, uc_value_t *uv2) } } +bool +ucv_is_truish(uc_value_t *val) +{ + double d; + + switch (ucv_type(val)) { + case UC_INTEGER: + if (ucv_is_u64(val)) + return (ucv_uint64_get(val) != 0); + + return (ucv_int64_get(val) != 0); + + case UC_DOUBLE: + d = ucv_double_get(val); + + return (d != 0 && !isnan(d)); + + case UC_BOOLEAN: + return ucv_boolean_get(val); + + case UC_STRING: + return (ucv_string_length(val) > 0); + + case UC_NULL: + return false; + + default: + return true; + } +} + + +bool +ucv_compare(int how, uc_value_t *v1, uc_value_t *v2) +{ + uc_type_t t1 = ucv_type(v1); + uc_type_t t2 = ucv_type(v2); + int64_t n1, n2, delta; + double d1, d2; + + if (t1 == UC_STRING && t2 == UC_STRING) { + delta = strcmp(ucv_string_get(v1), ucv_string_get(v2)); + } + else { + if (t1 == t2 && !ucv_is_scalar(v1)) { + delta = (intptr_t)v1 - (intptr_t)v2; + } + else { + t1 = ucv_cast_number(v1, &n1, &d1); + t2 = ucv_cast_number(v2, &n2, &d2); + + if (t1 == UC_DOUBLE || t2 == UC_DOUBLE) { + d1 = (t1 == UC_DOUBLE) ? d1 : (double)n1; + d2 = (t2 == UC_DOUBLE) ? d2 : (double)n2; + + /* all comparison results except `!=` involving NaN are false */ + if (isnan(d1) || isnan(d2)) + return (how == I_NE); + + if (d1 == d2) + delta = 0; + else if (d1 < d2) + delta = -1; + else + delta = 1; + } + else { + delta = n1 - n2; + } + } + } + + switch (how) { + case I_LT: + return (delta < 0); + + case I_LE: + return (delta <= 0); + + case I_GT: + return (delta > 0); + + case I_GE: + return (delta >= 0); + + case I_EQ: + return (delta == 0); + + case I_NE: + return (delta != 0); + + default: + return false; + } +} + + +static char * +ucv_key_to_string(uc_vm_t *vm, uc_value_t *val) +{ + if (ucv_type(val) != UC_STRING) + return ucv_to_string(vm, val); + + return NULL; +} + +static int64_t +ucv_key_to_index(uc_value_t *val) +{ + const char *k; + int64_t idx; + double d; + char *e; + + /* only consider doubles with integer values as array keys */ + if (ucv_type(val) == UC_DOUBLE) { + d = ucv_double_get(val); + + if ((double)(int64_t)(d) != d) + return -1; + + return (int64_t)d; + } + else if (ucv_type(val) == UC_INTEGER) { + return ucv_int64_get(val); + } + else if (ucv_type(val) == UC_STRING) { + errno = 0; + k = ucv_string_get(val); + idx = strtoll(k, &e, 0); + + if (errno != 0 || e == k || *e != 0) + return -1; + + return idx; + } + + return -1; +} + +uc_value_t * +ucv_key_get(uc_vm_t *vm, uc_value_t *scope, uc_value_t *key) +{ + uc_value_t *o, *v = NULL; + int64_t idx; + bool found; + char *k; + + if (ucv_type(scope) == UC_ARRAY) { + idx = ucv_key_to_index(key); + + if (idx >= 0 && (uint64_t)idx < ucv_array_length(scope)) + return ucv_get(ucv_array_get(scope, idx)); + } + + k = ucv_key_to_string(vm, key); + + for (o = scope; o; o = ucv_prototype_get(o)) { + if (ucv_type(o) != UC_OBJECT) + continue; + + v = ucv_object_get(o, k ? k : ucv_string_get(key), &found); + + if (found) + break; + } + + free(k); + + return ucv_get(v); +} + +uc_value_t * +ucv_key_set(uc_vm_t *vm, uc_value_t *scope, uc_value_t *key, uc_value_t *val) +{ + int64_t idx; + char *s; + bool rv; + + if (!key) + return NULL; + + if (ucv_type(scope) == UC_ARRAY) { + idx = ucv_key_to_index(key); + + if (idx < 0 || !ucv_array_set(scope, idx, val)) + return NULL; + + return ucv_get(val); + } + + s = ucv_key_to_string(vm, key); + rv = ucv_object_add(scope, s ? s : ucv_string_get(key), val); + free(s); + + return rv ? ucv_get(val) : NULL; +} + +bool +ucv_key_delete(uc_vm_t *vm, uc_value_t *scope, uc_value_t *key) +{ + char *s; + bool rv; + + if (!key) + return NULL; + + s = ucv_key_to_string(vm, key); + rv = ucv_object_delete(scope, s ? s : ucv_string_get(key)); + free(s); + + return rv; +} + + static void ucv_gc_common(uc_vm_t *vm, bool final) { @@ -22,7 +22,7 @@ #include "ucode/util.h" #include "ucode/chunk.h" -#include "ucode/value.h" +#include "ucode/vallist.h" #include "ucode/vm.h" #define TAG_TYPE uint64_t @@ -43,289 +43,6 @@ #define UC_VALLIST_CHUNK_SIZE 8 -bool -uc_val_is_truish(uc_value_t *val) -{ - double d; - - switch (ucv_type(val)) { - case UC_INTEGER: - if (ucv_is_u64(val)) - return (ucv_uint64_get(val) != 0); - - return (ucv_int64_get(val) != 0); - - case UC_DOUBLE: - d = ucv_double_get(val); - - return (d != 0 && !isnan(d)); - - case UC_BOOLEAN: - return ucv_boolean_get(val); - - case UC_STRING: - return (ucv_string_length(val) > 0); - - case UC_NULL: - return false; - - default: - return true; - } -} - -uc_type_t -uc_cast_number(uc_value_t *v, int64_t *n, double *d) -{ - bool is_double = false; - const char *s; - char *e; - - *d = 0.0; - *n = 0; - - switch (ucv_type(v)) { - case UC_INTEGER: - *n = ucv_int64_get(v); - - return UC_INTEGER; - - case UC_DOUBLE: - *d = ucv_double_get(v); - - return UC_DOUBLE; - - case UC_NULL: - return UC_INTEGER; - - case UC_BOOLEAN: - *n = ucv_boolean_get(v); - - return UC_INTEGER; - - case UC_STRING: - s = ucv_string_get(v); - - while (isspace(*s)) - s++; - - if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X') && isxdigit(s[2])) { - *n = strtoll(s, &e, 16); - } - else if (s[0] == '0' && isdigit(s[2])) { - *n = strtoll(s, &e, 8); - } - else { - *n = strtoll(s, &e, 10); - - if (*e == '.') { - *d = strtod(s, &e); - is_double = (e > s); - } - } - - while (isspace(*e)) - e++; - - if (*e) { - *d = NAN; - - return UC_DOUBLE; - } - - if (is_double) - return UC_DOUBLE; - - return UC_INTEGER; - - default: - *d = NAN; - - return UC_DOUBLE; - } -} - -static char * -uc_tostring(uc_vm_t *vm, uc_value_t *val) -{ - if (ucv_type(val) != UC_STRING) - return ucv_to_string(vm, val); - - return NULL; -} - -static int64_t -uc_toidx(uc_value_t *val) -{ - const char *k; - int64_t idx; - double d; - char *e; - - /* only consider doubles with integer values as array keys */ - if (ucv_type(val) == UC_DOUBLE) { - d = ucv_double_get(val); - - if ((double)(int64_t)(d) != d) - return -1; - - return (int64_t)d; - } - else if (ucv_type(val) == UC_INTEGER) { - return ucv_int64_get(val); - } - else if (ucv_type(val) == UC_STRING) { - errno = 0; - k = ucv_string_get(val); - idx = strtoll(k, &e, 0); - - if (errno != 0 || e == k || *e != 0) - return -1; - - return idx; - } - - return -1; -} - -uc_value_t * -uc_getval(uc_vm_t *vm, uc_value_t *scope, uc_value_t *key) -{ - uc_value_t *o, *v = NULL; - int64_t idx; - bool found; - char *k; - - if (ucv_type(scope) == UC_ARRAY) { - idx = uc_toidx(key); - - if (idx >= 0 && (uint64_t)idx < ucv_array_length(scope)) - return ucv_get(ucv_array_get(scope, idx)); - } - - k = uc_tostring(vm, key); - - for (o = scope; o; o = ucv_prototype_get(o)) { - if (ucv_type(o) != UC_OBJECT) - continue; - - v = ucv_object_get(o, k ? k : ucv_string_get(key), &found); - - if (found) - break; - } - - free(k); - - return ucv_get(v); -} - -uc_value_t * -uc_setval(uc_vm_t *vm, uc_value_t *scope, uc_value_t *key, uc_value_t *val) -{ - int64_t idx; - char *s; - bool rv; - - if (!key) - return NULL; - - if (ucv_type(scope) == UC_ARRAY) { - idx = uc_toidx(key); - - if (idx < 0 || !ucv_array_set(scope, idx, val)) - return NULL; - - return ucv_get(val); - } - - s = uc_tostring(vm, key); - rv = ucv_object_add(scope, s ? s : ucv_string_get(key), val); - free(s); - - return rv ? ucv_get(val) : NULL; -} - -bool -uc_delval(uc_vm_t *vm, uc_value_t *scope, uc_value_t *key) -{ - char *s; - bool rv; - - if (!key) - return NULL; - - s = uc_tostring(vm, key); - rv = ucv_object_delete(scope, s ? s : ucv_string_get(key)); - free(s); - - return rv; -} - -bool -uc_cmp(int how, uc_value_t *v1, uc_value_t *v2) -{ - uc_type_t t1 = ucv_type(v1); - uc_type_t t2 = ucv_type(v2); - int64_t n1, n2, delta; - double d1, d2; - - if (t1 == UC_STRING && t2 == UC_STRING) { - delta = strcmp(ucv_string_get(v1), ucv_string_get(v2)); - } - else { - if (t1 == t2 && !ucv_is_scalar(v1)) { - delta = (intptr_t)v1 - (intptr_t)v2; - } - else { - t1 = uc_cast_number(v1, &n1, &d1); - t2 = uc_cast_number(v2, &n2, &d2); - - if (t1 == UC_DOUBLE || t2 == UC_DOUBLE) { - d1 = (t1 == UC_DOUBLE) ? d1 : (double)n1; - d2 = (t2 == UC_DOUBLE) ? d2 : (double)n2; - - /* all comparison results except `!=` involving NaN are false */ - if (isnan(d1) || isnan(d2)) - return (how == I_NE); - - if (d1 == d2) - delta = 0; - else if (d1 < d2) - delta = -1; - else - delta = 1; - } - else { - delta = n1 - n2; - } - } - } - - switch (how) { - case I_LT: - return (delta < 0); - - case I_LE: - return (delta <= 0); - - case I_GT: - return (delta > 0); - - case I_GE: - return (delta >= 0); - - case I_EQ: - return (delta == 0); - - case I_NE: - return (delta != 0); - - default: - return false; - } -} - void uc_vallist_init(uc_value_list_t *list) { @@ -22,7 +22,7 @@ #include "ucode/vm.h" #include "ucode/compiler.h" -#include "ucode/lib.h" /* format_error_context() */ +#include "ucode/lib.h" /* uc_error_context_format() */ #undef __insn #define __insn(_name) #_name, @@ -599,7 +599,7 @@ uc_dump_insn(uc_vm_t *vm, uint8_t *pos, uc_vm_insn_t insn) if (last_srcpos == 0 || last_source != frame->closure->function->source || srcpos != last_srcpos) { buf = xprintbuf_new(); - format_source_context(buf, frame->closure->function->source, srcpos, true); + uc_source_context_format(buf, frame->closure->function->source, srcpos, true); fwrite(buf->buf, 1, printbuf_length(buf), stderr); printbuf_free(buf); @@ -835,7 +835,7 @@ uc_vm_capture_stacktrace(uc_vm_t *vm, size_t i) ucv_object_add(entry, "function", ucv_string_new(name)); } - if (!ucv_equal(last, entry)) { + if (!ucv_is_equal(last, entry)) { ucv_array_push(stacktrace, entry); last = entry; } @@ -873,7 +873,7 @@ uc_vm_get_error_context(uc_vm_t *vm) buf = ucv_stringbuf_new(); if (offset) - format_error_context(buf, frame->closure->function->source, stacktrace, offset); + uc_error_context_format(buf, frame->closure->function->source, stacktrace, offset); else if (frame->ip != chunk->entries) ucv_stringbuf_printf(buf, "At instruction %zu", (frame->ip - chunk->entries) - 1); else @@ -1016,7 +1016,7 @@ uc_vm_insn_load_val(uc_vm_t *vm, uc_vm_insn_t insn) switch (ucv_type(v)) { case UC_OBJECT: case UC_ARRAY: - uc_vm_stack_push(vm, uc_getval(vm, v, k)); + uc_vm_stack_push(vm, ucv_key_get(vm, v, k)); break; default: @@ -1191,7 +1191,7 @@ uc_vm_insn_store_val(uc_vm_t *vm, uc_vm_insn_t insn) switch (ucv_type(o)) { case UC_OBJECT: case UC_ARRAY: - uc_vm_stack_push(vm, uc_setval(vm, o, k, v)); + uc_vm_stack_push(vm, ucv_key_set(vm, o, k, v)); break; default: @@ -1236,10 +1236,10 @@ uc_vm_value_bitop(uc_vm_t *vm, uc_vm_insn_t operation, uc_value_t *value, uc_val int64_t n1, n2; double d; - if (uc_cast_number(value, &n1, &d) == UC_DOUBLE) + if (ucv_cast_number(value, &n1, &d) == UC_DOUBLE) n1 = isnan(d) ? 0 : (int64_t)d; - if (uc_cast_number(operand, &n2, &d) == UC_DOUBLE) + if (ucv_cast_number(operand, &n2, &d) == UC_DOUBLE) n2 = isnan(d) ? 0 : (int64_t)d; switch (operation) { @@ -1303,8 +1303,8 @@ uc_vm_value_arith(uc_vm_t *vm, uc_vm_insn_t operation, uc_value_t *value, uc_val return rv; } - t1 = uc_cast_number(value, &n1, &d1); - t2 = uc_cast_number(operand, &n2, &d2); + t1 = ucv_cast_number(value, &n1, &d1); + t2 = ucv_cast_number(operand, &n2, &d2); if (t1 == UC_DOUBLE || t2 == UC_DOUBLE) { d1 = (t1 == UC_DOUBLE) ? d1 : (double)n1; @@ -1438,8 +1438,8 @@ uc_vm_insn_update_val(uc_vm_t *vm, uc_vm_insn_t insn) switch (ucv_type(v)) { case UC_OBJECT: case UC_ARRAY: - val = uc_getval(vm, v, k); - uc_vm_stack_push(vm, uc_setval(vm, v, k, uc_vm_value_arith(vm, vm->arg.u8, val, inc))); + val = ucv_key_get(vm, v, k); + uc_vm_stack_push(vm, ucv_key_set(vm, v, k, uc_vm_value_arith(vm, vm->arg.u8, val, inc))); break; default: @@ -1634,7 +1634,7 @@ uc_vm_insn_plus_minus(uc_vm_t *vm, uc_vm_insn_t insn) int64_t n; double d; - t = uc_cast_number(v, &n, &d); + t = ucv_cast_number(v, &n, &d); ucv_put(v); @@ -1671,7 +1671,7 @@ uc_vm_insn_complement(uc_vm_t *vm, uc_vm_insn_t insn) int64_t n; double d; - if (uc_cast_number(v, &n, &d) == UC_DOUBLE) + if (ucv_cast_number(v, &n, &d) == UC_DOUBLE) n = isnan(d) ? 0 : (int64_t)d; ucv_put(v); @@ -1685,7 +1685,7 @@ uc_vm_insn_rel(uc_vm_t *vm, uc_vm_insn_t insn) uc_value_t *r2 = uc_vm_stack_pop(vm); uc_value_t *r1 = uc_vm_stack_pop(vm); - bool res = uc_cmp(insn, r1, r2); + bool res = ucv_compare(insn, r1, r2); ucv_put(r1); ucv_put(r2); @@ -1709,7 +1709,7 @@ uc_vm_insn_in(uc_vm_t *vm, uc_vm_insn_t insn) arridx < arrlen; arridx++) { item = ucv_array_get(r2, arridx); - if (uc_cmp(I_EQ, r1, item)) { + if (ucv_compare(I_EQ, r1, item)) { found = true; break; } @@ -1747,7 +1747,7 @@ uc_vm_insn_equality(uc_vm_t *vm, uc_vm_insn_t insn) bool equal; if (ucv_is_scalar(r1) && ucv_is_scalar(r2)) - equal = ucv_equal(r1, r2); + equal = ucv_is_equal(r1, r2); else equal = (r1 == r2); @@ -1762,7 +1762,7 @@ uc_vm_insn_not(uc_vm_t *vm, uc_vm_insn_t insn) { uc_value_t *r1 = uc_vm_stack_pop(vm); - uc_vm_stack_push(vm, ucv_boolean_new(!uc_val_is_truish(r1))); + uc_vm_stack_push(vm, ucv_boolean_new(!ucv_is_truish(r1))); ucv_put(r1); } @@ -1802,7 +1802,7 @@ uc_vm_insn_jmpz(uc_vm_t *vm, uc_vm_insn_t insn) return; } - if (!uc_val_is_truish(v)) + if (!ucv_is_truish(v)) frame->ip += addr; ucv_put(v); @@ -1908,7 +1908,7 @@ uc_vm_insn_mcall(uc_vm_t *vm, uc_vm_insn_t insn) size_t key_slot = vm->stack.count - (vm->arg.u32 & 0xffff) - 1; uc_value_t *ctx = vm->stack.entries[key_slot - 1]; uc_value_t *key = vm->stack.entries[key_slot]; - uc_value_t *fno = uc_getval(vm, ctx, key); + uc_value_t *fno = ucv_key_get(vm, ctx, key); uc_vm_stack_set(vm, key_slot, fno); @@ -1958,7 +1958,7 @@ uc_vm_insn_delete(uc_vm_t *vm, uc_vm_insn_t insn) switch (ucv_type(v)) { case UC_OBJECT: - rv = uc_delval(vm, v, k); + rv = ucv_key_delete(vm, v, k); uc_vm_stack_push(vm, ucv_boolean_new(rv)); break; @@ -2319,7 +2319,7 @@ uc_vm_execute(uc_vm_t *vm, uc_function_t *fn, uc_value_t **retval) if (vm->trace) { buf = xprintbuf_new(); - format_source_context(buf, fn->source, 0, true); + uc_source_context_format(buf, fn->source, 0, true); fwrite(buf->buf, 1, printbuf_length(buf), stderr); printbuf_free(buf); |