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 | |
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')
-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 |
5 files changed, 55 insertions, 61 deletions
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); |