Orthagonal
Orthagonal is a two-dimensional esoteric programming language created by Jeff Epler in 1994 after a discussion about two-dimensional languages in alt.folklore.computers. The following description of the language has been taken straight from the original "Specification".
The program execution
A program in Orthagonal has two parts:
- The grid.
- The stack.
When the Orthagonal interpreter is invoked, the grid is read from standard input, the PC is loaded with
(0,0),(1,0)
and the stack is initialized to be empty. The bottom row of the grid,
(0,255)(1,0)
is loaded with up to 256 characters from argv[1]. The format of the PC is
(grid coordinate),(delta coordinate).
Then, the interpreter performs the following steps:
- Interpret the contents of the current grid coordinate
- If the element is an operator, perform the action associated with the operator
- If the element is a quantity, push the quantity onto the stack (The stack can hold at most 256 elements)
- Add the delta coordinate to the grid coordinate, wrap around if necessary. (The grid size is 256x256 -- I wonder if this will be adequate?)
- go to 1
Program execution terminates when there is a stack underflow, or when the RET operator returns the top element of the stack as a result code to the operating system
All quantities are 32 bit signed. (Well, actually, they're the size of your compiler's int until you change the definition of s32)
Syntax
Operators
These are the operators:
Operator | Effect |
---|---|
NOP | Do nothing |
+ | Add top two elements on the stack and push result |
- | Subtract the top element from the second element |
* | Multiply top two elements |
/ | Divide second element by top element, result is integer quotient |
% | Divide second element by top element, result is integer remainder |
~ | Exchange top two stack elements |
! | Perform logical NOT on top stack element |
& | Perform binary AND on top two stack elements |
| | Perform binary OR on top two stack elements |
^ | Perform binary XOR on top two stack elements |
@ | Duplicate top stack element |
$ | Discard top stack element |
= | Push an absolute element; top of stack names x, second names y |
# | Set an absolute element; top = x, second = y, third = value to store |
? | If top element is zero, add (delta coordinate) to (grid coordinate) (double-step) |
dx | Load the delta coordinate X with the top stack value |
dy | Load the delta coordinate Y with the top stack value |
x | Load the grid coordinate X with the top stack value |
y | Load the grid coordinate Y with the top stack value |
c | Output the top stack element as a character, or newline if 0 |
s | Output stack elements as characters until a 0 is popped, then output newline |
d | Output top stack element as a decimal quantity |
ccw | Change delta coordinate: (dx,dy) → (-dy,dx) |
cw | Change delta coordinate: (dx,dy) → (dy,-dx) |
rev | Change delta coordinate: (dx,dy) → (-dx,-dy) |
h | Delta coordinate becomes (-1,0) |
j | Delta coordinate becomes (0,1) |
k | Delta coordinate becomes (0,-1) |
l | Delta coordinate becomes (1,0) |
ret | Terminate execution; return top stack element to OS |
Program Syntax
Comment lines begin with a semicolon. Other lines have the form:
x y element
where x and y are integers in the valid range, and element is one of:
- An integer quantity
-1 0 36 etc.
- A character, enclosed in single quotes
'a' 'z' '0' etc.
- An operator
ccw + - etc.
Examples
Hello world
0 0 0 1 0 0 2 0 'd' 3 0 'l' 4 0 'r' 5 0 'o' 6 0 'w' 7 0 32 8 0 'o' 9 0 'l' 10 0 'l' 11 0 'e' 12 0 'h' 13 0 s 14 0 c 15 0 0 16 0 ret
This program is licensed under the MIT License, copyright (c) 1994, 2016 Jeff Epler.