File tree Expand file tree Collapse file tree 3 files changed +14
-49
lines changed
Expand file tree Collapse file tree 3 files changed +14
-49
lines changed Original file line number Diff line number Diff line change @@ -607,21 +607,11 @@ TaggedValue Interpreter::sendMessage(TaggedValue receiver,
607607}
608608
609609Class *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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments