Thursday, January 21, 2010

I have a compiler going!

And the test for this is 'Number' - so I have essentially bootstrapped the Number library. It's all a bit first iteration; the opcode output is appallingly inefficient. Makes me shudder to think about it, but it works.

I'm in a conundrum (that's all this blog is about really :). Primitive things, such as Undefined, Null, List, Map, Number and String, are essential to nearly all programs. It seems painful to require that everything have these injected. If there was class nesting it wouldn't be such a faff because only the outermost class would need to include the primitive stuff.

Ahhhh.

So what I need is a way of nesting classes :) Back to newspeak. Not so bad though; I can simply add the enclosing class to the list of traits for that class. Call it something imaginative like 'EnclosingType'.

The biggest problem here being that EVERYTHING needs List to be able to create functions (which require a list of arguments). So the compiler will need access to this even if the programmer doesn't think it's necessary... oh dear. So maybe just list gets put onto RootObject.

Actually, how about ArgumentList gets put on - and all it can do is be used as an argument list. Oh hang on! I can add it to Activation, which is used to create functions anyway. That feels better.

Oh, BTW, I've decided that all primitives (as listed above) must be immutable. So the List object will return a new List object when you add something to it.

So what I'm going to do (right now) is
  • Add ArgumentList to Activation
  • Create 'primitive' object that can be passed as a parameter and be used to access the primitives
  • Make current primitives immutable
  • remove primitives from environment, so they must be accessed via the parameter (basically, get the compiled version of fibonacci working)
  • Create String primitive
  • Implement compiler in OpCodes!
Nothing too ambitious

No comments:

Post a Comment