rbartlensky / Lua-interpreter

A Lua interpreter in Rust
5 stars 2 forks source link

SSA intermediate representation #9

Closed rbartlensky closed 5 years ago

rbartlensky commented 5 years ago

This branch adds a new intermediate representation on which it is easier to perform optimizations, and to apply a register allocation algorithm. At the moment, the compiler will crash if the user's program uses more than 256 registers.

The compiler now translates Lua to the SSA IR, then to Lua bytecode.

ltratt commented 5 years ago

I'm confused by the 256 limitation: when are registers infinite (well, up to usize, at least) and when are they finite? What does "crash" mean (is it an orderly panic or ...?)?

rbartlensky commented 5 years ago

I'm confused by the 256 limitation: when are registers infinite (well, up to usize, at least) and when are they finite? What does "crash" mean (is it an orderly panic or ...?)?

Basically the irgen module generates IR that assumes there are infinite registers. Then the bytecodegen takes this IR and generates 32bit instructions that can only address 256 registers.

The compiler panics if a high-level instruction cannot be translated into a low level instruction. So for instance if the compiler generates something like: mov 300 1 2, and then tries to encode it in 32 bits, it will panic.

rbartlensky commented 5 years ago

Ready for another review! I use the entry api now, and I also removed the curr_instr field.

rbartlensky commented 5 years ago

I think this can be re-reviewed because I am going to use most of the things implemented here. The last 3 commits are new.

ltratt commented 5 years ago

Sorry for the grmtools changes. Hopefully you might benefit from the new actions stuff, when it's documented.

Anyway, agreed, let's squash this PR and get you moving on your way.

rbartlensky commented 5 years ago

Squashed, but it seems that rustfmt-preview is not part of the latest nightly build...

ltratt commented 5 years ago

Try using stable? grmtools now works on stable...

rbartlensky commented 5 years ago

I switched to stable, but I had to remove some of rustfmt's features.

ltratt commented 5 years ago

If it works, that's fine.

There are quite a few warnings that need to be fixed before we can think about merging.

rbartlensky commented 5 years ago

Ready! Should I squash?

ltratt commented 5 years ago

OK, the rustfmt thing is a pain, but there isn't much we can do until rustfmt catches back up with nightly. Let's fix that last nit, then we're pretty much there.

ltratt commented 5 years ago

It looks like rustfmt builds again on nightly (it was actually an intermediate library's fault), so you might be able to use rustfmt nightly again. I slightly tweaked my travis.yml, although it's probably not necessary (https://github.com/softdevteam/grmtools/commit/02b3da4eedd6f9c439febeb8b01cf623abb02af4).

rbartlensky commented 5 years ago

Can I squash?

ltratt commented 5 years ago

Please squash.

rbartlensky commented 5 years ago

Squashed and ready!