diff options
Diffstat (limited to 'tools/brainfuck/bf_compile.py')
-rwxr-xr-x | tools/brainfuck/bf_compile.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/brainfuck/bf_compile.py b/tools/brainfuck/bf_compile.py new file mode 100755 index 0000000..453ae77 --- /dev/null +++ b/tools/brainfuck/bf_compile.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +import sys + +if len(sys.argv) < 2: + print("Give me filename...") + exit() + +bytecode = { + '>': b"\x00", + '<': b"\x02", + '+': b"\x07", + '-': b"\x06", + '.': b"\x05", + ',': b"\x04", + '[': b"\x03", + ']': b"\x01", +} + +src_buff = open(sys.argv[1]).read() +bin_file = open(sys.argv[1]+".bin", mode="wb") + +for c in src_buff: + try: + b = bytecode[c] + bin_file.write(b) + except KeyError: + # Ignore whitespace, etc. + pass + +bin_file.close() |