I am working towards a core language for JavaScript... JavaScript by itself is nice for humans but not for compilers. The language definition has just one special case too many.
Here is a take on the Core:
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 32 33 34 35 36 37 38 39 40 41 | |
And then expressions are instances of Core Scheme expressions instantiated with Primitive.
1 2 3 4 5 6 7 8 9 | |
Notes:
No expression/statement distinction - this should be automated.
JavaScript calls are modelled with
Applywhere the first argument is alwaysthisargument. Thereforefoo.bar(baz)becomesApply (foo.[bar], foo :: baz).Global variable references are modelled as
Lookup, saywindowbecomesLookup "window".LetRecclause, as in Scheme, is derived - it is modelled withAssignandLet.Some JavaScript assignments are field assignments and not variable assignments - and these are a primitive, for example
foo.bar = 1becomesSet (foo, bar, 1).No
try-finally- can be reduced toTry.No loops other than
While- others can be reduced to it.
This seems to be expressive enough. I will probably update the definition after trying to write a few optimizations.
No comments:
Post a Comment