Skip to content

Restore block restart #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core-lib
Submodule core-lib updated 1 files
+72 −20 TestSuite/BlockTest.som
8 changes: 8 additions & 0 deletions src/interpreter/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
THE SOFTWARE.
*/

#include <assert.h>

#include "../misc/defs.h"
#include "../vmobjects/ObjectFormats.h"
#include "../vmobjects/VMFrame.h"
Expand Down Expand Up @@ -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();

Expand Down
13 changes: 13 additions & 0 deletions src/primitives/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/primitives/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@

class _Block : public PrimitiveContainer {
public:
_Block() = default;
_Block();
};
2 changes: 1 addition & 1 deletion src/primitives/Method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VMArray*>(frame->Pop());
auto* rcvr = frame->Pop();
auto* mthd = static_cast<VMMethod*>(frame->Pop());
Expand Down
2 changes: 0 additions & 2 deletions src/primitives/Method.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
class _Method : public PrimitiveContainer {
public:
_Method();

void InvokeOn_With_(VMFrame*);
};
2 changes: 1 addition & 1 deletion src/primitives/Primitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VMArray*>(frame->Pop());
auto* rcvr = frame->Pop();
auto* mthd = static_cast<VMInvokable*>(frame->Pop());
Expand Down
2 changes: 0 additions & 2 deletions src/primitives/Primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
class _Primitive : public PrimitiveContainer {
public:
_Primitive();

void InvokeOn_With_(VMFrame*);
};
6 changes: 6 additions & 0 deletions src/vmobjects/VMFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <string>

#include "../compiler/Disassembler.h"
#include "../interpreter/Interpreter.h"
#include "../memory/Heap.h"
#include "../misc/defs.h"
#include "../vm/Globals.h"
Expand Down Expand Up @@ -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);
}
12 changes: 10 additions & 2 deletions src/vmobjects/VMFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
Expand Down