Surface

From Esolang
Jump to: navigation, search

Surface is an esoteric programming language designed by User:Madk.

Surface logo.png

Characteristics

In Surface, the program's instructions are placed on a 2D grid wrapped around a Klein bottle (not, as intended, a sphere). The instruction pointer wraps according to this geometry.

The 2d memory array is also placed on the surface of a Klein bottle, and the memory pointer wraps according to the geometry.

Pointers wrap on the X axis. When Y bound is reached, the pointer is rotated 180 degrees (so that forward/backward toggles between up/down and left/right between west/east) and X=(X+width/2)%width

Commands

< move the memory pointer left and set the instruction pointer's direction to left (west by default)
> move the memory pointer right and set the instruction pointer's direction to right (east by default)
^ move the memory pointer forward and set the instruction pointer's direction to forward (north by default)
v move the memory pointer backward and set the instruction pointer's direction to backward (south by default)
+ increment the current memory cell
- decrement the current memory cell
o rotate the direction of the instruction pointer clockwise
e rotate the direction of the instruction pointer counter-clockwise
c rotate the direction of the instruction pointer clockwise, then become z
z rotate the direction of the instruction pointer counter-clockwise, then become c
/ reflect the direction of the instruction pointer and become a \
\ reflect the direction of the instruction pointer and become a /
? skip one instruction in the direction the pointer is facing if the current memory cell is <1
! skip one instruction in the direction the pointer is facing if the current memory cell is >0
* skip the quantity of following instructions as specified by the number contained in the current memory cell
( set a point to be jumped to by ) and ]
) unconditionally move the instruction pointer back to the most recent (
] move the instruction pointer back to the most recent ( if the current memory cell is >0
x do away with the most recently accumulated (
. output the current memory cell as a character
: output the current memory cell as a number
, input the current memory cell as a number
@ terminate the program

Computational class

Given an infinitely large memory and instruction bottle, Surface is Turing-complete because it is possible to reproduce any brainfuck code.

+ - and . are exactly equivalent, while input , is roughly equivalent in function.

<

becomes

oo
^e

>

becomes

vo
ee

[

becomes

!v(

 e

]

becomes

 oox
 v]
?e^

Nested [] are fairly trivial, requiring only that the distance between the first line and the rest be separated by two lines for every set of [] this set is inside.

Examples

The examples assume a 32x16 instruction space, which is the size used by the interpreter.

Hello, world!

++++++++(-v        .     o]v    
   +      e++++v   !     ^ v    
   +           e+++++++++^ x    
   +               -   v-(e.    
   +               -   +  ^o    
   +               -v]ev        
   +               -- ^+        
   +               -- ^o        
+++.v              -e-.+++++++..
-.^!+              -e-----------
  oo+              -.e+.@       
.--o+              .+v .--------
   -+              ++           
   -+              ++           
   -+              ++           
   -+              .+

External resources

Download Surface interpreter (This implementation features a 32x16 grid for both instruction space and memory. Anything outside the 32x16 grid originating at the code file's top-left is counted as comments.)