fast-brainfuck


Namefast-brainfuck JSON
Version 3.0.1 PyPI version JSON
download
home_pagehttps://github.com/none-None1/fast-bf
SummaryBrainfuck "compiler" for Python (fast)
upload_time2023-07-03 05:21:27
maintainer
docs_urlNone
author
requires_python>=3.6
license
keywords brainfuck
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p><span><span style="font-family:Verdana, Arial, Helvetica, sans-serif;line-height:19px;text-indent:26px;"><span style="font-size:14px;"><span style="font-family:Arial;line-height:26px;"><br></span></span></span></span></p>

# A big bugfix is applied to this package due to the technique Python uses to import modules.

In previous versions, when brainfuck_to_function is called, it creates a module named _foo, which is imported. But Python also stores it into a cache, that means when you call brainfuck_to_function again, the new module would not be imported, which causes a function the same as the previous function is returned.

However, in this version and higher, a module with a random name is created instead, which fixed the bug.

### This is a very fast brainfuck "compiler".

When used, it builds brainfuck code into Python extension modules, and imports it.

Requires:
1. Python>=3.6
2. C++ Compiler available
3. 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++.
```python
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:

```python
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
```python
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
```python
import os
os.environ['TMP']='C:\\Somedir'
```
before using fast-brainfuck to fix the error.

Note that moving the pointer to the left of the origin causes **UNDEFINED BEHAVIOR** in this version


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/none-None1/fast-bf",
    "name": "fast-brainfuck",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "brainfuck",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/c1/99/9284949e1ead0da83f1561510c81d8823db99e18a1f22c6789893a042e5a/fast-brainfuck-3.0.1.tar.gz",
    "platform": null,
    "description": "<p><span><span style=\"font-family:Verdana, Arial, Helvetica, sans-serif;line-height:19px;text-indent:26px;\"><span style=\"font-size:14px;\"><span style=\"font-family:Arial;line-height:26px;\"><br></span></span></span></span></p>\r\n\r\n# A big bugfix is applied to this package due to the technique Python uses to import modules.\r\n\r\nIn previous versions, when brainfuck_to_function is called, it creates a module named _foo, which is imported. But Python also stores it into a cache, that means when you call brainfuck_to_function again, the new module would not be imported, which causes a function the same as the previous function is returned.\r\n\r\nHowever, in this version and higher, a module with a random name is created instead, which fixed the bug.\r\n\r\n### This is a very fast brainfuck \"compiler\".\r\n\r\nWhen used, it builds brainfuck code into Python extension modules, and imports it.\r\n\r\nRequires:\r\n1. Python>=3.6\r\n2. C++ Compiler available\r\n3. pybind11\r\n\r\n#### Running brainfuck\r\n\r\nUse the 'brainfuck_to_function' function to convert brainfuck into function.\r\nIt 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++.\r\n```python\r\nfrom fastbf import brainfuck_to_function\r\ncode='++++++++[>++++++++<-]>++++++++.>++++++++++++[>++++++++<-]>+++++.+++++++..+++.>++++[>++++++++<-]>.<<<<+++++++++++++++.>>.+++.------.--------.>>+.'\r\nfunc=brainfuck_to_function(code)\r\nfunc() # Hello World!\r\n```\r\n\r\n#### Freezing brainfuck into executables\r\n\r\nfast-brainfuck is not supposed to be frozen into executables (e.g. using PyInstaller).\r\nBut fortunately, you can use the 'dist_brainfuck' function to convert brainfuck into Python modules.\r\nYou can write setup.py like this:\r\n\r\n```python\r\nfrom fastbf import dist_brainfuck\r\ncode='++++++++[>++++++++<-]>++++++++.>++++++++++++[>++++++++<-]>+++++.+++++++..+++.>++++[>++++++++<-]>.<<<<+++++++++++++++.>>.+++.------.--------.>>+.'\r\ndist_brainfuck(\r\n    code,'hello'\r\n)\r\n```\r\nThen 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\r\n```python\r\nimport hello\r\nhello.run()\r\n```\r\nto run the brainfuck in your script (which **CAN** be frozen into executables).\r\n\r\nNote that fast-brainfuck does **NOT** clean up the temporary files it creates. You have to manually delete them if you want.\r\n\r\nfast-brainfuck can run on **CPython** or **PyPy**.\r\n\r\n#### ImportError: xxx\r\nIf you encountered this error when using this package in PyPy in Windows, that means your username has non-ASCII characters.\r\nYou can run\r\n```python\r\nimport os\r\nos.environ['TMP']='C:\\\\Somedir'\r\n```\r\nbefore using fast-brainfuck to fix the error.\r\n\r\nNote that moving the pointer to the left of the origin causes **UNDEFINED BEHAVIOR** in this version\r\n\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Brainfuck \"compiler\" for Python (fast)",
    "version": "3.0.1",
    "project_urls": {
        "Homepage": "https://github.com/none-None1/fast-bf"
    },
    "split_keywords": [
        "brainfuck"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "87716a690048335bcd49859ce51bb8a0db8a423feb8db5c1c625bcb3355f1627",
                "md5": "dc41cde4a1788ae84820f393289e9386",
                "sha256": "a9819837bba8d0ffc61719906c60151421e4278ae2fcf0f54d622bbff0ef0413"
            },
            "downloads": -1,
            "filename": "fast_brainfuck-3.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dc41cde4a1788ae84820f393289e9386",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4606,
            "upload_time": "2023-07-03T05:21:11",
            "upload_time_iso_8601": "2023-07-03T05:21:11.217038Z",
            "url": "https://files.pythonhosted.org/packages/87/71/6a690048335bcd49859ce51bb8a0db8a423feb8db5c1c625bcb3355f1627/fast_brainfuck-3.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c1999284949e1ead0da83f1561510c81d8823db99e18a1f22c6789893a042e5a",
                "md5": "d00ea9e46ea978f6af41b90c1584569c",
                "sha256": "e96b7429699db147b0d441ad368bc46697b810d3a7c8840765c48c926e62832b"
            },
            "downloads": -1,
            "filename": "fast-brainfuck-3.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d00ea9e46ea978f6af41b90c1584569c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4486,
            "upload_time": "2023-07-03T05:21:27",
            "upload_time_iso_8601": "2023-07-03T05:21:27.291394Z",
            "url": "https://files.pythonhosted.org/packages/c1/99/9284949e1ead0da83f1561510c81d8823db99e18a1f22c6789893a042e5a/fast-brainfuck-3.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-03 05:21:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "none-None1",
    "github_project": "fast-bf",
    "github_not_found": true,
    "lcname": "fast-brainfuck"
}
        
Elapsed time: 0.08612s