{ "info": { "author": "Erik Nyquist", "author_email": "eknyquist@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Intended Audience :: Education", "Intended Audience :: Information Technology", "Intended Audience :: Science/Research", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7" ], "description": "fast Brainfuck interpreter in pure python\n=========================================\n\nThis is a pure python interpreter for the\n`Brainfuck `_ esoteric programming\nlanguage. ``bfi`` implements the standard optimisations for clear loop, copy\nloop, multiply loop and scan loop constructs, and is reasonably fast without\nrequiring any special python implementations or compiled extension modules.\nSupports Python 2x and 3x.\n\nCheck out `BrainfuckIntern `_,\nan implementation of a genetic algorithm that writes Brainfuck programs,\nusing ``bfi`` to provide information for a useful fitness evaluation on generated\nBrainfuck programs\n\nSpeed benchmark\n---------------\n\nHere is a quick comparison between ``bfi`` and two other popular pure-python\nbrainfuck interpreters on github. The time shown is the time that each\ninterpreter took to complete the \"Towers of Hanoi\" program (``hanoi.b``,\navailable in the ``examples`` directory):\n\n+---------------------------------------------------------------------------------+-------------------------------+\n| **Interpreter name** | **Time to complete hanoi.b** |\n+=================================================================================+===============================+\n| bfi | 1 minute, 9 seconds |\n+---------------------------------------------------------------------------------+-------------------------------+\n| `pocmo's interpreter `_ | 28 minutes, 51 seconds |\n+---------------------------------------------------------------------------------+-------------------------------+\n| `alexprengere's intrepreter `_ | 1 hour, 7 minutes, 54 seconds |\n+---------------------------------------------------------------------------------+-------------------------------+\n\n(I should note here that alexprengere's interpreter can actually go\nmuch faster than this, but not without using the alternative PyPy interpreter,\nor compiling some stuff. Speeds here are shown without such modifications.\nAll tests were done using the standard CPython 2.7.14 interpreter)\n\nImplementation details\n----------------------\n\n* No change on EOF\n* Tape size is configurable, default is 30,000 cells\n* Cells are one byte, valid values between 0-255. Overflow/underflow wraps\n around\n\nInstalling\n----------\n\nUse ``pip`` to install:\n\n::\n\n pip install bfi\n\nUsing the interpreter from the command-line\n--------------------------------------------\n\nOnce installed, the brainfuck interpreter can be invoked from the command line\nusing the ``bfi`` command. Just run ``bfi`` and pass a brainfuck source file.\nSeveral sample Brainfuck programs are provided in the ``examples`` directory\nwithin the installed package (in your system's python2.7/dist-packages\ndirectory- on linux-based systems, for example, the full path might be\n/usr/local/lib/python2.7/dist-packages/bfi/examples).\n\nIn the sample commands below, we will run \"Lost Kingdom\", a text-based adventure\ngame written in Brainfuck:\n\n::\n\n $> cd /bfi/examples\n $> bfi LostKingdom.b\n\n\nUsing the interpreter in your own code\n--------------------------------------\n\nHere is how you use the ``bfi`` module to execute some Brainfuck code\nnormally (reading data directly from stdin and writing directly to stdout):\n\n::\n\n >>> import bfi\n >>> with open('samples/hello_world.b', 'r') as fh:\n ... brainfuck_code = fh.read()\n ...\n >>> Brainfuck.interpret(brainfuck_code)\n\n Hello World!\n\n\nHere is how you use the ``bfi`` module to execute some Brainfuck code without\nreading/writing the user's terminal; input is passed a parameter to\n``interpret()``, and any output is returned as a string.\n\n::\n\n >>> input_data = \"test input\"\n >>> ret = bfi.interpret(brainfuck_code, stdin=input_data, buffer_stdout=True)\n >>> print ret\n\n Hello World!\n\nReference\n---------\n\nDocumentation for the python API is here: ``_\n\nGratuitous unnecessary extras\n-----------------------------\n\nIn order to make Brainfuck code execute more efficiently, it is compiled into\nan intermediate form that takes advantage of common brainfuck idioms and\nconstructs. This intermediate form consists of 11 opcodes, 8 of which are\nsimilar to the original 8 brainfuck instructions. The following table describes\nthe opcodes:\n\n+-----------------------------------+-----------------------------------------+\n| **Opcode** | **Description** |\n+===================================+=========================================+\n| ``move `` | Moves the cell pointer by ```` |\n| | cells. ```` is unused |\n+-----------------------------------+-----------------------------------------+\n| ``sub `` | Moves the cell pointer by ````, and|\n| | decrements value of current cell by |\n| | ```` cells |\n+-----------------------------------+-----------------------------------------+\n| ``add `` | Moves the cell pointer by ````, and|\n| | increments value of current cell by |\n| | ```` cells |\n+-----------------------------------+-----------------------------------------+\n| ``open `` | ```` is an index into the list|\n| | of program opcodes. If the value of |\n| | current cell is zero, jump to |\n| | ````. Otherwise, continue |\n| | execution normally (Same functionality |\n| | as brainfuck \"[\" instruction, except |\n| | jump location is stored with opcode). |\n| | ```` is unused |\n+-----------------------------------+-----------------------------------------+\n| ``close ``| ```` is an index into the list|\n| | of program opcodes. If the value of |\n| | current cell is zero, continue execution|\n| | normally. Otherwise, jump to |\n| | ```` (Same functionality as |\n| | brainfuck \"]\" instruction, except jump |\n| | location is stored with opcode). In all |\n| | cases the cell pointer will be moved by |\n| | ```` |\n+-----------------------------------+-----------------------------------------+\n| ``input `` | Moves the cell pointer by ````, |\n| | then reads one character of input and |\n| | writes to current cell |\n+-----------------------------------+-----------------------------------------+\n| ``output `` | Moves the cell pointer by ````, |\n| | then prints value of current cell as |\n| | an ASCII character |\n+-----------------------------------+-----------------------------------------+\n| ``clear `` | Moves the cell pointer by ````, |\n| | then sets the value of current cell to |\n| | zero |\n+-----------------------------------+-----------------------------------------+\n| ``copy {:,... }`` | Moves the cell pointer by ````, |\n| | then for each key/value pair, sets the |\n| | value of the cell at (current cell + |\n| | ````) to be (value of current cell * |\n| | ````) |\n+-----------------------------------+-----------------------------------------+\n| ``scanl `` | Moves the cell pointer by ````, |\n| | then decrements the cell pointer until |\n| | it points at a cell containing 0 |\n+-----------------------------------+-----------------------------------------+\n| ``scanr `` | Moves the cell pointer by ````, |\n| | then increments the cell pointer until |\n| | it points at a cell containing 0 |\n+-----------------------------------+-----------------------------------------+\n\nIf you *really want to*, you can actually view a brainfuck program in this\nintermediate form, by using the ``bfi.parse`` method and printing the resulting\nopcodes:\n\n::\n\n >>> with open('bfi/examples/mandel.b', 'r') as fh:\n ... program = fh.read()\n ... \n >>> opcodes = bfi.parse(program)\n >>> for c in opcodes: print c\n ...\n\n add 0 13\n copy 0 {1: 2, 4: 5, 5: 2, 6: 1}\n add 5 6\n sub 1 3\n add 10 15\n open 0 12\n open 0 7\n close 9 6\n add 0 1\n open 0 10\n\n ... (long output, truncated ...)\n\nAnd of course, you can execute the compiled opcodes as many times as you like\nusing ``bfi.execute``.\n\nExample Brainfuck programs\n--------------------------\n\nI have included several random Brainfuck programs that I've found in various\nplaces. I didn't write any of these programs, I just copied them as-is\nfrom other public sources. Descriptive comments (and author's name, in some\ncases) can be seen in the Brainfuck source files themselves.\n\nA description of the example Brainfuck programs included with this package\nfollows:\n\n* **bfcl.bf**: A Brainfuck-to-ELF translator, in Brainfuck. Reads in Brainfuck\n source from stdin and writes a Linux ELF file to stdout\n\n* **bitwidth.bf** Assorted tests for Brainfuck interpreter/compiler correctness\n\n* **collatz.b** A demonstration of the Collatz problem in Brainfuck\n\n* **eoftest.b** Tests EOF behaviour of brainfuck interpreters/compilers\n\n* **fib.b** Prints a neverending fibonacci sequence\n\n* **gameoflife.b** Conway's Game of Life in Brainfuck\n\n* **hanoi.b** Towers of Hanoi in Brainfuck\n\n* **hello_world.b** Classic \"hello, world!\" in Brainfuck\n\n* **LostKingdom.b** A text-based adventure game in Brainfuck\n\n* **mandel.b** An ASCII mandelbrot fractal set viewer in Brainfuck\n\n* **numwarp.b** Prints an enlarged ASCII representation of numbers entered by\n the user\n\n* **primes.bf** Prints prime numbers\n\n* **rot13.b** Prints the ROT13 encoding of the string entered by the user\n\n* **sierpinksi.b** Displays the Sierpinksi triangle\n\n* **TheBrainfuckedLoneWolf.b** ASCII asteroids-inspired top-down shooter game\n in Brainfuck", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/eriknyquist/bfi", "keywords": "", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "bfi", "package_url": "https://pypi.org/project/bfi/", "platform": "", "project_url": "https://pypi.org/project/bfi/", "project_urls": { "Homepage": "http://github.com/eriknyquist/bfi" }, "release_url": "https://pypi.org/project/bfi/1.0.2/", "requires_dist": null, "requires_python": "", "summary": "A fast optimizing Brainfuck interpreter in pure python", "version": "1.0.2" }, "last_serial": 4167827, "releases": { "0.2.6": [ { "comment_text": "", "digests": { "md5": "b128b14d4602c8bb85ea8ac4924cc39e", "sha256": "ae4ff5f2cf6f8e34a4c308bb441b3f169ac42e6589e04467bb6398c49def37f6" }, "downloads": -1, "filename": "bfi-0.2.6.tar.gz", "has_sig": false, "md5_digest": "b128b14d4602c8bb85ea8ac4924cc39e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 139128, "upload_time": "2017-09-14T05:26:34", "url": "https://files.pythonhosted.org/packages/2b/5f/5997dde740f27d2cb8c3396aff1ced54e5ee244934afb6ee1b07dc7576e0/bfi-0.2.6.tar.gz" } ], "0.2.7": [ { "comment_text": "", "digests": { "md5": "19f870ed40d58479cd2d84b8c6a4e753", "sha256": "92f62717974b030cea58dd1234c2ef06b56a034765ceb230c754ca426ccd4899" }, "downloads": -1, "filename": "bfi-0.2.7.tar.gz", "has_sig": false, "md5_digest": "19f870ed40d58479cd2d84b8c6a4e753", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 141812, "upload_time": "2017-09-16T18:57:58", "url": "https://files.pythonhosted.org/packages/82/01/ca3d3758cdc2bd9a8c3f06aa40a79a4a4e3b4dadb87658513323d1c29f9f/bfi-0.2.7.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "b122a26c9295d2841f13f5cacf150c8a", "sha256": "8ad3d0069f43e1647eeb9103aaaaa539acad49ef2cca81dc65892d442ae5db0c" }, "downloads": -1, "filename": "bfi-0.5.0.tar.gz", "has_sig": false, "md5_digest": "b122a26c9295d2841f13f5cacf150c8a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 143260, "upload_time": "2018-01-29T05:10:56", "url": "https://files.pythonhosted.org/packages/29/c5/18d1540e4889f3d5f27e96901b2e89a38924cbfc2866fb51337db7d607c2/bfi-0.5.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "c4557be5799e70d933220057f0aef90d", "sha256": "9697f24d76e59edc28c28d80ba2e04861bd8da2e310bab0f2c15ebc2de84ed62" }, "downloads": -1, "filename": "bfi-1.0.1.tar.gz", "has_sig": false, "md5_digest": "c4557be5799e70d933220057f0aef90d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 141094, "upload_time": "2018-08-12T23:25:33", "url": "https://files.pythonhosted.org/packages/a0/6d/8b3f6be72e6f5e9344c44de64371dd255056ae859e65399a8a1068c1d481/bfi-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "e939e1df72a6ab01ddaab6ade7cb3255", "sha256": "ab690ac2240c3f44e636c5967d2420119e7ab468ac0d926d638c860a1b5d05d7" }, "downloads": -1, "filename": "bfi-1.0.2-py2-none-any.whl", "has_sig": false, "md5_digest": "e939e1df72a6ab01ddaab6ade7cb3255", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 158738, "upload_time": "2018-08-14T05:17:15", "url": "https://files.pythonhosted.org/packages/29/83/8e288e3f54c62fb01d6d9a16abca41f1bf315b884a47ce2b0eaf29b0e6b7/bfi-1.0.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "784b0589799acd88d8e0df83e57c7340", "sha256": "0f11eecb2dcf056b0a6b2a763cf91a05d4a2a5c66af9915bff50c96cab969d0b" }, "downloads": -1, "filename": "bfi-1.0.2.tar.gz", "has_sig": false, "md5_digest": "784b0589799acd88d8e0df83e57c7340", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 140672, "upload_time": "2018-08-14T05:04:54", "url": "https://files.pythonhosted.org/packages/ae/2f/f1314c9ecbbfe2329a1106d29d269e7d8a878880f6ab06f9411f6c6fdea3/bfi-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e939e1df72a6ab01ddaab6ade7cb3255", "sha256": "ab690ac2240c3f44e636c5967d2420119e7ab468ac0d926d638c860a1b5d05d7" }, "downloads": -1, "filename": "bfi-1.0.2-py2-none-any.whl", "has_sig": false, "md5_digest": "e939e1df72a6ab01ddaab6ade7cb3255", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 158738, "upload_time": "2018-08-14T05:17:15", "url": "https://files.pythonhosted.org/packages/29/83/8e288e3f54c62fb01d6d9a16abca41f1bf315b884a47ce2b0eaf29b0e6b7/bfi-1.0.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "784b0589799acd88d8e0df83e57c7340", "sha256": "0f11eecb2dcf056b0a6b2a763cf91a05d4a2a5c66af9915bff50c96cab969d0b" }, "downloads": -1, "filename": "bfi-1.0.2.tar.gz", "has_sig": false, "md5_digest": "784b0589799acd88d8e0df83e57c7340", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 140672, "upload_time": "2018-08-14T05:04:54", "url": "https://files.pythonhosted.org/packages/ae/2f/f1314c9ecbbfe2329a1106d29d269e7d8a878880f6ab06f9411f6c6fdea3/bfi-1.0.2.tar.gz" } ] }