Brainfuck "compiler" for Python (fast)
Reason this release was yanked:
Bad Linux support
Project description
This is a very fast brainfuck "compiler".
When used, it builds brainfuck code into Python extension modules, and imports it.
Requires:
- Python>=3.6
- C++ Compiler available
- pybind11
Running brainfuck
Use the 'brainfuck_to_function' function to convert brainfuck into function. It will take several seconds for the C++ compiler to build the module, but after build, you can call it anytime without building, which will be faster, and about 3x faster than directly using a brainfuck interpreter implemented in C++.
from fastbf import brainfuck_to_function
code='--<-<<+[+[<+>--->->->-<<<]>]<<--.<++++++.<<-..<<.<+.>>.>>.<<<.+++.>>.>>-.<<<+.'
func=brainfuck_to_function(code)
func() # Hello World!
Freezing brainfuck into executables
fast-brainfuck is not supposed to be frozen into executables (e.g. using PyInstaller). But fortunately, you can use the 'dist_brainfuck' function to convert brainfuck into Python modules. You can write setup.py like this:
from fastbf import dist_brainfuck
code='--<-<<+[+[<+>--->->->-<<<]>]<<--.<++++++.<<-..<<.<+.>>.>>.<<<.+++.>>.>>-.<<<+.'
dist_brainfuck(
code,'hello'
)
Then run python setup.py build_ext --inplace, the files hello.py and hello.xxx.pyd (hello.xxx.so) will be created, you can now use
import hello
hello.run()
to run the brainfuck in your script (which CAN be frozen into executables).
Note that fast-brainfuck does NOT clean up the temporary files it creates. You have to manually delete them if you want.
fast-brainfuck can run on CPython or PyPy.
ImportError: xxx
If you encountered this error when using this package in PyPy in Windows, that means your username has non-ASCII characters. You can run
import os
os.environ['TMP']='C:\\Somedir'
before using fast-brainfuck to fix the error.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fast_brainfuck-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9344e7b2b5d818cf09592e22becafa75b64c8dfe6bc69a851f0913213c4c4cc |
|
MD5 | 6fc9701248c19c5509f8eb59d58419e7 |
|
BLAKE2b-256 | 81f79290d806c9f53eb504e1585c31d25894709e6353860b44bf62898e2ae0aa |