Inline

From Esolang
Jump to navigation Jump to search

Inline is an esoteric programming language created by User:OberoN.

Description

Every value is 8-bit long and has a suffix: :b for binaries, :h for hexadecimal, :d for decimal and :a for ASCIIs.

:r and :m for indexed addressing is also possible, like [0:h:r] is the address pointed by register 0 and [0:h:m] is the address pointed by memory cell 0. You can write [0-1:h:r] which is the address pointed by 0 and 1 registers, treating 0 as high part and 1 as low, and also [0-1-2:h:r] and such. Suffixes can be nested like :h:r:m:r.

In Inline immediate values are closed in parentheses. Memory indexing is also possible in the same manner as values, but in square brackets: the memory is virtually infinite. Labels are ASCII strings consisting of alnum chars and underscores.

All other numbers are treated as registers.

Every line is treated as a subroutine/labeled code. Execution starts from line 0 and continues to the other lines until the // instruction is reached; if the program does end without a // instruction, an exception is raised. Obviously, if a line hasn't a label (first thing in the line, in {}s) it isn't callable nor jumpable to.

List of commands

IO

!(s) memory
Inputs a char in ASCII to the memory. If there is the "s" it inputs a string.
*(s) position
Outputs a char in ASCII from the position (register or memory). If there is the "s" the position must be memory and it outputs a C-string.
" position
Outputs a number from the position (register or memory).

Memory

register > memory
Transfers the register into the memory.
register < memory
Transfers the memory into the register.
register <> memory
Exchanges register and memory.

Jumps and calls

@ label
Unconditionally jumps to the line labeled.
? register condition _ label1 (_ label2)
Conditioned jump: if the register is in the condition specified (so like (>5:d) will be "bigger than decimal 5" and possible are >,<,=,!,>=,<= and in this case :r defines a real register, not memory which is defined by :m) , jump to label1; else, to label2 (if any). Labels can be also single instructions in this case.
//
Die instruction: terminates the program.
# label
Call line labeled.
/
Return.
% label register condition amount
LOOPs over a label while the register is in the condition specified (see ? instruction) and adds the amount to the register (amount could be a register, an immediate or a memory position).

Assignment

\ register immediate
Assigns to the register an immediate value.
$(s) memory immediate
Assigns to the memory an immediate value. If there is the "s", the immediate is a string and should terminate with :a suffix.
. register register
Copies first register in second.
, register register
Exchanges registers.

Arithmetics

+ register
Increments register.
- register
Decrements register.
++ register / register / ...
Adds registers together. The result is stored in the last register.
-- register / register
Subtracts registers. The result is stored in the first register.
** register / register / ...
Multiplicates registers together. The result is stored in the last register.
\ register / register
Divides registers. Result of division is stored in the first, modulo in the second.
^^ register / register
Power-raises registers. Result is stored in the first register.
& register / register / ...
ANDs registers. Result is stored in the last register.
| register / register / ...
ORs registers. Result is stored in the last register.
^ register / register / ...
XORs registers. Result is stored in the last register.
>> register / register
SHRs registers. Result is stored in the first register.
<< register / register
SHLs registers. Result is stored in the first register.
>>> register / register
ROLs registers. Result is stored in the first register.
<<< register / register
RORs registers. Result is stored in the first register.

Comments

' comment
Standard comment. One per line.
; comment
Definition comment. One per line, and can be nested with standard comment (see above).
~ label
Prints definition comment of line labeled.

Examples

Hello world

Hello World can be either

$s[0:h](Hello, World!:a)*s[0:h]//

or

{h}~{h}//;Hello, World!

99 bottles of beer

$[0:h](99:d)$s[1:h]( bottles of beer on the wall,\n:a)
$s[20:h](Take one down, pass it around,\n:a)
\1:h(2e:h)\2:h(a:h)\3:h(0:h)
$s[40:h](No more:a)
$s[48:h](Go to the store and buy some more,:a)
{b_loop}#{print} ' x bottles of beer on the wall,
1:h<>[11:h]2:h<>[12:h]3:h<>[13:h]#{print} ' x bottles of beer.
*s[20:h] ' Take one down and pass it around,
0:h<[0:h]-0:h0:h>[0:h]1:h<>[11:h]2:h<>[12:h]3:h<>[13:h]1:h<>[1d:h]#{print} ' x bottles of beer on the wall.
1:h<>[1d:h]?0:h(!2:h)_{b_loop}
#{print} ' 2 bottles of beer on the wall,
1:h<>[11:h]2:h<>[12:h]3:h<>[13:h]#{print} ' 2 bottles of beer.
*s[20:h] ' Take one down and pass it around,
\5:h(1e:h)4:h<[1f:h]
{canc_s}4:h<>[5:h:r]%{canc_s}5:h(=8:h)(ff:h)
0:h<[0:h]-0:h0:h>[0:h]1:h<>[10:h]2:h<>[11:h]3:h<>[12:h]1:h<>[1c:h]#{print} ' 1 bottle of beer on the wall.
1:h<>[1c:h]#{print} '1 bottle of beer on the wall,
1:h<>[10:h]2:h<>[11:h]3:h<>[12<:h](0:h)#{print} ' 1 bottle of beer.
*s[20:h] ' Take one down and pass it around,
*s[40:h]\5:h(8:h)\4:h(73:h) ' No more
{add_s}4:h<>[5:h:r]%{canc_s}5:h(=20:h)(1:h)
1:h<>[11:h]2:h<>[12:h]3:h<>[13:h]1:h<>[1d:h]*s[1:h] ' bottles of beer on the wall.
1:h<>[1d:h]*s[40:h]*s[1:h] ' No more bottles of beer on the wall,
1:h<>[11:h]2:h<>[12:h]3:h<>[13:h]*s[40:h]*s[1:h] ' No more bottles of beer.
*s[48] ' Go to the store and buy some more,
$[0:h](99:d)1:h<>[11:h]2:h<>[12:h]3:h<>[13:h]1:h<>[1d:h]#{print}//
{print}"[0:h]*s[1:h]/

Implementation of brainfuck

'0-1  codeptr
'2-3  memptr
'4    stackptr
'5    instruction scratch
'6    loop scratch
'0-ff loop start locations
'Fill code into 100, place tape after 0 byte after code
\0:h(1:h)
\2:h(1:h)
!s[1-0:h]
{scanmemstart}
5:h<[2-3:h:r]
?5:h(=0:h)_{markstart}
+3:h?3h(=0:h)_+2:h
@{scanmemstart}
{markstart}+3h?3:h(=0:h)+2:h
@{read}
{next}+1:h?1:h(=0:h)_+0:h
{read}5:h<[0-1:h:r]
?5:h(=>:a)_{addp}
?5:h(=<:a)_{subp}
?5:h(=+:a)_{addc}
?5:h(=-:a)_{subc}
?5:h(=]:a)_{looptail}
?5:h(=[:a)_{loophead}
?5:h(=.:a)_{pc}
?5:h(=,:a)_{gc}
?5:h(!0:h)_{next}_//
{addp}+3:h?3:h(=0:h)_+2:h@{next}
{subp}-3:h?3:h(=ff:h)_-3:h@{next}
{addc}5:h<[2-3:h:r]+5:h5:h>[2-3:h:r]@{next}
{subc}5:h<[2-3:h:r]-5:h5:h>[2-3:h:r]@{next}
{pc}*[2-3:h:r]@{next}
{gc}![2-3:h:r]@{next}
{loophead}
5:h<[2-3:h:r]
?5:h(=0:h)_{skippasttail}
0:h>[4:h:r]
+4:h
1:h>[4:h:r]
+4:h
@{next}
{looptail}
5:h<[2-3:h:r]
?5:h(=0:h)_{skipfromtail}
-4:h
1:h<[4:h:r]
-4:h
0:h<[4:h:r]
+4:h+4:h
@{next}
{skipfromtail}
-4:h
@{next}
{skippasttail}
\6:h(1:h)
{skippasttailoop}
+1:h?1:h(=0:h)_+0:h
5:h<[0-1:h:r]
?5:h(=]:a)_-6:h_?5:h(=[:a)_+6:h
?6:h(=0:h)_{next}_{skippasttailloop}

This demonstrates that Inline is also Turing-complete.

External resources

Implementation