esolang

Kyu

The script language of an operating system built in Scratch, where printing a computed value means rewriting your own code.

BoundedBeans, 2021 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Hello_world!

The idea

BoundedBeans made Kyu in 2021 for Kronos-QOS, a console-only operating system written as a Scratch project. Its file system is one big queue of entries, and a script is a file of entries that starts with @script. Commands are entries like @@@console, and their arguments are the entries after them.

Read the story

@@@console prints the entry that follows it, as written. There is no command that prints a value, so to print a number a script computes it, stores it in function memory and uses @@@modifycode to write it over the entry after its own @@@console. The specification says self-modification is the only way to print anything that was not in the script already.

This implementation runs the scripts and leaves out the parts that need the operating system, the file queue, drives and shell commands.

The machine

A script has two current values, which work like accumulators, and a function memory, a list that counts from 1. Code indices count entries from 1, so with one entry a line they are line numbers.

CommandDoes
@@@console xPrint x
@@@set1 x @@@set2 xSet a current value
@@@add @@@sub @@@mult @@@div @@@modCurrent value 1 op current value 2
@@@push x @@@input @@@genAdd x, a line of input or a random number to memory
@@@getmem i @@@destroy i @@@insert i xRead, delete or insert an entry of memory
@@@joinmem @@@letter @@@substringWork on text in memory
@@@skip @@@skipbackMove the code pointer by current value 1
@@@label i @@@clabel i nameGo to @@@LABEL:name; the second only if memory i is above 0
@@@modifycode i jWrite memory j over code entry i
@@@integrate i jAppend memory i to j to the script
@ScriptEndStop

Commands and labels are matched without case, as everything is in Scratch, and an entry that is not a command does nothing.

Example

The second script multiplies 6 by 7 and pushes the result, then overwrites entry 12, the x after…
Expected: 42
Expected: Kyu

The second script multiplies 6 by 7 and pushes the result, then overwrites entry 12, the x after @@@console, with it. The third is a cat. It writes each line of input over the word output, prints it, deletes it from memory and jumps back to @@@LABEL:start. In Scratch it would then wait for the next line; in this implementation the run ends when the input does.

Patterns it teaches

Further

Self-modifying

Write your own in Run Convert a program from Kyu

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run kyu -e '@@@console
Hello_world!'
shib manual kyu

Source

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

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

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