August 2008

Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Recently on this blog
Recently on other blogs

Map

Audrey

My Photo

License

« Day 4 of Text.Parser.Rule. | Main | Mixing Rules with OpTable. »

2006.01.01

::Array and ::Hash lands.

Today Leo sent me a set of design notes, including his recent thinking about how Parrot's PMC layout and interfaces may be improved, allegedly inspired by pugs/docs/quickref/data. Coincidentally, I was feeling unhappy about the steadily-growing vtable of PILN's NativeObj structure, so I implemented Leo's design, and it worked beautifully.

The basic idea is that instead of having a large fixed set of things that all objects may do, we split them out into interfaces, which are simple mappings from method names to native code. At class composition time, the class selects a representation for its object by mixing in one or more interfaces.

The chosen interfaces determines which primitive operations the object can perform, which stays immutable during the entire runtime (just like the old vtables did), and as such may still be checked statically.

Under this scheme, we don't need to allocate stub throw-an-execption for value classes's set method, and the distinction of Containers is clear: unlike ordinary Objects, they do not use the p6opaque representation (set_attr, get_attr...). I have just coded in p6array and p6hash representations, with primitive operations such as fetch_elem and store_elem.

This also addressed the problem of how attributes are handled when we extend builtin classes with Perl 6 code. Because "has $!x = 3" ultimately desugars into set_attr operations, which does not exist in a boxed p6integer, code like "class ::Int is extended { has $!foo }" can be rejected at compile time, which is probably a good thing.

Tomorrow I'll move to ::Args and ::Sigs, and ::Code after them if all works out. Then we'll add some sugar to it and serve the dish by compiling PIL2 to it. It's already smelling good...

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451e8fb69e200d8355a5bee69e2

Listed below are links to weblogs that reference ::Array and ::Hash lands.:

Comments

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment