diff --git a/src/compiler/ClassGenerationContext.cpp b/src/compiler/ClassGenerationContext.cpp index d9cd9e48..0927c9b8 100644 --- a/src/compiler/ClassGenerationContext.cpp +++ b/src/compiler/ClassGenerationContext.cpp @@ -99,26 +99,25 @@ VMClass* ClassGenerationContext::Assemble() { std::string ccname = string(name->GetStdString()) + " class"; // Load the super class - VMClass* superClass = GetUniverse()->LoadClass(superName); + VMClass* superClass = Universe::LoadClass(superName); // Allocate the class of the resulting class - VMClass* resultClass = GetUniverse()->NewClass(load_ptr(metaClassClass)); + VMClass* resultClass = Universe::NewClass(load_ptr(metaClassClass)); // Initialize the class of the resulting class - resultClass->SetInstanceFields(GetUniverse()->NewArrayList(classFields)); - resultClass->SetInstanceInvokables( - GetUniverse()->NewArrayList(classMethods)); + resultClass->SetInstanceFields(Universe::NewArrayList(classFields)); + resultClass->SetInstanceInvokables(Universe::NewArrayList(classMethods)); resultClass->SetName(SymbolFor(ccname)); VMClass* superMClass = superClass->GetClass(); resultClass->SetSuperClass(superMClass); // Allocate the resulting class - VMClass* result = GetUniverse()->NewClass(resultClass); + VMClass* result = Universe::NewClass(resultClass); // Initialize the resulting class - result->SetInstanceFields(GetUniverse()->NewArrayList(instanceFields)); - result->SetInstanceInvokables(GetUniverse()->NewArrayList(instanceMethods)); + result->SetInstanceFields(Universe::NewArrayList(instanceFields)); + result->SetInstanceInvokables(Universe::NewArrayList(instanceMethods)); result->SetName(name); result->SetSuperClass(superClass); @@ -126,12 +125,10 @@ VMClass* ClassGenerationContext::Assemble() { } void ClassGenerationContext::AssembleSystemClass(VMClass* systemClass) { - systemClass->SetInstanceInvokables( - GetUniverse()->NewArrayList(instanceMethods)); - systemClass->SetInstanceFields(GetUniverse()->NewArrayList(instanceFields)); + systemClass->SetInstanceInvokables(Universe::NewArrayList(instanceMethods)); + systemClass->SetInstanceFields(Universe::NewArrayList(instanceFields)); // class-bound == class-instance-bound VMClass* superMClass = systemClass->GetClass(); - superMClass->SetInstanceInvokables( - GetUniverse()->NewArrayList(classMethods)); - superMClass->SetInstanceFields(GetUniverse()->NewArrayList(classFields)); + superMClass->SetInstanceInvokables(Universe::NewArrayList(classMethods)); + superMClass->SetInstanceFields(Universe::NewArrayList(classFields)); } diff --git a/src/compiler/Disassembler.cpp b/src/compiler/Disassembler.cpp index 010a8006..f53c478c 100644 --- a/src/compiler/Disassembler.cpp +++ b/src/compiler/Disassembler.cpp @@ -63,7 +63,7 @@ void Disassembler::dispatch(vm_oop_t o) { DebugPrint("{System Class object}"); } else if (o == load_ptr(blockClass)) { DebugPrint("{Block Class object}"); - } else if (o == GetUniverse()->GetGlobal(SymbolFor("system"))) { + } else if (o == Universe::GetGlobal(SymbolFor("system"))) { DebugPrint("{System}"); } else { VMClass* c = CLASS_OF(o); @@ -489,7 +489,7 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method, long bc_idx) { case BC_PUSH_GLOBAL: { VMSymbol* name = static_cast(method->GetConstant(bc_idx)); - vm_oop_t o = GetUniverse()->GetGlobal(name); + vm_oop_t o = Universe::GetGlobal(name); VMSymbol* cname; const char* c_cname; diff --git a/src/compiler/MethodGenerationContext.cpp b/src/compiler/MethodGenerationContext.cpp index 33dabacc..dea4a619 100644 --- a/src/compiler/MethodGenerationContext.cpp +++ b/src/compiler/MethodGenerationContext.cpp @@ -70,9 +70,9 @@ VMInvokable* MethodGenerationContext::Assemble() { // create a method instance with the given number of bytecodes and literals size_t numLiterals = literals.size(); size_t numLocals = locals.size(); - VMMethod* meth = GetUniverse()->NewMethod( - signature, bytecode.size(), numLiterals, numLocals, maxStackDepth, - lexicalScope, inlinedLoops); + VMMethod* meth = + Universe::NewMethod(signature, bytecode.size(), numLiterals, numLocals, + maxStackDepth, lexicalScope, inlinedLoops); // copy literals into the method for (size_t i = 0; i < numLiterals; i++) { diff --git a/src/compiler/Parser.cpp b/src/compiler/Parser.cpp index 31942642..7a92ea2b 100644 --- a/src/compiler/Parser.cpp +++ b/src/compiler/Parser.cpp @@ -247,7 +247,7 @@ void Parser::superclass(ClassGenerationContext& cgenc) { // Load the super class, if it is not nil (break the dependency cycle) if (superName != SymbolFor("nil")) { - VMClass* superClass = GetUniverse()->LoadClass(superName); + VMClass* superClass = Universe::LoadClass(superName); cgenc.SetInstanceFieldsOfSuper(superClass->GetInstanceFields()); cgenc.SetClassFieldsOfSuper( superClass->GetClass()->GetInstanceFields()); @@ -260,7 +260,7 @@ void Parser::superclass(ClassGenerationContext& cgenc) { vector fieldNamesOfClass{"class", "name", "instanceFields", "instanceInvokables", "superClass"}; VMArray* fieldNames = - GetUniverse()->NewArrayOfSymbolsFromStrings(fieldNamesOfClass); + Universe::NewArrayOfSymbolsFromStrings(fieldNamesOfClass); cgenc.SetClassFieldsOfSuper(fieldNames); } } @@ -748,7 +748,7 @@ vm_oop_t Parser::literalDouble(bool negateValue) { d = 0 - d; } expect(Double); - return GetUniverse()->NewDouble(d); + return Universe::NewDouble(d); } void Parser::literalSymbol(MethodGenerationContext& mgenc) { @@ -801,7 +801,7 @@ void Parser::literalArray(MethodGenerationContext& mgenc) { void Parser::literalString(MethodGenerationContext& mgenc) { StdString s = _string(); - VMString* str = GetUniverse()->NewString(s); + VMString* str = Universe::NewString(s); EmitPUSHCONSTANT(mgenc, str); } diff --git a/src/interpreter/Interpreter.cpp b/src/interpreter/Interpreter.cpp index 9b9452f8..1172be52 100644 --- a/src/interpreter/Interpreter.cpp +++ b/src/interpreter/Interpreter.cpp @@ -56,9 +56,13 @@ const std::string Interpreter::doesNotUnderstand = "doesNotUnderstand:arguments:"; const std::string Interpreter::escapedBlock = "escapedBlock:"; -Interpreter::Interpreter() : frame(nullptr) {} +VMFrame* Interpreter::frame = nullptr; +VMMethod* Interpreter::method = nullptr; -Interpreter::~Interpreter() {} +// The following three variables are used to cache main parts of the +// current execution context +long Interpreter::bytecodeIndexGlobal; +uint8_t* Interpreter::currentBytecodes; vm_oop_t Interpreter::StartAndPrintBytecodes() { #define PROLOGUE(bc_count) \ @@ -81,24 +85,24 @@ vm_oop_t Interpreter::Start() { } VMFrame* Interpreter::PushNewFrame(VMMethod* method) { - SetFrame(GetUniverse()->NewFrame(GetFrame(), method)); + SetFrame(Universe::NewFrame(GetFrame(), method)); return GetFrame(); } -void Interpreter::SetFrame(VMFrame* frame) { - if (this->frame != nullptr) { - this->frame->SetBytecodeIndex(bytecodeIndexGlobal); +void Interpreter::SetFrame(VMFrame* frm) { + if (frame != nullptr) { + frame->SetBytecodeIndex(bytecodeIndexGlobal); } - this->frame = frame; + frame = frm; // update cached values - method = frame->GetMethod(); - bytecodeIndexGlobal = frame->GetBytecodeIndex(); + method = frm->GetMethod(); + bytecodeIndexGlobal = frm->GetBytecodeIndex(); currentBytecodes = method->GetBytecodes(); } -vm_oop_t Interpreter::GetSelf() const { +vm_oop_t Interpreter::GetSelf() { VMFrame* context = GetFrame()->GetOuterContext(); return context->GetArgumentInCurrentContext(0); } @@ -135,19 +139,18 @@ void Interpreter::send(VMSymbol* signature, VMClass* receiverClass) { if (invokable != nullptr) { #ifdef LOG_RECEIVER_TYPES std::string name = receiverClass->GetName()->GetStdString(); - if (GetUniverse()->callStats.find(name) == - GetUniverse()->callStats.end()) { - GetUniverse()->callStats[name] = {0, 0}; + if (Universe::callStats.find(name) == Universe::callStats.end()) { + Universe::callStats[name] = {0, 0}; } - GetUniverse()->callStats[name].noCalls++; + Universe::callStats[name].noCalls++; if (invokable->IsPrimitive()) { - GetUniverse()->callStats[name].noPrimitiveCalls++; + Universe::callStats[name].noPrimitiveCalls++; } #endif // since an invokable is able to change/use the frame, we have to write // cached values before, and read cached values after calling GetFrame()->SetBytecodeIndex(bytecodeIndexGlobal); - invokable->Invoke(this, GetFrame()); + invokable->Invoke(GetFrame()); bytecodeIndexGlobal = GetFrame()->GetBytecodeIndex(); } else { triggerDoesNotUnderstand(signature); @@ -160,7 +163,7 @@ void Interpreter::triggerDoesNotUnderstand(VMSymbol* signature) { vm_oop_t receiver = GetFrame()->GetStackElement(numberOfArgs - 1); VMArray* argumentsArray = - GetUniverse()->NewArray(numberOfArgs - 1); // without receiver + Universe::NewArray(numberOfArgs - 1); // without receiver // the receiver should not go into the argumentsArray // so, numberOfArgs - 2 @@ -182,7 +185,7 @@ void Interpreter::triggerDoesNotUnderstand(VMSymbol* signature) { SetFrame(VMFrame::EmergencyFrameFrom(GetFrame(), additionalStackSlots)); } - AS_OBJ(receiver)->Send(this, doesNotUnderstand, arguments, 2); + AS_OBJ(receiver)->Send(doesNotUnderstand, arguments, 2); } void Interpreter::doDup() { @@ -266,14 +269,13 @@ void Interpreter::doPushBlock(long bytecodeIndex) { long numOfArgs = blockMethod->GetNumberOfArguments(); - GetFrame()->Push( - GetUniverse()->NewBlock(blockMethod, GetFrame(), numOfArgs)); + GetFrame()->Push(Universe::NewBlock(blockMethod, GetFrame(), numOfArgs)); } void Interpreter::doPushGlobal(long bytecodeIndex) { VMSymbol* globalName = static_cast(method->GetConstant(bytecodeIndex)); - vm_oop_t global = GetUniverse()->GetGlobal(globalName); + vm_oop_t global = Universe::GetGlobal(globalName); if (global != nullptr) { GetFrame()->Push(global); @@ -296,7 +298,7 @@ void Interpreter::SendUnknownGlobal(VMSymbol* globalName) { SetFrame(VMFrame::EmergencyFrameFrom(GetFrame(), additionalStackSlots)); } - AS_OBJ(self)->Send(this, unknownGlobal, arguments, 1); + AS_OBJ(self)->Send(unknownGlobal, arguments, 1); } void Interpreter::doPop() { @@ -358,7 +360,7 @@ void Interpreter::doSend(long bytecodeIndex) { assert(IsValidObject(receiverClass)); #ifdef LOG_RECEIVER_TYPES - GetUniverse()->receiverTypes[receiverClass->GetName()->GetStdString()]++; + Universe::receiverTypes[receiverClass->GetName()->GetStdString()]++; #endif send(signature, receiverClass); @@ -377,11 +379,11 @@ void Interpreter::doSuperSend(long bytecodeIndex) { static_cast(super->LookupInvokable(signature)); if (invokable != nullptr) { - invokable->Invoke(this, GetFrame()); + invokable->Invoke(GetFrame()); } else { long numOfArgs = Signature::GetNumberOfArguments(signature); vm_oop_t receiver = GetFrame()->GetStackElement(numOfArgs - 1); - VMArray* argumentsArray = GetUniverse()->NewArray(numOfArgs); + VMArray* argumentsArray = Universe::NewArray(numOfArgs); for (long i = numOfArgs - 1; i >= 0; --i) { vm_oop_t o = GetFrame()->Pop(); @@ -389,7 +391,7 @@ void Interpreter::doSuperSend(long bytecodeIndex) { } vm_oop_t arguments[] = {signature, argumentsArray}; - AS_OBJ(receiver)->Send(this, doesNotUnderstand, arguments, 2); + AS_OBJ(receiver)->Send(doesNotUnderstand, arguments, 2); } } @@ -430,7 +432,7 @@ void Interpreter::doReturnNonLocal() { VMFrame::EmergencyFrameFrom(GetFrame(), additionalStackSlots)); } - AS_OBJ(sender)->Send(this, escapedBlock, arguments, 1); + AS_OBJ(sender)->Send(escapedBlock, arguments, 1); return; } @@ -449,7 +451,7 @@ void Interpreter::doInc() { val = NEW_INT(result); } else if (CLASS_OF(val) == load_ptr(doubleClass)) { double d = static_cast(val)->GetEmbeddedDouble(); - val = GetUniverse()->NewDouble(d + 1.0); + val = Universe::NewDouble(d + 1.0); } else { ErrorExit("unsupported"); } @@ -489,14 +491,14 @@ void Interpreter::startGC() { currentBytecodes = method->GetBytecodes(); } -VMMethod* Interpreter::GetMethod() const { +VMMethod* Interpreter::GetMethod() { return GetFrame()->GetMethod(); } -uint8_t* Interpreter::GetBytecodes() const { +uint8_t* Interpreter::GetBytecodes() { return method->GetBytecodes(); } -void Interpreter::disassembleMethod() const { +void Interpreter::disassembleMethod() { Disassembler::DumpBytecode(GetFrame(), GetMethod(), bytecodeIndexGlobal); } diff --git a/src/interpreter/Interpreter.h b/src/interpreter/Interpreter.h index ed747dd0..4ae58bd1 100644 --- a/src/interpreter/Interpreter.h +++ b/src/interpreter/Interpreter.h @@ -44,75 +44,70 @@ class Interpreter { public: - Interpreter(); - ~Interpreter(); + static vm_oop_t StartAndPrintBytecodes(); + static vm_oop_t Start(); - vm_oop_t StartAndPrintBytecodes(); - vm_oop_t Start(); + static VMFrame* PushNewFrame(VMMethod* method); + static void SetFrame(VMFrame* frame); - VMFrame* PushNewFrame(VMMethod* method); - void SetFrame(VMFrame* frame); - inline VMFrame* GetFrame() const; - VMMethod* GetMethod() const; - uint8_t* GetBytecodes() const; - void WalkGlobals(walk_heap_fn); + static inline VMFrame* GetFrame() { return frame; } - void SendUnknownGlobal(VMSymbol* globalName); + static VMMethod* GetMethod(); + static uint8_t* GetBytecodes(); + static void WalkGlobals(walk_heap_fn); + + static void SendUnknownGlobal(VMSymbol* globalName); private: - vm_oop_t GetSelf() const; + static vm_oop_t GetSelf(); - VMFrame* frame; - VMMethod* method; + static VMFrame* frame; + static VMMethod* method; // The following three variables are used to cache main parts of the // current execution context - long bytecodeIndexGlobal; - uint8_t* currentBytecodes; + static long bytecodeIndexGlobal; + static uint8_t* currentBytecodes; static const StdString unknownGlobal; static const StdString doesNotUnderstand; static const StdString escapedBlock; - void startGC(); - void disassembleMethod() const; + static void startGC(); + static void disassembleMethod(); - VMFrame* popFrame(); - void popFrameAndPushResult(vm_oop_t result); + static VMFrame* popFrame(); + static void popFrameAndPushResult(vm_oop_t result); - void send(VMSymbol* signature, VMClass* receiverClass); + static void send(VMSymbol* signature, VMClass* receiverClass); - void triggerDoesNotUnderstand(VMSymbol* signature); + static void triggerDoesNotUnderstand(VMSymbol* signature); - void doDup(); - void doPushLocal(long bytecodeIndex); - void doPushLocalWithIndex(uint8_t localIndex); - void doReturnFieldWithIndex(uint8_t fieldIndex); - void doPushArgument(long bytecodeIndex); - void doPushField(long bytecodeIndex); - void doPushFieldWithIndex(uint8_t fieldIndex); - void doPushBlock(long bytecodeIndex); + static void doDup(); + static void doPushLocal(long bytecodeIndex); + static void doPushLocalWithIndex(uint8_t localIndex); + static void doReturnFieldWithIndex(uint8_t fieldIndex); + static void doPushArgument(long bytecodeIndex); + static void doPushField(long bytecodeIndex); + static void doPushFieldWithIndex(uint8_t fieldIndex); + static void doPushBlock(long bytecodeIndex); - inline void doPushConstant(long bytecodeIndex) { + static inline void doPushConstant(long bytecodeIndex) { vm_oop_t constant = method->GetConstant(bytecodeIndex); GetFrame()->Push(constant); } - void doPushGlobal(long bytecodeIndex); - void doPop(void); - void doPopLocal(long bytecodeIndex); - void doPopLocalWithIndex(uint8_t localIndex); - void doPopArgument(long bytecodeIndex); - void doPopField(long bytecodeIndex); - void doPopFieldWithIndex(uint8_t fieldIndex); - void doSend(long bytecodeIndex); - void doSuperSend(long bytecodeIndex); - void doReturnLocal(); - void doReturnNonLocal(); - void doInc(); - bool checkIsGreater(); + static void doPushGlobal(long bytecodeIndex); + static void doPop(void); + static void doPopLocal(long bytecodeIndex); + static void doPopLocalWithIndex(uint8_t localIndex); + static void doPopArgument(long bytecodeIndex); + static void doPopField(long bytecodeIndex); + static void doPopFieldWithIndex(uint8_t fieldIndex); + static void doSend(long bytecodeIndex); + static void doSuperSend(long bytecodeIndex); + static void doReturnLocal(); + static void doReturnNonLocal(); + static void doInc(); + static bool checkIsGreater(); }; - -inline VMFrame* Interpreter::GetFrame() const { - return frame; -} diff --git a/src/memory/CopyingCollector.cpp b/src/memory/CopyingCollector.cpp index 64be3636..80cc492d 100644 --- a/src/memory/CopyingCollector.cpp +++ b/src/memory/CopyingCollector.cpp @@ -60,7 +60,7 @@ void CopyingCollector::Collect() { heap->switchBuffers(increaseMemory); increaseMemory = false; - GetUniverse()->WalkGlobals(copy_if_necessary); + Universe::WalkGlobals(copy_if_necessary); // now copy all objects that are referenced by the objects we have moved so // far diff --git a/src/memory/DebugCopyingCollector.cpp b/src/memory/DebugCopyingCollector.cpp index 2f457edf..af8fcb51 100644 --- a/src/memory/DebugCopyingCollector.cpp +++ b/src/memory/DebugCopyingCollector.cpp @@ -59,7 +59,7 @@ void DebugCopyingCollector::Collect() { heap->switchBuffers(increaseMemory); increaseMemory = false; - GetUniverse()->WalkGlobals(copy_if_necessary); + Universe::WalkGlobals(copy_if_necessary); // now copy all objects that are referenced by the objects we have moved so // far diff --git a/src/memory/GenerationalCollector.cpp b/src/memory/GenerationalCollector.cpp index 8744f12e..8f7742d8 100644 --- a/src/memory/GenerationalCollector.cpp +++ b/src/memory/GenerationalCollector.cpp @@ -86,7 +86,7 @@ void GenerationalCollector::MinorCollection() { DebugLog("GenGC MinorCollection\n"); // walk all globals of universe, and implicily the interpreter - GetUniverse()->WalkGlobals(©_if_necessary); + Universe::WalkGlobals(©_if_necessary); // and also all objects that have been detected by the write barriers for (vector::iterator objIter = @@ -108,7 +108,7 @@ void GenerationalCollector::MajorCollection() { DebugLog("GenGC MajorCollection\n"); // first we have to mark all objects (globals and current frame recursively) - GetUniverse()->WalkGlobals(&mark_object); + Universe::WalkGlobals(&mark_object); // now that all objects are marked we can safely delete all allocated // objects that are not marked diff --git a/src/memory/MarkSweepCollector.cpp b/src/memory/MarkSweepCollector.cpp index b80bdd20..484bff23 100644 --- a/src/memory/MarkSweepCollector.cpp +++ b/src/memory/MarkSweepCollector.cpp @@ -68,5 +68,5 @@ static gc_oop_t mark_object(gc_oop_t oop) { void MarkSweepCollector::markReachableObjects() { // This walks the globals of the universe, and the interpreter - GetUniverse()->WalkGlobals(mark_object); + Universe::WalkGlobals(mark_object); } diff --git a/src/primitives/Array.cpp b/src/primitives/Array.cpp index 82a99c00..323982ab 100644 --- a/src/primitives/Array.cpp +++ b/src/primitives/Array.cpp @@ -53,7 +53,7 @@ static vm_oop_t arrLength(vm_oop_t leftObj) { static vm_oop_t arrNew(vm_oop_t, vm_oop_t arg) { int64_t size = INT_VAL(arg); - return GetUniverse()->NewArray(size); + return Universe::NewArray(size); } static vm_oop_t arrCopy(vm_oop_t rcvr) { diff --git a/src/primitives/Class.cpp b/src/primitives/Class.cpp index 21bf2eb7..2073166c 100644 --- a/src/primitives/Class.cpp +++ b/src/primitives/Class.cpp @@ -35,7 +35,7 @@ static vm_oop_t clsNew(vm_oop_t rcvr) { VMClass* self = static_cast(rcvr); - return GetUniverse()->NewInstance(self); + return Universe::NewInstance(self); } static vm_oop_t clsName(vm_oop_t rcvr) { diff --git a/src/primitives/Double.cpp b/src/primitives/Double.cpp index 2bf96a41..06f10b0a 100644 --- a/src/primitives/Double.cpp +++ b/src/primitives/Double.cpp @@ -76,39 +76,39 @@ double coerceDouble(vm_oop_t x) { static vm_oop_t dblPlus(vm_oop_t leftPtr, vm_oop_t rightObj) { PREPARE_OPERANDS; - return GetUniverse()->NewDouble(left + right); + return Universe::NewDouble(left + right); } static vm_oop_t dblMinus(vm_oop_t leftPtr, vm_oop_t rightObj) { PREPARE_OPERANDS; - return GetUniverse()->NewDouble(left - right); + return Universe::NewDouble(left - right); } static vm_oop_t dblStar(vm_oop_t leftPtr, vm_oop_t rightObj) { PREPARE_OPERANDS; - return GetUniverse()->NewDouble(left * right); + return Universe::NewDouble(left * right); } static vm_oop_t dblCos(vm_oop_t rcvr) { VMDouble* self = (VMDouble*)rcvr; double result = cos(self->GetEmbeddedDouble()); - return GetUniverse()->NewDouble(result); + return Universe::NewDouble(result); } static vm_oop_t dblSin(vm_oop_t rcvr) { VMDouble* self = (VMDouble*)rcvr; double result = sin(self->GetEmbeddedDouble()); - return GetUniverse()->NewDouble(result); + return Universe::NewDouble(result); } static vm_oop_t dblSlashslash(vm_oop_t leftPtr, vm_oop_t rightObj) { PREPARE_OPERANDS; - return GetUniverse()->NewDouble(left / right); + return Universe::NewDouble(left / right); } vm_oop_t dblPercent(vm_oop_t leftPtr, vm_oop_t rightObj) { PREPARE_OPERANDS; - return GetUniverse()->NewDouble((double)((int64_t)left % (int64_t)right)); + return Universe::NewDouble((double)((int64_t)left % (int64_t)right)); } /* @@ -140,13 +140,12 @@ static vm_oop_t dblAsString(vm_oop_t rcvr) { ostringstream Str; Str.precision(17); Str << dbl; - return GetUniverse()->NewString(Str.str().c_str()); + return Universe::NewString(Str.str().c_str()); } static vm_oop_t dblSqrt(vm_oop_t rcvr) { VMDouble* self = static_cast(rcvr); - VMDouble* result = - GetUniverse()->NewDouble(sqrt(self->GetEmbeddedDouble())); + VMDouble* result = Universe::NewDouble(sqrt(self->GetEmbeddedDouble())); return result; } @@ -165,14 +164,14 @@ static vm_oop_t dblAsInteger(vm_oop_t rcvr) { } static vm_oop_t dblPositiveInfinity(vm_oop_t) { - return GetUniverse()->NewDouble(INFINITY); + return Universe::NewDouble(INFINITY); } static vm_oop_t dblFromString(vm_oop_t, vm_oop_t rightObj) { VMString* self = (VMString*)rightObj; double value = stod(std::string(self->GetRawChars(), self->GetStringLength())); - return GetUniverse()->NewDouble(value); + return Universe::NewDouble(value); } static vm_oop_t dblLowerThanEqual(vm_oop_t leftPtr, vm_oop_t rightObj) { diff --git a/src/primitives/Integer.cpp b/src/primitives/Integer.cpp index 2c8bf93b..721c9900 100644 --- a/src/primitives/Integer.cpp +++ b/src/primitives/Integer.cpp @@ -49,14 +49,14 @@ double coerceDouble(vm_oop_t x); -#define doDoubleOpIfNeeded(leftInt, rightObj, op) \ - { \ - VMClass* cl = CLASS_OF(rightObj); \ - if (cl == load_ptr(doubleClass)) { \ - double leftDbl = (double)leftInt; \ - double rightDbl = coerceDouble(rightObj); \ - return GetUniverse()->NewDouble(leftDbl op rightDbl); \ - } \ +#define doDoubleOpIfNeeded(leftInt, rightObj, op) \ + { \ + VMClass* cl = CLASS_OF(rightObj); \ + if (cl == load_ptr(doubleClass)) { \ + double leftDbl = (double)leftInt; \ + double rightDbl = coerceDouble(rightObj); \ + return Universe::NewDouble(leftDbl op rightDbl); \ + } \ } static vm_oop_t intPlus(vm_oop_t leftObj, vm_oop_t rightObj) { @@ -106,7 +106,7 @@ static vm_oop_t intSlashslash(vm_oop_t leftObj, vm_oop_t rightObj) { doDoubleOpIfNeeded(left, rightObj, /); double result = (double)left / (double)INT_VAL(rightObj); - return GetUniverse()->NewDouble(result); + return Universe::NewDouble(result); } static vm_oop_t intSlash(vm_oop_t leftObj, vm_oop_t rightObj) { @@ -237,12 +237,12 @@ static vm_oop_t intAsString(vm_oop_t self) { long integer = INT_VAL(self); ostringstream Str; Str << integer; - return GetUniverse()->NewString(Str.str()); + return Universe::NewString(Str.str()); } static vm_oop_t intAsDouble(vm_oop_t self) { long integer = INT_VAL(self); - return GetUniverse()->NewDouble((double)integer); + return Universe::NewDouble((double)integer); } static vm_oop_t intAs32BitSigned(vm_oop_t self) { @@ -261,7 +261,7 @@ static vm_oop_t intSqrt(vm_oop_t self) { if (result == rint(result)) { return NEW_INT((int64_t)result); } else { - return GetUniverse()->NewDouble(result); + return Universe::NewDouble(result); } } @@ -333,7 +333,7 @@ static vm_oop_t intRange(vm_oop_t leftObj, vm_oop_t rightObj) { int64_t right = INT_VAL(rightObj); int64_t numInteger = right - left + 1; - VMArray* arr = GetUniverse()->NewArray(numInteger); + VMArray* arr = Universe::NewArray(numInteger); size_t index = 0; for (int64_t i = left; i <= right; i += 1, index += 1) { diff --git a/src/primitives/Method.cpp b/src/primitives/Method.cpp index 0364d219..fbaad07d 100644 --- a/src/primitives/Method.cpp +++ b/src/primitives/Method.cpp @@ -21,7 +21,7 @@ static vm_oop_t mSignature(vm_oop_t rcvr) { return self->GetSignature(); } -void _Method::InvokeOn_With_(Interpreter* interp, VMFrame* frame) { +void _Method::InvokeOn_With_(VMFrame* frame) { // REM: this is a clone with _Primitive::InvokeOn_With_ VMArray* args = static_cast(frame->Pop()); vm_oop_t rcvr = static_cast(frame->Pop()); @@ -34,7 +34,7 @@ void _Method::InvokeOn_With_(Interpreter* interp, VMFrame* frame) { vm_oop_t arg = args->GetIndexableField(i); frame->Push(arg); } - mthd->Invoke(interp, frame); + mthd->Invoke(frame); } _Method::_Method() : PrimitiveContainer() { diff --git a/src/primitives/Method.h b/src/primitives/Method.h index 3de059a3..69621090 100644 --- a/src/primitives/Method.h +++ b/src/primitives/Method.h @@ -7,5 +7,5 @@ class _Method : public PrimitiveContainer { public: _Method(void); - void InvokeOn_With_(Interpreter*, VMFrame*); + void InvokeOn_With_(VMFrame*); }; diff --git a/src/primitives/Object.cpp b/src/primitives/Object.cpp index c0b0527f..7c446b80 100644 --- a/src/primitives/Object.cpp +++ b/src/primitives/Object.cpp @@ -66,26 +66,26 @@ vm_oop_t objHalt(vm_oop_t) { return load_ptr(falseObject); } -void _Object::Perform(Interpreter* interp, VMFrame* frame) { +void _Object::Perform(VMFrame* frame) { VMSymbol* selector = (VMSymbol*)frame->Pop(); vm_oop_t self = frame->GetStackElement(0); VMClass* clazz = CLASS_OF(self); VMInvokable* invokable = clazz->LookupInvokable(selector); - invokable->Invoke(interp, frame); + invokable->Invoke(frame); } -void _Object::PerformInSuperclass(Interpreter* interp, VMFrame* frame) { +void _Object::PerformInSuperclass(VMFrame* frame) { VMClass* clazz = (VMClass*)frame->Pop(); VMSymbol* selector = (VMSymbol*)frame->Pop(); VMInvokable* invokable = clazz->LookupInvokable(selector); - invokable->Invoke(interp, frame); + invokable->Invoke(frame); } -void _Object::PerformWithArguments(Interpreter* interp, VMFrame* frame) { +void _Object::PerformWithArguments(VMFrame* frame) { VMArray* args = (VMArray*)frame->Pop(); VMSymbol* selector = (VMSymbol*)frame->Pop(); vm_oop_t self = frame->GetStackElement(0); @@ -99,11 +99,10 @@ void _Object::PerformWithArguments(Interpreter* interp, VMFrame* frame) { VMClass* clazz = CLASS_OF(self); VMInvokable* invokable = clazz->LookupInvokable(selector); - invokable->Invoke(interp, frame); + invokable->Invoke(frame); } -void _Object::PerformWithArgumentsInSuperclass(Interpreter* interp, - VMFrame* frame) { +void _Object::PerformWithArgumentsInSuperclass(VMFrame* frame) { VMClass* clazz = (VMClass*)frame->Pop(); VMArray* args = (VMArray*)frame->Pop(); VMSymbol* selector = (VMSymbol*)frame->Pop(); @@ -116,7 +115,7 @@ void _Object::PerformWithArgumentsInSuperclass(Interpreter* interp, VMInvokable* invokable = clazz->LookupInvokable(selector); - invokable->Invoke(interp, frame); + invokable->Invoke(frame); } vm_oop_t objInstVarAt(vm_oop_t self, vm_oop_t idx) { diff --git a/src/primitives/Object.h b/src/primitives/Object.h index 498fcaa0..7ca1a09f 100644 --- a/src/primitives/Object.h +++ b/src/primitives/Object.h @@ -32,8 +32,8 @@ class _Object : public PrimitiveContainer { public: _Object(); - void Perform(Interpreter*, VMFrame*); - void PerformWithArguments(Interpreter*, VMFrame*); - void PerformInSuperclass(Interpreter*, VMFrame*); - void PerformWithArgumentsInSuperclass(Interpreter*, VMFrame*); + void Perform(VMFrame*); + void PerformWithArguments(VMFrame*); + void PerformInSuperclass(VMFrame*); + void PerformWithArgumentsInSuperclass(VMFrame*); }; diff --git a/src/primitives/Primitive.cpp b/src/primitives/Primitive.cpp index ddcf2eb0..c31f7110 100644 --- a/src/primitives/Primitive.cpp +++ b/src/primitives/Primitive.cpp @@ -7,7 +7,6 @@ #include "../vmobjects/ObjectFormats.h" #include "../vmobjects/VMClass.h" // NOLINT(misc-include-cleaner) it's required to make the types complete #include "../vmobjects/VMFrame.h" -#include "../vmobjects/VMMethod.h" #include "../vmobjects/VMSymbol.h" // NOLINT(misc-include-cleaner) it's required to make the types complete static vm_oop_t pHolder(vm_oop_t rcvr) { @@ -20,7 +19,7 @@ static vm_oop_t pSignature(vm_oop_t rcvr) { return self->GetSignature(); } -void _Primitive::InvokeOn_With_(Interpreter* interp, VMFrame* frame) { +void _Primitive::InvokeOn_With_(VMFrame* frame) { // REM: this is a clone with _Primitive::InvokeOn_With_ VMArray* args = static_cast(frame->Pop()); vm_oop_t rcvr = static_cast(frame->Pop()); @@ -33,7 +32,7 @@ void _Primitive::InvokeOn_With_(Interpreter* interp, VMFrame* frame) { vm_oop_t arg = args->GetIndexableField(i); frame->Push(arg); } - mthd->Invoke(interp, frame); + mthd->Invoke(frame); } _Primitive::_Primitive() : PrimitiveContainer() { diff --git a/src/primitives/Primitive.h b/src/primitives/Primitive.h index 544d0144..fc564a3a 100644 --- a/src/primitives/Primitive.h +++ b/src/primitives/Primitive.h @@ -7,5 +7,5 @@ class _Primitive : public PrimitiveContainer { public: _Primitive(void); - void InvokeOn_With_(Interpreter*, VMFrame*); + void InvokeOn_With_(VMFrame*); }; diff --git a/src/primitives/String.cpp b/src/primitives/String.cpp index bf985510..6999ccc1 100644 --- a/src/primitives/String.cpp +++ b/src/primitives/String.cpp @@ -52,7 +52,7 @@ static vm_oop_t strConcatenate_(vm_oop_t leftObj, vm_oop_t rightObj) { StdString result = s + a; - return GetUniverse()->NewString(result); + return Universe::NewString(result); } static vm_oop_t strAsSymbol(vm_oop_t rcvr) { @@ -107,7 +107,7 @@ static vm_oop_t strPrimSubstringFromTo(vm_oop_t rcvr, int64_t e = INT_VAL(end) - 1; std::string result = str.substr(s, e - s + 1); - return GetUniverse()->NewString(result); + return Universe::NewString(result); } static vm_oop_t strCharAt(vm_oop_t rcvr, vm_oop_t indexPtr) { @@ -115,10 +115,10 @@ static vm_oop_t strCharAt(vm_oop_t rcvr, vm_oop_t indexPtr) { int64_t index = INT_VAL(indexPtr) - 1; if (unlikely(index < 0 || (size_t)index >= self->GetStringLength())) { - return GetUniverse()->NewString("Error - index out of bounds"); + return Universe::NewString("Error - index out of bounds"); } - return GetUniverse()->NewString(1, &self->GetRawChars()[index]); + return Universe::NewString(1, &self->GetRawChars()[index]); } static vm_oop_t strIsWhiteSpace(vm_oop_t rcvr) { diff --git a/src/primitives/Symbol.cpp b/src/primitives/Symbol.cpp index 2f1ca6e3..7198cd2b 100644 --- a/src/primitives/Symbol.cpp +++ b/src/primitives/Symbol.cpp @@ -38,7 +38,7 @@ static vm_oop_t symAsString(vm_oop_t rcvr) { VMSymbol* sym = static_cast(rcvr); std::string str = sym->GetStdString(); - return GetUniverse()->NewString(str); + return Universe::NewString(str); } _Symbol::_Symbol() : PrimitiveContainer() { diff --git a/src/primitives/System.cpp b/src/primitives/System.cpp index 10e63040..0674d136 100644 --- a/src/primitives/System.cpp +++ b/src/primitives/System.cpp @@ -58,21 +58,21 @@ _System* System_; static vm_oop_t sysGlobal_(vm_oop_t, vm_oop_t rightObj) { VMSymbol* arg = static_cast(rightObj); - vm_oop_t result = GetUniverse()->GetGlobal(arg); + vm_oop_t result = Universe::GetGlobal(arg); return result ? result : load_ptr(nilObject); } static vm_oop_t sysGlobalPut(vm_oop_t sys, vm_oop_t sym, vm_oop_t val) { VMSymbol* arg = static_cast(sym); - GetUniverse()->SetGlobal(arg, val); + Universe::SetGlobal(arg, val); return sys; } static vm_oop_t sysHasGlobal_(vm_oop_t, vm_oop_t rightObj) { VMSymbol* arg = static_cast(rightObj); - if (GetUniverse()->HasGlobal(arg)) { + if (Universe::HasGlobal(arg)) { return load_ptr(trueObject); } else { return load_ptr(falseObject); @@ -81,7 +81,7 @@ static vm_oop_t sysHasGlobal_(vm_oop_t, vm_oop_t rightObj) { static vm_oop_t sysLoad_(vm_oop_t, vm_oop_t rightObj) { VMSymbol* arg = static_cast(rightObj); - VMClass* result = GetUniverse()->LoadClass(arg); + VMClass* result = Universe::LoadClass(arg); if (result) { return result; } else { @@ -160,14 +160,14 @@ static vm_oop_t sysLoadFile_(vm_oop_t, vm_oop_t rightObj) { std::stringstream buffer; buffer << file.rdbuf(); - VMString* result = GetUniverse()->NewString(buffer.str()); + VMString* result = Universe::NewString(buffer.str()); return result; } else { return load_ptr(nilObject); } } -void _System::PrintStackTrace(Interpreter*, VMFrame* frame) { +void _System::PrintStackTrace(VMFrame* frame) { frame->PrintStackTrace(); } diff --git a/src/primitives/System.h b/src/primitives/System.h index 17d93e48..26226007 100644 --- a/src/primitives/System.h +++ b/src/primitives/System.h @@ -36,5 +36,5 @@ class _System : public PrimitiveContainer { _System(void); virtual ~_System(); - void PrintStackTrace(Interpreter*, VMFrame*); + void PrintStackTrace(VMFrame*); }; diff --git a/src/primitivesCore/Routine.h b/src/primitivesCore/Routine.h index dd4f44a5..3c970f1a 100644 --- a/src/primitivesCore/Routine.h +++ b/src/primitivesCore/Routine.h @@ -36,20 +36,20 @@ class Interpreter; template class Routine : public PrimitiveRoutine { private: - void (TClass::*func)(Interpreter*, VMFrame*); // pointer to member function + void (TClass::*func)(VMFrame*); // pointer to member function TClass* primContainerObj; const bool classSide; public: // takes pointer to an object, pointer to a member, and a bool indicating // whether it is a class-side primitive or not - Routine(TClass* primContainerObj, - void (TClass::*_fpt)(Interpreter*, VMFrame*), bool classSide) + Routine(TClass* primContainerObj, void (TClass::*_fpt)(VMFrame*), + bool classSide) : PrimitiveRoutine(), func(_fpt), primContainerObj(primContainerObj), classSide(classSide) {}; - void Invoke(Interpreter* interp, VMFrame* frm) override { - (*primContainerObj.*func)(interp, frm); // execute member function + void Invoke(VMFrame* frm) override { + (*primContainerObj.*func)(frm); // execute member function } bool isClassSide() override { return classSide; } diff --git a/src/unitTests/BasicInterpreterTests.h b/src/unitTests/BasicInterpreterTests.h index f84a49d2..97389d0c 100644 --- a/src/unitTests/BasicInterpreterTests.h +++ b/src/unitTests/BasicInterpreterTests.h @@ -197,8 +197,7 @@ class BasicInterpreterTests : public CPPUNIT_NS::TestFixture { void testBasic(TestData data) { // The Unit Test harness will initialize Universe for a standard run. // This is different from other SOMs. - vm_oop_t result = - GetUniverse()->interpret(data.className, data.methodName); + vm_oop_t result = Universe::interpret(data.className, data.methodName); CPPUNIT_ASSERT(result != nullptr); assertEqualsSOMValue(result, data); } diff --git a/src/unitTests/CloneObjectsTest.cpp b/src/unitTests/CloneObjectsTest.cpp index 0bda61dd..b7def32c 100644 --- a/src/unitTests/CloneObjectsTest.cpp +++ b/src/unitTests/CloneObjectsTest.cpp @@ -47,7 +47,7 @@ void CloneObjectsTest::testCloneObject() { } void CloneObjectsTest::testCloneInteger() { - VMInteger* orig = GetUniverse()->NewInteger(42); + VMInteger* orig = Universe::NewInteger(42); VMInteger* clone = orig->CloneForMovingGC(); CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone); @@ -61,7 +61,7 @@ void CloneObjectsTest::testCloneInteger() { } void CloneObjectsTest::testCloneDouble() { - VMDouble* orig = GetUniverse()->NewDouble(123.4); + VMDouble* orig = Universe::NewDouble(123.4); VMDouble* clone = orig->CloneForMovingGC(); CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone); @@ -75,7 +75,7 @@ void CloneObjectsTest::testCloneDouble() { } void CloneObjectsTest::testCloneString() { - VMString* orig = GetUniverse()->NewString("foobar"); + VMString* orig = Universe::NewString("foobar"); VMString* clone = orig->CloneForMovingGC(); CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone); @@ -116,10 +116,10 @@ void CloneObjectsTest::testCloneSymbol() { } void CloneObjectsTest::testCloneArray() { - VMArray* orig = GetUniverse()->NewArray(3); - orig->SetIndexableField(0, GetUniverse()->NewString("foobar42")); - orig->SetIndexableField(1, GetUniverse()->NewString("foobar43")); - orig->SetIndexableField(2, GetUniverse()->NewString("foobar44")); + VMArray* orig = Universe::NewArray(3); + orig->SetIndexableField(0, Universe::NewString("foobar42")); + orig->SetIndexableField(1, Universe::NewString("foobar43")); + orig->SetIndexableField(2, Universe::NewString("foobar44")); VMArray* clone = orig->CloneForMovingGC(); CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone); @@ -147,12 +147,11 @@ void CloneObjectsTest::testCloneBlock() { VMSymbol* methodSymbol = NewSymbol("someMethod"); vector inlinedLoops; - VMMethod* method = GetUniverse()->NewMethod( - methodSymbol, 0, 0, 0, 0, new LexicalScope(nullptr, {}, {}), - inlinedLoops); - VMBlock* orig = GetUniverse()->NewBlock( - method, GetUniverse()->GetInterpreter()->GetFrame(), - method->GetNumberOfArguments()); + VMMethod* method = + Universe::NewMethod(methodSymbol, 0, 0, 0, 0, + new LexicalScope(nullptr, {}, {}), inlinedLoops); + VMBlock* orig = Universe::NewBlock(method, Interpreter::GetFrame(), + method->GetNumberOfArguments()); VMBlock* clone = orig->CloneForMovingGC(); CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone); @@ -203,14 +202,14 @@ void CloneObjectsTest::testCloneFrame() { VMSymbol* methodSymbol = NewSymbol("frameMethod"); vector inlinedLoops; - VMMethod* method = GetUniverse()->NewMethod( - methodSymbol, 0, 0, 0, 0, new LexicalScope(nullptr, {}, {}), - inlinedLoops); + VMMethod* method = + Universe::NewMethod(methodSymbol, 0, 0, 0, 0, + new LexicalScope(nullptr, {}, {}), inlinedLoops); - VMFrame* orig = GetUniverse()->NewFrame(nullptr, method); + VMFrame* orig = Universe::NewFrame(nullptr, method); VMFrame* context = orig->CloneForMovingGC(); orig->SetContext(context); - VMInteger* dummyArg = GetUniverse()->NewInteger(1111); + VMInteger* dummyArg = Universe::NewInteger(1111); orig->SetArgument(0, 0, dummyArg); VMFrame* clone = orig->CloneForMovingGC(); @@ -237,9 +236,9 @@ void CloneObjectsTest::testCloneMethod() { VMSymbol* methodSymbol = NewSymbol("myMethod"); vector inlinedLoops; - VMMethod* orig = GetUniverse()->NewMethod(methodSymbol, 0, 0, 0, 0, - new LexicalScope(nullptr, {}, {}), - inlinedLoops); + VMMethod* orig = + Universe::NewMethod(methodSymbol, 0, 0, 0, 0, + new LexicalScope(nullptr, {}, {}), inlinedLoops); VMMethod* clone = orig->CloneForMovingGC(); CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone); @@ -266,11 +265,11 @@ void CloneObjectsTest::testCloneMethod() { } void CloneObjectsTest::testCloneClass() { - VMClass* orig = GetUniverse()->NewClass(load_ptr(integerClass)); + VMClass* orig = Universe::NewClass(load_ptr(integerClass)); orig->SetName(NewSymbol("MyClass")); orig->SetSuperClass(load_ptr(doubleClass)); - orig->SetInstanceFields(GetUniverse()->NewArray(2)); - orig->SetInstanceInvokables(GetUniverse()->NewArray(4)); + orig->SetInstanceFields(Universe::NewArray(2)); + orig->SetInstanceInvokables(Universe::NewArray(4)); VMClass* clone = orig->CloneForMovingGC(); CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone); diff --git a/src/unitTests/WalkObjectsTest.cpp b/src/unitTests/WalkObjectsTest.cpp index 4e007b38..644e3cc3 100644 --- a/src/unitTests/WalkObjectsTest.cpp +++ b/src/unitTests/WalkObjectsTest.cpp @@ -62,7 +62,7 @@ bool WalkerHasFound(gc_oop_t obj) { void WalkObjectsTest::testWalkInteger() { walkedObjects.clear(); - VMInteger* int1 = GetUniverse()->NewInteger(42); + VMInteger* int1 = Universe::NewInteger(42); int1->WalkObjects(collectMembers); // Integers have no additional members @@ -71,7 +71,7 @@ void WalkObjectsTest::testWalkInteger() { void WalkObjectsTest::testWalkDouble() { walkedObjects.clear(); - VMDouble* d1 = GetUniverse()->NewDouble(432.1); + VMDouble* d1 = Universe::NewDouble(432.1); d1->WalkObjects(collectMembers); // Doubles have no additional members @@ -104,7 +104,7 @@ void WalkObjectsTest::testWalkObject() { void WalkObjectsTest::testWalkString() { walkedObjects.clear(); - VMString* str1 = GetUniverse()->NewString("str1"); + VMString* str1 = Universe::NewString("str1"); str1->WalkObjects(collectMembers); CPPUNIT_ASSERT_EQUAL(NoOfFields_String, walkedObjects.size()); @@ -120,7 +120,7 @@ void WalkObjectsTest::testWalkSymbol() { void WalkObjectsTest::testWalkClass() { walkedObjects.clear(); - VMClass* meta = GetUniverse()->NewMetaclassClass(); + VMClass* meta = Universe::NewMetaclassClass(); meta->superClass = stringClass; meta->WalkObjects(collectMembers); @@ -150,14 +150,14 @@ void WalkObjectsTest::testWalkFrame() { VMSymbol* methodSymbol = NewSymbol("frameMethod"); vector inlinedLoops; - VMMethod* method = GetUniverse()->NewMethod( - methodSymbol, 0, 0, 0, 0, new LexicalScope(nullptr, {}, {}), - inlinedLoops); + VMMethod* method = + Universe::NewMethod(methodSymbol, 0, 0, 0, 0, + new LexicalScope(nullptr, {}, {}), inlinedLoops); - VMFrame* frame = GetUniverse()->NewFrame(nullptr, method); + VMFrame* frame = Universe::NewFrame(nullptr, method); frame->SetPreviousFrame(frame->CloneForMovingGC()); frame->SetContext(frame->CloneForMovingGC()); - VMInteger* dummyArg = GetUniverse()->NewInteger(1111); + VMInteger* dummyArg = Universe::NewInteger(1111); frame->SetArgument(0, 0, dummyArg); frame->WalkObjects(collectMembers); @@ -205,7 +205,7 @@ void WalkObjectsTest::testWalkMethod() { vector inlinedLoops; VMMethod* method = - GetUniverse()->NewMethod(methodSymbol, 0, 0, 0, 0, scope, inlinedLoops); + Universe::NewMethod(methodSymbol, 0, 0, 0, 0, scope, inlinedLoops); method->SetHolder(load_ptr(symbolClass)); method->WalkObjects(collectMembers); @@ -223,13 +223,12 @@ void WalkObjectsTest::testWalkBlock() { VMSymbol* methodSymbol = NewSymbol("someMethod"); vector inlinedLoops; - VMMethod* method = GetUniverse()->NewMethod( - methodSymbol, 0, 0, 0, 0, new LexicalScope(nullptr, {}, {}), - inlinedLoops); + VMMethod* method = + Universe::NewMethod(methodSymbol, 0, 0, 0, 0, + new LexicalScope(nullptr, {}, {}), inlinedLoops); - VMBlock* block = GetUniverse()->NewBlock( - method, GetUniverse()->GetInterpreter()->GetFrame(), - method->GetNumberOfArguments()); + VMBlock* block = Universe::NewBlock(method, Interpreter::GetFrame(), + method->GetNumberOfArguments()); block->WalkObjects(collectMembers); CPPUNIT_ASSERT_EQUAL(NoOfFields_Block, walkedObjects.size()); CPPUNIT_ASSERT(WalkerHasFound(tmp_ptr(block->GetClass()))); @@ -239,9 +238,9 @@ void WalkObjectsTest::testWalkBlock() { void WalkObjectsTest::testWalkArray() { walkedObjects.clear(); - VMString* str1 = GetUniverse()->NewString("str1"); - VMInteger* int1 = GetUniverse()->NewInteger(42); - VMArray* a = GetUniverse()->NewArray(2); + VMString* str1 = Universe::NewString("str1"); + VMInteger* int1 = Universe::NewInteger(42); + VMArray* a = Universe::NewArray(2); a->SetIndexableField(0, str1); a->SetIndexableField(1, int1); a->WalkObjects(collectMembers); diff --git a/src/unitTests/WriteBarrierTest.cpp b/src/unitTests/WriteBarrierTest.cpp index d409a101..22e3b677 100644 --- a/src/unitTests/WriteBarrierTest.cpp +++ b/src/unitTests/WriteBarrierTest.cpp @@ -38,10 +38,10 @@ void WriteBarrierTest::testWriteArray() { // reset set... GetHeap()->writeBarrierCalledOn.clear(); - VMArray* arr = GetUniverse()->NewArray(3); - VMInteger* newInt = GetUniverse()->NewInteger(12345); - VMString* str = GetUniverse()->NewString("asdfghjkl"); - VMDouble* doub = GetUniverse()->NewDouble(9876.654); + VMArray* arr = Universe::NewArray(3); + VMInteger* newInt = Universe::NewInteger(12345); + VMString* str = Universe::NewString("asdfghjkl"); + VMDouble* doub = Universe::NewDouble(9876.654); VMClass* cloneClass = load_ptr(arrayClass)->CloneForMovingGC(); VMClass* clone2Class = cloneClass->CloneForMovingGC(); arr->SetClass(cloneClass); @@ -80,13 +80,12 @@ void WriteBarrierTest::testWriteBlock() { VMSymbol* methodSymbol = NewSymbol("someMethod"); vector inlinedLoops; - VMMethod* method = GetUniverse()->NewMethod( - methodSymbol, 0, 0, 0, 0, new LexicalScope(nullptr, {}, {}), - inlinedLoops); + VMMethod* method = + Universe::NewMethod(methodSymbol, 0, 0, 0, 0, + new LexicalScope(nullptr, {}, {}), inlinedLoops); - VMBlock* block = GetUniverse()->NewBlock( - method, GetUniverse()->GetInterpreter()->GetFrame(), - method->GetNumberOfArguments()); + VMBlock* block = Universe::NewBlock(method, Interpreter::GetFrame(), + method->GetNumberOfArguments()); TEST_WB_CALLED("VMBlock failed to call writeBarrier when creating", block, block->GetClass()); TEST_WB_CALLED("VMBlock failed to call writeBarrier when creating", block, @@ -104,13 +103,12 @@ void WriteBarrierTest::testWriteFrame() { // reset set... GetHeap()->writeBarrierCalledOn.clear(); - VMFrame* frame = - GetUniverse()->GetInterpreter()->GetFrame()->CloneForMovingGC(); + VMFrame* frame = Interpreter::GetFrame()->CloneForMovingGC(); frame->SetContext(frame->CloneForMovingGC()); - frame->SetPreviousFrame(GetUniverse()->GetInterpreter()->GetFrame()); + frame->SetPreviousFrame(Interpreter::GetFrame()); TEST_WB_CALLED("VMFrame failed to call writeBarrier on SetPreviousFrame", - frame, GetUniverse()->GetInterpreter()->GetFrame()); + frame, Interpreter::GetFrame()); frame->SetContext(frame->GetContext()->CloneForMovingGC()); TEST_WB_CALLED("VMFrame failed to call writeBarrier on SetContext", frame, frame->GetContext()); @@ -127,11 +125,7 @@ void WriteBarrierTest::testWriteMethod() { // reset set... GetHeap()->writeBarrierCalledOn.clear(); - VMMethod* method = GetUniverse() - ->GetInterpreter() - ->GetFrame() - ->GetMethod() - ->CloneForMovingGC(); + VMMethod* method = Interpreter::GetFrame()->GetMethod()->CloneForMovingGC(); method->SetHolder(load_ptr(integerClass)); TEST_WB_CALLED("VMMethod failed to call writeBarrier on SetHolder", method, load_ptr(integerClass)); diff --git a/src/vm/Shell.cpp b/src/vm/Shell.cpp index 6e6020bf..a52f75d7 100644 --- a/src/vm/Shell.cpp +++ b/src/vm/Shell.cpp @@ -61,7 +61,7 @@ Shell::~Shell() { // TODO } -void Shell::Start(Interpreter* interp) { +void Shell::Start() { #define QUIT_CMD "system exit" #define QUIT_CMD_L 11 + 1 @@ -78,7 +78,7 @@ void Shell::Start(Interpreter* interp) { cout << "SOM Shell. Type \"" << QUIT_CMD << "\" to exit.\n"; // Create a fake bootstrap frame - currentFrame = interp->PushNewFrame(GetBootstrapMethod()); + currentFrame = Interpreter::PushNewFrame(GetBootstrapMethod()); // Remember the first bytecode index, e.g. index of the halt instruction bytecodeIndex = currentFrame->GetBytecodeIndex(); @@ -108,21 +108,21 @@ void Shell::Start(Interpreter* interp) { statement = ss.str(); ++counter; - runClass = GetUniverse()->LoadShellClass(statement); + runClass = Universe::LoadShellClass(statement); // Compile and load the newly generated class if (runClass == nullptr) { cout << "can't compile statement."; continue; } - currentFrame = interp->GetFrame(); + currentFrame = Interpreter::GetFrame(); // Go back, so we will evaluate the bootstrap frames halt // instruction again currentFrame->SetBytecodeIndex(bytecodeIndex); // Create and push a new instance of our class on the stack - currentFrame->Push(GetUniverse()->NewInstance(runClass)); + currentFrame->Push(Universe::NewInstance(runClass)); // Push the old value of "it" on the stack currentFrame->Push(it); @@ -131,14 +131,14 @@ void Shell::Start(Interpreter* interp) { VMInvokable* initialize = runClass->LookupInvokable(SymbolFor("run:")); // Invoke the run method - initialize->Invoke(interp, currentFrame); + initialize->Invoke(currentFrame); // Start the Interpreter if (dumpBytecodes > 1) { - interp->StartAndPrintBytecodes(); + Interpreter::StartAndPrintBytecodes(); } else { - interp->Start(); + Interpreter::Start(); } // Save the result of the run method diff --git a/src/vm/Shell.h b/src/vm/Shell.h index bbff65c3..570e17d6 100644 --- a/src/vm/Shell.h +++ b/src/vm/Shell.h @@ -36,7 +36,7 @@ class Shell { ~Shell(); void SetBootstrapMethod(VMMethod* bsm) { bootstrapMethod = bsm; }; VMMethod* GetBootstrapMethod() const { return bootstrapMethod; }; - void Start(Interpreter*); + void Start(); private: VMMethod* bootstrapMethod; diff --git a/src/vm/Universe.cpp b/src/vm/Universe.cpp index 1ea44ca5..83ed4df3 100644 --- a/src/vm/Universe.cpp +++ b/src/vm/Universe.cpp @@ -44,7 +44,6 @@ #include "../interpreter/bytecodes.h" #include "../memory/Heap.h" #include "../misc/defs.h" -#include "../vmobjects/AbstractObject.h" #include "../vmobjects/IntegerBox.h" #include "../vmobjects/ObjectFormats.h" #include "../vmobjects/VMArray.h" @@ -76,20 +75,22 @@ gc_oop_t prebuildInts[INT_CACHE_MAX_VALUE - INT_CACHE_MIN_VALUE + 1]; short dumpBytecodes; short gcVerbosity; -Universe* Universe::theUniverse = nullptr; - std::string bm_name; map integerHist; +map Universe::globals; +map Universe::blockClassesByNoOfArgs; +vector Universe::classPath; +long Universe::heapSize; + void Universe::Start(long argc, char** argv) { BasicInit(); - theUniverse->initialize(argc, argv); + Universe::initialize(argc, argv); } void Universe::BasicInit() { assert(Bytecode::BytecodeDefinitionsAreConsistent()); - theUniverse = new Universe(); } void Universe::Shutdown() { @@ -135,10 +136,6 @@ void Universe::Shutdown() { << it->second.noCalls - it->second.noPrimitiveCalls << endl; } #endif - - if (theUniverse) { - delete (theUniverse); - } } vector Universe::handleArguments(long argc, char** argv) { @@ -194,7 +191,7 @@ vector Universe::handleArguments(long argc, char** argv) { } long Universe::getClassPathExt(vector& tokens, - const StdString& arg) const { + const StdString& arg) { #define EXT_TOKENS 2 long result = ERR_SUCCESS; size_t fpIndex = arg.find_last_of(fileSeparator); @@ -241,7 +238,7 @@ long Universe::addClassPath(const StdString& cp) { return ERR_SUCCESS; } -void Universe::printUsageAndExit(char* executable) const { +void Universe::printUsageAndExit(char* executable) { cout << "Usage: " << executable << " [-options] [args...]" << endl << endl; cout << "where options include:" << endl; cout << " -cp " @@ -260,10 +257,6 @@ void Universe::printUsageAndExit(char* executable) const { Quit(ERR_SUCCESS); } -Universe::Universe() { - interpreter = nullptr; -} - VMMethod* Universe::createBootstrapMethod(VMClass* holder, long numArgsOfMsgSend) { vector inlinedLoops; @@ -283,8 +276,6 @@ vm_oop_t Universe::interpret(StdString className, StdString methodName) { bm_name = "BasicInterpreterTests"; - interpreter = new Interpreter(); - VMSymbol* classNameSym = SymbolFor(className); VMClass* clazz = LoadClass(classNameSym); @@ -310,14 +301,14 @@ vm_oop_t Universe::interpretMethod(VMObject* receiver, VMInvokable* initialize, VMMethod* bootstrapMethod = createBootstrapMethod(load_ptr(systemClass), 2); - VMFrame* bootstrapFrame = interpreter->PushNewFrame(bootstrapMethod); + VMFrame* bootstrapFrame = Interpreter::PushNewFrame(bootstrapMethod); bootstrapFrame->Push(receiver); if (argumentsArray != nullptr) { bootstrapFrame->Push(argumentsArray); } - initialize->Invoke(interpreter, bootstrapFrame); + initialize->Invoke(bootstrapFrame); // reset "-d" indicator if (!(trace > 0)) { @@ -325,9 +316,9 @@ vm_oop_t Universe::interpretMethod(VMObject* receiver, VMInvokable* initialize, } if (dumpBytecodes > 1) { - return interpreter->StartAndPrintBytecodes(); + return Interpreter::StartAndPrintBytecodes(); } - return interpreter->Start(); + return Interpreter::Start(); } void Universe::initialize(long _argc, char** _argv) { @@ -344,8 +335,6 @@ void Universe::initialize(long _argc, char** _argv) { Heap::InitializeHeap(heapSize); - interpreter = new Interpreter(); - #if CACHE_INTEGER // create prebuilt integers for (long it = INT_CACHE_MIN_VALUE; it <= INT_CACHE_MAX_VALUE; ++it) { @@ -360,7 +349,7 @@ void Universe::initialize(long _argc, char** _argv) { VMMethod* bootstrapMethod = createBootstrapMethod(load_ptr(systemClass), 2); Shell* shell = new Shell(bootstrapMethod); - shell->Start(interpreter); + shell->Start(); return; } @@ -372,10 +361,6 @@ void Universe::initialize(long _argc, char** _argv) { } Universe::~Universe() { - if (interpreter) { - delete (interpreter); - } - // check done inside Heap::DestroyHeap(); } @@ -471,13 +456,13 @@ VMObject* Universe::InitializeGlobals() { return systemObject; } -void Universe::Assert(bool value) const { +void Universe::Assert(bool value) { if (!value) { ErrorPrint("Universe::Assert Assertion failed\n"); } } -VMClass* Universe::GetBlockClass() const { +VMClass* Universe::GetBlockClass() { return load_ptr(blockClass); } @@ -618,7 +603,7 @@ void Universe::LoadSystemClass(VMClass* systemClass) { } } -VMArray* Universe::NewArray(size_t size) const { +VMArray* Universe::NewArray(size_t size) { size_t additionalBytes = size * sizeof(VMObject*); bool outsideNursery; @@ -644,8 +629,7 @@ VMArray* Universe::NewArray(size_t size) const { return result; } -VMArray* Universe::NewArrayFromStrings( - const vector& strings) const { +VMArray* Universe::NewArrayFromStrings(const vector& strings) { VMArray* result = NewArray(strings.size()); size_t j = 0; for (const std::string& str : strings) { @@ -656,7 +640,7 @@ VMArray* Universe::NewArrayFromStrings( } VMArray* Universe::NewArrayOfSymbolsFromStrings( - const vector& strings) const { + const vector& strings) { VMArray* result = NewArray(strings.size()); size_t j = 0; for (const std::string& str : strings) { @@ -666,17 +650,17 @@ VMArray* Universe::NewArrayOfSymbolsFromStrings( return result; } -VMArray* Universe::NewArrayList(std::vector& list) const { +VMArray* Universe::NewArrayList(std::vector& list) { std::vector& objList = (std::vector&)list; return NewArrayList(objList); } -VMArray* Universe::NewArrayList(std::vector& list) const { +VMArray* Universe::NewArrayList(std::vector& list) { std::vector& objList = (std::vector&)list; return NewArrayList(objList); } -VMArray* Universe::NewArrayList(std::vector& list) const { +VMArray* Universe::NewArrayList(std::vector& list) { size_t size = list.size(); VMArray* result = NewArray(size); @@ -698,7 +682,7 @@ VMBlock* Universe::NewBlock(VMInvokable* method, VMFrame* context, return result; } -VMClass* Universe::NewClass(VMClass* classOfClass) const { +VMClass* Universe::NewClass(VMClass* classOfClass) { size_t numFields = classOfClass->GetNumberOfInstanceFields(); VMClass* result = nullptr; @@ -716,12 +700,12 @@ VMClass* Universe::NewClass(VMClass* classOfClass) const { return result; } -VMDouble* Universe::NewDouble(double value) const { +VMDouble* Universe::NewDouble(double value) { LOG_ALLOCATION("VMDouble", sizeof(VMDouble)); return new (GetHeap(), 0) VMDouble(value); } -VMFrame* Universe::NewFrame(VMFrame* previousFrame, VMMethod* method) const { +VMFrame* Universe::NewFrame(VMFrame* previousFrame, VMMethod* method) { VMFrame* result = nullptr; #ifdef UNSAFE_FRAME_OPTIMIZATION result = method->GetCachedFrame(); @@ -746,7 +730,7 @@ VMFrame* Universe::NewFrame(VMFrame* previousFrame, VMMethod* method) const { return result; } -VMObject* Universe::NewInstance(VMClass* classOfInstance) const { +VMObject* Universe::NewInstance(VMClass* classOfInstance) { long numOfFields = classOfInstance->GetNumberOfInstanceFields(); // the additional space needed is calculated from the number of fields long additionalBytes = numOfFields * sizeof(VMObject*); @@ -759,13 +743,13 @@ VMObject* Universe::NewInstance(VMClass* classOfInstance) const { return result; } -VMObject* Universe::NewInstanceWithoutFields() const { +VMObject* Universe::NewInstanceWithoutFields() { VMObject* result = new (GetHeap(), 0) VMObject(0, sizeof(VMObject)); return result; } -VMInteger* Universe::NewInteger(int64_t value) const { +VMInteger* Universe::NewInteger(int64_t value) { #ifdef GENERATE_INTEGER_HISTOGRAM integerHist[value / INT_HIST_SIZE] = integerHist[value / INT_HIST_SIZE] + 1; #endif @@ -781,7 +765,7 @@ VMInteger* Universe::NewInteger(int64_t value) const { return new (GetHeap(), 0) VMInteger(value); } -VMClass* Universe::NewMetaclassClass() const { +VMClass* Universe::NewMetaclassClass() { VMClass* result = new (GetHeap(), 0) VMClass; VMClass* mclass = new (GetHeap(), 0) VMClass; result->SetClass(mclass); @@ -849,13 +833,13 @@ void Universe::WalkGlobals(walk_heap_fn walk) { bcIter->second = static_cast(walk(bcIter->second)); } - interpreter->WalkGlobals(walk); + Interpreter::WalkGlobals(walk); } VMMethod* Universe::NewMethod(VMSymbol* signature, size_t numberOfBytecodes, size_t numberOfConstants, size_t numLocals, size_t maxStackDepth, LexicalScope* lexicalScope, - vector& inlinedLoops) const { + vector& inlinedLoops) { assert(lexicalScope != nullptr && "A method is expected to have a lexical scope"); @@ -884,11 +868,11 @@ VMMethod* Universe::NewMethod(VMSymbol* signature, size_t numberOfBytecodes, return result; } -VMString* Universe::NewString(const StdString& str) const { +VMString* Universe::NewString(const StdString& str) { return NewString(str.length(), str.c_str()); } -VMString* Universe::NewString(const size_t length, const char* str) const { +VMString* Universe::NewString(const size_t length, const char* str) { VMString* result = new (GetHeap(), PADDED_SIZE(length)) VMString(length, str); @@ -896,7 +880,7 @@ VMString* Universe::NewString(const size_t length, const char* str) const { return result; } -VMClass* Universe::NewSystemClass() const { +VMClass* Universe::NewSystemClass() { VMClass* systemClass = new (GetHeap(), 0) VMClass(); VMClass* mclass = new (GetHeap(), 0) VMClass(); diff --git a/src/vm/Universe.h b/src/vm/Universe.h index ecc7e82f..6dfb4643 100644 --- a/src/vm/Universe.h +++ b/src/vm/Universe.h @@ -45,114 +45,91 @@ extern short gcVerbosity; using namespace std; class Universe { public: - inline Universe* operator->(); - // static methods static void Start(long argc, char** argv); static void BasicInit(); - vm_oop_t interpret(StdString className, StdString methodName); - - long setupClassPath(const StdString& cp); + static vm_oop_t interpret(StdString className, StdString methodName); - Interpreter* GetInterpreter() { return interpreter; } + static long setupClassPath(const StdString& cp); - void Assert(bool) const; + static void Assert(bool); // VMObject instanciation methods. These should probably be refactored to a // new class - VMArray* NewArray(size_t) const; - - VMArray* NewArrayList(std::vector& list) const; - VMArray* NewArrayList(std::vector& list) const; - VMArray* NewArrayList(std::vector& list) const; - - VMArray* NewArrayFromStrings(const vector&) const; - VMArray* NewArrayOfSymbolsFromStrings(const vector&) const; - - VMBlock* NewBlock(VMInvokable*, VMFrame*, long); - VMClass* NewClass(VMClass*) const; - VMFrame* NewFrame(VMFrame*, VMMethod*) const; - VMMethod* NewMethod(VMSymbol*, size_t numberOfBytecodes, - size_t numberOfConstants, size_t numLocals, - size_t maxStackDepth, LexicalScope*, - vector& inlinedLoops) const; - VMObject* NewInstance(VMClass*) const; - VMObject* NewInstanceWithoutFields() const; - VMInteger* NewInteger(int64_t) const; - void WalkGlobals(walk_heap_fn); - VMDouble* NewDouble(double) const; - VMClass* NewMetaclassClass(void) const; - VMString* NewString(const StdString&) const; - VMString* NewString(const size_t, const char*) const; - VMClass* NewSystemClass(void) const; - - void InitializeSystemClass(VMClass*, VMClass*, const char*); - - vm_oop_t GetGlobal(VMSymbol*); - void SetGlobal(VMSymbol* name, vm_oop_t val); - bool HasGlobal(VMSymbol*); - VMObject* InitializeGlobals(); - VMClass* GetBlockClass(void) const; - VMClass* GetBlockClassWithArgs(long); - - VMClass* LoadClass(VMSymbol*); - void LoadSystemClass(VMClass*); - VMClass* LoadClassBasic(VMSymbol*, VMClass*); - VMClass* LoadShellClass(StdString&); - - Universe(); + static VMArray* NewArray(size_t); + + static VMArray* NewArrayList(std::vector& list); + static VMArray* NewArrayList(std::vector& list); + static VMArray* NewArrayList(std::vector& list); + + static VMArray* NewArrayFromStrings(const vector&); + static VMArray* NewArrayOfSymbolsFromStrings(const vector&); + + static VMBlock* NewBlock(VMInvokable*, VMFrame*, long); + static VMClass* NewClass(VMClass*); + static VMFrame* NewFrame(VMFrame*, VMMethod*); + static VMMethod* NewMethod(VMSymbol*, size_t numberOfBytecodes, + size_t numberOfConstants, size_t numLocals, + size_t maxStackDepth, LexicalScope*, + vector& inlinedLoops); + static VMObject* NewInstance(VMClass*); + static VMObject* NewInstanceWithoutFields(); + static VMInteger* NewInteger(int64_t); + static void WalkGlobals(walk_heap_fn); + static VMDouble* NewDouble(double); + static VMClass* NewMetaclassClass(); + static VMString* NewString(const StdString&); + static VMString* NewString(const size_t, const char*); + static VMClass* NewSystemClass(); + + static void InitializeSystemClass(VMClass*, VMClass*, const char*); + + static vm_oop_t GetGlobal(VMSymbol*); + static void SetGlobal(VMSymbol* name, vm_oop_t val); + static bool HasGlobal(VMSymbol*); + static VMObject* InitializeGlobals(); + static VMClass* GetBlockClass(); + static VMClass* GetBlockClassWithArgs(long); + + static VMClass* LoadClass(VMSymbol*); + static void LoadSystemClass(VMClass*); + static VMClass* LoadClassBasic(VMSymbol*, VMClass*); + static VMClass* LoadShellClass(StdString&); + + Universe() {} ~Universe(); #ifdef LOG_RECEIVER_TYPES struct stat_data { long noCalls; long noPrimitiveCalls; }; - map receiverTypes; - map callStats; + static map receiverTypes; + static map callStats; #endif // static void Shutdown(); private: - vm_oop_t interpretMethod(VMObject* receiver, VMInvokable* initialize, - VMArray* argumentsArray); - - vector handleArguments(long argc, char** argv); - long getClassPathExt(vector& tokens, const StdString& arg) const; + static vm_oop_t interpretMethod(VMObject* receiver, VMInvokable* initialize, + VMArray* argumentsArray); - VMMethod* createBootstrapMethod(VMClass* holder, long numArgsOfMsgSend); + static vector handleArguments(long argc, char** argv); + static long getClassPathExt(vector& tokens, + const StdString& arg); - friend Universe* GetUniverse(); - static Universe* theUniverse; + static VMMethod* createBootstrapMethod(VMClass* holder, + long numArgsOfMsgSend); - long addClassPath(const StdString& cp); - void printUsageAndExit(char* executable) const; + static long addClassPath(const StdString& cp); + static void printUsageAndExit(char* executable); - void initialize(long, char**); + static void initialize(long, char**); - long heapSize; - map globals; + static long heapSize; + static map globals; - map blockClassesByNoOfArgs; - vector classPath; - - Interpreter* interpreter; + static map blockClassesByNoOfArgs; + static vector classPath; }; - -// Singleton accessor -inline Universe* GetUniverse() __attribute__((always_inline)); -Universe* GetUniverse() { - if (DEBUG && Universe::theUniverse == nullptr) { - ErrorExit("Trying to access uninitialized Universe, exiting."); - } - return Universe::theUniverse; -} - -Universe* Universe::operator->() { - if (DEBUG && theUniverse == nullptr) { - ErrorExit("Trying to access uninitialized Universe, exiting."); - } - return theUniverse; -} diff --git a/src/vmobjects/AbstractObject.cpp b/src/vmobjects/AbstractObject.cpp index 509dc6eb..163b55a9 100644 --- a/src/vmobjects/AbstractObject.cpp +++ b/src/vmobjects/AbstractObject.cpp @@ -17,9 +17,9 @@ #include "VMInvokable.h" #include "VMSymbol.h" -void AbstractVMObject::Send(Interpreter* interp, std::string selectorString, - vm_oop_t* arguments, long argc) { - VMFrame* frame = interp->GetFrame(); +void AbstractVMObject::Send(std::string selectorString, vm_oop_t* arguments, + long argc) { + VMFrame* frame = Interpreter::GetFrame(); VMSymbol* selector = SymbolFor(selectorString); frame->Push(this); @@ -29,7 +29,7 @@ void AbstractVMObject::Send(Interpreter* interp, std::string selectorString, VMClass* cl = GetClass(); VMInvokable* invokable = cl->LookupInvokable(selector); - invokable->Invoke(interp, frame); + invokable->Invoke(frame); } long AbstractVMObject::GetFieldIndex(VMSymbol* fieldName) const { diff --git a/src/vmobjects/AbstractObject.h b/src/vmobjects/AbstractObject.h index 94c61be8..eb5c6705 100644 --- a/src/vmobjects/AbstractObject.h +++ b/src/vmobjects/AbstractObject.h @@ -21,8 +21,6 @@ using namespace std; -class Interpreter; - // this is the base class for all VMObjects class AbstractVMObject : public VMObjectBase { public: @@ -31,7 +29,7 @@ class AbstractVMObject : public VMObjectBase { virtual int64_t GetHash() const = 0; virtual VMClass* GetClass() const = 0; virtual AbstractVMObject* CloneForMovingGC() const = 0; - void Send(Interpreter*, StdString, vm_oop_t*, long); + void Send(StdString, vm_oop_t*, long); /** Size in bytes of the object. */ virtual size_t GetObjectSize() const = 0; diff --git a/src/vmobjects/ObjectFormats.h b/src/vmobjects/ObjectFormats.h index 6e7ca576..5d855dc5 100644 --- a/src/vmobjects/ObjectFormats.h +++ b/src/vmobjects/ObjectFormats.h @@ -44,14 +44,14 @@ #if ADDITIONAL_ALLOCATION #define TAG_INTEGER(X) \ (((X) >= VMTAGGEDINTEGER_MIN && (X) <= VMTAGGEDINTEGER_MAX && \ - GetUniverse()->NewInteger(0)) \ + Universe::NewInteger(0)) \ ? ((vm_oop_t)(((X) << 1) | 1)) \ - : (GetUniverse()->NewInteger(X))) + : (Universe::NewInteger(X))) #else #define TAG_INTEGER(X) \ (((X) >= VMTAGGEDINTEGER_MIN && (X) <= VMTAGGEDINTEGER_MAX) \ ? ((vm_oop_t)((((uint64_t)(X)) << 1) | 1U)) \ - : (GetUniverse()->NewInteger(X))) + : (Universe::NewInteger(X))) #endif #if USE_TAGGING @@ -67,7 +67,7 @@ (IS_TAGGED(X) ? GlobalBox::IntegerBox() : ((AbstractVMObject*)(X))) #else #define INT_VAL(X) (static_cast(X)->GetEmbeddedInteger()) - #define NEW_INT(X) (GetUniverse()->NewInteger(X)) + #define NEW_INT(X) (Universe::NewInteger(X)) #define IS_TAGGED(X) false #define CLASS_OF(X) (AS_OBJ(X)->GetClass()) #define AS_OBJ(X) ((AbstractVMObject*)(X)) diff --git a/src/vmobjects/PrimitiveRoutine.h b/src/vmobjects/PrimitiveRoutine.h index 52985429..1348dbf3 100644 --- a/src/vmobjects/PrimitiveRoutine.h +++ b/src/vmobjects/PrimitiveRoutine.h @@ -34,7 +34,7 @@ class PrimitiveRoutine { public: PrimitiveRoutine() {}; - virtual void Invoke(Interpreter*, VMFrame*) = 0; // call using operator + virtual void Invoke(VMFrame*) = 0; // call using operator virtual bool isClassSide() = 0; }; diff --git a/src/vmobjects/VMArray.cpp b/src/vmobjects/VMArray.cpp index 9460b20c..78e268db 100644 --- a/src/vmobjects/VMArray.cpp +++ b/src/vmobjects/VMArray.cpp @@ -69,7 +69,7 @@ void VMArray::SetIndexableField(size_t idx, vm_oop_t value) { } VMArray* VMArray::Copy() const { - VMArray* copy = GetUniverse()->NewArray(GetNumberOfIndexableFields()); + VMArray* copy = Universe::NewArray(GetNumberOfIndexableFields()); const size_t additionalSpace = totalObjectSize - sizeof(VMArray); void* destination = SHIFTED_PTR(copy, sizeof(VMArray)); @@ -81,7 +81,7 @@ VMArray* VMArray::Copy() const { VMArray* VMArray::CopyAndExtendWith(vm_oop_t item) const { const size_t fields = GetNumberOfIndexableFields(); - VMArray* result = GetUniverse()->NewArray(fields + 1); + VMArray* result = Universe::NewArray(fields + 1); CopyIndexableFieldsTo(result); result->SetIndexableField(fields, item); return result; diff --git a/src/vmobjects/VMEvaluationPrimitive.cpp b/src/vmobjects/VMEvaluationPrimitive.cpp index d41ad9e1..a7d700a3 100644 --- a/src/vmobjects/VMEvaluationPrimitive.cpp +++ b/src/vmobjects/VMEvaluationPrimitive.cpp @@ -33,7 +33,6 @@ #include "../compiler/LexicalScope.h" #include "../memory/Heap.h" #include "../misc/defs.h" -#include "../primitivesCore/Routine.h" #include "../vm/Print.h" #include "../vm/Symbols.h" #include "../vm/Universe.h" // NOLINT(misc-include-cleaner) it's required to make the types complete @@ -84,7 +83,7 @@ VMSymbol* VMEvaluationPrimitive::computeSignatureString(long argc) { return SymbolFor(signatureString); } -VMFrame* VMEvaluationPrimitive::Invoke(Interpreter* interp, VMFrame* frame) { +VMFrame* VMEvaluationPrimitive::Invoke(VMFrame* frame) { // Get the block (the receiver) from the stack VMBlock* block = static_cast(frame->GetStackElement(numberOfArguments - 1)); @@ -94,7 +93,7 @@ VMFrame* VMEvaluationPrimitive::Invoke(Interpreter* interp, VMFrame* frame) { VMInvokable* method = block->GetMethod(); - VMFrame* newFrame = method->Invoke(interp, frame); + VMFrame* newFrame = method->Invoke(frame); // Push set its context to be the one specified in the block if (newFrame != nullptr) { diff --git a/src/vmobjects/VMEvaluationPrimitive.h b/src/vmobjects/VMEvaluationPrimitive.h index 20a8b17e..f7d60f0f 100644 --- a/src/vmobjects/VMEvaluationPrimitive.h +++ b/src/vmobjects/VMEvaluationPrimitive.h @@ -47,7 +47,7 @@ class VMEvaluationPrimitive : public VMInvokable { void MarkObjectAsInvalid() override; bool IsMarkedInvalid() const override; - VMFrame* Invoke(Interpreter* interp, VMFrame* frm) override; + VMFrame* Invoke(VMFrame* frm) override; void InlineInto(MethodGenerationContext& mgenc, bool mergeScope = true) final; @@ -57,7 +57,7 @@ class VMEvaluationPrimitive : public VMInvokable { private: static VMSymbol* computeSignatureString(long argc); - void evaluationRoutine(Interpreter*, VMFrame*); + void evaluationRoutine(VMFrame*); make_testable(public); diff --git a/src/vmobjects/VMInvokable.h b/src/vmobjects/VMInvokable.h index 603e2d95..3a112a7f 100644 --- a/src/vmobjects/VMInvokable.h +++ b/src/vmobjects/VMInvokable.h @@ -43,7 +43,7 @@ class VMInvokable : public AbstractVMObject { int64_t GetHash() const override { return hash; } - virtual VMFrame* Invoke(Interpreter*, VMFrame*) = 0; + virtual VMFrame* Invoke(VMFrame*) = 0; virtual void InlineInto(MethodGenerationContext& mgenc, bool mergeScope = true) = 0; virtual void MergeScopeInto( diff --git a/src/vmobjects/VMMethod.cpp b/src/vmobjects/VMMethod.cpp index b9c35f54..3518b518 100644 --- a/src/vmobjects/VMMethod.cpp +++ b/src/vmobjects/VMMethod.cpp @@ -126,8 +126,8 @@ void VMMethod::SetCachedFrame(VMFrame* frame) { } #endif -VMFrame* VMMethod::Invoke(Interpreter* interp, VMFrame* frame) { - VMFrame* frm = interp->PushNewFrame(this); +VMFrame* VMMethod::Invoke(VMFrame* frame) { + VMFrame* frm = Interpreter::PushNewFrame(this); frm->CopyArgumentsFrom(frame); return frm; } diff --git a/src/vmobjects/VMMethod.h b/src/vmobjects/VMMethod.h index f164b6d5..c4e96f4b 100644 --- a/src/vmobjects/VMMethod.h +++ b/src/vmobjects/VMMethod.h @@ -149,7 +149,7 @@ class VMMethod : public VMInvokable { store_ptr(indexableFields[idx], item); } - VMFrame* Invoke(Interpreter* interp, VMFrame* frame) override; + VMFrame* Invoke(VMFrame* frame) override; void MarkObjectAsInvalid() override { VMInvokable::MarkObjectAsInvalid(); diff --git a/src/vmobjects/VMObject.cpp b/src/vmobjects/VMObject.cpp index 0289ffc1..b4d99992 100644 --- a/src/vmobjects/VMObject.cpp +++ b/src/vmobjects/VMObject.cpp @@ -81,7 +81,7 @@ VMSymbol* VMObject::GetFieldName(long index) const { } void VMObject::Assert(bool value) const { - GetUniverse()->Assert(value); + Universe::Assert(value); } void VMObject::WalkObjects(walk_heap_fn walk) { diff --git a/src/vmobjects/VMPrimitive.cpp b/src/vmobjects/VMPrimitive.cpp index d2b0498a..f0cb03c8 100644 --- a/src/vmobjects/VMPrimitive.cpp +++ b/src/vmobjects/VMPrimitive.cpp @@ -58,7 +58,7 @@ VMPrimitive* VMPrimitive::CloneForMovingGC() const { return prim; } -void VMPrimitive::EmptyRoutine(Interpreter*, VMFrame*) { +void VMPrimitive::EmptyRoutine(VMFrame*) { VMSymbol* sig = GetSignature(); ErrorPrint("undefined primitive called: " + sig->GetStdString() + "\n"); } diff --git a/src/vmobjects/VMPrimitive.h b/src/vmobjects/VMPrimitive.h index 05404a94..5ffdace5 100644 --- a/src/vmobjects/VMPrimitive.h +++ b/src/vmobjects/VMPrimitive.h @@ -53,8 +53,8 @@ class VMPrimitive : public VMInvokable { void SetEmpty(bool value) { empty = value; }; VMPrimitive* CloneForMovingGC() const override; - VMFrame* Invoke(Interpreter* interp, VMFrame* frm) override { - routine->Invoke(interp, frm); + VMFrame* Invoke(VMFrame* frm) override { + routine->Invoke(frm); return nullptr; }; @@ -78,7 +78,7 @@ class VMPrimitive : public VMInvokable { } private: - void EmptyRoutine(Interpreter*, VMFrame*); + void EmptyRoutine(VMFrame*); public: PrimitiveRoutine* routine; diff --git a/src/vmobjects/VMSafePrimitive.cpp b/src/vmobjects/VMSafePrimitive.cpp index 4f38d6f8..192bbb09 100644 --- a/src/vmobjects/VMSafePrimitive.cpp +++ b/src/vmobjects/VMSafePrimitive.cpp @@ -19,7 +19,7 @@ VMSafePrimitive* VMSafePrimitive::GetSafeUnary(VMSymbol* sig, UnaryPrim prim) { return p; } -VMFrame* VMSafeUnaryPrimitive::Invoke(Interpreter*, VMFrame* frame) { +VMFrame* VMSafeUnaryPrimitive::Invoke(VMFrame* frame) { vm_oop_t receiverObj = frame->Pop(); frame->Push(prim.pointer(receiverObj)); @@ -33,7 +33,7 @@ VMSafePrimitive* VMSafePrimitive::GetSafeBinary(VMSymbol* sig, return p; } -VMFrame* VMSafeBinaryPrimitive::Invoke(Interpreter*, VMFrame* frame) { +VMFrame* VMSafeBinaryPrimitive::Invoke(VMFrame* frame) { vm_oop_t rightObj = frame->Pop(); vm_oop_t leftObj = frame->Pop(); @@ -48,7 +48,7 @@ VMSafePrimitive* VMSafePrimitive::GetSafeTernary(VMSymbol* sig, return p; } -VMFrame* VMSafeTernaryPrimitive::Invoke(Interpreter*, VMFrame* frame) { +VMFrame* VMSafeTernaryPrimitive::Invoke(VMFrame* frame) { vm_oop_t arg2 = frame->Pop(); vm_oop_t arg1 = frame->Pop(); vm_oop_t self = frame->Pop(); diff --git a/src/vmobjects/VMSafePrimitive.h b/src/vmobjects/VMSafePrimitive.h index cb0d8384..e5f7a1da 100644 --- a/src/vmobjects/VMSafePrimitive.h +++ b/src/vmobjects/VMSafePrimitive.h @@ -40,7 +40,7 @@ class VMSafeUnaryPrimitive : public VMSafePrimitive { return sizeof(VMSafeUnaryPrimitive); } - VMFrame* Invoke(Interpreter*, VMFrame*) override; + VMFrame* Invoke(VMFrame*) override; AbstractVMObject* CloneForMovingGC() const final; @@ -68,7 +68,7 @@ class VMSafeBinaryPrimitive : public VMSafePrimitive { return sizeof(VMSafeBinaryPrimitive); } - VMFrame* Invoke(Interpreter*, VMFrame*) override; + VMFrame* Invoke(VMFrame*) override; AbstractVMObject* CloneForMovingGC() const final; @@ -96,7 +96,7 @@ class VMSafeTernaryPrimitive : public VMSafePrimitive { return sizeof(VMSafeTernaryPrimitive); } - VMFrame* Invoke(Interpreter*, VMFrame*) override; + VMFrame* Invoke(VMFrame*) override; AbstractVMObject* CloneForMovingGC() const final; diff --git a/src/vmobjects/VMTrivialMethod.cpp b/src/vmobjects/VMTrivialMethod.cpp index 566f5613..7013e7e6 100644 --- a/src/vmobjects/VMTrivialMethod.cpp +++ b/src/vmobjects/VMTrivialMethod.cpp @@ -8,6 +8,7 @@ #include "../compiler/BytecodeGenerator.h" #include "../compiler/MethodGenerationContext.h" #include "../compiler/Variable.h" +#include "../interpreter/Interpreter.h" #include "../memory/Heap.h" #include "../misc/defs.h" #include "../vm/LogAllocation.h" @@ -49,7 +50,7 @@ VMTrivialMethod* MakeSetter(VMSymbol* sig, vector& arguments, return result; } -VMFrame* VMLiteralReturn::Invoke(Interpreter*, VMFrame* frame) { +VMFrame* VMLiteralReturn::Invoke(VMFrame* frame) { for (int i = 0; i < numberOfArguments; i += 1) { frame->Pop(); } @@ -77,16 +78,16 @@ void VMLiteralReturn::InlineInto(MethodGenerationContext& mgenc, bool) { EmitPUSHCONSTANT(mgenc, load_ptr(literal)); } -VMFrame* VMGlobalReturn::Invoke(Interpreter* interpreter, VMFrame* frame) { +VMFrame* VMGlobalReturn::Invoke(VMFrame* frame) { for (int i = 0; i < numberOfArguments; i += 1) { frame->Pop(); } - vm_oop_t value = GetUniverse()->GetGlobal(load_ptr(globalName)); + vm_oop_t value = Universe::GetGlobal(load_ptr(globalName)); if (value != nullptr) { frame->Push(value); } else { - interpreter->SendUnknownGlobal(load_ptr(globalName)); + Interpreter::SendUnknownGlobal(load_ptr(globalName)); } return nullptr; @@ -112,7 +113,7 @@ AbstractVMObject* VMGlobalReturn::CloneForMovingGC() const { return prim; } -VMFrame* VMGetter::Invoke(Interpreter*, VMFrame* frame) { +VMFrame* VMGetter::Invoke(VMFrame* frame) { vm_oop_t self = nullptr; for (int i = 0; i < numberOfArguments; i += 1) { self = frame->Pop(); @@ -150,7 +151,7 @@ std::string VMGetter::AsDebugString() const { return "VMGetter(fieldIndex: " + to_string(fieldIndex) + ")"; } -VMFrame* VMSetter::Invoke(Interpreter*, VMFrame* frame) { +VMFrame* VMSetter::Invoke(VMFrame* frame) { vm_oop_t value = nullptr; vm_oop_t self = nullptr; diff --git a/src/vmobjects/VMTrivialMethod.h b/src/vmobjects/VMTrivialMethod.h index f65e6569..ad2c9df1 100644 --- a/src/vmobjects/VMTrivialMethod.h +++ b/src/vmobjects/VMTrivialMethod.h @@ -66,7 +66,7 @@ class VMLiteralReturn : public VMTrivialMethod { return sizeof(VMLiteralReturn); } - VMFrame* Invoke(Interpreter*, VMFrame*) override; + VMFrame* Invoke(VMFrame*) override; void InlineInto(MethodGenerationContext& mgenc, bool mergeScope = true) final; @@ -105,7 +105,7 @@ class VMGlobalReturn : public VMTrivialMethod { return sizeof(VMGlobalReturn); } - VMFrame* Invoke(Interpreter*, VMFrame*) override; + VMFrame* Invoke(VMFrame*) override; void InlineInto(MethodGenerationContext& mgenc, bool mergeScope = true) final; @@ -141,7 +141,7 @@ class VMGetter : public VMTrivialMethod { inline size_t GetObjectSize() const override { return sizeof(VMGetter); } - VMFrame* Invoke(Interpreter*, VMFrame*) override; + VMFrame* Invoke(VMFrame*) override; void InlineInto(MethodGenerationContext& mgenc, bool mergeScope = true) final; @@ -176,7 +176,7 @@ class VMSetter : public VMTrivialMethod { inline size_t GetObjectSize() const override { return sizeof(VMSetter); } - VMFrame* Invoke(Interpreter*, VMFrame*) override; + VMFrame* Invoke(VMFrame*) override; void InlineInto(MethodGenerationContext& mgenc, bool mergeScope = true) final;