diff --git a/src/unitTests/CloneObjectsTest.cpp b/src/unitTests/CloneObjectsTest.cpp index 9fdb713f..0bda61dd 100644 --- a/src/unitTests/CloneObjectsTest.cpp +++ b/src/unitTests/CloneObjectsTest.cpp @@ -192,9 +192,6 @@ void CloneObjectsTest::testCloneEvaluationPrimitive() { clone->signature); CPPUNIT_ASSERT_EQUAL_MESSAGE("holder differs!!", orig->holder, clone->holder); - CPPUNIT_ASSERT_EQUAL_MESSAGE("empty differs!!", orig->empty, clone->empty); - CPPUNIT_ASSERT_EQUAL_MESSAGE("routine differs!!", orig->routine, - clone->routine); CPPUNIT_ASSERT_EQUAL_MESSAGE("numberOfArguments differs!!", orig->numberOfArguments, clone->numberOfArguments); diff --git a/src/unitTests/WalkObjectsTest.cpp b/src/unitTests/WalkObjectsTest.cpp index bc2b10aa..4e007b38 100644 --- a/src/unitTests/WalkObjectsTest.cpp +++ b/src/unitTests/WalkObjectsTest.cpp @@ -42,7 +42,7 @@ static const size_t NoOfFields_Class = 4 + NoOfFields_Object; static const size_t NoOfFields_Frame = 3 + NoOfFields_Array; static const size_t NoOfFields_Block = 2 + NoOfFields_Object; static const size_t NoOfFields_Primitive = NoOfFields_Invokable; -static const size_t NoOfFields_EvaluationPrimitive = 1 + NoOfFields_Primitive; +static const size_t NoOfFields_EvaluationPrimitive = NoOfFields_Invokable; static vector walkedObjects; /* @@ -88,7 +88,6 @@ void WalkObjectsTest::testWalkEvaluationPrimitive() { CPPUNIT_ASSERT(WalkerHasFound(tmp_ptr(evPrim->GetSignature()))); CPPUNIT_ASSERT(WalkerHasFound(tmp_ptr(evPrim->GetHolder()))); - CPPUNIT_ASSERT(WalkerHasFound(tmp_ptr(evPrim))); CPPUNIT_ASSERT_EQUAL(NoOfFields_EvaluationPrimitive, walkedObjects.size()); } diff --git a/src/vm/Universe.cpp b/src/vm/Universe.cpp index 666b0b5d..dac70ef3 100644 --- a/src/vm/Universe.cpp +++ b/src/vm/Universe.cpp @@ -504,7 +504,7 @@ VMClass* Universe::GetBlockClassWithArgs(long numberOfArguments) { VMSymbol* name = SymbolFor(Str.str()); VMClass* result = LoadClassBasic(name, nullptr); - result->AddInstancePrimitive(new (GetHeap(), 0) + result->AddInstanceInvokable(new (GetHeap(), 0) VMEvaluationPrimitive(numberOfArguments)); SetGlobal(name, result); diff --git a/src/vmobjects/ObjectFormats.h b/src/vmobjects/ObjectFormats.h index 1771e2a3..ae5d72ad 100644 --- a/src/vmobjects/ObjectFormats.h +++ b/src/vmobjects/ObjectFormats.h @@ -145,7 +145,7 @@ class GCInteger : public GCAbstractObject { public: typedef VMInteger class GCInvokable : public GCAbstractObject { public: typedef VMInvokable Loaded; }; class GCMethod : public GCInvokable { public: typedef VMMethod Loaded; }; class GCPrimitive : public GCInvokable { public: typedef VMPrimitive Loaded; }; -class GCEvaluationPrimitive : public GCPrimitive { public: typedef VMEvaluationPrimitive Loaded; }; +class GCEvaluationPrimitive : public GCInvokable { public: typedef VMEvaluationPrimitive Loaded; }; class GCSafePrimitive : public GCInvokable { public: typedef VMSafePrimitive Loaded; }; class GCSafeUnaryPrimitive : public GCSafePrimitive { public: typedef VMSafeUnaryPrimitive Loaded; }; class GCSafeBinaryPrimitive : public GCSafePrimitive { public: typedef VMSafeBinaryPrimitive Loaded; }; diff --git a/src/vmobjects/VMClass.cpp b/src/vmobjects/VMClass.cpp index e7c2d8c5..c6f38e0c 100644 --- a/src/vmobjects/VMClass.cpp +++ b/src/vmobjects/VMClass.cpp @@ -40,7 +40,6 @@ #include "VMArray.h" #include "VMInvokable.h" #include "VMObject.h" -#include "VMPrimitive.h" #include "VMSymbol.h" const size_t VMClass::VMClassNumberOfFields = 4; @@ -96,13 +95,6 @@ bool VMClass::AddInstanceInvokable(VMInvokable* ptr) { return true; } -void VMClass::AddInstancePrimitive(VMPrimitive* ptr) { - if (AddInstanceInvokable(ptr)) { - // cout << "Warn: Primitive "<GetSignature<<" is not in class - // definition for class " << name->GetStdString() << endl; - } -} - VMSymbol* VMClass::GetInstanceFieldName(long index) const { long numSuperInstanceFields = numberOfSuperInstanceFields(); if (index >= numSuperInstanceFields) { diff --git a/src/vmobjects/VMClass.h b/src/vmobjects/VMClass.h index b29eeba3..1d63bb47 100644 --- a/src/vmobjects/VMClass.h +++ b/src/vmobjects/VMClass.h @@ -63,7 +63,6 @@ class VMClass : public VMObject { VMInvokable* LookupInvokable(VMSymbol*) const; long LookupFieldIndex(VMSymbol*) const; bool AddInstanceInvokable(VMInvokable*); - void AddInstancePrimitive(VMPrimitive*); VMSymbol* GetInstanceFieldName(long) const; size_t GetNumberOfInstanceFields() const; bool HasPrimitives() const; diff --git a/src/vmobjects/VMEvaluationPrimitive.cpp b/src/vmobjects/VMEvaluationPrimitive.cpp index 7ccdaf17..59c34ede 100644 --- a/src/vmobjects/VMEvaluationPrimitive.cpp +++ b/src/vmobjects/VMEvaluationPrimitive.cpp @@ -38,12 +38,11 @@ #include "ObjectFormats.h" #include "VMBlock.h" #include "VMFrame.h" -#include "VMPrimitive.h" #include "VMSymbol.h" VMEvaluationPrimitive::VMEvaluationPrimitive(size_t argc) - : VMPrimitive(computeSignatureString(argc)), numberOfArguments(argc) { - SetRoutine(new EvaluationRoutine(this), false); + : VMInvokable(computeSignatureString(argc)), numberOfArguments(argc) { + write_barrier(this, load_ptr(signature)); } VMEvaluationPrimitive* VMEvaluationPrimitive::CloneForMovingGC() const { @@ -53,8 +52,7 @@ VMEvaluationPrimitive* VMEvaluationPrimitive::CloneForMovingGC() const { } void VMEvaluationPrimitive::WalkObjects(walk_heap_fn walk) { - VMPrimitive::WalkObjects(walk); - static_cast(routine)->WalkObjects(walk); + VMInvokable::WalkObjects(walk); } VMSymbol* VMEvaluationPrimitive::computeSignatureString(long argc) { @@ -84,12 +82,10 @@ VMSymbol* VMEvaluationPrimitive::computeSignatureString(long argc) { return SymbolFor(signatureString); } -void EvaluationRoutine::Invoke(Interpreter* interp, VMFrame* frame) { - VMEvaluationPrimitive* prim = load_ptr(evalPrim); - +void VMEvaluationPrimitive::Invoke(Interpreter* interp, VMFrame* frame) { // Get the block (the receiver) from the stack - long numArgs = prim->GetNumberOfArguments(); - VMBlock* block = static_cast(frame->GetStackElement(numArgs - 1)); + VMBlock* block = + static_cast(frame->GetStackElement(numberOfArguments - 1)); // Get the context of the block... VMFrame* context = block->GetContext(); @@ -100,10 +96,6 @@ void EvaluationRoutine::Invoke(Interpreter* interp, VMFrame* frame) { NewFrame->SetContext(context); } -void EvaluationRoutine::WalkObjects(walk_heap_fn walk) { - evalPrim = static_cast(walk(evalPrim)); -} - std::string VMEvaluationPrimitive::AsDebugString() const { return "VMEvaluationPrimitive(" + to_string(numberOfArguments) + ")"; } @@ -111,7 +103,7 @@ std::string VMEvaluationPrimitive::AsDebugString() const { #define INVALID_INT_MARKER 9002002002002002002 void VMEvaluationPrimitive::MarkObjectAsInvalid() { - VMPrimitive::MarkObjectAsInvalid(); + VMInvokable::MarkObjectAsInvalid(); numberOfArguments = INVALID_INT_MARKER; } diff --git a/src/vmobjects/VMEvaluationPrimitive.h b/src/vmobjects/VMEvaluationPrimitive.h index 653a794d..86a934f1 100644 --- a/src/vmobjects/VMEvaluationPrimitive.h +++ b/src/vmobjects/VMEvaluationPrimitive.h @@ -28,7 +28,7 @@ #include "VMPrimitive.h" -class VMEvaluationPrimitive : public VMPrimitive { +class VMEvaluationPrimitive : public VMInvokable { public: typedef GCEvaluationPrimitive Stored; @@ -38,15 +38,17 @@ class VMEvaluationPrimitive : public VMPrimitive { StdString AsDebugString() const override; - int64_t GetNumberOfArguments() { return numberOfArguments; } - inline size_t GetObjectSize() const override { return sizeof(VMEvaluationPrimitive); } + VMClass* GetClass() const final { return load_ptr(primitiveClass); } + void MarkObjectAsInvalid() override; bool IsMarkedInvalid() const override; + void Invoke(Interpreter* interp, VMFrame* frm) override; + private: static VMSymbol* computeSignatureString(long argc); void evaluationRoutine(Interpreter*, VMFrame*); @@ -55,20 +57,3 @@ class VMEvaluationPrimitive : public VMPrimitive { size_t numberOfArguments; }; - -class EvaluationRoutine : public PrimitiveRoutine { -private: - GCEvaluationPrimitive* evalPrim; - -public: - EvaluationRoutine(VMEvaluationPrimitive* prim) - : PrimitiveRoutine(), - // the store without barrier is fine here, - // because it's a cyclic structure with `prim` itself, - // which will be store in another object, - // which will then have a barrier - evalPrim(store_with_separate_barrier(prim)) {}; - void WalkObjects(walk_heap_fn); - bool isClassSide() override { return false; } - void Invoke(Interpreter* interp, VMFrame* frame) override; -}; diff --git a/src/vmobjects/VMPrimitive.h b/src/vmobjects/VMPrimitive.h index 1badf432..6ea9c26c 100644 --- a/src/vmobjects/VMPrimitive.h +++ b/src/vmobjects/VMPrimitive.h @@ -38,7 +38,7 @@ class VMPrimitive : public VMInvokable { VMPrimitive(VMSymbol* sig); - VMClass* GetClass() const override { return load_ptr(primitiveClass); } + VMClass* GetClass() const final { return load_ptr(primitiveClass); } inline size_t GetObjectSize() const override { return sizeof(VMPrimitive); }