From a69e178823873ef28940aaad4901a7b29781db50 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Fri, 9 May 2025 21:42:13 +0100 Subject: [PATCH 1/3] Restore the implementation of the restart primitive on Block This needs to update the global bytecode index. I chose to do this in the reset primitive explicitly, and do not generalize this by updating the bytecode index on every primitive, to avoid overhead. Signed-off-by: Stefan Marr --- src/interpreter/Interpreter.h | 8 ++++++++ src/primitives/Block.cpp | 13 +++++++++++++ src/primitives/Block.h | 2 +- src/vmobjects/VMFrame.cpp | 6 ++++++ src/vmobjects/VMFrame.h | 8 ++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/interpreter/Interpreter.h b/src/interpreter/Interpreter.h index 52072317..7262da5c 100644 --- a/src/interpreter/Interpreter.h +++ b/src/interpreter/Interpreter.h @@ -26,6 +26,8 @@ THE SOFTWARE. */ +#include + #include "../misc/defs.h" #include "../vmobjects/ObjectFormats.h" #include "../vmobjects/VMFrame.h" @@ -62,6 +64,12 @@ class Interpreter { static inline size_t GetBytecodeIndex() { return bytecodeIndexGlobal; } + static void ResetBytecodeIndex(VMFrame* forFrame) { + assert(frame == forFrame); + assert(forFrame != nullptr); + bytecodeIndexGlobal = 0; + } + private: static vm_oop_t GetSelf(); diff --git a/src/primitives/Block.cpp b/src/primitives/Block.cpp index 733525e0..6a46928c 100644 --- a/src/primitives/Block.cpp +++ b/src/primitives/Block.cpp @@ -23,3 +23,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#include "Block.h" + +#include "../vmobjects/VMFrame.h" + +static void bRestart(VMFrame* frame) { + frame->ResetBytecodeIndex(); + frame->ResetStackPointer(); +} + +_Block::_Block() { + Add("restart", &bRestart, false); +} diff --git a/src/primitives/Block.h b/src/primitives/Block.h index 25cc73dc..3833f456 100644 --- a/src/primitives/Block.h +++ b/src/primitives/Block.h @@ -31,5 +31,5 @@ class _Block : public PrimitiveContainer { public: - _Block() = default; + _Block(); }; diff --git a/src/vmobjects/VMFrame.cpp b/src/vmobjects/VMFrame.cpp index 83707048..5989a1fa 100644 --- a/src/vmobjects/VMFrame.cpp +++ b/src/vmobjects/VMFrame.cpp @@ -32,6 +32,7 @@ #include #include "../compiler/Disassembler.h" +#include "../interpreter/Interpreter.h" #include "../memory/Heap.h" #include "../misc/defs.h" #include "../vm/Globals.h" @@ -256,3 +257,8 @@ void VMFrame::CopyArgumentsFrom(VMFrame* frame) { std::string VMFrame::AsDebugString() const { return "VMFrame(" + GetMethod()->AsDebugString() + ")"; } + +void VMFrame::ResetBytecodeIndex() { + bytecodeIndex = 0; + Interpreter::ResetBytecodeIndex(this); +} diff --git a/src/vmobjects/VMFrame.h b/src/vmobjects/VMFrame.h index ff03b05c..e54ce472 100644 --- a/src/vmobjects/VMFrame.h +++ b/src/vmobjects/VMFrame.h @@ -181,6 +181,14 @@ class VMFrame : public AbstractVMObject { size_t bytecodeIndex{0}; size_t totalObjectSize; + void ResetStackPointer() { + VMMethod* meth = GetMethod(); + // Set the stack pointer to its initial value thereby clearing the stack + stack_ptr = locals + meth->GetNumberOfLocals() - 1; + } + + void ResetBytecodeIndex(); + private: GCFrame* previousFrame; GCFrame* context{nullptr}; From 5a19c9208af439d0af8ab8a36d93f08935e10150 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Fri, 9 May 2025 21:42:29 +0100 Subject: [PATCH 2/3] Remove dead code, update outdated comment, fix spelling Signed-off-by: Stefan Marr --- src/primitives/Method.cpp | 2 +- src/primitives/Method.h | 2 -- src/primitives/Primitive.cpp | 2 +- src/primitives/Primitive.h | 2 -- src/vmobjects/VMFrame.h | 4 ++-- 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/primitives/Method.cpp b/src/primitives/Method.cpp index df781ec8..c2ecfc83 100644 --- a/src/primitives/Method.cpp +++ b/src/primitives/Method.cpp @@ -20,7 +20,7 @@ static vm_oop_t mSignature(vm_oop_t rcvr) { } static void mInvokeOnWith(VMFrame* frame) { - // REM: this is a clone with _Primitive::InvokeOn_With_ + // REM: this is a clone with _Primitive pInvokeOnWith auto* args = static_cast(frame->Pop()); auto* rcvr = frame->Pop(); auto* mthd = static_cast(frame->Pop()); diff --git a/src/primitives/Method.h b/src/primitives/Method.h index f275a84b..9a1d42ed 100644 --- a/src/primitives/Method.h +++ b/src/primitives/Method.h @@ -6,6 +6,4 @@ class _Method : public PrimitiveContainer { public: _Method(); - - void InvokeOn_With_(VMFrame*); }; diff --git a/src/primitives/Primitive.cpp b/src/primitives/Primitive.cpp index f6887f25..c10a9cda 100644 --- a/src/primitives/Primitive.cpp +++ b/src/primitives/Primitive.cpp @@ -18,7 +18,7 @@ static vm_oop_t pSignature(vm_oop_t rcvr) { } static void pInvokeOnWith(VMFrame* frame) { - // REM: this is a clone with _Primitive::InvokeOn_With_ + // REM: this is a clone with _Method mInvokeOnWith auto* args = static_cast(frame->Pop()); auto* rcvr = frame->Pop(); auto* mthd = static_cast(frame->Pop()); diff --git a/src/primitives/Primitive.h b/src/primitives/Primitive.h index 944aed98..3b23d543 100644 --- a/src/primitives/Primitive.h +++ b/src/primitives/Primitive.h @@ -6,6 +6,4 @@ class _Primitive : public PrimitiveContainer { public: _Primitive(); - - void InvokeOn_With_(VMFrame*); }; diff --git a/src/vmobjects/VMFrame.h b/src/vmobjects/VMFrame.h index e54ce472..00e03e74 100644 --- a/src/vmobjects/VMFrame.h +++ b/src/vmobjects/VMFrame.h @@ -52,8 +52,8 @@ class VMFrame : public AbstractVMObject { arguments((gc_oop_t*)&(stack_ptr) + 1), locals(arguments + method->GetNumberOfArguments()), stack_ptr(locals + method->GetNumberOfLocals() - 1) { - // initilize all other fields. Don't need to initalize arguments, - // because they iwll be copied in still + // initialize all other fields. Don't need to initialize arguments, + // because they will be copied in still // --> until end of Frame auto* end = (gc_oop_t*)SHIFTED_PTR(this, totalObjectSize); size_t i = 0; From dccfabcdc0acf709095b3ffa5e13622661585afe Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Fri, 9 May 2025 23:10:56 +0100 Subject: [PATCH 3/3] Update core-lib Signed-off-by: Stefan Marr --- core-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-lib b/core-lib index 1daeec77..22bfeb10 160000 --- a/core-lib +++ b/core-lib @@ -1 +1 @@ -Subproject commit 1daeec77f16e0bf5ed119466fa91cf24e17b9cde +Subproject commit 22bfeb10df0e8e53300cfe18d8eeee3de02ecfdf