Hase Paper Computer
git clone http://jummit.com/repos/hase/hase.git- Cargo.lock
- Cargo.toml
- LICENSE
- examples/aoc.hase
- examples/loop.hase
- examples/sort.hase
- src/assembler.rs
- src/debugger.rs
- src/lib.rs
- src/main.rs
A simple language for paper-computing.
Although the language is designed to be executed by a human, this repo provides an interpreter where programs can be run much faster than by hand.
Example
; define registers
l:[1 2 3 0]
s:1
; sum the values
1svl
l>
ln1
=s
cargo install --git https://git@git.sr.ht/~jummit/hase
Defining Registers
The hase virtual machine is initialized with a set of registers, which have one-character long names.
They can be specified to be a set size like this:
; Register with five empty slots:
r:5
Registers can also be pre-filled with values:
; Register with the values 1, 2 and 3:
r:[1 2 3]
; pointer on the first slot
; r:[[1] 2 3]
r:[1 2 3]
; move right instruction
r>
; pointer on the second slot
; r:[1 [2] 3]
Each line begins with a register name, followed by an instruction.
; move the pointer of register a one slot to the right
a>
; add one
a+1
; add the value a register is pointing to
a+b
Move the pointer of a register to the right by the given amount.
When no parameter is given, the pointer is moved by one.
The cursor wraps around (the slots are arranged in a circle).
Move Left (<)
Same as move right, just backwards.
Take (v)
Move values from the second register to the first (empty the second, add it to the first).
Add (+)
Add the value to the register.
Subtract (-)
Subtract the value from the register.
Values can never be lower than zero.
Jump (n)
Jump to the given label when the register is not empty.
Labels are defined by adding a number to a line:
5a+b; line labeled "5"
a+1 an1; jump to label one =0; was zero 1=1; was one
The jump instruction can be unconditional:
Result (=)
Stops the program and returns the result.
This instruction can be used in two different ways:
Returning a value:
=1
=a
a=