jetForth BASICan easy way to write jetForth, as Bitcoin BASIC is for Bitcoin Script

Write a program in BASIC and get jetForth, the script a jetmora thread runs. Paste jetForth and read it back as BASIC. It all runs in this page: nothing you type leaves it.

BASIC VERSION · LET · IF · FOR · DIM · INPUT · VERIFY

jetForth

Write some BASIC and press Compile.

What it writes

a numberone 64-bit cell
bytestwo cells, ( c-addr u ): where they are and how many
a variableat an address fixed when compiling: one cell for a number, two for bytes
FOR … NEXTa real loop. jetForth can branch back, so nothing is unrolled
^a multiply loop. Nothing is worked out in advance: the script says what the program says
VERSION JF 3the first line. It becomes the script's first five bytes, VER JF 3: the lock declares the version its code is written for. A tick spending it must name the same version, nVersion 0x464a0003

A thread

With DIM, the program is a covenant: its fields are the thread's state, fixed-width, at the head of the script. DIM owner$20 is required, and holds HASH160 of the owner's key, as the deployed Bitcoin covenants store it. The compiler writes the rules every tick must meet:

1 · the ownerthe key's hash is the owner's, and its signature over the tick holds
2 · the next tickthe value goes up by one, and the tick's sequence number is that same number
3 · the same scriptthe next tip carries this script
4 · its statewith the fields your program sets, rebuilt into it

The compiler writes the script once. After that the script rebuilds itself into each new tip, and the rules travel with it.

With INPUT, each tick brings values with it, pushed after the owner's signature and key in the order INPUT names them. code$ is bytes of any length, code$32 exactly 32; r%2 is a number in at most 2 bytes, r% in at most 8. The owner's signature covers an input only through what your program puts into the next tip's state.

How a tick is judged

As a BSV node judges a spend: the unlocking script is byte pushes only; it runs, then the lock runs on what it left; the tick is accepted with exactly one non-zero item. JF revision 3's limits are the same on every host: 500,000 instructions, each 64 bytes moved costing one more; 64 KB of memory; 64 KB of pushed bytes, read-only; 1,000 items; 100 signature checks.