From 5fe61462a244e5a919a79740d28483dc9e047660 Mon Sep 17 00:00:00 2001 From: Sahil Jain Date: Mon, 30 Jun 2025 23:58:54 +0530 Subject: [PATCH] Support COPY opcde --- ASTree.cpp | 6 ++++++ FastStack.h | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ASTree.cpp b/ASTree.cpp index 281d224..851f735 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -2540,6 +2540,12 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) curblock->append(new ASTStore(values, new ASTSubscr(dest, slice))); } break; + case Pyc::COPY_A: + { + PycRef value = stack.top(operand); + stack.push(value); + } + break; default: fprintf(stderr, "Unsupported opcode: %s (%d)\n", Pyc::OpcodeName(opcode), opcode); cleanBuild = false; diff --git a/FastStack.h b/FastStack.h index 45f8ed5..d8fb08b 100644 --- a/FastStack.h +++ b/FastStack.h @@ -32,11 +32,21 @@ public: m_stack[m_ptr--] = nullptr; } - PycRef top() const + PycRef top(int i = 1) const { - if (m_ptr > -1) - return m_stack[m_ptr]; - else + if (i > 0) { + int idx = m_ptr + 1 - i; + if ((m_ptr > -1) && (idx >= 0)) + return m_stack[idx]; + else { + #ifdef BLOCK_DEBUG + fprintf(stderr, "insufficient values on stack\n"); + #endif + return nullptr; + } + } + else { + fprintf(stderr, "incorrect operand %i\n", i); return nullptr; }