Braincells

From Esolang
Jump to navigation Jump to search

Braincells is just another brainfuck derivative by User:SoundOfScripting.

Language overview

Braincells features a right-unbounded tape of unbounded integers called memory cells. It also stores a pointer to one of those cells which can be moved along the tape.
The instruction pointer - IP for short - points to the instruction that is currently being executed in the program. The IP is incremented after every instruction unless it was just changed.

Braincells shares some instructions with its predecessor language, brainfuck, and also has some new ones. Its instructions are:

Instruction Description
>
Move the pointer to the right
<
Move the pointer to the left
+
Increment the memory cell under the pointer
-
Decrement the memory cell under the pointer
.
Output the character signified by the cell at the pointer
,
Input a character and store it in the cell at the pointer
[
Create a listener event that triggers whenever the memory cell under the pointer is set to 0, and push that event to the event queue. When the event is triggered, the IP is pushed to the return stack and then is set to the instruction after this [
]
Jump to the instruction after the matching [ instruction
@
Pop from the return stack and jump there
?
If the memory cell under the pointer is positive, do the following:
  • If the next instruction is a [, jump to the instruction after its matching ]
  • Else, jump to the instruction after the next one
|
Create a concurrent fork of the program that executes its instructions immediately after this one. The new fork's tape pointer, event queue, and return stack are initialized to copies of this fork's tape pointer, event queue, and return stack, but all forks share the same tape. The fork's IP is initialized to this one's IP plus two, but it only begins execution after this fork executes its next instruction
}
Move the pointer to the right by the memory cell under the pointer
{
Move the pointer to the left by the memory cell under the pointer

All characters other than ><+-.,[]@?|}{ should be considered comments and ignored.

Cell I Ii II I_

Braincells is meant to model a brainfuck program (and maybe the programmer, too) chronically losing its Braincells. After every two groups of concurrent instructions, the left-most, non-lost memory cell becomes lost and is cleared. Any program/fork that attempts to modify or access the value of a lost cell exists with an error.

Edge cases

  • The return stack is initialized with a -1 on top. Jumping to -1 (or any value outside of the program source code) is exciting exits with an error.
  • If multiple listener events in the event queue would trigger at once, only the one closest to the front of the queue triggers (and is removed from it).
  • If the pointer moves off the left side of the tape, the program exits with an error. Similarly, if the IP moves off the right side of the program source code, the program exits with an error.

Privilege Escalation

It is required that the implementation feature a hard-to-exploit "bug" that allows the program to "escalate its privileges" (left undefined). The validity of an implementation is determined by whoever is currently winning the debate over whether or not this requirement is followed. It is recommended that the implementation does not feature a way to prevent the loss of Braincells.

Concurrency/cell loss demonstration

Below is an execution trace of the following program:

>>|>>+++.
TODO: Make the execution trace.