Projects & Tests :(

Agh, not enough time to work on platformer recently.

I did get a little time to implement a prototype of a throwing knife weapon, which is interesting, but I still need to add some actual enemies and gameplay.

Also, I messed around with the scripting language, doing some completely unnecessary (but fun) work like control-flow graph optimizations and peephole optimizations. Some graphs follow:

Before optimization (notice jump-to-jumps) and some slightly redundant bytecode:

output_beforedot1

Before

After:

After

After

There’s some weirdness still, like right now the STVAR (store variable) opcode doesn’t actually eat the top-of-stack because it results in less instructions for a naive code generator to support things like A = B = C, but now that there’s peephole support I’ll probably change it to be more reasonable — the codegen can just emit DUP, STVAR to support that, all statements will be suffixed with a POP, and I can add a peephole rule to change that to just STVAR for the common case.

There’s also a bunch of things that it still doesn’t support, like right now it doesn’t actually assemble the basic block graph into linear code yet because I haven’t thought of a smart way to choose how to order blocks so it can take advantage of fallthrough and not need a JMP at the end of every basic block, or a JT <ifTrue>, JMP <ifFalse>.

It also doesn’t do anything really fun like variable liveness analysis, common subexpression elimination, or code motion; it’s also a stack based architecture so there’s no register allocation to be done. Maybe I’ll spin this into a separate project to write a JIT or something, so I can actually get a game done while also satisfying my bizarre compiler desires.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>