esolang

Composite

A small assembly language where every number is a prime. To say 72 you write 359, the 72nd prime.

ArthroStar11, 2021 · Turing complete: with unbounded memory · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: HI

The idea

ArthroStar11 made Composite in 2021. It has 26 registers, a stack of up to 1000 values and one flag that is true or false. The twist is in the numbers. Opcode n is written as the nth prime, and so is every argument, so a program is a column of primes. The specification says the name is a pun.

Read the story

There is no prime for 0. A program that needs 0 sets a register to 1 and subtracts it from itself.

The machine

OpcodeWrittenDoes
12Start a subroutine
23Call a subroutine
35Return
4, 57 ... 11Loop while the flag is true
6, 7, 813 17 19Flag becomes a > b, a = b, or its opposite
9 to 1323 29 31 37 41Add, subtract, multiply, divide or take the remainder, into a
14, 1543 47Push a register, pop into one
1653Set a register to a number, or copy another register
17, 1859 61Read a character or a number
19, 2067 71Print a character or a number

Arguments are primes too. 53 2 2 359 is opcode 16 with 1, 1 and 72, which sets register 1 to 72. The main routine stops at the first subroutine, and subroutines are numbered from 1 in the order they appear.

Example

The HI puts 72 and 73 in registers 1 and 2 and prints them as characters.

The HI puts 72 and 73 in registers 1 and 2 and prints them as characters.

The specification counts down from 99 with a space after each number. This one starts at 5, the 5th prime being

  1. Register 3 holds 32, a space, and 19 sets the flag before the loop.
Expected: 5 4 3 2 1

The truth machine makes 0 as 1 minus 1, reads a number and prints it. If the number is more than 0, the loop calls subroutine 1, which prints it again for ever.

Expected: 0

Patterns it teaches

Further

Stack-based

Write your own in Run Convert a program from Composite

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run composite -e '53 2 2 359
53 2 3 367
67 2
67 3'
shib manual composite

Source

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

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

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