tbas – TBAS Interpreter
Description
TBAS is an interpreter for the TBAS language. TBAS belongs to a class of languages colloquially referred to as Turing Tarpits, for their computational minimalism.
Operation
The TBAS Interpreter is constantly executing, even when another app is running. The TBAS execution environment consists of a program containing single character operators, a data buffer of unsigned 8-bit variables to use as working memory, a global IO Mode, and a separate buffer of unsigned 8-bit variables that can be used as a FIFO or a FILO. Access to the data buffer is restricted to a single pointer, in the style of a ‘tape’. The instruction pointer for the source code is referred to as eptr. The data buffer and data pointer are referred to as mcell[] and mptr.
Operators
> Advance mptr to the right one cell. The pointer will not advance beyond the end of the buffer, and it will not wrap.
< Retreat mptr to the left one cell. The pointer will not advance beyond the beginning of the buffer, and it will not wrap.
+ Increment the value in mcell[mptr]. The value will not increase beyond the maximum unsigned 8-bits, and it will not wrap.
– Decrement the value in mcell[mptr]. The value will not decrease beyond the minimum unsigned 8-bits, and it will not wrap.
[] This pair of operators indicates a looping construct. The open bracket evaluates the value of mcell[mptr], and the instructions inside the brackets are executed if the value is non-zero; otherwise, execution resumes after the corresponding close bracket. The close bracket ends the loop, and returns execution to the corresponding open bracket for reevaluation. These operators may be nested.
= Sets the IO Mode to the value of mcell[mptr]. For more about IO Modes, see below.
? Carries out the corresponding IO Mode operation using the current state of the execution environment, which may include the data buffer, data pointer, FIFO, FILO, etc.
IO Modes
The ? operator will trigger the behavior identified below, when the IO Mode is equal to the corresponding value.
0: Serial Console – Decimal Write
TBAS will write the value of mcell[mptr] to the serial console as a decimal value (eg. 123). If the serial console is not connected, this instruction is discarded.
1: Serial Console – Decimal Read
TBAS will read a decimal value from the serial console and store it in mcell[mptr]. Triggering this causes TBAS to stall until data is availabe on the console.
2: Serial Console – ASCII Write
TBAS will write the value of mcell[mptr] to the serial console as an ASCII value (eg. ‘A’). If the serial console is not connected, this instruction is discarded.
3: Serial Console – ASCII Read
TBAS will read an ASCII value from the serial console and store it in mcell[mptr]. Triggering this causes TBAS to stall until data is available on the console.
4: Serial Modem – ASCII Write
TBAS will write the value of mcell[mptr] to the serial modem as an ASCII value.
5: Serial modem – ASCII Read
TBAS will read an ASCII value from the serial modem and store it in mcell[mptr]. Triggering this causes TBAS to stall until data is available from the modem.
6: Buffer Program
TBAS will clear the FIFO buffer, and then copy the currently executing TBAS program into the FIFO buffer.
7: Execute Task
TBAS will execute the app corresponding to the value of mcell[mptr], with the contents of the FIFO buffer as its arguments. This operation also clears the FIFO buffer.
# App Format of Arguments
0 TBAS [TBAS Program String…]
1 DIALER [Touch Tone String…]
2 SPEAKER [Touch Tone String…]
3 BLINKEN [Part#][Position][Color Mask][Vel][Vel Delay][LFO][LFO Delay]
4 SCROLLER [PingPong][Steps][Blanks][Message String…]
5 WAR DIALER [Num][Touch Tone String…]
6 BOX [Audio Score String…]
7 TBASCL [TBAS Program String…]
8 TBASED [TBAS Program String…]
8: Buffer Enqueue
TBAS will enqueue the value of mcell[mptr] to the FIFO/FILO buffer. If the buffer is full, this instruction is discarded.
9: Buffer Dequeue – FILO
TBAS will treat the FIFO/FILO buffer as a stack, and pop the last value into mcell[mptr]. If the stack is empty, this instruction stores zero instead.
10: Buffer Dequeue – FIFO
TBAS will treat the FIFO/FILO buffer as a queue, and dequeue the first value into mcell[mptr]. If the queue is empty, this instruction stores zero instead.
11: Buffer Clear
TBAS will clear the FIFO/FILO buffer, returning it to the empty state.
12: Converter – Lower Case ASCII Enumeration
TBAS will convert numeric values (0-25) in mcell[mptr] to lower case ASCII. Values outside of the specified range are unconverted.
13: Converter – Upper Case ASCII Enumeration
TBAS will convert numeric values (0-25) in mcell[mptr] to upper case ASCII. Values outside of the specified range are unconverted.
14: Converter – ASCII Numeral
TBAS will convert numeric values (0-9) in mcell[mptr] to ASCII decimals (‘0’-‘9’). Values outside of the specified range are unconverted.
15: Converter – TBAS Enumeration
TBAS will map numeric values (0-7) in mcell[mptr] to the TBAS operators (+-<>[]=?). Values outside of the specified range are unconverted.
16: ALU – Add
mcell[mptr] + dequeue(FIFO) -> mcell[mptr]. The value is clamped to unsigned 8-bit and will not wrap.
17: ALU – Sub
mcell[mptr] – dequeue(FIFO) -> mcell[mptr]. The value is clamped to unsigned 8-bit and will not wrap.
18: ALU – Mul
mcell[mptr] * dequeue(FIFO) -> mcell[mptr]. The value is clamped to unsigned 8-bit and will not wrap.
19: ALU – Div
mcell[mptr] / dequeue(FIFO) -> mcell[mptr]. The value is clamped to unsigned 8-bit and will not wrap. If the divisor is zero, the instruction is discarded without action.
20: ALU – Bit And
mcell[mptr] & dequeue(FIFO) -> mcell[mptr].
21: ALU – Bit Or
mcell[mptr] | dequeue(FIFO) -> mcell[mptr].
22: ALU – Logical Not
TBAS will normalize and invert the logical value of mcell[mptr].
23: ALU – Bit Xor
mcell[mptr] ^ dequeue(FIFO) -> mcell[mptr].
24: Meta – Get MPTR
TBAS will store the value of mptr into mcell[mptr].
25: Meta – Get EPTR
TBAS will store the value of the (instruction execution pointer + 1) into mcell[mptr].
26: Meta – Relative Jump Left
TBAS will decrease the instruction execution pointer by mcell[mptr]. The value is clamped to the length of the source.
27: Meta – Relative Jump Right
TBAS will increase the instruction execution pointer by mcell[mptr]. The value is clamped to the length of the source.
Example Programs
+++[?-] Prints “321” to the serial console.
++=++++++[->++++++++<]>+?+?+? Prints “ABC” to the serial console.
Hello World is left as an exercise for the reader 😐