about summary refs log tree commit diff stats
path: root/js/scripting-lang/baba-yaga-c/src/function.c
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-08-02 09:24:48 -0400
committerelioat <elioat@tilde.institute>2025-08-02 09:24:48 -0400
commit883b42c8e5b3a28a2bda0c554c68b7a556e0e989 (patch)
treeeb6ca2ced4cdc537a7ed384b1d6967bb37cb332e /js/scripting-lang/baba-yaga-c/src/function.c
parent5f99dfea8a4c2a95e3ea5008216823c7dcb43e73 (diff)
downloadtour-master.tar.gz
Diffstat (limited to 'js/scripting-lang/baba-yaga-c/src/function.c')
-rw-r--r--js/scripting-lang/baba-yaga-c/src/function.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/js/scripting-lang/baba-yaga-c/src/function.c b/js/scripting-lang/baba-yaga-c/src/function.c
index 57910cc..2eca14d 100644
--- a/js/scripting-lang/baba-yaga-c/src/function.c
+++ b/js/scripting-lang/baba-yaga-c/src/function.c
@@ -46,6 +46,8 @@ typedef struct {
     char* source;       /**< Source code for debugging */
 } FunctionBody;
 
+
+
 /**
  * @brief Function value structure
  */
@@ -56,7 +58,7 @@ typedef struct {
     int param_count;            /**< Number of parameters */
     int required_params;        /**< Number of required parameters */
     union {
-        Value (*native_func)(Value*, int);  /**< Native function pointer */
+        Value (*native_func)(Value*, int, Scope*);  /**< Native function pointer */
         FunctionBody user_body;             /**< User function body */
     } body;
     void* closure_scope;        /**< Closure scope (placeholder) */
@@ -86,7 +88,9 @@ static void function_body_destroy(FunctionBody* body) {
  * Public Function API
  * ============================================================================ */
 
-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) {
     Value value;
     value.type = VAL_FUNCTION;
@@ -140,7 +144,9 @@ Value baba_yaga_function_call(const Value* func, const Value* args,
     
     FunctionValue* func_value = (FunctionValue*)func->data.function;
     
-    /* Check if we have enough arguments */
+
+    
+    /* Check if we have enough arguments for partial application */
     if (arg_count < func_value->required_params) {
         /* TODO: Implement partial application */
         /* For now, return a new function with fewer required parameters */
@@ -151,7 +157,7 @@ Value baba_yaga_function_call(const Value* func, const Value* args,
     switch (func_value->type) {
     case FUNC_NATIVE:
         if (func_value->body.native_func != NULL) {
-            return func_value->body.native_func((Value*)args, arg_count);
+            return func_value->body.native_func((Value*)args, arg_count, scope);
         }
         break;
         
@@ -187,6 +193,8 @@ Value baba_yaga_function_call(const Value* func, const Value* args,
             return result;
         }
         break;
+        
+
     }
     
     return baba_yaga_value_nil();
@@ -231,9 +239,9 @@ void function_decrement_ref(Value* func) {
             }
             
                     /* Clean up function body */
-        if (func_value->type == FUNC_USER) {
-            function_body_destroy(&func_value->body.user_body);
-        }
+            if (func_value->type == FUNC_USER) {
+                function_body_destroy(&func_value->body.user_body);
+            }
             
             /* TODO: Clean up closure scope */