Ral

From Esolang
Jump to navigation Jump to search

Ral is a stack-based random-access esoteric language created by Code Golf and Coding Challenges user Endenite.

Description

Ral has a stack and a random-access memory. The stack is used as working memory by all commands. The memory is initially filled with zeroes. Popping from the stack when empty returns zero. Similar to brainfuck, all opcodes are single bytes. The opcodes in Ral are:

Opcode Pseudocode Description
0 Push 0 Push 0 to the stack
1 Push 1 Push 1 to the stack
+ Pop A Pop B Push A+B Integer addition
- Pop A Pop B Push A-B Integer subtraction
: Pop A Push A Push A Duplicate the top of the stack
/ Pop A Pop B Push A Push B Swap the top two values on the stack
* Pop A Push Memory[A] Load a value from memory
= Pop A Pop B Memory[A]=B Store a value to memory
, Input A Push A Input a value; zero if end of input is reached
. Pop A Output A Output a value
? Pop A Pop B If B>0 Goto A Jump to A if B is positive
_ Does nothing

The jump opcode jumps to the A-th opcode in the program (zero-indexed), ignoring comments. The _ opcode can be used to pad jump destinations, as it does nothing but does count as an opcode. For example, jumping to index 4 in the following program jumps to the +:

0 foo 1__+ bar :

Jumping to negative indexes results in jumping to the start of the program. Jumping to indexes larger than the number of opcodes jumps to the end of the program, terminating it.

Sample Code

Add two values

,,+.

Cat program

Copies all input to the output until end of file is reached.

,:1-1:+:+1+:+:+?.10?

Hello, world!

Outputs the values 72 101 108 108 111 44 32 87 111 114 108 100 33, the code points of Hello, World!.

11+:+:+:0=1+:+:+::+:.+0*/-::1+.0*+:::..1+1+1+::.0*:+:+:11+1+:+:++..10*1+1+1+:+:+:+-..1+1+1+...0*:+:+1+.

Quine

A program that prints itself.

1111111101011101011101010101111101011101010101111101010101111101011101010101111101010101111101011101010101111000111000111000111000111000110101010000110101110111011101011101010101111101011101010101111101011101010101111101011101010101111101011101010101111101011011010101111111111101011101010101111101011101010101111101010101111101011101010101111101011101010101111000111000111000111000110101010000111011010101010000110101111111010111011101011101010101111101010101111101010101111101010101111101011000111101011000111000110101110101010101111101011000111111111101011101010101111101010101111101011101010101111101011101010101111000111000111000110101010000110101111011010101011011010000111000111000111011111011111011010000111000110101111011110000110101111101010101111011011101010101111101010101111101010101111101010101111101010101111101010101111101011101010101111101011101010101111000111000111000111000111111:++:++:+:+:+:+:+:+-:+:0=:10-==110-*-:0*111:++:++:+:++?1+:*:11+1+:+:+:+:++./:0*-0*1111:++:++:+:++:++?:-+:++:++:++:++:++.:0*11111:++:+:++:+:++:+++?

Implementation notes

  • Values are integers and can be arbitrarily large.
  • The memory should support negative and extremly large indexes.
  • Input and output format is intentionally left undefined. An interpreter may, for example, take input as bytes, UTF-8 encoded characters, a list of integers, or in any other format.

Interpreters