Showing posts with label internals. Show all posts
Showing posts with label internals. Show all posts

Monday, March 22, 2010

I'm back!

With the completion of Kakapo release-10 a while back, I've been focusing on compiler work again. I have to say, Kakapo is making it smooth.

The change to NQP-rx is causing all kinds of problems. Some of them are voluntary: I'm moving to attribute based classes, and I'm taking advantage of a bunch of features of the new -rx engine. But some of them are involuntary, like climbing the learning curve for how optable parsing works.

I put up a wiki page about that over on the Parrot.org trac site, but even after writing out a bunch of stuff, it's still not totally obvious to me how some parts work. That's part of the learning process, I guess.

One thing I'm doing somewhat differently now is testing. Before, I was writing tests for the compiler. Now I'm writing tests of the compiler.

Friday, February 12, 2010

There's more than one way to do it...

In the process of paying the taxes, I've come across one of the important classes in Kakapo that needs "updating."

In this case, "updating" means "complete rewrite," since I've got the new class system working. So I thought I'd show a before/after version of the code.

Wednesday, February 10, 2010

More snow .. err, code!

We got some more snow here in the northeast. Which means I've had plenty of time to code. Sadly, though, while I've been very active on Parrot's trac submitting tickets, I haven't made much forward progress. This was my tree at about 4:30pm.

Monday, October 19, 2009

rtype not set

I just got this diagnostic from NQP, and boy, is that not a helpful error message. Of course, since it's in PAST->POST compilation, there's no line number or token output.

FWIW, the problem was that I was doing this:
self.declarator := '' ~ $name;
when, as anyone can plainly see, I should have been doing this:
self.declarator('' ~ $name);
because .declarator is a method, not an attribute. D'oh.

I've seen this error once before, and I didn't remember what caused it. I hope that next time I'll remember it, or that The All-Knowing Oz will be able to remind me.

Friday, October 16, 2009

Parrot Multi-Subs and Inheritance

One of the things I've added to Slam (the Close compiler) is support for declaring multi-subs. In another language, these would be called "overloaded methods" or "overloaded functions," but in Close, it's all about the underlying hardware, and that means MultiSubs.

Before I write too much, let me make this clear: Parrot is not the same as Perl6, or Python, or whatever your favorite language is. And so, the way Parrot (and Close) handle things like object dispatch -- the "Object Meta-model," as it is called -- is different from the way other languages handle these things. This is one of those times where the difference matters. (And specifically, the stuff I write below about inheritance isn't true for Perl6. You have been warned.)

Friday, September 25, 2009

Recursive Compiling

Years ago, back when GCC was still on version 1.x, I went looking through the code. I don't remember why, but I was looking for a way to "just make a function." I had some notion that down in the bowels of the code there would be a function called "create_function" or some such, and I could pass it a return type and a name and who-knows-what-else, and it would return a function object. Or maybe it would automatically emit the function object. I don't remember what I was thinking at the time, I just remember being frustrated by the nest of snakes I uncovered, each function requiring a huge initialized data structure as input, making a small update to the tree, and returning.

The other day I was working on Close, and I needed to create a function for the namespace init code. And I thought, "what I need is a function that will just create this one thing for me." Deja vu!

Tuesday, September 22, 2009

Output ordering and Initializers

Output ordering

Today I got Close to emit functions in the same sequence they occur in the input file. That was easy.

What wasn't easy was automatically creating a namespace init function to handle initialized declarators.

If you compile code that looks like this:
int x = 10;
There's no function involved. Clearly, this is a global variable 'x', and its initial value is 10. But Parrot does not use the same model that *nix uses, of loading a file that contains a partial memory image. Since there's no data segment, any and all initialization have to be done by code.