#tape #byte #file #offset #read-file #tapir #moderately

bin+lib tapir-bf

Tapir is a moderately useful Brainfuck interpreter

4 releases

new 0.2.2 Jan 16, 2025
0.2.1 Jan 15, 2025
0.2.0 Jan 15, 2025
0.1.0 Jan 15, 2025

#223 in Programming languages

Download history 149/week @ 2025-01-09

156 downloads per month

Apache-2.0

20KB
473 lines

tapir-bf

Tapir is a Brainfuck interpreter that supports using arbitrary files as program tape during execution and for storing tape state afterward.

With this all (okay, most) things are possible.

Command Line

Tapir has the ability to perform file I/O to and from the program tape prior and/or subsequent to execution. Options are provided for specifying a file to be read to the tape or a file to which the tape is written, as well as the number of bytes to copy and offsets from which to operate for both the source and destination buffers. See the tapir usage message.

USAGE: tapir SOURCE [OPTIONS]
    -r <arg> the path of a file to which the program memory is initialized before execution
    -i <arg> the number of bytes to read from the file passed to -r
    -a <arg> the offset in bytes starting from which to read the file passed to -r
    -b <arg> the offset in bytes starting from which to write the file passed to -r
    -w <arg> the path of a file to which the memory will be written out upon completion
    -o <arg> the number of bytes of memory to write to the file passed to -w
    -x <arg> the offset in bytes starting from which to read the tape for writing
    -y <arg> the offset in bytes starting from which to write out the memory

    Tapir will treat any argument appearing after '--' as the source argument.

Tapir can thus perform arbitrary transformations of files, copying and/or updating data between locations. Only the program source argument is required, however, and using these I/O capabilities is entirely optional.

Interpretation

Tapir uses a tape memory of eight-bit cells which is unbounded to the right. The tape pointer is initialized at 0, the leftmost position, and is always valid. Each cell is initialized to 0 unless specified by a command line option.

User Input

Tapir is of the class of Brainfuck implementations that require a newline character when submitting input. Input is not read until the user presses enter, whereupon the entire line they have submitted is parsed into raw bytes which are added to the input queue. When the interpreter encounters a read instruction, it checks to see if the input queue is empty, dequeueing a single byte if not and prompting the user for input only if it is. A user can thus submit input for a series of separate read instructions (each of which consumes a single byte) by typing multiple bytes before the newline.

The interpreter supports three modes for specifying input values.

  1. By character: simply press a key (except \ or #) to enter its ascii value.
  2. By escape code: type \n, \r, \t, \\, or \# to enter a newline, return, tab, backslash, or octothorpe respectively.
  3. By byte literal: type #xyz, where xyz is a three-digit, base-ten ascii code to enter the value of xyz.

These modes provide good compatibility with the vast majority of Brainfuck programs and make it to easy to enter values that don't correspond to characters on a keyboard.

No runtime deps