Like brainfuck, pointerfuck operates on an array of integers that are initially set to 0, and has a pointer associated with the memory and initially pointing to cell 0 (the start of the memory). Unlike brainfuck, the memory can hold negative integers. There is also a call stack, containing integers. Both the memory array and the call-stack may have infinite size, and may contain unbounded integers, depending on the implementation.
Also, how input and output works is implementation-specific. Reading from input must always give an integer, and the output must be able to recieve integers.
If an implementation doesn't want to specify these, it can use this default: the input is a queue of character codes, and yields 0 if you try to read from it when it's empty; the output prints numbers as their corresponding Unicode characters, and ignores negative values.
These instructions do the same thing as in brainfuck:
These instructions are new or have changed semantics:
[ if the current cell is not positive, goto the instruction after the matching ]. ] goto the matching [. @ push the current pointer to the call stack, then set the pointer to the value of the current cell (i.e. dereference the current cell). ! pop the call stack and set the pointer to the popped value.
As in brainfuck, all other characters are no-ops/comments/ignored.
Trying to execute ! when the call stack is empty halts the program. Trying to jump to a negative memory address also halts the program.
Note that since there currently does not exist any implementation of pointerfuck, all of these are untested.
This works the same way as in brainfuck. Note that it relies on the assumption that all of the input is positive, and that after reading all input trying to read more yields a non-positive value.
This assumes that the first input value is non-negative, and outputs 2 times that value.
+@ increment cell 0 from 0 to 1, then jump to cell 1. , write input to cell 1. [ while cell 1 holds a positive number, -! decrease that number by 1, then go back to the previous pointer location, i.e. cell 0. +@ increment cell 0 from 1 to 2, then jump to cell 2. ++ increment cell 2 by 2. ! jump back to cell 0. -@ decrement cell 0 from 2 to 1, then jump to cell 1. ] end of loop. . output the value of the current cell, i.e. cell 1.