Autrijus Tang <[EMAIL PROTECTED]> wrote:

>     class Point {
>       has $.x;
>       has $.y;

The progress pugs makes is really impressive.

[ ... ]

> Pugs's Parrot codegen backend needs to be updated

Object attribute access, yeah. IMHO Parrot's current implementation is
wrong.

0) class construction      # a bit shortened for this example

  .local pmc cl, o, x, y   # decls for example
  cl = newclass "Point"
  addattribute cl, "x"     # "$x" what does Python then?
  addattribute cl, "y"     # "$y" what does Python then?
  o = new "Point"          # make instance -  __init not shown

1) indexed access

  $I0 = classoffset o, "Point"
  x = getattribute o, $I0       # 1st attribute at ofs + 0
  $I1 = $I0 + 1
  y = getattribute o, $I1       # 2nd attribute at ofs + 1

The offset is cached in the bytecode, you could keep it over the whole
program life-time. If the class layout ever changes, things would break
horribly. The compiler needs intimate knowledge of the attribute order
and it's usable for an array-ish object layout only.

2) named access

  x = getattribute o, "Point\0x"

This needs a full qualified attribute name "Class" ~ NUL ~ "Attribute".
That's unusable for at least Python and probably more HLLs as the
compiler has to know in which class the attribute was defined.

We should just have:

  x = getattribute o, "x"

and the set equivalent:

  setattribute o, "x", x

Comments welcome,
leo

Reply via email to