User:Maharba/Yttrium

From Esolang
Jump to navigation Jump to search

Work In Progress

Yttrium is an esoteric programming language by Abraham Karplus. It has only one command, which copies a value from one register to another. For memory storage besides the registers, there are 10 unbounded tapes of integers, only accessible through certain registers.

A pound sign # begins a comment. All other characters are ignored; it is conventional to separate commands with commas.

Registers

All registers are initialized at 0, except that r starts at the result of function 0, which is 1.

m0 to m9 Address of current cell.
v0 to v9 Value of current cell.
i Reading gets a character from input; writing sends a character to output.
f ID number of the operation.
a and b Arguments for the operation.
r Result of the operation. Read-only.
j Jump.

Tapes

There are 10 tapes, numbered 0 through 9. Each is completely independent of the others. To specify the address on a specific tape, write to the m register for that tape. To read or write a cell value, use the v register for that tape, whose contents are those of the currently addressed cell.

Input and Output

Input and output are done by reading and writing register i. One character at a time is sent. End of file is represented by the value -1.

Operations

To use a built-in operation, the f register must contain the ID for that operation:

0 Always returns 1.
1 Addition.
2 Multiplication.
3 Negation (ignores second argument).
4 Division (rounds toward zero).
5 Boolean not (ignores second argument).
6 Boolean or.

The a and b registers contain the first and second arguments for the operation, and the r register becomes the result.

Jumps

To jump, write a number to the j register. This jumps forward (or backward, for a negative number) the written number of commands. Since the next command is normally selected after the current one finishes, a jump of 0 goes to the next command as normal, while a jump of 1 skips a command. To go to the command before the jump would require a jump of -2. Jumping outside of the program terminates it. When the jump register is read from, it always returns 0.

Examples

Cat

I have no idea if this works.

r b, r f # change to addition
r a, r a, r v3 # set v3 to 3
r a, r a, r v5 # set v5 to 5
r a, r a, r a, r a, r a, v3 f, r v9 # set v9 to -9
b f # change back to addition
i v0, v0 i # input and output
v0 a, r a, v5 f, r v1, b f # check for EOF
v1 j, v9 j # repeat if not EOF

Truth machine

Ditto.

r b, r f # change to addition
r a, r v2 # set v2 to 2
r a, r v3 # set v3 to 3
v2 a, v3 f, r v9 # set v9 to -2
b f # change back to addition
i a # get input
a b, r j # jump 2 on '1'
j i, v3 j # print '0' and exit
f i, v9 j # print '1' and repeat