From acb1c33ab258dc14dcc51b405b44cc5923b34324 Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Fri, 18 Apr 2025 08:52:16 +0000
Subject: [PATCH] add function call

---
 src/Interpreter/Interpreter.hpp |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/Interpreter/Interpreter.hpp b/src/Interpreter/Interpreter.hpp
index b8e2ce8..fe1dfb7 100644
--- a/src/Interpreter/Interpreter.hpp
+++ b/src/Interpreter/Interpreter.hpp
@@ -12,6 +12,22 @@
 
 class Interpreter {
   private:
+
+
+  public:
+    Interpreter() {}
+
+    /**
+     * @brief Execute all operations in the current namespace (e.g., file-level or function-level).
+     */
+    void run() {
+        // Determine namespace to execute
+        const std::string ns = Symbols::SymbolContainer::instance()->currentScopeName();
+        for (const auto & operation : Operations::Container::instance()->getAll(ns)) {
+            runOperation(*operation);
+        }
+    }
+
     void runOperation(const Operations::Operation & op) {
         std::cout << "Operation: " << op.toString() << "\n";
 
@@ -39,13 +55,11 @@
                     break;
                 }
 
-            case Operations::Type::FunctionCall: {
-                // Check that the called function is defined in the symbol table
-                if (!Symbols::SymbolContainer::instance()->exists(op.targetName)) {
-                    throw std::runtime_error("Function not declared: " + op.targetName);
+            case Operations::Type::FunctionCall:
+                if (op.statement) {
+                    op.statement->interpret(*this);
                 }
                 break;
-            }
             case Operations::Type::Return:
             case Operations::Type::Loop:
             case Operations::Type::Break:
@@ -58,15 +72,6 @@
                 break;
             default:
                 throw std::runtime_error("Not implemented operation type");
-        }
-    }
-
-  public:
-    Interpreter() {}
-
-    void run() {
-        for (const auto & operation : Operations::Container::instance()->getAll()) {
-            runOperation(*operation);
         }
     }
 

--
Gitblit v1.9.3