Semantic Brain

Semantic Brain, or SBrain, is a brainfuck-like language created by Leo Tindall. It is based on brainfuck, but adds a stack, a general-purpose register, and additional arithmetic instructions. It was created in as part of a genetic programming project, and its implementation is still a work in progress.

Language overview
Semantic Brain, or SBrain, extends brainfuck with a stack, a general-purpose register, and additional commands. It is an attempt to make brainfuck more amenable to genetic programming. As it implements classical brainfuck with extensions, rather than modifying it, SBrain is necessarily Turing complete. While it does add useful features like data tape initialization and single instruction arithmetic, SBrain is still firmly a Turing tarpit.

Data Structures
SBrain requires:


 * a read/write tape datastructure ("data tape") which is addressable up to, at minimum, 65,536 (0x0 - 0xFFFF) 32-bit cells. Not all of these must be active in memory; however, SBrain programs may assume that they are all addressable. They must be initially set to zero unless set with an initialization instruction.
 * a read/write stack (FILO) datastructure ("data stack") which must support, at minimum, 256 values. Not all of these must be active in memory; however, SBrain programs may assume that they are addressable. They must be initially set to zero.
 * a read/write stack (FILO) datastructure ("jump stack") which must support, at minimum, 256 values large enough to store an address on the data tape.
 * a read-only tape datastructure which contains the executable code. This code is represented as a list of unsigned integers of, at minimum, six bits in width.
 * a read-only nonreversable tape containing the program's input (note: as this tape is nonreversable and nonwriteable, a function like C's getch works fine.)
 * a write-only nonreversable tape containing the program's output (note: as this tape is nonreversable and nonreadable, a function like C's putch works fine.)
 * a read/write register of enough bits to store a position on the data tape
 * a read/write register of enough bits to store a position on the instruction tape
 * a read/write register of enough bits to store a position on the instruction tape
 * a read/write register of the same size as a cell on the data tape

Commands and Source Code
SBrain source code consists of text characters. Executable code consists of unsigned integers of six bits. A transliterator converts the source code to executable code by a one-to-one mapping, with two exceptions. The first is noted in the entry for instruction 31 (@), which is a metacharacter in certain circumstances. The second is the comment character, #. All data between # characters, including those characters, is ignored by the transliterator.

The first eight instructions are the standard brainf--- instructions. Any brainf--- program is a valid SBrain program and should behave in the same way as in a standard, semantically equivalent brainf--- interpreter, as long as comments are correctly escaped.

The following instructions are separated because they all follow similar rules. Each one performs an operation on the value at the cell pointed to by   and the value in , in that order if the operation is not commutative, storing it in the cell pointed at by. The creation of a value in a cell greater than the maximum value able to be held by that cell shall result in a wraparound (e.g. 0xFFFFFFFF + 0b11 = 0b11)

Further Rules
No read operation shall ever disrupt a cell on the data tape.

Reading an EOF always produces a 0.

Non-command characters in the instruction section of source code must be ignored.

Examples
Any brainfuck program will run and behave in the same way in SBrain; however, many simple programs are much, much shorter in SBrain. For example, hello world is simply:

[.>]@@Hello, World!

The simple subtraction program, assuming binary (not ASCII) input, is:

,>,({ #Pop two numbers off the stack.#    [a(>{]).*(@ #Add, pop into new cell, then loop.# # Note this while this section IS after the end of the program, no @@ has been encountered outside of a comment, so there is no data on the tape when the program starts. That would be bad.# # This program has a bug where it outputs the final answer twice. This is because I'm lazy and it's just an example. #