diff options
Diffstat (limited to 'js/scripting-lang/baba-yaga-c/src/interpreter.c')
-rw-r--r-- | js/scripting-lang/baba-yaga-c/src/interpreter.c | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/js/scripting-lang/baba-yaga-c/src/interpreter.c b/js/scripting-lang/baba-yaga-c/src/interpreter.c index 58535f5..f865adb 100644 --- a/js/scripting-lang/baba-yaga-c/src/interpreter.c +++ b/js/scripting-lang/baba-yaga-c/src/interpreter.c @@ -74,7 +74,7 @@ static void register_stdlib(Scope* scope) { DEBUG_INFO("Registering standard library functions"); /* Core combinator */ - Value apply_func = baba_yaga_value_function("apply", stdlib_apply, 10, 1); + Value apply_func = baba_yaga_value_function("apply", stdlib_apply_wrapper, 10, 1); scope_define(scope, "apply", apply_func, true); /* Predefined variables for testing */ @@ -82,90 +82,90 @@ static void register_stdlib(Scope* scope) { scope_define(scope, "hello", hello_var, true); /* Arithmetic functions */ - Value add_func = baba_yaga_value_function("add", stdlib_add, 2, 2); + Value add_func = baba_yaga_value_function("add", stdlib_add_wrapper, 2, 2); scope_define(scope, "add", add_func, true); - Value subtract_func = baba_yaga_value_function("subtract", stdlib_subtract, 2, 2); + Value subtract_func = baba_yaga_value_function("subtract", stdlib_subtract_wrapper, 2, 2); scope_define(scope, "subtract", subtract_func, true); - Value multiply_func = baba_yaga_value_function("multiply", stdlib_multiply, 2, 2); + Value multiply_func = baba_yaga_value_function("multiply", stdlib_multiply_wrapper, 2, 2); scope_define(scope, "multiply", multiply_func, true); - Value divide_func = baba_yaga_value_function("divide", stdlib_divide, 2, 2); + Value divide_func = baba_yaga_value_function("divide", stdlib_divide_wrapper, 2, 2); scope_define(scope, "divide", divide_func, true); - Value modulo_func = baba_yaga_value_function("modulo", stdlib_modulo, 2, 2); + Value modulo_func = baba_yaga_value_function("modulo", stdlib_modulo_wrapper, 2, 2); scope_define(scope, "modulo", modulo_func, true); - Value pow_func = baba_yaga_value_function("pow", stdlib_pow, 2, 2); + Value pow_func = baba_yaga_value_function("pow", stdlib_pow_wrapper, 2, 2); scope_define(scope, "pow", pow_func, true); - Value negate_func = baba_yaga_value_function("negate", stdlib_negate, 1, 1); + Value negate_func = baba_yaga_value_function("negate", stdlib_negate_wrapper, 1, 1); scope_define(scope, "negate", negate_func, true); /* Comparison functions */ - Value equals_func = baba_yaga_value_function("equals", stdlib_equals, 2, 2); + Value equals_func = baba_yaga_value_function("equals", stdlib_equals_wrapper, 2, 2); scope_define(scope, "equals", equals_func, true); - Value not_equals_func = baba_yaga_value_function("not_equals", stdlib_not_equals, 2, 2); + Value not_equals_func = baba_yaga_value_function("not_equals", stdlib_not_equals_wrapper, 2, 2); scope_define(scope, "not_equals", not_equals_func, true); - Value less_func = baba_yaga_value_function("less", stdlib_less, 2, 2); + Value less_func = baba_yaga_value_function("less", stdlib_less_wrapper, 2, 2); scope_define(scope, "less", less_func, true); - Value less_equal_func = baba_yaga_value_function("less_equal", stdlib_less_equal, 2, 2); + Value less_equal_func = baba_yaga_value_function("less_equal", stdlib_less_equal_wrapper, 2, 2); scope_define(scope, "less_equal", less_equal_func, true); - Value greater_func = baba_yaga_value_function("greater", stdlib_greater, 2, 2); + Value greater_func = baba_yaga_value_function("greater", stdlib_greater_wrapper, 2, 2); scope_define(scope, "greater", greater_func, true); - Value greater_equal_func = baba_yaga_value_function("greater_equal", stdlib_greater_equal, 2, 2); + Value greater_equal_func = baba_yaga_value_function("greater_equal", stdlib_greater_equal_wrapper, 2, 2); scope_define(scope, "greater_equal", greater_equal_func, true); /* Add canonical names for JavaScript compatibility */ - Value greater_than_func = baba_yaga_value_function("greaterThan", stdlib_greater, 2, 2); + Value greater_than_func = baba_yaga_value_function("greaterThan", stdlib_greater_wrapper, 2, 2); scope_define(scope, "greaterThan", greater_than_func, true); - Value less_than_func = baba_yaga_value_function("lessThan", stdlib_less, 2, 2); + Value less_than_func = baba_yaga_value_function("lessThan", stdlib_less_wrapper, 2, 2); scope_define(scope, "lessThan", less_than_func, true); - Value greater_equal_than_func = baba_yaga_value_function("greaterEqual", stdlib_greater_equal, 2, 2); + Value greater_equal_than_func = baba_yaga_value_function("greaterEqual", stdlib_greater_equal_wrapper, 2, 2); scope_define(scope, "greaterEqual", greater_equal_than_func, true); - Value less_equal_than_func = baba_yaga_value_function("lessEqual", stdlib_less_equal, 2, 2); + Value less_equal_than_func = baba_yaga_value_function("lessEqual", stdlib_less_equal_wrapper, 2, 2); scope_define(scope, "lessEqual", less_equal_than_func, true); /* Logical functions */ - Value and_func = baba_yaga_value_function("and", stdlib_and, 2, 2); + Value and_func = baba_yaga_value_function("and", stdlib_and_wrapper, 2, 2); scope_define(scope, "and", and_func, true); - Value or_func = baba_yaga_value_function("or", stdlib_or, 2, 2); + Value or_func = baba_yaga_value_function("or", stdlib_or_wrapper, 2, 2); scope_define(scope, "or", or_func, true); - Value xor_func = baba_yaga_value_function("xor", stdlib_xor, 2, 2); + Value xor_func = baba_yaga_value_function("xor", stdlib_xor_wrapper, 2, 2); scope_define(scope, "xor", xor_func, true); - Value not_func = baba_yaga_value_function("not", stdlib_not, 1, 1); + Value not_func = baba_yaga_value_function("not", stdlib_not_wrapper, 1, 1); scope_define(scope, "not", not_func, true); /* Function composition */ - Value compose_func = baba_yaga_value_function("compose", stdlib_compose, 4, 2); + Value compose_func = baba_yaga_value_function("compose", stdlib_compose_wrapper, 4, 2); scope_define(scope, "compose", compose_func, true); /* IO functions */ - Value out_func = baba_yaga_value_function("out", stdlib_out, 1, 1); + Value out_func = baba_yaga_value_function("out", stdlib_out_wrapper, 1, 1); scope_define(scope, "out", out_func, true); - Value in_func = baba_yaga_value_function("in", stdlib_in, 0, 0); + Value in_func = baba_yaga_value_function("in", stdlib_in_wrapper, 0, 0); scope_define(scope, "in", in_func, true); - Value assert_func = baba_yaga_value_function("assert", stdlib_assert, 1, 1); + Value assert_func = baba_yaga_value_function("assert", stdlib_assert_wrapper, 1, 1); scope_define(scope, "assert", assert_func, true); - Value emit_func = baba_yaga_value_function("emit", stdlib_emit, 1, 1); + Value emit_func = baba_yaga_value_function("emit", stdlib_emit_wrapper, 1, 1); scope_define(scope, "emit", emit_func, true); - Value listen_func = baba_yaga_value_function("listen", stdlib_listen, 0, 0); + Value listen_func = baba_yaga_value_function("listen", stdlib_listen_wrapper, 0, 0); scope_define(scope, "listen", listen_func, true); /* Higher-order functions */ @@ -179,45 +179,45 @@ static void register_stdlib(Scope* scope) { scope_define(scope, "reduce", reduce_func, true); /* Advanced combinators */ - Value each_func = baba_yaga_value_function("each", stdlib_each, 3, 2); + Value each_func = baba_yaga_value_function("each", stdlib_each, 3, 3); scope_define(scope, "each", each_func, true); - Value flip_func = baba_yaga_value_function("flip", stdlib_flip, 3, 1); + Value flip_func = baba_yaga_value_function("flip", stdlib_flip_wrapper, 3, 1); scope_define(scope, "flip", flip_func, true); - Value constant_func = baba_yaga_value_function("constant", stdlib_constant, 2, 1); + Value constant_func = baba_yaga_value_function("constant", stdlib_constant_wrapper, 2, 1); scope_define(scope, "constant", constant_func, true); /* Table operations namespace */ - Value t_map_func = baba_yaga_value_function("t.map", stdlib_t_map, 2, 2); + Value t_map_func = baba_yaga_value_function("t.map", stdlib_t_map_wrapper, 2, 2); scope_define(scope, "t.map", t_map_func, true); - Value t_filter_func = baba_yaga_value_function("t.filter", stdlib_t_filter, 2, 2); + Value t_filter_func = baba_yaga_value_function("t.filter", stdlib_t_filter_wrapper, 2, 2); scope_define(scope, "t.filter", t_filter_func, true); - Value t_reduce_func = baba_yaga_value_function("t.reduce", stdlib_t_reduce, 3, 3); + Value t_reduce_func = baba_yaga_value_function("t.reduce", stdlib_t_reduce_wrapper, 3, 3); scope_define(scope, "t.reduce", t_reduce_func, true); - Value t_set_func = baba_yaga_value_function("t.set", stdlib_t_set, 3, 3); + Value t_set_func = baba_yaga_value_function("t.set", stdlib_t_set_wrapper, 3, 3); scope_define(scope, "t.set", t_set_func, true); - Value t_delete_func = baba_yaga_value_function("t.delete", stdlib_t_delete, 2, 2); + Value t_delete_func = baba_yaga_value_function("t.delete", stdlib_t_delete_wrapper, 2, 2); scope_define(scope, "t.delete", t_delete_func, true); - Value t_merge_func = baba_yaga_value_function("t.merge", stdlib_t_merge, 2, 2); + Value t_merge_func = baba_yaga_value_function("t.merge", stdlib_t_merge_wrapper, 2, 2); scope_define(scope, "t.merge", t_merge_func, true); - Value t_length_func = baba_yaga_value_function("t.length", stdlib_t_length, 1, 1); + Value t_length_func = baba_yaga_value_function("t.length", stdlib_t_length_wrapper, 1, 1); scope_define(scope, "t.length", t_length_func, true); - Value t_has_func = baba_yaga_value_function("t.has", stdlib_t_has, 2, 2); + Value t_has_func = baba_yaga_value_function("t.has", stdlib_t_has_wrapper, 2, 2); scope_define(scope, "t.has", t_has_func, true); - Value t_get_func = baba_yaga_value_function("t.get", stdlib_t_get, 3, 3); + Value t_get_func = baba_yaga_value_function("t.get", stdlib_t_get_wrapper, 3, 3); scope_define(scope, "t.get", t_get_func, true); /* Internal table entry function for key-value pairs */ - Value table_entry_func = baba_yaga_value_function("table_entry", stdlib_table_entry, 2, 2); + Value table_entry_func = baba_yaga_value_function("table_entry", stdlib_table_entry_wrapper, 2, 2); scope_define(scope, "table_entry", table_entry_func, true); /* Create t namespace table */ @@ -686,6 +686,9 @@ Value interpreter_evaluate_expression(void* node, Scope* scope) { strcmp(pattern_test_value.data.string, "_") == 0) { /* Wildcard pattern always matches */ matches = true; + } else if (pattern_test_value.type == VAL_NIL && test_value.type == VAL_NIL) { + /* Both are nil - match */ + matches = true; } else if (pattern_test_value.type == VAL_TABLE && test_value.type == VAL_TABLE) { /* Table pattern matching: check if all pattern properties exist and match */ matches = true; |