about summary refs log tree commit diff stats
path: root/js/scripting-lang/baba-yaga-c/src/scope.c
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/baba-yaga-c/src/scope.c')
-rw-r--r--js/scripting-lang/baba-yaga-c/src/scope.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/js/scripting-lang/baba-yaga-c/src/scope.c b/js/scripting-lang/baba-yaga-c/src/scope.c
index d546989..93ba957 100644
--- a/js/scripting-lang/baba-yaga-c/src/scope.c
+++ b/js/scripting-lang/baba-yaga-c/src/scope.c
@@ -89,6 +89,25 @@ void scope_destroy(Scope* scope) {
 }
 
 /**
+ * @brief Get the global scope (root scope with no parent)
+ * 
+ * @param scope Starting scope
+ * @return Global scope, or NULL if not found
+ */
+Scope* scope_get_global(Scope* scope) {
+    if (scope == NULL) {
+        return NULL;
+    }
+    
+    /* Traverse up the scope chain until we find a scope with no parent */
+    while (scope->parent != NULL) {
+        scope = scope->parent;
+    }
+    
+    return scope;
+}
+
+/**
  * @brief Find an entry in the scope chain
  * 
  * @param scope Starting scope
@@ -123,9 +142,11 @@ Value scope_get(Scope* scope, const char* name) {
     
     ScopeEntry* entry = scope_find_entry(scope, name);
     if (entry == NULL) {
+        DEBUG_DEBUG("scope_get: variable '%s' not found in scope", name);
         return baba_yaga_value_nil();
     }
     
+    DEBUG_DEBUG("scope_get: found variable '%s' in scope with type %d", name, entry->value.type);
     /* Return a copy of the value */
     return baba_yaga_value_copy(&entry->value);
 }
@@ -218,6 +239,8 @@ bool scope_define(Scope* scope, const char* name, Value value, bool is_constant)
     scope->entries = entry;
     scope->entry_count++;
     
+    DEBUG_DEBUG("scope_define: defined variable '%s' in scope with type %d", name, entry->value.type);
+    
     return true;
 }