Oblivious-Oblivious / Zircon

Zircon: a small parser for object oriented programming in C.
GNU General Public License v3.0
1 stars 0 forks source link

Selectors on different classes with the same names collide, because of having the same namespacing. #4

Open Oblivious-Oblivious opened 4 years ago

Oblivious-Oblivious commented 4 years ago

When two objects in the same compilation range have same named messages, their selectors get translated into two functions with the same name.

object First implements Object {
    (void) self |> "message" |> {}
}
object Second implements Object {
    (void) self |> "meesage" |> {}
}

./zircon First.zc Second.zc

(selectors produced):

void *zircon_message(void *self) {}
void *zircon_message(void *self) {}

hence the name collision.

Oblivious-Oblivious commented 4 years ago

The 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.