Barely

From Esolang
Jump to navigation Jump to search

Barely is an esoteric programming language created by Jeffry Johnston in 2006, with the goal of having as small a Turing complete interpreter as possible. The interpreter is in MS-DOS COM binary format and is 59 bytes in size. It was written using DEBUG, so the source listing is made from disassemblies at different points in the program.

The language was originally based on BF, but only somewhat resembles it in its current form. There is a tape of uninitialized memory cells, a memory pointer (mp) initially 0, instruction pointer (ip) initially the last input, jump offset (jmp) initially 0, and 8-bit accumulator (acc) initially 126. Commands consist of a single character. Programs are read from stdin, should be written from right to left (rather than the customary left to right), and must not contain any non-command characters (newlines, etc). The program is separated from its input by a tilde (~).

Commands (letters in parenthesis are commands that are also executed as a side effect):

]   exit program
^   if acc == 0 then (b)
b   ip += jmp  
f   no-op
g   acc = contents of cell at mp (i)
h   acc += 71 (k)
i   mp++ (j)
j   acc++ (k)
k   jmp--
l   no-op
m   contents of cell at mp = acc (o)
n   mp-- (o)
o   acc-- (p)
p   jmp += 10
q   no-op
s   no-op
t   stdin -> acc
x   acc -> stdout
~   mandatory no-op, marks end of program input

BF Conversions (read right to left):

<   kkkkkkkkkjn
>   kkkkkkkkkoi
+   kkkkkkkkkkkkkkkkkjmjng
-   kkkkkkkkkkkkkkkkkkkkkkkkkkkkjmong
.   kkkkkkkkkxg
,   kkkkkkkkkjmt

The `[' and `]' commands do not have a 1:1 mapping. The following algorithm can be used to find the number of l's, k's, and p's for a BF-like loop:

Initial values:
i = number of characters inside the loop (not counting the wrapping `^' or `b' characters)
k = 0
p = 0

Perform the following two calculations until the `k' and `p' values no longer change.
k = i + p + 2
p = ceil((i + p + k + 1) / 10)

l = 9p - i - k - 1

Example (read right to left):
b?????^, so i = 5, k = 0, p = 0
k = 5 + 0 + 2 = 7, p = ceil((5 + 0 + 7 + 1) / 10) = ceil(13 / 10) = 2
k = 5 + 2 + 2 = 9, p = ceil((5 + 2 + 9 + 1) / 10) = ceil(17 / 10) = 2  
k = 5 + 2 + 2 = 9, p = ceil((5 + 2 + 9 + 1) / 10) = ceil(17 / 10) = 2  (no change)
l = 9x2 - 5 - 9 - 1 = 3
The loop becomes: bpp?????^kkkkkkkkklll

Example

This prints "Hello, World!" and exits.

]xhhhhooooooooohhhhhhxooooooooxooooooxjjjxhoooohhhxhohhhhhhhxhhhhjjjhhhxhhhhooooooooohhhhhhxjjjxxjjjjjjjxjhhhhxjhhhhhhhhjjjhh~

See also

External resources