Execution Model
How Sanguis runs your program, and how its numbers behave
Two kinds of cells
Every cell in Sanguis is one of two kinds. What it gives back decides which.
A cell that gives back a float (-> float) is the everyday kind. It works with text, lists, math and files. It runs on the floor, the small C program at the bottom of everything, and sanguis drip is how you start it.
A cell that gives back a u64 or i64 is a system cell. It's compiled to x86-64 machine code and packed into a module, so it runs directly on your processor. Its arguments go in through the processor's registers, and its answer comes back in rax.
The two kinds work together. The kit's cell demo calls back and forth between them and checks its own answers.
How integers behave
We measured these on the floor that ships in the kit:
| When you do this | You get |
|---|---|
| add, subtract, multiply | the exact 64-bit result, wrapping around past the top |
| divide or remainder by 0 | 0 |
| the smallest i64 divided by -1 | the smallest i64 |
| an i64 remainder by -1 | 0 |
| shift by 64 or more | 0 for u64 and for shl; i64 shr fills with the sign |
| a < 0, with a = -20 | 1 in an i64 cell, 0 in a u64 cell |
A system cell works in one integer type, the one after its ->. That type decides how dividing and comparing work for the whole cell. If you need signed fixed-point math inside a u64 cell, add a bias of 263. The shader example's source shows how.
The checker
Before any machine code runs, a program called natcheck reads it. If it finds anything it doesn't know is safe, it says no, and the code never runs. The kit's demos show it saying no as well as yes.
Where it runs
On your computer, programs can print, use files and do math. In a web page, the same floor runs as WebAssembly. There's no clock and no network there, so a program only sees what the page hands it. Inside Sanguix, our operating system, programs can also open windows, pass messages and talk to hardware. Ask for hardware anywhere else and you get an error that names what you asked for.