DROL

From Esolang
Jump to navigation Jump to search

DROL (Double Register Optimization Language) is a simple single-character compiled language created by Bradley Sadowsky (User:BradleySadowsky). The compiler was released under the MIT License and written in Python 2.7.12. Everything in DROL is done by manipulating two virtual registers, Register One and Register Two (somewhat similar to Deadfish). Each register has its own distinct set of commands. A key feature of DROL is its inability to handle errors: it simply ignores them (unless they pertain to loops or subroutines). DROL is currently on version 3.0.0.

Commands

Non Register Specific Commands

Command Name Command Explanation
Noop
0
Does nothing
Exit
x
Exits the program succesfully
Newline
!
Prints a newline to the screen
Register Swap
*
Switchs the values of the registers (e.g.
R1:8 R2:16
would become
R1:16 R2:8
Begin Comment
{
Begins a DROL comment
End Comment
}
Ends a DROL comment

Register Specific Commands

Command Name Register 1 Command Register 2 Command Explanation
Increment
i
k
Increments register by one
Decrement
d
e
Decrements register by one
Display
o
p
Displays the numerical value of the register
ASCII Write
a
b
Displays the value of the register as ASCII if the character is 0-256
Input
n
q
Sets the register to a user-inputed numerical value
Zero
z
y
Sets the register to zero
Copy
1
2
Sets both registers to the value of the one register
Add
s
u
Sets the register to the sum of the registers
Subtraction
f
g
Sets the register to the difference between the registers (R1 - R2)
Multiply
m
r
Sets the register to the product of the two registers
Square
l
h
Sets the register to istelf squared
Left Shift
<
,
Left shifts the register by one
Right Shift
>
.
Right shifts the register by one
Bit Flip
~
`
Flips the bits in the register
XOR
^
6
XORs the register with the other register
OR
|
\
ORs the register with the other register
AND
&
7
ANDs the register with the other register

Loop and Subroutine Commands

Command Name Command Extended Command Format Explanation
If Loop
j
"
j XX YYYYZZZZ
Where XX is the comparison operator (==, !=, >=, <=, >>, <<) and YYYY is the Loop Length Identifier. (8 characters long for extended)
While Loop
w
'
w XX YYYYZZZZ
Where XX is the comparison operator (==, !=, >=, <=, >>, <<) and YYYY is the Loop Length Identifier. (8 characters long for extended)
Forever Loop
@
#
@ XXXXYYYY
Where XXXX is the Loop Length Identifier. (8 characters long for extended)
Subroutine Declaration
:
(
: XXXXYYYY ZZZZAAAA
Where XXXX is the Length Identifier (8 characters long for extended) and ZZZZ is the subroutine name (8 characters long for extended)
Subroutine Call
;
)
; XXXXYYYY
Where XXXX is the subroutine name (8 characters long for extended)

Etymology of "DROL"

DROL (Double Register Optimization Language) refers to the existence of two registers, and the fact that it is a language. The optimization part of the acronym just sounded nice, as it is very far from an optimized way of doing things.

Implementations

Python Implementation

Currently, this is the only implementation. Written in Python, it translates DROL source into C code. It assumes GCC on the host system, although that can be easily changed in the source.

Language Features

Extension

Both loops and subroutines (and calls) require a small section at the beginning identifying their length known as the Optional Command Header. For example, in the following code

j != 0129

the not equal to comparison operator and the 4 digit number specifying how many commands are to be included in the loop would (!=0129) would be the Optional Command Header. However, for commands with longer Optional Command Headers, extended commands were added that essentially doubled the header (with the exception of if and while loops, which went from a 6 character long header to a 10 character long header). Here is a table of all the original commands and their extensions:

Type of Command Command Extension
If Loop
j
"
While Loop
w
'
Forever Loop
@
#
Subroutine Declaration
:
(
Subroutine Call
;
)

Loops

There are three types of loops in DROL: the If Loop, the While Loop, and the Forever Loop. The If Loop is used with the either standard J or the extended ". The if command is used as follows

j XX YYYY

Where XX is either == (equal to), != (not equal to), >= (greater than or equal to), <= (less than or equal to), >> (greater than), or << (less than). YYYY is the amount of commands to be encompassed by the loop. The While Loop is used the same way, with the w and ' replacing j and ".
The forever loop (@, #) is unconditional, and simply repeats the commands forever. An example of the forever command is as follows:

@ 0003

which would be followed by three commands that would be repeated forever.

Subroutines

Subroutines in DROL take no arguments and return no value. They are declared with the : command or the extended (. Standard subroutines must have 4 character-long names, while extended subroutines must have 8 character-long names. An example subroutine named subr could be declared as follows:

: 0056 subr

or alternatively it could be declared with the extended command as follows:

( 00000056 function

which could be called as follows:

; subr

or (if it was an extended subroutine):

) function

Sample Programs

Simple Single Register Hello World

iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiaziiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii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<azi<<<<<ia!

Truth Machine

nj==0002oxkj==0006@0001o

Which could be extended to the following

n         { Get user inputted number R1 }
j == 0002 { Check if registers are equivalent, as R2 will be 0 }
  o       { If so, output R1, which will be 0 }
  x       { Exit program successfuly }
k         { Increment R2 by 1 for the next comparison }
j == 0006 { If R1 == R2 then R1 will be 1 }
  @ 0001  { Loop the next instruction infinitely }
    o     { Output R1, which will be 1 }

External Links

DROL Interpreter DOCS.txt