esolang

ACIDIC

Two lines of characters, and all a program can do is move them from one line to the other.

iconmaster, 2010 · Turing complete: unknown · ●●● hard · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: Hello, world!

The idea

iconmaster made ACIDIC in 2010. The opposite of a base is an acid, and as BASIC is an easy language, ACIDIC is a hard one. A program is two lines. The first is the Storage Stack, which holds the data, and the second is the Command Stack, which runs from right to left and starts again at the right end when it passes the left one.

Read the story

No command makes a new character. A program can only move characters between the two lines, and OUTPUT prints the whole Storage Stack, so the specification calls meaningful output nigh impossible. Taking a character out of the Command Stack also takes a command out of the program, so a program rewrites itself as it runs.

The machine

All 95 printable characters are commands. They are dealt out to the 19 commands in turn, from space to ~, so each command has five, and the code minus 32, modulo 19, picks it. A and B are two numbers that start at 0.

CharactersCommandDoes
space 3 F Y lPUSHMove the leftmost stored character to the left end of the commands
! 4 G Z mPOPMove the command to its left to the front of storage
" 5 H [ nROTRotate storage one place to the right
# 6 I \ oINCAdd 1 to A
$ 7 J ] pDECTake 1 from A
% 8 K ^ qJUMPGo to command A, counted from the left
& 9 L _ rSTKSZESet A to the size of storage
' : M and the backtick sJMPRJump A places to the left
( ; N a tPUSHRMove stored character A to the left end of the commands
) < O b uPOPRMove command A to the front of storage
* = P c vOUTPUTPrint storage
+ > Q d wBRKHalt
, ? R e xEXCSwap A and B
- @ S f yINPUTSet A to the next input byte, or -1 at the end
. A T g zRPLCReplace this command with the stored character in the same column
/ B U h {ROTARotate storage A places to the right
0 C V i |JMPZJump to command A if B is 0
1 D W j }JMPNZJump to command A if B is not 0
2 E X k ~PLCSet A to this command's place

A command whose place is out of range does nothing. A run ends at BRK, or when no commands are left. This implementation runs the commands as the C# interpreter in the specification does.

Example

The first Hello World keeps the text in storage.

The first Hello World keeps the text in storage. The commands run from the right, so P prints it first and then w halts.

The better version starts with empty storage. Every ! is POP and moves the character to its left to the front of storage. They run from the right, so ! and d arrive first and H last, and the text ends up in order.

Expected: Hello, world!

Four # set A to 4, and / turns storage four places to the right, which brings Hell round to the front.

Expected: Hello, world!

Patterns it teaches

  • Self-modifying code: moving a character to storage takes a command out of the program, and PUSH puts one in.
  • Every text runs: every printable character is one of the 19 commands.

Further

Also in Hostile

Write your own in Run Convert a program from ACIDIC

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: acidic.

Command line

shib run acidic -e 'Hello, world!
wP'
shib manual acidic

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/acidic.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org