Skip to main content

This is an Interpreter and debugger for the programming language `BrainFuck` written in `Python`

Project description

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

pip install brainhurt

You can either call it Programmiticaly in script or direclty from terminal

From Command Line

python -m brainhurt file_name.bf

From Python Script

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.

debug_points = [
    (0, 3),
    (3, 10),
    (100, 2),
    # ....
]

setting debug mode

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

# 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

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

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

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...

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brainhurt-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

brainhurt-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file brainhurt-0.1.0.tar.gz.

File metadata

  • Download URL: brainhurt-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for brainhurt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8dfb36328bf0f24e0399911aa611ace6c8b038ebac4d6b5e202046fdca5b3c7d
MD5 a89e2a4723bd8dfbe7cfb1f2546f82e0
BLAKE2b-256 ab501f493670c675ffc9f4e36123ec41282e78af0c65805ceea9ea9370274b2b

See more details on using hashes here.

File details

Details for the file brainhurt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: brainhurt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for brainhurt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7076f7a1d86c75fd2bb8cc4aef63dee72ddb12a92f8ca56e32aeec7d38acd8d
MD5 1070df153c1f829583a88c14a1ca64eb
BLAKE2b-256 915fd4f36df67efe7d5f8612ff8c5815511fcbc155f8a22f957f5597cd4a4d4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page