From d14935dd5375f0ca6bf4008f6ea2e503bc13a560 Mon Sep 17 00:00:00 2001 From: Anthony Rabine Date: Tue, 28 Oct 2025 00:57:30 +0100 Subject: [PATCH] Multiple compiler and node fixes --- .../compiler/assembly_generator_chip32_tac.h | 5 +++-- core/story-manager/src/compiler/tac.h | 12 +++++++++++- core/story-manager/src/nodes/operator_node.h | 17 ++++++++++++++++- .../src/node_editor/branch_node_widget.cpp | 1 + .../src/node_editor/for_loop_node_widget.cpp | 1 + .../src/node_editor/operator_node_widget.cpp | 1 + 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/core/story-manager/src/compiler/assembly_generator_chip32_tac.h b/core/story-manager/src/compiler/assembly_generator_chip32_tac.h index e1ae0a9..b177278 100644 --- a/core/story-manager/src/compiler/assembly_generator_chip32_tac.h +++ b/core/story-manager/src/compiler/assembly_generator_chip32_tac.h @@ -548,8 +548,9 @@ private: m_functionCallParamIndex++; } else { // C'est pour un syscall (Print, etc.) → empiler sur la stack - std::string paramReg = LoadOperand(instr->GetDest(), "r0"); - m_assembly << " push " << paramReg << "\n"; + // std::string paramReg = LoadOperand(instr->GetDest(), "r0"); + // m_assembly << " push " << paramReg << "\n"; + m_printParams.push_back(instr->GetDest()); } } diff --git a/core/story-manager/src/compiler/tac.h b/core/story-manager/src/compiler/tac.h index 16a16fd..9ebd76f 100644 --- a/core/story-manager/src/compiler/tac.h +++ b/core/story-manager/src/compiler/tac.h @@ -430,6 +430,8 @@ private: std::shared_ptr m_currentFunction; + bool m_insideLoop = false; + // =================================================================== // HELPERS // =================================================================== @@ -683,6 +685,12 @@ private: // Génération pour FunctionExitNode std::shared_ptr GenerateFunctionExitNode(std::shared_ptr node) { + + if (m_insideLoop) { + std::cout << " Skipping FunctionExitNode (inside loop)\n"; + return nullptr; + } + auto* exitNode = node->GetAs(); if (!exitNode) return nullptr; @@ -709,7 +717,7 @@ private: nullptr )); - std::cout << " Return value: " << returnValue.name << "\n"; + std::cout << " Return value: " << returnValue.name << "\n"; } portIndex++; } @@ -911,8 +919,10 @@ private: // === 5. CORPS DE LA BOUCLE - CORRECTION === // Générer toute la chaîne d'exécution (pas juste le premier enfant) if (node->GetChild(0)) { + m_insideLoop = true; // ← Marquer qu'on est dans une boucle std::cout << " Generating loop body execution chain...\n"; GenerateExecutionChain(node->GetChild(0)); + m_insideLoop = false; } // === 6. LABEL loop_continue (pour Continue) === diff --git a/core/story-manager/src/nodes/operator_node.h b/core/story-manager/src/nodes/operator_node.h index 34a4ac0..afb4d03 100644 --- a/core/story-manager/src/nodes/operator_node.h +++ b/core/story-manager/src/nodes/operator_node.h @@ -70,11 +70,14 @@ public: : BaseNode(type, typeName, BaseNode::Behavior::BEHAVIOR_DATA) , m_operationType(OperationType::ADD) { - Initialize(); + } void Initialize() override { // Define input ports based on operator type + nlohmann::json j = GetInternalData(); + std::string typeName = JsonReader::get(j, "operation_type", "Equal to"); + m_operationType = TypeNameToOperationType(typeName); UpdatePorts(); } @@ -82,6 +85,7 @@ public: void SetOperationType(OperationType type) { m_operationType = type; UpdatePorts(); + SetInternalData({"operation_type", OperatorTypeName(m_operationType)}); } OperationType GetOperationType() const { @@ -135,4 +139,15 @@ private: } return OperationType::ADD; // Default to ADD if not found } + + OperationType TypeNameToOperationType(const std::string& str) const { + auto symbolMap = GetOperators(); + + for (const auto& pair : symbolMap) { + if (pair.second.name == str) { + return pair.first; + } + } + return OperationType::ADD; // Default to ADD if not found + } }; diff --git a/story-editor/src/node_editor/branch_node_widget.cpp b/story-editor/src/node_editor/branch_node_widget.cpp index 12b9d1f..918af9a 100644 --- a/story-editor/src/node_editor/branch_node_widget.cpp +++ b/story-editor/src/node_editor/branch_node_widget.cpp @@ -8,6 +8,7 @@ BranchNodeWidget::BranchNodeWidget(IStoryManager &manager, std::shared_ptr(node); + SetTitle("Branch"); } void BranchNodeWidget::Initialize() diff --git a/story-editor/src/node_editor/for_loop_node_widget.cpp b/story-editor/src/node_editor/for_loop_node_widget.cpp index 47b4063..4102ae5 100644 --- a/story-editor/src/node_editor/for_loop_node_widget.cpp +++ b/story-editor/src/node_editor/for_loop_node_widget.cpp @@ -7,6 +7,7 @@ ForLoopNodeWidget::ForLoopNodeWidget(IStoryManager &manager, std::shared_ptr(base); + SetTitle("For loop"); } void ForLoopNodeWidget::Draw() diff --git a/story-editor/src/node_editor/operator_node_widget.cpp b/story-editor/src/node_editor/operator_node_widget.cpp index 3aa2d85..70b5904 100644 --- a/story-editor/src/node_editor/operator_node_widget.cpp +++ b/story-editor/src/node_editor/operator_node_widget.cpp @@ -11,6 +11,7 @@ OperatorNodeWidget::OperatorNodeWidget(IStoryManager &manager, std::shared_ptr(node); + SetTitle("Operator"); } void OperatorNodeWidget::Initialize()