From 6e7d9b34cda0dcb7c3133cdf716b264e8315d847 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Sun, 18 Aug 2024 23:57:04 +0200 Subject: [PATCH] More int work Signed-off-by: Stefan Marr --- src/compiler/Disassembler.cpp | 2 +- src/memory/DebugCopyingCollector.cpp | 2 +- src/primitives/Integer.cpp | 4 ++-- src/primitives/System.cpp | 7 +++--- src/vm/Shell.cpp | 2 +- src/vm/Universe.cpp | 31 ++++++++++++------------- src/vm/Universe.h | 12 +++++----- src/vmobjects/VMClass.cpp | 4 ++-- src/vmobjects/VMEvaluationPrimitive.cpp | 2 +- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/compiler/Disassembler.cpp b/src/compiler/Disassembler.cpp index 2cfd0f10..518e1df5 100644 --- a/src/compiler/Disassembler.cpp +++ b/src/compiler/Disassembler.cpp @@ -333,7 +333,7 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes, */ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method, size_t bc_idx) { - static long long indentc = 0; + static int64_t indentc = 0; static char ikind = '@'; uint8_t const bc = BC_0; VMClass* cl = method->GetHolder(); diff --git a/src/memory/DebugCopyingCollector.cpp b/src/memory/DebugCopyingCollector.cpp index eee9511b..f1cad1f1 100644 --- a/src/memory/DebugCopyingCollector.cpp +++ b/src/memory/DebugCopyingCollector.cpp @@ -41,7 +41,7 @@ static gc_oop_t copy_if_necessary(gc_oop_t oop) { obj->MarkObjectAsInvalid(); } - obj->SetGCField((long)newObj); + obj->SetGCField((uintptr_t)newObj); return tmp_ptr(newObj); } diff --git a/src/primitives/Integer.cpp b/src/primitives/Integer.cpp index da26f95a..38b2a065 100644 --- a/src/primitives/Integer.cpp +++ b/src/primitives/Integer.cpp @@ -234,14 +234,14 @@ static vm_oop_t intGreaterThanEqual(vm_oop_t leftObj, vm_oop_t rightObj) { } static vm_oop_t intAsString(vm_oop_t self) { - long const integer = INT_VAL(self); + int64_t const integer = INT_VAL(self); ostringstream Str; Str << integer; return Universe::NewString(Str.str()); } static vm_oop_t intAsDouble(vm_oop_t self) { - long const integer = INT_VAL(self); + int64_t const integer = INT_VAL(self); return Universe::NewDouble((double)integer); } diff --git a/src/primitives/System.cpp b/src/primitives/System.cpp index ec47ecf9..5bcd00ad 100644 --- a/src/primitives/System.cpp +++ b/src/primitives/System.cpp @@ -26,6 +26,7 @@ #include "System.h" +#include #include #include #include @@ -87,7 +88,7 @@ static vm_oop_t sysLoad_(vm_oop_t /*unused*/, vm_oop_t rightObj) { } static vm_oop_t sysExit_(vm_oop_t /*unused*/, vm_oop_t err) { - long const err_no = INT_VAL(err); + int64_t const err_no = INT_VAL(err); Quit(err_no); } @@ -124,7 +125,7 @@ static vm_oop_t sysTime(vm_oop_t /*unused*/) { gettimeofday(&now, nullptr); - long long const diff = + int64_t const diff = ((now.tv_sec - start_time.tv_sec) * 1000) + // seconds ((now.tv_usec - start_time.tv_usec) / 1000); // useconds @@ -136,7 +137,7 @@ static vm_oop_t sysTicks(vm_oop_t /*unused*/) { gettimeofday(&now, nullptr); - long long const diff = + int64_t const diff = ((now.tv_sec - start_time.tv_sec) * 1000 * 1000) + // seconds ((now.tv_usec - start_time.tv_usec)); // useconds diff --git a/src/vm/Shell.cpp b/src/vm/Shell.cpp index 1c19b106..e616e8ad 100644 --- a/src/vm/Shell.cpp +++ b/src/vm/Shell.cpp @@ -70,7 +70,7 @@ void Shell::Start() { } // the statement to evaluate char inbuf[INPUT_MAX_SIZE]; - long bytecodeIndex = 0, counter = 0; + size_t bytecodeIndex = 0, counter = 0; VMFrame* currentFrame = nullptr; VMClass* runClass = nullptr; vm_oop_t it = load_ptr(nilObject); // last evaluation result. diff --git a/src/vm/Universe.cpp b/src/vm/Universe.cpp index c2f9421b..19ae1793 100644 --- a/src/vm/Universe.cpp +++ b/src/vm/Universe.cpp @@ -139,12 +139,12 @@ void Universe::Shutdown() { #endif } -vector Universe::handleArguments(long argc, char** argv) { +vector Universe::handleArguments(int32_t argc, char** argv) { vector vmArgs = vector(); dumpBytecodes = 0; gcVerbosity = 0; - for (long i = 1; i < argc; ++i) { + for (int32_t i = 1; i < argc; ++i) { if (strncmp(argv[i], "-cp", 3) == 0) { if ((argc == i + 1) || classPath.size() > 0) { printUsageAndExit(argv[0]); @@ -155,7 +155,7 @@ vector Universe::handleArguments(long argc, char** argv) { } else if (strncmp(argv[i], "-g", 2) == 0) { ++gcVerbosity; } else if (strncmp(argv[i], "-H", 2) == 0) { - long heap_size = 0; + size_t heap_size = 0; char unit[3]; if (sscanf(argv[i], "-H%ld%2s", &heap_size, unit) == 2) { if (strcmp(unit, "KB") == 0) { @@ -173,7 +173,7 @@ vector Universe::handleArguments(long argc, char** argv) { } else { vector extPathTokens = vector(2); std::string const tmpString = std::string(argv[i]); - if (getClassPathExt(extPathTokens, tmpString) == ERR_SUCCESS) { + if (getClassPathExt(extPathTokens, tmpString)) { addClassPath(extPathTokens[0]); } // Different from CSOM!!!: @@ -191,10 +191,10 @@ vector Universe::handleArguments(long argc, char** argv) { return vmArgs; } -long Universe::getClassPathExt(vector& tokens, +bool Universe::getClassPathExt(vector& tokens, const std::string& arg) { #define EXT_TOKENS 2 - long result = ERR_SUCCESS; + bool result = true; size_t fpIndex = arg.find_last_of(fileSeparator); size_t ssepIndex = arg.find(".som"); @@ -206,7 +206,7 @@ long Universe::getClassPathExt(vector& tokens, fpIndex = -1; // instead of returning here directly, we have to remember that // there is no new class path and return it later - result = ERR_FAIL; + result = false; } else { tokens[0] = arg.substr(0, fpIndex); } @@ -219,7 +219,7 @@ long Universe::getClassPathExt(vector& tokens, return result; } -long Universe::setupClassPath(const std::string& cp) { +void Universe::setupClassPath(const std::string& cp) { try { std::stringstream ss(cp); std::string token; @@ -228,15 +228,14 @@ long Universe::setupClassPath(const std::string& cp) { classPath.push_back(token); } - return ERR_SUCCESS; + return; } catch (std::exception e) { - return ERR_FAIL; + return; } } -long Universe::addClassPath(const std::string& cp) { +void Universe::addClassPath(const std::string& cp) { classPath.push_back(cp); - return ERR_SUCCESS; } void Universe::printUsageAndExit(char* executable) { @@ -259,7 +258,7 @@ void Universe::printUsageAndExit(char* executable) { } VMMethod* Universe::createBootstrapMethod(VMClass* holder, - long numArgsOfMsgSend) { + uint8_t numArgsOfMsgSend) { vector inlinedLoops; auto* bootStrapScope = new LexicalScope(nullptr, {}, {}); VMMethod* bootstrapMethod = @@ -328,7 +327,7 @@ vm_oop_t Universe::interpretMethod(VMObject* receiver, VMInvokable* initialize, return Interpreter::Start(); } -void Universe::initialize(long _argc, char** _argv) { +void Universe::initialize(int32_t _argc, char** _argv) { InitializeAllocationLog(); heapSize = 1 * 1024 * 1024; @@ -729,9 +728,9 @@ VMFrame* Universe::NewFrame(VMFrame* previousFrame, VMMethod* method) { } VMObject* Universe::NewInstance(VMClass* classOfInstance) { - long const numOfFields = classOfInstance->GetNumberOfInstanceFields(); + size_t const numOfFields = classOfInstance->GetNumberOfInstanceFields(); // the additional space needed is calculated from the number of fields - long const additionalBytes = numOfFields * sizeof(VMObject*); + size_t const additionalBytes = numOfFields * sizeof(VMObject*); auto* result = new (GetHeap(), additionalBytes) VMObject(numOfFields, additionalBytes + sizeof(VMObject)); result->SetClass(classOfInstance); diff --git a/src/vm/Universe.h b/src/vm/Universe.h index ceecf6e0..8e0bbd27 100644 --- a/src/vm/Universe.h +++ b/src/vm/Universe.h @@ -52,7 +52,7 @@ class Universe { static vm_oop_t interpret(const std::string& className, const std::string& methodName); - static long setupClassPath(const std::string& cp); + static void setupClassPath(const std::string& cp); static void Assert(bool /*value*/); @@ -123,17 +123,17 @@ class Universe { static vm_oop_t interpretMethod(VMObject* receiver, VMInvokable* initialize, VMArray* argumentsArray); - static vector handleArguments(long argc, char** argv); - static long getClassPathExt(vector& tokens, + static vector handleArguments(int32_t argc, char** argv); + static bool getClassPathExt(vector& tokens, const std::string& arg); static VMMethod* createBootstrapMethod(VMClass* holder, - long numArgsOfMsgSend); + uint8_t numArgsOfMsgSend); - static long addClassPath(const std::string& cp); + static void addClassPath(const std::string& cp); static void printUsageAndExit(char* executable); - static void initialize(long /*_argc*/, char** /*_argv*/); + static void initialize(int32_t _argc, char** _argv); static size_t heapSize; static map globals; diff --git a/src/vmobjects/VMClass.cpp b/src/vmobjects/VMClass.cpp index b6c21d1b..7478c3d8 100644 --- a/src/vmobjects/VMClass.cpp +++ b/src/vmobjects/VMClass.cpp @@ -181,8 +181,8 @@ size_t VMClass::GetNumberOfInstanceFields() const { } bool VMClass::HasPrimitives() const { - long const numInvokables = GetNumberOfInstanceInvokables(); - for (long i = 0; i < numInvokables; ++i) { + size_t const numInvokables = GetNumberOfInstanceInvokables(); + for (size_t i = 0; i < numInvokables; ++i) { VMInvokable* invokable = GetInstanceInvokable(i); if (invokable->IsPrimitive()) { return true; diff --git a/src/vmobjects/VMEvaluationPrimitive.cpp b/src/vmobjects/VMEvaluationPrimitive.cpp index ae994f28..f5fb54a4 100644 --- a/src/vmobjects/VMEvaluationPrimitive.cpp +++ b/src/vmobjects/VMEvaluationPrimitive.cpp @@ -122,7 +122,7 @@ std::string VMEvaluationPrimitive::AsDebugString() const { return "VMEvaluationPrimitive(" + to_string(numberOfArguments) + ")"; } -#define INVALID_INT_MARKER 9002002002002002002 +#define INVALID_INT_MARKER 0xFF void VMEvaluationPrimitive::MarkObjectAsInvalid() { VMInvokable::MarkObjectAsInvalid();