Skip to content

Commit

Permalink
More consistent int types
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Aug 18, 2024
1 parent d73baf3 commit 7c8cf11
Show file tree
Hide file tree
Showing 29 changed files with 81 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "vmobjects/VMObject.h"
#include "vmobjects/VMString.h"

int main(int argc, char** argv) {
int32_t main(int32_t argc, char** argv) {
cout << "This is SOM++" << endl;

if (GC_TYPE == GENERATIONAL) {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/BytecodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void EmitPOPFIELD(MethodGenerationContext& mgenc, VMSymbol* field) {
void EmitSEND(MethodGenerationContext& mgenc, VMSymbol* msg) {
const int8_t idx = mgenc.AddLiteralIfAbsent(msg);

const int numArgs = Signature::GetNumberOfArguments(msg);
const uint8_t numArgs = Signature::GetNumberOfArguments(msg);
const size_t stackEffect = -numArgs + 1; // +1 for the result

Emit2(mgenc, numArgs == 1 ? BC_SEND_1 : BC_SEND, idx, stackEffect);
Expand All @@ -240,7 +240,7 @@ void EmitSEND(MethodGenerationContext& mgenc, VMSymbol* msg) {
void EmitSUPERSEND(MethodGenerationContext& mgenc, VMSymbol* msg) {
const int8_t idx = mgenc.AddLiteralIfAbsent(msg);

const int numArgs = Signature::GetNumberOfArguments(msg);
const uint8_t numArgs = Signature::GetNumberOfArguments(msg);
const size_t stackEffect = -numArgs + 1; // +1 for the result

Emit2(mgenc, BC_SUPER_SEND, idx, stackEffect);
Expand Down
13 changes: 7 additions & 6 deletions src/compiler/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void Disassembler::dispatch(vm_oop_t o) {
* Dump a class and all subsequent methods.
*/
void Disassembler::Dump(VMClass* cl) {
long const numInvokables = cl->GetNumberOfInstanceInvokables();
for (long i = 0; i < numInvokables; ++i) {
size_t const numInvokables = cl->GetNumberOfInstanceInvokables();
for (size_t i = 0; i < numInvokables; ++i) {
auto* inv = static_cast<VMInvokable*>(cl->GetInstanceInvokable(i));
// output header and skip if the Invokable is a Primitive
VMSymbol* sig = inv->GetSignature();
Expand Down Expand Up @@ -131,7 +131,7 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,

#ifdef _DEBUG
Print("bytecodes: ");
for (long i = 0; i < numberOfBytecodes; ++i) {
for (size_t i = 0; i < numberOfBytecodes; ++i) {
Print(to_string((int)(*method)[i]) + " ");
}
Print("\n");
Expand Down Expand Up @@ -240,7 +240,7 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
case BC_INC_FIELD_PUSH:
case BC_POP_FIELD:
case BC_PUSH_FIELD: {
long const fieldIdx = bytecodes[bc_idx + 1];
uint8_t const fieldIdx = bytecodes[bc_idx + 1];
if (method != nullptr && printObjects) {
auto* holder =
dynamic_cast<VMClass*>((VMObject*)method->GetHolder());
Expand Down Expand Up @@ -331,7 +331,8 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
/**
* Dump bytecode from the frame running
*/
void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method, long bc_idx) {
void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
size_t bc_idx) {
static long long indentc = 0;
static char ikind = '@';
uint8_t const bc = BC_0;
Expand Down Expand Up @@ -520,7 +521,7 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method, long bc_idx) {
vm_oop_t o = ((VMObject*)arg)->GetField(fieldIndex);
VMClass* c = CLASS_OF(o);
VMSymbol* cname = c->GetName();
long const fieldIdx = BC_1;
uint8_t const fieldIdx = BC_1;
VMSymbol* name =
method->GetHolder()->GetInstanceFieldName(fieldIdx);
DebugPrint("(index: %d) field: %s <(%s) ", BC_1,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/Disassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Disassembler {
static void DumpMethod(VMMethod* method, const char* indent,
bool printObjects = true);
static void DumpMethod(MethodGenerationContext* mgenc, const char* indent);
static void DumpBytecode(VMFrame* frame, VMMethod* method, long bc_idx);
static void DumpBytecode(VMFrame* frame, VMMethod* method, size_t bc_idx);

private:
static void dispatch(vm_oop_t o);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/LexicalScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LexicalScope {
: outer(outer), arguments(std::move(arguments)),
locals(std::move(locals)) {}

inline size_t GetNumberOfArguments() const { return arguments.size(); }
inline uint8_t GetNumberOfArguments() const { return arguments.size(); }

inline size_t GetNumberOfLocals() const { return locals.size(); }

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/MethodGenerationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ bool MethodGenerationContext::HasField(VMSymbol* field) {
return holderGenc.HasField(field);
}

size_t MethodGenerationContext::GetNumberOfArguments() {
uint8_t MethodGenerationContext::GetNumberOfArguments() {
return arguments.size();
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/MethodGenerationContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MethodGenerationContext {
void RemoveLastBytecode() { bytecode.pop_back(); };
void RemoveLastPopForBlockLocalReturn();

size_t GetNumberOfArguments();
uint8_t GetNumberOfArguments();
void AddBytecode(uint8_t bc, size_t stackEffect);
void AddBytecodeArgument(uint8_t bc);
size_t AddBytecodeArgumentAndGetIndex(uint8_t bc);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,8 @@ void Parser::nestedBlock(MethodGenerationContext& mgenc) {
// generate Block signature
std::string block_sig =
"$blockMethod@" + to_string(lexer.GetCurrentLineNumber());
size_t const arg_size = mgenc.GetNumberOfArguments();
for (size_t i = 1; i < arg_size; i++) {
uint8_t const arg_size = mgenc.GetNumberOfArguments();
for (uint8_t i = 1; i < arg_size; i++) {
block_sig += ":";
}

Expand Down
18 changes: 9 additions & 9 deletions src/interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ void Interpreter::popFrameAndPushResult(vm_oop_t result) {
VMFrame* prevFrame = popFrame();

VMMethod* method = prevFrame->GetMethod();
long const numberOfArgs = method->GetNumberOfArguments();
uint8_t const numberOfArgs = method->GetNumberOfArguments();

for (long i = 0; i < numberOfArgs; ++i) {
for (uint8_t i = 0; i < numberOfArgs; ++i) {
GetFrame()->Pop();
}

Expand Down Expand Up @@ -156,7 +156,7 @@ void Interpreter::send(VMSymbol* signature, VMClass* receiverClass) {
}

void Interpreter::triggerDoesNotUnderstand(VMSymbol* signature) {
long const numberOfArgs = Signature::GetNumberOfArguments(signature);
uint8_t const numberOfArgs = Signature::GetNumberOfArguments(signature);

vm_oop_t receiver = GetFrame()->GetStackElement(numberOfArgs - 1);

Expand Down Expand Up @@ -265,7 +265,7 @@ void Interpreter::doPushBlock(size_t bytecodeIndex) {
vm_oop_t block = method->GetConstant(bytecodeIndex);
auto* blockMethod = static_cast<VMInvokable*>(block);

long const numOfArgs = blockMethod->GetNumberOfArguments();
uint8_t const numOfArgs = blockMethod->GetNumberOfArguments();

GetFrame()->Push(Universe::NewBlock(blockMethod, GetFrame(), numOfArgs));
}
Expand Down Expand Up @@ -345,7 +345,7 @@ void Interpreter::doSend(size_t bytecodeIndex) {
auto* signature =
static_cast<VMSymbol*>(method->GetConstant(bytecodeIndex));

int const numOfArgs = Signature::GetNumberOfArguments(signature);
uint8_t const numOfArgs = Signature::GetNumberOfArguments(signature);

vm_oop_t receiver = GetFrame()->GetStackElement(numOfArgs - 1);

Expand Down Expand Up @@ -418,11 +418,11 @@ void Interpreter::doSuperSend(size_t bytecodeIndex) {
if (invokable != nullptr) {
invokable->Invoke(GetFrame());
} else {
long const numOfArgs = Signature::GetNumberOfArguments(signature);
uint8_t const numOfArgs = Signature::GetNumberOfArguments(signature);
vm_oop_t receiver = GetFrame()->GetStackElement(numOfArgs - 1);
VMArray* argumentsArray = Universe::NewArray(numOfArgs);

for (long i = numOfArgs - 1; i >= 0; --i) {
for (uint8_t i = numOfArgs - 1; i >= 0; --i) {
vm_oop_t o = GetFrame()->Pop();
argumentsArray->SetIndexableField(i, o);
}
Expand Down Expand Up @@ -454,8 +454,8 @@ void Interpreter::doReturnNonLocal() {

// Pop old arguments from stack
VMMethod* method = GetFrame()->GetMethod();
long const numberOfArgs = method->GetNumberOfArguments();
for (long i = 0; i < numberOfArgs; ++i) {
uint8_t const numberOfArgs = method->GetNumberOfArguments();
for (uint8_t i = 0; i < numberOfArgs; ++i) {
GetFrame()->Pop();
}

Expand Down
4 changes: 2 additions & 2 deletions src/memory/Heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "MarkSweepHeap.h" // NOLINT(misc-include-cleaner)

template <class HEAP_T>
void Heap<HEAP_T>::InitializeHeap(long objectSpaceSize) {
void Heap<HEAP_T>::InitializeHeap(size_t objectSpaceSize) {
if (theHeap) {
ErrorPrint(
"Warning, reinitializing already initialized Heap, "
Expand Down Expand Up @@ -64,7 +64,7 @@ void Heap<HEAP_T>::FullGC() {
}

// Instantitate Template for the heap classes
template void Heap<HEAP_CLS>::InitializeHeap(long);
template void Heap<HEAP_CLS>::InitializeHeap(size_t);
template void Heap<HEAP_CLS>::DestroyHeap();
template void Heap<HEAP_CLS>::FullGC();

Expand Down
2 changes: 1 addition & 1 deletion src/memory/Heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Heap {
friend class GarbageCollector<HEAP_T>;

public:
static void InitializeHeap(long objectSpaceSize);
static void InitializeHeap(size_t objectSpaceSize);
static void DestroyHeap();
explicit Heap(GarbageCollector<HEAP_T>* const gc) : gc(gc) {}
~Heap();
Expand Down
4 changes: 2 additions & 2 deletions src/unitTests/TrivialMethodTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void TrivialMethodTest::fieldSetter0(const std::string& source) {
auto* setter = (VMSetter*)m;
CPPUNIT_ASSERT_EQUAL(setter->fieldIndex, (size_t)0);
CPPUNIT_ASSERT_EQUAL(setter->argIndex, (size_t)1);
CPPUNIT_ASSERT_EQUAL(setter->numberOfArguments, 2);
CPPUNIT_ASSERT_EQUAL((size_t)setter->numberOfArguments, (size_t)2);

tearDown();
}
Expand Down Expand Up @@ -254,7 +254,7 @@ void TrivialMethodTest::fieldSetterN(const std::string& source) {
auto* setter = (VMSetter*)m;
CPPUNIT_ASSERT_EQUAL(setter->fieldIndex, (size_t)5);
CPPUNIT_ASSERT_EQUAL(setter->argIndex, (size_t)2);
CPPUNIT_ASSERT_EQUAL(setter->numberOfArguments, 4);
CPPUNIT_ASSERT_EQUAL((size_t)setter->numberOfArguments, (size_t)4);

tearDown();
}
Expand Down
4 changes: 2 additions & 2 deletions src/unitTests/WalkObjectsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ void WalkObjectsTest::testWalkFrame() {
// CPPUNIT_ASSERT(WalkerHasFound(frame->bytecodeIndex));
CPPUNIT_ASSERT(WalkerHasFound(tmp_ptr(dummyArg)));
CPPUNIT_ASSERT_EQUAL(
(long)(NoOfFields_Frame + method->GetNumberOfArguments()),
(long)walkedObjects.size() +
(size_t)(NoOfFields_Frame + method->GetNumberOfArguments()),
(size_t)walkedObjects.size() +
1); // + 1 for the class field that's still in there
}

Expand Down
3 changes: 2 additions & 1 deletion src/unitTests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <cppunit/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cstdint>
#include <iostream>

#include "../misc/defs.h"
Expand All @@ -36,7 +37,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BytecodeGenerationTest);
CPPUNIT_TEST_SUITE_REGISTRATION(TrivialMethodTest);
CPPUNIT_TEST_SUITE_REGISTRATION(BasicInterpreterTests);

int main(int ac, char** av) {
int32_t main(int32_t ac, char** av) {
Universe::Start(ac, av);

//--- Create the event manager and test controller
Expand Down
5 changes: 3 additions & 2 deletions src/vm/Print.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Print.h"

#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <mutex>
Expand Down Expand Up @@ -39,12 +40,12 @@ __attribute__((noreturn)) __attribute__((noinline)) void ErrorExit(
Quit(ERR_FAIL);
}

__attribute__((noreturn)) __attribute__((noinline)) void Quit(long err) {
__attribute__((noreturn)) __attribute__((noinline)) void Quit(int32_t err) {
ErrorPrint("Time spent in GC: [" +
to_string(Timer::GCTimer->GetTotalTime()) + "] msec\n");

Universe::Shutdown();

OutputAllocationLogFile();
exit((int)err);
exit(err);
}
2 changes: 1 addition & 1 deletion src/vm/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ void Print(const char* str);
void ErrorPrint(const std::string& str);
void ErrorPrint(const char* str);

__attribute__((noreturn)) __attribute__((noinline)) void Quit(long /*err*/);
__attribute__((noreturn)) __attribute__((noinline)) void Quit(int32_t err);
__attribute__((noreturn)) __attribute__((noinline)) void ErrorExit(
const char* /*err*/);
22 changes: 11 additions & 11 deletions src/vm/Universe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ gc_oop_t prebuildInts[INT_CACHE_MAX_VALUE - INT_CACHE_MIN_VALUE + 1];

// Here we go:

short dumpBytecodes;
short gcVerbosity;
uint8_t dumpBytecodes;
uint8_t gcVerbosity;

std::string bm_name;

map<int64_t, int64_t> integerHist;

map<GCSymbol*, gc_oop_t> Universe::globals;
map<long, GCClass*> Universe::blockClassesByNoOfArgs;
map<uint8_t, GCClass*> Universe::blockClassesByNoOfArgs;
vector<std::string> Universe::classPath;
long Universe::heapSize;
size_t Universe::heapSize;

void Universe::Start(long argc, char** argv) {
void Universe::Start(int32_t argc, char** argv) {
BasicInit();
Universe::initialize(argc, argv);
}
Expand Down Expand Up @@ -296,7 +296,7 @@ vm_oop_t Universe::interpret(const std::string& className,
vm_oop_t Universe::interpretMethod(VMObject* receiver, VMInvokable* initialize,
VMArray* argumentsArray) {
/* only trace bootstrap if the number of cmd-line "-d"s is > 2 */
short const trace = 2 - dumpBytecodes;
uint8_t const trace = 2 - dumpBytecodes;
if (!(trace > 0)) {
dumpBytecodes = 1;
}
Expand All @@ -306,7 +306,7 @@ vm_oop_t Universe::interpretMethod(VMObject* receiver, VMInvokable* initialize,
VMFrame* bootstrapFrame = Interpreter::PushNewFrame(bootstrapMethod);
for (size_t argIdx = 0; argIdx < bootstrapMethod->GetNumberOfArguments();
argIdx += 1) {
bootstrapFrame->SetArgument((long)argIdx, (long)0, load_ptr(nilObject));
bootstrapFrame->SetArgument(argIdx, 0, load_ptr(nilObject));
}

bootstrapFrame->Push(receiver);
Expand Down Expand Up @@ -473,7 +473,7 @@ VMClass* Universe::GetBlockClass() {
return load_ptr(blockClass);
}

VMClass* Universe::GetBlockClassWithArgs(long numberOfArguments) {
VMClass* Universe::GetBlockClassWithArgs(uint8_t numberOfArguments) {
auto const it = blockClassesByNoOfArgs.find(numberOfArguments);
if (it != blockClassesByNoOfArgs.end()) {
return load_ptr(it->second);
Expand All @@ -482,7 +482,7 @@ VMClass* Universe::GetBlockClassWithArgs(long numberOfArguments) {
Assert(numberOfArguments < 10);

ostringstream Str;
Str << "Block" << numberOfArguments;
Str << "Block" << to_string(numberOfArguments);
VMSymbol* name = SymbolFor(Str.str());
VMClass* result = LoadClassBasic(name, nullptr);

Expand Down Expand Up @@ -675,7 +675,7 @@ VMArray* Universe::NewArrayList(std::vector<vm_oop_t>& list) {
}

VMBlock* Universe::NewBlock(VMInvokable* method, VMFrame* context,
long arguments) {
uint8_t arguments) {
auto* result = new (GetHeap<HEAP_CLS>(), 0) VMBlock(method, context);
result->SetClass(GetBlockClassWithArgs(arguments));

Expand Down Expand Up @@ -823,7 +823,7 @@ void Universe::WalkGlobals(walk_heap_fn walk) {

WalkSymbols(walk);

map<long, GCClass*>::iterator bcIter;
map<uint8_t, GCClass*>::iterator bcIter;
for (bcIter = blockClassesByNoOfArgs.begin();
bcIter != blockClassesByNoOfArgs.end();
bcIter++) {
Expand Down
Loading

0 comments on commit 7c8cf11

Please sign in to comment.