Skip to content

Commit

Permalink
Move Symbol related things to vm/Symbols.h/cpp
Browse files Browse the repository at this point in the history
- also move GENERATE_ALLOCATION_STATISTICS related code to its own header/cpp

Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Jul 21, 2024
1 parent 52df071 commit d9fbaed
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 159 deletions.
16 changes: 16 additions & 0 deletions SOM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
0A1887451832C62100A2CBCA /* Smalltalk in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0A18873E1832C62100A2CBCA /* Smalltalk */; };
0A1887471832C62100A2CBCA /* TestSuite in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0A1887401832C62100A2CBCA /* TestSuite */; };
0A1C98582C3DD88500735850 /* unitTests/BytecodeGenerationTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A1C98572C3DD88500735850 /* unitTests/BytecodeGenerationTest.cpp */; };
0A1C98672C4D340300735850 /* Symbols.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A1C98652C4D340300735850 /* Symbols.cpp */; };
0A1C98682C4D340300735850 /* Symbols.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A1C98652C4D340300735850 /* Symbols.cpp */; };
0A1C986B2C4D363A00735850 /* LogAllocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A1C986A2C4D363A00735850 /* LogAllocation.cpp */; };
0A1C986C2C4D363A00735850 /* LogAllocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A1C986A2C4D363A00735850 /* LogAllocation.cpp */; };
0A32B7FE199D6143002825DF /* IntegerBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A32B7FC199D6143002825DF /* IntegerBox.cpp */; };
0A3A3C921A5D546D004CB03B /* Array.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F5203120FA6624C00E75857 /* Array.cpp */; };
0A3A3C931A5D546D004CB03B /* Block.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F5203160FA6624C00E75857 /* Block.cpp */; };
Expand Down Expand Up @@ -186,6 +190,10 @@
0A1C98562C3DD87300735850 /* unitTests/BytecodeGenerationTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = unitTests/BytecodeGenerationTest.h; sourceTree = "<group>"; };
0A1C98572C3DD88500735850 /* unitTests/BytecodeGenerationTest.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = unitTests/BytecodeGenerationTest.cpp; sourceTree = "<group>"; };
0A1C98592C432E0E00735850 /* VectorUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VectorUtil.h; sourceTree = "<group>"; };
0A1C98642C4D33F300735850 /* Symbols.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Symbols.h; sourceTree = "<group>"; };
0A1C98652C4D340300735850 /* Symbols.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Symbols.cpp; sourceTree = "<group>"; };
0A1C98692C4D35BB00735850 /* LogAllocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LogAllocation.h; sourceTree = "<group>"; };
0A1C986A2C4D363A00735850 /* LogAllocation.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LogAllocation.cpp; sourceTree = "<group>"; };
0A32B7FC199D6143002825DF /* IntegerBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntegerBox.cpp; sourceTree = "<group>"; };
0A32B7FD199D6143002825DF /* IntegerBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntegerBox.h; sourceTree = "<group>"; };
0A32B80119A12A03002825DF /* VMObjectBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VMObjectBase.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -581,6 +589,10 @@
0AB80AD52C392BAD006B6419 /* Print.h */,
0AB80AD62C3947F7006B6419 /* Globals.h */,
0AB80AD72C394806006B6419 /* Globals.cpp */,
0A1C98642C4D33F300735850 /* Symbols.h */,
0A1C98652C4D340300735850 /* Symbols.cpp */,
0A1C98692C4D35BB00735850 /* LogAllocation.h */,
0A1C986A2C4D363A00735850 /* LogAllocation.cpp */,
);
path = vm;
sourceTree = "<group>";
Expand Down Expand Up @@ -832,6 +844,7 @@
0A1887361832C10E00A2CBCA /* MarkSweepHeap.cpp in Sources */,
0A1886DD1832BCC800A2CBCA /* ClassGenerationContext.cpp in Sources */,
0A3A3C941A5D546D004CB03B /* Class.cpp in Sources */,
0A1C98672C4D340300735850 /* Symbols.cpp in Sources */,
0A18870B1832C0E400A2CBCA /* AbstractObject.cpp in Sources */,
0AB80AD82C394806006B6419 /* Globals.cpp in Sources */,
0A3A3C991A5D546D004CB03B /* Primitive.cpp in Sources */,
Expand Down Expand Up @@ -869,6 +882,7 @@
0A1886FC1832BCF500A2CBCA /* VMClass.cpp in Sources */,
0A1886DF1832BCC800A2CBCA /* Lexer.cpp in Sources */,
0A1886F51832BCED00A2CBCA /* Shell.cpp in Sources */,
0A1C986B2C4D363A00735850 /* LogAllocation.cpp in Sources */,
0A1887321832C10E00A2CBCA /* CopyingHeap.cpp in Sources */,
0A1887061832BCFA00A2CBCA /* VMSymbol.cpp in Sources */,
0A1887011832BCFA00A2CBCA /* VMInvokable.cpp in Sources */,
Expand Down Expand Up @@ -935,7 +949,9 @@
0A67EA8819ACD74800830E3B /* VMPrimitive.cpp in Sources */,
0A3A3CA21A5D546D004CB03B /* Block.cpp in Sources */,
0A3A3CA91A5D546D004CB03B /* String.cpp in Sources */,
0A1C986C2C4D363A00735850 /* LogAllocation.cpp in Sources */,
0A67EA9319ACD83200830E3B /* SourcecodeCompiler.cpp in Sources */,
0A1C98682C4D340300735850 /* Symbols.cpp in Sources */,
0AB80AD42C392B78006B6419 /* Print.cpp in Sources */,
0A3A3CA41A5D546D004CB03B /* Double.cpp in Sources */,
0A67EA8519ACD74800830E3B /* VMInteger.cpp in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/BytecodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "../interpreter/bytecodes.h"
#include "../vm/Globals.h"
#include "../vm/Universe.h"
#include "../vm/Symbols.h"
#include "../vmobjects/ObjectFormats.h"
#include "../vmobjects/Signature.h"
#include "../vmobjects/VMMethod.h"
Expand Down Expand Up @@ -166,11 +166,11 @@ void EmitPUSHCONSTANTString(MethodGenerationContext& mgenc,
}

void EmitPUSHGLOBAL(MethodGenerationContext& mgenc, VMSymbol* global) {
if (global == GetUniverse()->SymbolFor("nil")) {
if (global == SymbolFor("nil")) {
EmitPUSHCONSTANT(mgenc, load_ptr(nilObject));
} else if (global == GetUniverse()->SymbolFor("true")) {
} else if (global == SymbolFor("true")) {
EmitPUSHCONSTANT(mgenc, load_ptr(trueObject));
} else if (global == GetUniverse()->SymbolFor("false")) {
} else if (global == SymbolFor("false")) {
EmitPUSHCONSTANT(mgenc, load_ptr(falseObject));
} else {
const int8_t idx = mgenc.AddLiteralIfAbsent(global);
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/ClassGenerationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "../misc/VectorUtil.h"
#include "../vm/Globals.h"
#include "../vm/Symbols.h"
#include "../vm/Universe.h"
#include "../vmobjects/ObjectFormats.h"
#include "../vmobjects/VMArray.h"
Expand Down Expand Up @@ -101,7 +102,7 @@ VMClass* ClassGenerationContext::Assemble() {
// Initialize the class of the resulting class
resultClass->SetInstanceFields(GetUniverse()->NewArrayList(classFields));
resultClass->SetInstanceInvokables(GetUniverse()->NewArrayList(classMethods));
resultClass->SetName(GetUniverse()->SymbolFor(ccname));
resultClass->SetName(SymbolFor(ccname));

VMClass* superMClass = superClass->GetClass();
resultClass->SetSuperClass(superMClass);
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "../misc/debug.h"
#include "../misc/defs.h"
#include "../vm/Globals.h"
#include "../vm/Symbols.h"
#include "../vm/Universe.h"
#include "../vmobjects/ObjectFormats.h"
#include "../vmobjects/Signature.h"
Expand Down Expand Up @@ -63,7 +64,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(GetUniverse()->SymbolFor("system"))) {
} else if (o == GetUniverse()->GetGlobal(SymbolFor("system"))) {
DebugPrint("{System}");
} else {
VMClass* c = CLASS_OF(o);
Expand Down
9 changes: 5 additions & 4 deletions src/compiler/MethodGenerationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <string>

#include "../misc/VectorUtil.h"
#include "../vm/Symbols.h"
#include "../vm/Universe.h"
#include "../vmobjects/ObjectFormats.h"
#include "../vmobjects/VMMethod.h"
Expand Down Expand Up @@ -133,12 +134,12 @@ void MethodGenerationContext::SetPrimitive(bool prim) {
}

void MethodGenerationContext::AddArgument(const std::string& arg) {
VMSymbol* argSym = GetUniverse()->SymbolFor(arg);
VMSymbol* argSym = SymbolFor(arg);
arguments.push_back(argSym);
}

void MethodGenerationContext::AddLocal(const std::string& local) {
VMSymbol* localSym = GetUniverse()->SymbolFor(local);
VMSymbol* localSym =SymbolFor(local);
locals.push_back(localSym);
}

Expand All @@ -154,7 +155,7 @@ void MethodGenerationContext::UpdateLiteral(vm_oop_t oldValue, uint8_t index, vm
}

bool MethodGenerationContext::AddArgumentIfAbsent(const std::string& arg) {
VMSymbol* argSym = GetUniverse()->SymbolFor(arg);
VMSymbol* argSym = SymbolFor(arg);
if (Contains(locals, argSym)) {
return false;
}
Expand All @@ -163,7 +164,7 @@ bool MethodGenerationContext::AddArgumentIfAbsent(const std::string& arg) {
}

bool MethodGenerationContext::AddLocalIfAbsent(const std::string& local) {
VMSymbol* localSym = GetUniverse()->SymbolFor(local);
VMSymbol* localSym = SymbolFor(local);
if (Contains(locals, localSym)) {
return false;
}
Expand Down
39 changes: 20 additions & 19 deletions src/compiler/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "../misc/defs.h"
#include "../vm/Globals.h"
#include "../vm/Print.h"
#include "../vm/Symbols.h"
#include "../vm/Universe.h"
#include "../vmobjects/ObjectFormats.h"
#include "../vmobjects/VMClass.h"
Expand Down Expand Up @@ -184,7 +185,7 @@ Symbol binaryOpSyms[] = { Or, Comma, Minus, Equal, Not, And, Or, Star, Div, Mod,
Symbol keywordSelectorSyms[] = { Keyword, KeywordSequence };

void Parser::Classdef(ClassGenerationContext& cgenc) {
cgenc.SetName(GetUniverse()->SymbolFor(text));
cgenc.SetName(SymbolFor(text));
expect(Identifier);

expect(Equal);
Expand Down Expand Up @@ -233,15 +234,15 @@ void Parser::Classdef(ClassGenerationContext& cgenc) {
void Parser::superclass(ClassGenerationContext& cgenc) {
VMSymbol* superName;
if (sym == Identifier) {
superName = GetUniverse()->SymbolFor(text);
superName = SymbolFor(text);
accept(Identifier);
} else {
superName = GetUniverse()->SymbolFor("Object");
superName = SymbolFor("Object");
}
cgenc.SetSuperName(superName);

// Load the super class, if it is not nil (break the dependency cycle)
if (superName != GetUniverse()->SymbolFor("nil")) {
if (superName != SymbolFor("nil")) {
VMClass* superClass = GetUniverse()->LoadClass(superName);
cgenc.SetInstanceFieldsOfSuper(superClass->GetInstanceFields());
cgenc.SetClassFieldsOfSuper(superClass->GetClass()->GetInstanceFields());
Expand All @@ -262,7 +263,7 @@ void Parser::instanceFields(ClassGenerationContext& cgenc) {
if (accept(Or)) {
while (symIsIdentifier()) {
StdString var = variable();
cgenc.AddInstanceField(GetUniverse()->SymbolFor(var));
cgenc.AddInstanceField(SymbolFor(var));
}
expect(Or);
}
Expand All @@ -272,7 +273,7 @@ void Parser::classFields(ClassGenerationContext& cgenc) {
if (accept(Or)) {
while (symIsIdentifier()) {
StdString var = variable();
cgenc.AddClassField(GetUniverse()->SymbolFor(var));
cgenc.AddClassField(SymbolFor(var));
}
expect(Or);
}
Expand Down Expand Up @@ -325,7 +326,7 @@ void Parser::keywordPattern(MethodGenerationContext& mgenc) {
mgenc.AddArgumentIfAbsent(argument());
} while (sym == Keyword);

mgenc.SetSignature(GetUniverse()->SymbolFor(kw));
mgenc.SetSignature(SymbolFor(kw));
}

void Parser::methodBlock(MethodGenerationContext& mgenc) {
Expand All @@ -345,7 +346,7 @@ void Parser::methodBlock(MethodGenerationContext& mgenc) {
}

VMSymbol* Parser::unarySelector() {
return GetUniverse()->SymbolFor(identifier());
return SymbolFor(identifier());
}

VMSymbol* Parser::binarySelector() {
Expand All @@ -357,7 +358,7 @@ VMSymbol* Parser::binarySelector() {
expect(NONE);
}

VMSymbol* symb = GetUniverse()->SymbolFor(s);
VMSymbol* symb = SymbolFor(s);
return symb;
}

Expand Down Expand Up @@ -484,7 +485,7 @@ VMSymbol* Parser::assignment(MethodGenerationContext& mgenc) {

expect(Assign);

return GetUniverse()->SymbolFor(v);
return SymbolFor(v);
}

void Parser::evaluation(MethodGenerationContext& mgenc) {
Expand All @@ -507,7 +508,7 @@ bool Parser::primary(MethodGenerationContext& mgenc) {
v = StdString("self");
}

genPushVariable(mgenc, GetUniverse()->SymbolFor(v));
genPushVariable(mgenc, SymbolFor(v));
break;
}
case NewTerm:
Expand Down Expand Up @@ -610,7 +611,7 @@ void Parser::keywordMessage(MethodGenerationContext& mgenc, bool super) {
formula(mgenc);
}

VMSymbol* msg = GetUniverse()->SymbolFor(kw);
VMSymbol* msg = SymbolFor(kw);

if (super) {
EmitSUPERSEND(mgenc, msg);
Expand Down Expand Up @@ -702,7 +703,7 @@ void Parser::literalSymbol(MethodGenerationContext& mgenc) {
expect(Pound);
if (sym == STString) {
StdString s = _string();
symb = GetUniverse()->SymbolFor(s);
symb = SymbolFor(s);

} else {
symb = selector();
Expand All @@ -714,10 +715,10 @@ void Parser::literalArray(MethodGenerationContext& mgenc) {
expect(Pound);
expect(NewTerm);

VMSymbol* arrayClassName = GetUniverse()->SymbolFor("Array");
VMSymbol* arraySizePlaceholder = GetUniverse()->SymbolFor("ArraySizeLiteralPlaceholder");
VMSymbol* newMessage = GetUniverse()->SymbolFor("new:");
VMSymbol* atPutMessage = GetUniverse()->SymbolFor("at:put:");
VMSymbol* arrayClassName = SymbolFor("Array");
VMSymbol* arraySizePlaceholder = SymbolFor("ArraySizeLiteralPlaceholder");
VMSymbol* newMessage = SymbolFor("new:");
VMSymbol* atPutMessage = SymbolFor("at:put:");

const uint8_t arraySizeLiteralIndex = mgenc.AddLiteral(arraySizePlaceholder);

Expand Down Expand Up @@ -761,7 +762,7 @@ VMSymbol* Parser::selector() {
VMSymbol* Parser::keywordSelector() {
StdString s(text);
expectOneOf(keywordSelectorSyms);
VMSymbol* symb = GetUniverse()->SymbolFor(s);
VMSymbol* symb = SymbolFor(s);
return symb;
}

Expand All @@ -784,7 +785,7 @@ void Parser::nestedBlock(MethodGenerationContext& mgenc) {
for (size_t i = 1; i < arg_size; i++)
block_sig += ":";

mgenc.SetSignature(GetUniverse()->SymbolFor(block_sig));
mgenc.SetSignature(SymbolFor(block_sig));

blockContents(mgenc, false);

Expand Down
13 changes: 6 additions & 7 deletions src/memory/CopyingCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static gc_oop_t copy_if_necessary(gc_oop_t oop) {
// don't process tagged objects
if (IS_TAGGED(oop))
return oop;

AbstractVMObject* obj = AS_OBJ(oop);
assert(IsValidObject(obj));

Expand All @@ -27,15 +27,14 @@ static gc_oop_t copy_if_necessary(gc_oop_t oop) {
//if someone has moved before, return the moved object
if (gcField != 0)
return (gc_oop_t) gcField;

// we have to clone ourselves
AbstractVMObject* newObj = obj->Clone();

if (DEBUG)
obj->MarkObjectAsInvalid();

obj->SetGCField((long)newObj);
#warning not sure about the use of _store_ptr here, or whether it should be a plain cast
return _store_ptr(newObj);
}

Expand All @@ -62,7 +61,7 @@ void CopyingCollector::Collect() {
if (heap->currentBuffer == nullptr)
GetUniverse()->ErrorExit("unable to allocate more memory");
}

// init currentBuffer with zeros
memset(heap->currentBuffer, 0x0, (size_t)(heap->currentBufferEnd) -
(size_t)(heap->currentBuffer));
Expand All @@ -74,7 +73,7 @@ void CopyingCollector::Collect() {
curObject->WalkObjects(copy_if_necessary);
curObject = (AbstractVMObject*)((size_t)curObject + curObject->GetObjectSize());
}

//increase memory if scheduled in collection before
if (increaseMemory) {
increaseMemory = false;
Expand Down
3 changes: 2 additions & 1 deletion src/primitives/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "../primitivesCore/PrimitiveContainer.h"
#include "../primitivesCore/Routine.h"
#include "../vm/Globals.h"
#include "../vm/Symbols.h"
#include "../vm/Universe.h"
#include "../vmobjects/ObjectFormats.h"
#include "../vmobjects/VMFrame.h"
Expand Down Expand Up @@ -68,7 +69,7 @@ void _String::Concatenate_(Interpreter*, VMFrame* frame) {
void _String::AsSymbol(Interpreter*, VMFrame* frame) {
VMString* self = static_cast<VMString*>(frame->Pop());
StdString result = self->GetStdString();
frame->Push(GetUniverse()->SymbolFor(result));
frame->Push(SymbolFor(result));
}

void _String::Hashcode(Interpreter*, VMFrame* frame) {
Expand Down
Loading

0 comments on commit d9fbaed

Please sign in to comment.