Open Oblivious-Oblivious opened 4 years ago
is_a
, is_of
, and cast
functions can be used for dynamic typing.static bool is_a(void *_self, void *class) {
return _self && classOf(_self) == class;
}
static bool is_of(void *_self, void *class) {
if(_self) {
struct Class *myClass = classOf(_self);
if(class != Object) {
while(myClass != class)
if(myClass != Object)
myClass = super(myClass);
else
return false;
}
return true;
}
return false;
}
static void *cast(void *_self, void *class) {
assert(is_of(_self, class));
return (void*)_self;
}
Possibly use casting function on selectors to cast to different objects optionally (preserves encapsulation oO), and possibly solve the namespacing problem.
cast(other, Object);
And in case of a message with parameter: (Test): @obj
, translate into:
cast(obj, Test);
I might need to add new syntax for object pointers with the @
symbol I removed a few weeks back.
When two objects in the same compilation range have same named messages, their selectors get translated into two functions with the same name.
./zircon First.zc Second.zc
(selectors produced):
hence the name collision.