Skip to content

Commit da0ce6d

Browse files
committed
Core: centralize TaggedValue class resolution; use value.getClass() in interpreter and primitives; fix pointer classification (Strings vs objects).
1 parent 9a9dd4b commit da0ce6d

File tree

3 files changed

+14
-49
lines changed

3 files changed

+14
-49
lines changed

src/cpp/src/interpreter.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -607,21 +607,11 @@ TaggedValue Interpreter::sendMessage(TaggedValue receiver,
607607
}
608608

609609
Class *Interpreter::getObjectClass(TaggedValue value) {
610-
if (value.isSmallInteger()) {
611-
return ClassUtils::getIntegerClass();
610+
Class *cls = value.getClass();
611+
if (!cls) {
612+
throw std::runtime_error("Unknown value type");
612613
}
613-
if (value.isBoolean()) {
614-
return value.getBoolean() ? ClassUtils::getTrueClass()
615-
: ClassUtils::getFalseClass();
616-
}
617-
if (value.isNil()) {
618-
return ClassRegistry::getInstance().getClass("UndefinedObject");
619-
}
620-
if (value.isPointer()) {
621-
return value.asObject()->getClass();
622-
}
623-
624-
throw std::runtime_error("Unknown value type");
614+
return cls;
625615
}
626616

627617
// Temporarily removed - will implement proper message send parsing later

src/cpp/src/primitives/object.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,8 @@ TaggedValue primitive_class(TaggedValue receiver,
148148
// Check argument count
149149
Primitives::checkArgumentCount(args, 0, "class");
150150

151-
Class *receiverClass = nullptr;
152-
153-
// Handle immediate values
154-
if (receiver.isSmallInteger()) {
155-
receiverClass = ClassUtils::getIntegerClass();
156-
} else if (receiver.isBoolean()) {
157-
receiverClass = receiver.getBoolean() ? ClassUtils::getTrueClass()
158-
: ClassUtils::getFalseClass();
159-
} else if (receiver.isNil()) {
160-
// UndefinedObject class for nil
161-
receiverClass = ClassRegistry::getInstance().getClass("UndefinedObject");
162-
if (receiverClass == nullptr) {
163-
throw PrimitiveFailure("UndefinedObject class not found");
164-
}
165-
} else if (receiver.isPointer()) {
166-
Object *obj = receiver.asObject();
167-
receiverClass = obj->getClass();
168-
if (receiverClass == nullptr) {
169-
throw PrimitiveFailure("Object has no class");
170-
}
171-
} else {
151+
Class *receiverClass = receiver.getClass();
152+
if (receiverClass == nullptr) {
172153
throw PrimitiveFailure("Unknown receiver type");
173154
}
174155

src/cpp/src/tagged_value.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,15 @@ Class *TaggedValue::getClass() const {
3232
return ClassUtils::getObjectClass();
3333
} else if (isPointer()) {
3434
try {
35-
// Try as Symbol first
36-
asSymbol(); // Just check if it's a symbol
37-
return ClassUtils::getSymbolClass();
38-
} catch (...) {
39-
try {
40-
// Try as String
41-
Object *obj = asObject();
42-
if (StringUtils::isString(*this)) {
43-
return ClassUtils::getStringClass();
44-
}
45-
// Try as generic Object
46-
return obj->getClass();
47-
} catch (...) {
48-
return nullptr;
35+
// Strings are byte-indexable and detected via utility
36+
if (StringUtils::isString(*this)) {
37+
return ClassUtils::getStringClass();
4938
}
39+
// Otherwise use the object's class directly
40+
Object *obj = asObject();
41+
return obj ? obj->getClass() : nullptr;
42+
} catch (...) {
43+
return nullptr;
5044
}
5145
}
5246
return nullptr;

0 commit comments

Comments
 (0)