diff options
Diffstat (limited to 'js/scripting-lang/baba-yaga-c/include/baba_yaga.h')
-rw-r--r-- | js/scripting-lang/baba-yaga-c/include/baba_yaga.h | 96 |
1 files changed, 92 insertions, 4 deletions
diff --git a/js/scripting-lang/baba-yaga-c/include/baba_yaga.h b/js/scripting-lang/baba-yaga-c/include/baba_yaga.h index b8660e1..1e9eead 100644 --- a/js/scripting-lang/baba-yaga-c/include/baba_yaga.h +++ b/js/scripting-lang/baba-yaga-c/include/baba_yaga.h @@ -256,6 +256,25 @@ size_t baba_yaga_table_size(const Value* table); */ bool baba_yaga_table_has_key(const Value* table, const char* key); +/** + * @brief Get all keys from a table + * + * @param table Table value + * @param keys Array to store keys (caller must free) + * @param max_keys Maximum number of keys to retrieve + * @return Number of keys retrieved + */ +size_t baba_yaga_table_get_keys(const Value* table, char** keys, size_t max_keys); + +/** + * @brief Get a value from table by key (supports both string and numeric keys) + * + * @param table Table value + * @param key Key (string or numeric as string) + * @return Value at key, or nil if not found + */ +Value baba_yaga_table_get_by_key(const Value* table, const char* key); + /* ============================================================================ * Function Management Functions * ============================================================================ */ @@ -269,9 +288,11 @@ bool baba_yaga_table_has_key(const Value* table, const char* key); * @param body Function body (function pointer) * @return New function value */ -Value baba_yaga_value_function(const char* name, Value (*body)(Value*, int), +Value baba_yaga_value_function(const char* name, Value (*body)(Value*, int, Scope*), int param_count, int required_param_count); + + /** * @brief Call a function with arguments * @@ -445,6 +466,12 @@ void* baba_yaga_ast_get_when_expr_pattern(void* node, int index); void* baba_yaga_ast_get_when_pattern_test(void* node); void* baba_yaga_ast_get_when_pattern_result(void* node); +/* Table AST accessor functions */ +int baba_yaga_ast_get_table_element_count(void* node); +void* baba_yaga_ast_get_table_element(void* node, int index); +void* baba_yaga_ast_get_table_access_object(void* node); +void* baba_yaga_ast_get_table_access_key(void* node); + /** * @brief Print AST for debugging * @@ -542,6 +569,47 @@ void baba_yaga_error_destroy(BabaYagaError* error); /* Core combinator */ Value stdlib_apply(Value* args, int argc); +/* Wrapper functions for function signature compatibility */ +Value stdlib_apply_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_add_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_subtract_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_multiply_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_divide_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_modulo_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_pow_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_negate_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_equals_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_not_equals_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_less_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_less_equal_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_greater_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_greater_equal_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_and_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_or_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_xor_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_not_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_compose_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_out_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_in_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_assert_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_emit_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_listen_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_flip_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_constant_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_apply_wrapper(Value* args, int argc, Scope* scope); + +/* Table operation wrappers */ +Value stdlib_t_map_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_t_filter_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_t_reduce_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_t_set_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_t_delete_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_t_merge_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_t_length_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_t_has_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_t_get_wrapper(Value* args, int argc, Scope* scope); +Value stdlib_table_entry_wrapper(Value* args, int argc, Scope* scope); + /* Arithmetic functions */ Value stdlib_add(Value* args, int argc); Value stdlib_subtract(Value* args, int argc); @@ -572,11 +640,30 @@ Value stdlib_compose(Value* args, int argc); Value stdlib_out(Value* args, int argc); Value stdlib_in(Value* args, int argc); Value stdlib_assert(Value* args, int argc); +Value stdlib_emit(Value* args, int argc); +Value stdlib_listen(Value* args, int argc); /* Higher-order functions */ -Value stdlib_map(Value* args, int argc); -Value stdlib_filter(Value* args, int argc); -Value stdlib_reduce(Value* args, int argc); +Value stdlib_map(Value* args, int argc, Scope* scope); +Value stdlib_filter(Value* args, int argc, Scope* scope); +Value stdlib_reduce(Value* args, int argc, Scope* scope); +Value stdlib_each(Value* args, int argc, Scope* scope); +Value stdlib_each_partial(Value* args, int argc, Scope* scope); +Value stdlib_partial_apply(Value* args, int argc, Scope* scope); +Value stdlib_flip(Value* args, int argc); +Value stdlib_constant(Value* args, int argc); + +/* Table operations namespace */ +Value stdlib_t_map(Value* args, int argc); +Value stdlib_t_filter(Value* args, int argc); +Value stdlib_t_reduce(Value* args, int argc); +Value stdlib_t_set(Value* args, int argc); +Value stdlib_t_delete(Value* args, int argc); +Value stdlib_t_merge(Value* args, int argc); +Value stdlib_t_length(Value* args, int argc); +Value stdlib_t_has(Value* args, int argc); +Value stdlib_t_get(Value* args, int argc); +Value stdlib_table_entry(Value* args, int argc); /* ============================================================================ * Scope Management Functions @@ -593,6 +680,7 @@ bool scope_define(Scope* scope, const char* name, Value value, bool is_constant) bool scope_has(Scope* scope, const char* name); /* Scope utilities */ +Scope* scope_get_global(Scope* scope); int scope_get_names(Scope* scope, char** names, int max_names); void scope_print(Scope* scope, int indent); |