Emblema

From Esolang
Jump to navigation Jump to search

Emblema is an esolang based on Successor machine by User:ChuckEsoteric08.

Description

Language has two counters, named a and b. There is also a special register r called repetition number. Each line starts and ends with a label which is an alphanumeric string with length of at least 2. First label is an identifier to a set of commands while second label is an uncondiitonal jump instruction. If both labels are the same then program halts after executing instructions between them.

Command Definition
+ Increments current register.
! Swaps the registers.
* Zeroes current register.
{...} Repetition block. It sets r to a value in the current register. After each cycle r is decremented by one and if it becomes zero then the loop ends. It can not be nested.
r Decrements r. Could only occur in a loop.
label (other than at the start or at the end) if two registers are equal jump to that label.

Computational class

Emblema is Turing-complete since it can simulate Minsky machine. As an example here is this program (same as used on the Vein page):

1 inc A 2
2 inc A 3
3 dec B 4 4
4 dec A 5 6
5 inc B 4
6 halt

When tranlsated to Emblema it becomes:

init + i1
i1 { ! + + ! } * ! { ! + ! } i2
i2 { ! + + ! } * ! { ! + ! } i3
i3 { ! + f3 + f3 + ! } ! * ! { ! + r r ! } i4
f3 * ! i4
i4 { ! + f4 + ! } ! * ! { ! + r ! } i5
f4 * ! i6
i5 { ! + + + ! } * ! { ! + ! } i4
i6 i6

It works by storing registers as prime factors, in this example A is stored as 2A and B as 3B

Useful snippets of code

Multiplying by 2:

{ ! + + ! } * ! { ! + ! }

Multiplying by 3:

{ ! + + + ! } * ! { ! + ! }

Check if divisible by 2, if not jump to fai, else divide

{ ! + swp + ! } ! * ! { ! + r ! }
swp * ! fai

Check if divisible by 3, if not jump to fai, else divide

{ ! + swp + swp + ! } ! * ! { ! + r r ! }
swp * ! fai