esolang

SICKBAY

A BASIC without IF. Each line number is an expression, and the lines run in the order their numbers have right now.

Chris Pressey · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 9 known programs · Test method

Run it

Expected: HELLO, WORLD!

The idea

Chris Pressey built SICKBAY from two ideas he probably had around 2009 to 2012. Some BASICs let GOTO compute the line it jumps to. SICKBAY computes only the line numbers themselves. A line numbered (200+A%) moves whenever A% changes, so it can slide in front of another line or land on top of one. That is enough to branch, and so there is no IF.

Read the story

The second idea is the call ring buffer. GOSUB and RETURN use its top as usual. PROLONG puts a return address on the bottom, which runs more code after the program ends, and CUTSHORT takes one off the bottom, which ends the program early.

The machine

StatementDoes
LET A% = eSet a variable; each one is also an unbounded array, A%(i)
GOTO n GOSUB nJump, or jump and put this line number on top of the ring
RETURN ENDTake the top of the ring and go on after that line; stop when it is empty
PROLONG n CUTSHORTPut a line number on the bottom of the ring; take one off the bottom
DIM RING (e)Set the size of the ring, 10 by default
PRINT "text" PRINT e PRINT CHR$ ePrint one thing and a line feed, or no line feed after ;
INPUT A% INPUT CHR$ A%Read an integer or one character
REMA comment to the end of the line

Operators have no precedence. Every operation sits in its own brackets, as in ((A%+1)*2), and / rounds down and gives 0 for a division by 0. After a line, the next one is the lowest number above it. When two lines share a number, the first in the text wins and the other is never seen.

Example

Line 10 runs first.

Line 10 runs first. Two lines are numbered 20, and the one that comes first in the text wins.

The truth machine. On 0 the line (200+A%) lands on 200, comes first in the text and prints 0. On 1 it moves to 201, and line 200 prints 1 forever.

Expected: 0

PROLONG 300 pretends that a GOSUB was made from line 300 before the program began. So the RETURN at line 300 goes on at line 400.

Expected: PRINTED! THIS IS PRINTED TOO!

The 99 bottles of beer ends without a test. Its line (100+B%) END stands before line 100 in the text, so when B% reaches 0 it takes over number 100 and the loop's GOTO 100 ends the program. All 99 verses come out, as do the CUTSHORT example and its range checker.

Further

Ideas it shows

Also in Strange time

Write your own in Run Convert a program from SICKBAY

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run sickbay -e '100 INPUT A%
(200+A%) PRINT 0;
200 PRINT 1;:GOTO 200' --input '0
'
shib manual sickbay

Source

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

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

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