Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nickdesaulniers/bf_interpreter_jit_compiler
Teach myself about interpreters, JITs, and compilers using the Brainfuck language as the toy language
https://github.com/nickdesaulniers/bf_interpreter_jit_compiler
Last synced: 3 months ago
JSON representation
Teach myself about interpreters, JITs, and compilers using the Brainfuck language as the toy language
- Host: GitHub
- URL: https://github.com/nickdesaulniers/bf_interpreter_jit_compiler
- Owner: nickdesaulniers
- License: other
- Created: 2013-04-29T03:49:59.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-12-21T18:42:40.000Z (almost 3 years ago)
- Last Synced: 2024-07-06T04:12:41.756Z (4 months ago)
- Language: C
- Homepage: https://nickdesaulniers.github.io/blog/2015/05/25/interpreter-compiler-jit/
- Size: 37.1 KB
- Stars: 81
- Watchers: 15
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- AwesomeCompiler - bf_interpreter_jit_compiler
- AwesomeInterpreter - bf_interpreter_jit_compiler
README
# Interpreter, Compiler, JIT
This repo contains three programs used in my [blog post](https://nickdesaulniers.github.io/blog/2015/05/25/interpreter-compiler-jit/); an interpreter, a compiler, and a Just In Time (JIT) compiler for the brainfuck language. It's meant to show how similar these techniques are.### Portability
While all three are written in C, only the interpreter should be portable, even to emscripten. The compiler and JIT is highly dependant on the x64 Instruction Set Architecture (ISA), and Linux/OSX style calling convention. The assembler is made for OSX, but you can probably just link using GCC/Clang on Linux.### Warning
I take no responsibility for you running arbitrary brainfuck programs you found on the Internet through the compiler or the JIT. I would only run either in a virtual machine, just to be safe! You've been warned!## Building
### Native
```bash
mkdir build
cd build
cmake ..
make
```
### Emscripten
Only the interpreter is portable to JavaScript.```bash
mkdir build
cd build
cp ../samples/* .
emcmake cmake ..
emmake make
```## Running
### The Interpreter
```bash
./interpreter ../samples/hello_world.bf
```
or Emscripten-ized:```bash
node interpreter.js hello_world.bf
```### The Compiler
```bash
./compiler ../samples/hello_world.bf > temp.s
../assemble.sh temp.s
rm temp.s
./a.out
```### The JIT
```bash
./jit ../samples/hello_world.bf
```## License
The code in this repo _except_ the code in `samples/` has the following license:```bash
THE BEER-WARE LICENSE (Revision 42):
wrote this file. As long as you retain this notice you
can do whatever you want with this stuff. If we meet some day, and you think
this stuff is worth it, you can buy me a beer in return.Nick Desaulniers
```