top | item 17604129

(no title)

m4tx | 7 years ago

Yes, the project was fun, yet simple and fast to write! I was thinking about doing some more advanced optimizations, although I believe the opportunities for that are pretty limited for Brainfuck. Also, I think the code is pretty nice and clean and generic enough to be partially moved to another possible project, which is the gain of doing things more generic than they actually needed to be.

You said you were working on another JIT - what was that? Also, do you have any suggestions of another project/language to implement compiler for to gain some knowledge about writing optimizations, actual intepretation/compilation logic, etc?

Thanks for the additional resources about the instruction encoding - seems like this is a bit easier to understand than AMD64 documentation!

discuss

order

vardump|7 years ago

I'm not an expert in this field, also currently in learning mode.

> You said you were working on another JIT - what was that?

A JIT for a custom 32-bit RISC soft-CPU (FPGA).

> Also, do you have any suggestions of another project/language to implement compiler for to gain some knowledge about writing optimizations, actual intepretation/compilation logic, etc?

You could write another C compiler. Or a JIT for some scripting language. Lua is about as simple as it gets when it comes to JITtable scripting languages. Of course amazing http://luajit.org/ already exists.

Existing CPUs and bytecode formats are also potentially good.

In particular, other people might actually want to use a small WebAssembly (https://webassembly.org/) AOT/JIT compiler. I know I would. :)

Some source code I've personally found educating on this topic:

1) Lots of easier stuff (ARM/x86 encoding, basic optimizations, etc.) can be found in JITting emulators, like Dolphin: (https://github.com/dolphin-emu/dolphin)

2) Web browser Javascript engines, like (https://github.com/v8/v8/tree/master/src). And of course LuaJIT.

3) Compiler codegen, like LLVM (https://github.com/llvm-mirror/llvm)