hikari-no-yume / Firth

Firth is a functional, strongly dynamically-typed, concatenative stack-oriented programming language.
Other
29 stars 2 forks source link

Optimising compiler #7

Open hikari-no-yume opened 9 years ago

hikari-no-yume commented 9 years ago

Currently we just have the naïve interpreter. However, it should do some optimisation passes and eventually have the option to produce code (in C or JavaScript).

hikari-no-yume commented 9 years ago

In order to do this, we need an easy-to-optimise AST. While the opcodes sort of work as an AST, they aren't really.

Currently we have two stages with a certain output (in brackets):

lex     -> parse
(tokens)   (opcodes)

What we need is three stages:

lex     -> parse  -> compile
(tokens)   (ast)     (opcodes)

Though that only works for the interpreter - JS output isn't just opcodes. So you need one further stage:

lex     -> parse  -> optimise        -> compile
(tokens)   (ast)     (optimised ast)    (js/opcodes)