esolang

Textile

Tile without the grid. The same opcodes, written as text, with jumps between functions where Tile has paths.

Dtp09, 2022 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello, World

The idea

Dtp09 made Textile in 2022 as a textual form of Tile, their two-dimensional language of tiles made of four black or white squares. In Tile the program counter walks a path across the grid, and a comparison tile turns it left or right. Textile drops the grid. Code lives in named functions, and the turn to the right becomes a jump to a function. A jump never comes back, so a function is a place to go, not a subroutine. The name is text and tile run together.

The machine

Everything is a byte. Below the bottom of the stack every value reads as 0.

OpcodeDoes
push 72, $48, %01001000, "text"Push bytes, or a 0 with no operands
outPrint the top and pop it
add sub mulPop two, push the result modulo 256
divPop two, push the quotient and then the remainder
read writeLoad and store memory at the address [s2][s1]
inputPush the input byte at the address [s2][s1]
jump FGo to the function F
equal F less F greater FGo to F if s2 = s1, s2 < s1 or s2 > s1
random F GGo to one of up to three functions

Every opcode has a three-letter form too, such as psh and jmp. add*3 repeats an opcode, and [F] copies in the code of a function declared before it. A run starts in main or MAIN and ends at the end of a function, or on a division by 0. The comparisons do not pop. So loops push a 0, compare against it, and then add the 0 away again.

Example

The Hello World pushes its string in reverse, so the H is on top, and prints until the comparison with 0…

The Hello World pushes its string in reverse, so the H is on top, and prints until the comparison with 0 finds the empty stack. Its string has no exclamation mark.

Numbers can be written in decimal, in hex after $ or in binary after %.

Expected: Hi

The cat keeps a 16-bit read address on the stack as two bytes and adds 1 to the low byte after each character. When the low byte wraps to 0, OVERFLOW carries 1 into the high byte. Input past its end reads as 0, which ends the run.

Expected: cat

Patterns it teaches

  • Stack machines: eight-bit values, and comparisons that look without popping.

Further

Stack-based

Write your own in Run Convert a program from Textile

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run textile -e 'MAIN: { 
push "Hello, World".reverse
jump OUTPUT
}

OUTPUT: {
out
push
equal EXIT
add
jump OUTPUT
}

EXIT: {
}'
shib manual textile

Source

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

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

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