Thursday, 4 August 2011
But CoffeeScript is still a dynamic language and in some ways it's just a syntax improvement (albeit a major one).
So, after not finding something I liked and a pretty severe bout of Not Invented Here Syndrome, I've started work on a new language and a compiler for it (as one does).
C# as the Inspiration, Not the Goal
classes. In particular, jQuery needs to work as is so
$ will be supported as a valid identifier character.
Primarily the language will be strongly/statically typed but allow dropping back to dynamic typing. Internally, strong typing will be enforced where you use it. Imported external objects can be treated as strongly typed by casting to defined types, or accessed directly as dynamic objects. Objects returned out of the language will obviously need to be dynamic.
Elimination of Evil and Ambiguity (and some annoyances)
eval statements which simply wont be supported.
- Local variable scoping
- Handling of
thisin nested closures (ie: the private
thatconvention described here)
- The need to reference one's own member variables via
The code generated by this compiler will strive for:
No Runtime Dependencies - This is paramount. There may be a need for a few internal helper functions, but these will be tiny, neatly hidden away and automatically written by the compiler.
Readability - The generated code will be readable and recognizable as the original input program. This is important in order to make debugging as easy as possible. This includes maintaining original comments, minimal mangling of identifiers and simply producing clean code.
Best practice techniques - rather than provide a bunch of different options for how code is generated, as much as possible I hope to choose one technique that is considered best practice and stick to it.
Compatibility - The generated Javascipt will work across all browsers (well probably, that's not a fixed goal - perhaps I should say all modern browsers)
So that's the plan - where to start? The code base for MiniME seemed like a good place.
After cloning and ripping out the minification logic I was left with just the tokenizer, parser and renderer. I then spent a few hours tinkering and soon had a simple proof of concept up and running - it could process a simple class syntax and generate a
prototype based "class" as the output.
Since then I've made good progress (which I'll write up over the coming days) but there's still a fair way to go.
I'm not sure yet whether this will be an open source project. At least initially I'll be keeping it closed but developing it in public. There'll probably be a series of blog posts over the coming weeks as I'd like to keep a record of what's been done and why.
Finally, I'm going to have to decide on name. I've got something in mind but I'm not committed yet... stay tuned.
Leave a comment