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 /include/ucode/lib.h | |
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>
Diffstat (limited to 'include/ucode/lib.h')
-rw-r--r-- | include/ucode/lib.h | 70 |
1 files changed, 22 insertions, 48 deletions
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_ */ |