Both the old and new metamodels allow you to set and get an attribute for a parent class that has the same name as an attribute in the child class (Perl 6 and .NET both use this feature in different forms). The old metamodel used this syntax:

  # Foo has an attribute named 'j'
  newclass $P1, "Foo"
  addattribute $P1, "j"

  # subclass Bar also has an attribute 'j'
  subclass $P2, $P1, "Bar"
  addattribute $P2, "j"

  .local pmc obj
  obj = new 'Bar'

  # Set the core object attribute 'j'
  setattribute obj, 'j', $P3

  # Set the parent's attribute 'j'
  setattribute obj, "Foo\0j", $P4

I really don't like the "Foo\0j" syntax on the last line: it requires parsing inline string names, doesn't allow multi-level namespaces, and has no checking whether the class referenced really is a parent of the subclass (a parent class named ['Foo';'Fi';'Fo';'Fum'] allows an attribute to be set for class 'Foo').

We need a new syntax for the new metamodel. I'm thinking of:

  setattribute obj, ["Foo"], "j", $P4

It uses the familiar keyed access syntax to allow multi-level parent class names. We would need to add two additional vtable entries get_attr_keyed and set_attr_keyed.

PMC* get_attr_keyed(PMC* key, STRING* idx)
void set_attr_keyed(PMC* key, STRING* idx, PMC* value) :write

Thoughts?

Allison

Reply via email to