Kajo Lab is the desktop app where you can look at a recording, rerun a program on the saved inputs and examine individual instructions. These two small programs give you a way to see how each machine works.
Forth and the Forth VM
Forth puts values on a data stack. Commands and definitions are called words. Enter these two lines at a Forth prompt.
: double DUP + ;
7 double .S
The first line defines a word called double. The colon starts the definition and the semicolon finishes it.
7 double puts 7 on the stack and calls the word.
The Forth virtual machine (VM) runs the word. DUP copies the top value. + replaces both sevens with their sum, 14. .S displays the stack.
In Lab’s Forth editor, keep the first line and use : on-sample 7 double ; on the second line to run the word during replay.
Rust, KAF1 and the Kajo CPU
A guest is a program that runs inside Kajo’s software machine. This Rust guest starts at the function sample, which gives double a fixed value of 7.
u16 is a 16-bit whole number with no negative values. Here wrapping_add adds the number to itself.
The Rust guest compiler translates a small subset of Rust into Kajo instructions.
The compiler produces a KAF1 image, a program ready to load. This one holds seven instructions for two functions and names sample as the starting point.
The Kajo CPU is a processor built in software. It executes those instructions, loading 7 twice, adding the values and returning 14.
Rust is also the language used to build parts of Kajo itself, including the Forth VM. Here you see it in its other role, as the source code of a guest program.
What the Pico’s timer does.
Native ARM kernel
The Pico has a physical ARM processor. Native means the kernel runs directly on that processor. A kernel manages running tasks, and its scheduler decides which task runs next.
In a separate Pico timer experiment, one task was running the interpreter for a KAF1 program. The hardware timer fired during the task. The kernel saved its place, ran another task, then resumed the first. The Pico logged the pause and resume during observation 160, a numbered sensor reading.
Three questions to try offline.
Try them here or use a scrap of paper. Open each explanation after you have an answer.
What does Forth put on the stack after each step of doubling 9?
Start with [9]. DUP copies the top value, leaving [9 9]. + takes both copies and leaves their sum, [18].
What order do the Rust guest compiler, KAF1 and Kajo CPU go in?
The Rust guest compiler reads the source and produces a KAF1 image. The Kajo CPU then runs the instructions stored in that image.
What pauses and resumes a task on the physical Pico?
The hardware timer signals that it is time to interrupt. The native ARM kernel saves the running task’s place and schedules another task. When the original task runs again, the kernel restores its place.
Continue with a real recording.
Night Light records light readings and the LED commands that Forth produced. Use the earlier guides to change a threshold in your browser or follow a recorded decision into the Forth stack. You can also download that same Night Light capture and open it in Kajo Lab without a board.