Wednesday, December 2, 2009

...But in the end it helps out

Gilad's post got me thinking about the difference between objects and hashes, and specifically the encapsulation that objects bring to the table.

This then lead me to realise that ultimately, in my VM and presumably Newspeak, the slots that are available in a function call are exactly the same as the slots available in an object. And the only things that have direct access to these slots are the sub-contexts (closures) that exist beneath this level.

And so objects and functions come closer and closer as closures save the day. There are two differences I've found so far, and both are additional object behaviour, and both are because of inheritance.

Firstly Objects have parents - otherwise there would be no inheritance at all!

Secondly, according to the newspeak message lookup scheme, if the receiver hasn't been found within the context, then it should be found up the object hierarchy (though only of the deepest nested object).

Interestingly this fits well with the access rights. If you can only access things within your context, you can't affect parent objects unless they provide a message to you - which is the desired behaviour.

Anyway, I have this almost implemented (surprisingly easy) and will get back to the compiler as soon as I've
  • written test to make sure that objects created in situ will honour their parents (at the moment they won't because they are actually function contexts...)
  • found a way to enforce contextualisation of objects/functions to only the current context... at the moment you could potentially hack the context that an object is defined within!

No comments:

Post a Comment