# BrainHurt
This is an Interpreter and debugger for the programming language `BrainFuck` written in `Python`
## Features and Notes
* Need to end input with `cntrl + z` on windows and `cmd + d + d` on mac
* Returns `0` as `EOF`
* Generally would have an array of `65535` elements each being an unsigned integer of `8 bytes`
## How To Use
**Install the package**
```powershell
pip install brainhurt
```
You can either call it Programmiticaly in script or direclty from terminal
**From Command Line**
```powershell
python -m brainhurt file_name.bf
```
**From Python Script**
```py
from brainhurt import BrainHurt
brainhurt = BrainHurt()
brainhurt.load_file('file_name.bf')
brainhurt.execute_programm()
```
## Debugging
In order to use debug mode First you need to do these 2 things
* Set debug points
* turn on debug mode
**What is debug points?**
It is an list of tuples with 2 items first is the line number and the other is character number in that line.
_Example._
```py
debug_points = [
(0, 3),
(3, 10),
(100, 2),
# ....
]
```
setting debug mode
```py
brainhurt = BrainHurt(
debug=True,
conf=debug_points
)
# or you can also do it later
brainhurt.conf_debug(debug_points, True)
```
Now whenever you will execute your programm using `execute_programm` method the code execution will stop at breaking point and return an tuple with information
```py
# Example of return tuple in debug mode
print(brainhurt.execute_programm())
# The code execution would stop at the next breakpoint
"""
OUTPUT:
(
2, # it is return type, could be debug, success etc..
(
0, #memory offset
2, #memory pointer
[0, 0, 10, 0, 0] #memory
),
(
5 #programm pointer ,
)
"""
```
Now if you would try to see the return value of same method when debug mode is off you will get something like this
```py
brainhurt.conf_debug(None, False)
print(brainhurt.execute_programm())
# Whole programm would be executed while ignoring all the debug breakpoints
"""
OUTPUT::
(
0, # it is return type
)
"""
```
## IO Operations
Both input and output are stored inside python list and Follows FIFO.
### INPUT
**How can you provide input**
One way to provide input it to pass an list or string in the contructor
```py
brainhurt = BrainHurt(input='pankaj') # passing string
# OR
brainhurt = BrainHurt(input=['p','a', 'n', 'k', 'a', 'j']) # passing list
```
other way is to pass list or string in the `load_input` method
```py
brainhurt.load_input('pankaj')
# OR
brainhurt.load_input(['p', 'a', 'n', 'k'])
brainhurt.load_input(['a', 'j'])
```
By default if input array is empty and programm is asking for input, then our interpreter would use the python's `sys.stdin.read` method to read for input and would store it in input extending with `0` as `EOF`
If you want to change this default behaviour you can pass an `callback(function)` to the constructor as keyword argument `input_callback` which will be executed whenever programm wants input and input array is empty.
_Example..._
```py
brainhurt = BrainHurt(input_callback=some_function)
# OR
brainhurt.input_callback = some_function
```
### OUTPUT
By default whenever the programm wants to output something, interpreter would output to the standard output using python's `print` function
If you want to change this default behaviour, you can pass an `callback(fuction)` to the constructor as keyword argument `output_callback` which should accept 1 argument. Once setted, whenever your programm wants to output something this callback function would be executed with the data passed to it.
Raw data
{
"_id": null,
"home_page": "https://github.com/PankajVishw50/brainhurt",
"name": "brainhurt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "pankaj, pankaj vishw, brainfuck, brainhurt, brainfuck compiler, brainfuck interpreter, brainfuck debugger, debugger, interpretter, compiler",
"author": "Pankaj Vishwakarma",
"author_email": "vishw.dev.1000@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ab/50/1f493670c675ffc9f4e36123ec41282e78af0c65805ceea9ea9370274b2b/brainhurt-0.1.0.tar.gz",
"platform": null,
"description": "\r\n# BrainHurt \r\n\r\nThis is an Interpreter and debugger for the programming language `BrainFuck` written in `Python`\r\n\r\n\r\n## Features and Notes\r\n* Need to end input with `cntrl + z` on windows and `cmd + d + d` on mac\r\n* Returns `0` as `EOF`\r\n* Generally would have an array of `65535` elements each being an unsigned integer of `8 bytes`\r\n\r\n## How To Use\r\n\r\n**Install the package** \r\n\r\n```powershell\r\npip install brainhurt\r\n```\r\n\r\nYou can either call it Programmiticaly in script or direclty from terminal \r\n\r\n**From Command Line**\r\n```powershell\r\npython -m brainhurt file_name.bf\r\n```\r\n\r\n**From Python Script**\r\n```py\r\nfrom brainhurt import BrainHurt\r\n\r\nbrainhurt = BrainHurt()\r\nbrainhurt.load_file('file_name.bf')\r\nbrainhurt.execute_programm()\r\n```\r\n\r\n## Debugging\r\nIn order to use debug mode First you need to do these 2 things \r\n* Set debug points\r\n* turn on debug mode\r\n\r\n\r\n**What is debug points?** \r\nIt is an list of tuples with 2 items first is the line number and the other is character number in that line. \r\n_Example._\r\n```py\r\ndebug_points = [\r\n (0, 3),\r\n (3, 10),\r\n (100, 2),\r\n # ....\r\n]\r\n```\r\n\r\nsetting debug mode\r\n```py\r\nbrainhurt = BrainHurt(\r\n debug=True,\r\n conf=debug_points\r\n)\r\n\r\n# or you can also do it later \r\nbrainhurt.conf_debug(debug_points, True)\r\n```\r\n\r\nNow whenever you will execute your programm using `execute_programm` method the code execution will stop at breaking point and return an tuple with information\r\n```py\r\n# Example of return tuple in debug mode\r\nprint(brainhurt.execute_programm())\r\n\r\n# The code execution would stop at the next breakpoint\r\n\r\n\"\"\"\r\nOUTPUT:\r\n(\r\n 2, # it is return type, could be debug, success etc..\r\n\r\n (\r\n 0, #memory offset\r\n 2, #memory pointer\r\n [0, 0, 10, 0, 0] #memory \r\n ),\r\n\r\n (\r\n 5 #programm pointer ,\r\n )\r\n\r\n\"\"\"\r\n```\r\n\r\nNow if you would try to see the return value of same method when debug mode is off you will get something like this \r\n```py\r\nbrainhurt.conf_debug(None, False)\r\nprint(brainhurt.execute_programm())\r\n\r\n# Whole programm would be executed while ignoring all the debug breakpoints\r\n\r\n\"\"\"\r\nOUTPUT::\r\n(\r\n 0, # it is return type \r\n)\r\n\"\"\"\r\n```\r\n\r\n## IO Operations\r\nBoth input and output are stored inside python list and Follows FIFO. \r\n\r\n### INPUT\r\n**How can you provide input** \r\nOne way to provide input it to pass an list or string in the contructor\r\n```py\r\nbrainhurt = BrainHurt(input='pankaj') # passing string \r\n# OR \r\nbrainhurt = BrainHurt(input=['p','a', 'n', 'k', 'a', 'j']) # passing list\r\n```\r\n\r\nother way is to pass list or string in the `load_input` method\r\n```py\r\nbrainhurt.load_input('pankaj')\r\n# OR\r\nbrainhurt.load_input(['p', 'a', 'n', 'k'])\r\nbrainhurt.load_input(['a', 'j'])\r\n```\r\n\r\nBy default if input array is empty and programm is asking for input, then our interpreter would use the python's `sys.stdin.read` method to read for input and would store it in input extending with `0` as `EOF`\r\n\r\nIf you want to change this default behaviour you can pass an `callback(function)` to the constructor as keyword argument `input_callback` which will be executed whenever programm wants input and input array is empty. \r\n_Example..._\r\n```py\r\nbrainhurt = BrainHurt(input_callback=some_function)\r\n# OR\r\nbrainhurt.input_callback = some_function\r\n```\r\n\r\n### OUTPUT\r\nBy default whenever the programm wants to output something, interpreter would output to the standard output using python's `print` function \r\n\r\nIf you want to change this default behaviour, you can pass an `callback(fuction)` to the constructor as keyword argument `output_callback` which should accept 1 argument. Once setted, whenever your programm wants to output something this callback function would be executed with the data passed to it. \r\n",
"bugtrack_url": null,
"license": null,
"summary": "This is an Interpreter and debugger for the programming language `BrainFuck` written in `Python`",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/PankajVishw50/brainhurt"
},
"split_keywords": [
"pankaj",
" pankaj vishw",
" brainfuck",
" brainhurt",
" brainfuck compiler",
" brainfuck interpreter",
" brainfuck debugger",
" debugger",
" interpretter",
" compiler"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "915fd4f36df67efe7d5f8612ff8c5815511fcbc155f8a22f957f5597cd4a4d4c",
"md5": "1070df153c1f829583a88c14a1ca64eb",
"sha256": "b7076f7a1d86c75fd2bb8cc4aef63dee72ddb12a92f8ca56e32aeec7d38acd8d"
},
"downloads": -1,
"filename": "brainhurt-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1070df153c1f829583a88c14a1ca64eb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7327,
"upload_time": "2024-07-03T19:43:53",
"upload_time_iso_8601": "2024-07-03T19:43:53.919493Z",
"url": "https://files.pythonhosted.org/packages/91/5f/d4f36df67efe7d5f8612ff8c5815511fcbc155f8a22f957f5597cd4a4d4c/brainhurt-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ab501f493670c675ffc9f4e36123ec41282e78af0c65805ceea9ea9370274b2b",
"md5": "a89e2a4723bd8dfbe7cfb1f2546f82e0",
"sha256": "8dfb36328bf0f24e0399911aa611ace6c8b038ebac4d6b5e202046fdca5b3c7d"
},
"downloads": -1,
"filename": "brainhurt-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "a89e2a4723bd8dfbe7cfb1f2546f82e0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 7902,
"upload_time": "2024-07-03T19:43:55",
"upload_time_iso_8601": "2024-07-03T19:43:55.801082Z",
"url": "https://files.pythonhosted.org/packages/ab/50/1f493670c675ffc9f4e36123ec41282e78af0c65805ceea9ea9370274b2b/brainhurt-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-03 19:43:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "PankajVishw50",
"github_project": "brainhurt",
"github_not_found": true,
"lcname": "brainhurt"
}