You can clone this repo, but this package is published on PyPI, too. Therefore, you can also install it using pip:
pip install llvmlite jitbf # The package also requires llvmlite
To use it, you can either write your code like this:
from jitbf import bf2jit
code='<code>'
jit=bf2jit(code)
jit()
, or use the jitbf command.
You have to install tha package 'llvmlite' before using this package.
I compared this JIT interpreter with the Quick Dirty Interpreter In C. The brainfuck code used in the test is mandel.b. The operating system used in the test is Windows 10 64 bit.
Interpreter: jitbf 1.0.0 Time to run: 3.5764139 s
Interpreter: Quick Dirty Interpreter In C Time to run: 8.3990561 s
The package is based on LLVM, it first translates brainfuck into LLVM IR code, then uses llvmlite to compile and run it.
Advantages:
- Fast.
- Consists of only one small Python file.
- Provides a commandline tool.
Disadvantages:
- It does NOT free allocated memory.
- Once you run brainfuck code which never ends, using this package, all you can do to terminate it is to kill it (Ctrl+C won't work).
I will improve it by making the LLVM IR code it translates smaller, and runs faster.