A run never outlives its fuel
A run that spends its fuel returns YIELD; running again continues the same call, and any other call into the realm abandons it.
Your application never hands tinyscript a file handle, a socket or a clock. It runs a call for some fuel and reads back a status; when the script wants something, it parks on a message and waits for your answer.
A script you did not write can loop forever, block on I/O or throw. Your event loop has to keep turning through all three.
So tinyscript never takes the thread. You call ta_tinyscript_run with an amount of fuel, and it comes back with a status before the fuel is gone.
Each status tells you exactly one thing to do next. I like that a lot: there is no callback that fires while you are not looking.
| Status | What happened | What you do |
|---|---|---|
YIELD | The fuel ran out mid-call | Run again to continue where it stopped, or abandon the call |
EFFECT | The script asked the host for something | Read the request, then reply when you have the answer |
SUSPENDED | A generator yielded a value | Resume it with next, return or throw |
DONE | The call returned | Read the result |
THROWN | The call threw and nothing caught it | Read the exception |
A run that spends its fuel returns YIELD; running again continues the same call, and any other call into the realm abandons it.
A sandbox that blocks file and network access has to find every way out. Miss one, and a plugin reads your environment.
tinyscript has one way out, and you write the other end of it. A script imports request from tinyscript:host and calls it with a method name and its arguments.
The VM encodes that as CBOR in a packet buffer you gave it, parks the call and returns EFFECT. You decide whether to answer, how and when; the call resumes at the same expression with your value.
The core has no ambient filesystem, clock, output or random source; a call parks on a request and resumes on a validated reply with the same request number.
Source:tinyscript, README.md
An engine that allocates for itself can grow until the process falls over. One hostile tenant then costs every other tenant.
tinyscript calls no allocator of its own. The compiler, the image and each session work inside buffers you hand over, and a buffer that is too short is a status, never a truncation.
The packet and scratch buffers for requests are yours too: ta_tinyscript_set_host_buffers gives them to a realm. Because a session is just bytes you own, you can copy it, store it and put it under a microscope.
Most engines speak one API in C, another in Node.js and a third in Swift. A host written for one is rewritten for the next.
tinyscript's engine is freestanding and deterministic, so it runs anywhere a C compiler or a WebAssembly engine does. Every build ships the same engine and speaks the same messages; only the language around them changes.
The C library with its CLI ships today as development snapshots. The other builds come from the same source, as the specification records them.
| Build | For | Published as |
|---|---|---|
| WebAssembly | Browsers and restricted contexts | A WebAssembly module and its JavaScript host |
| napi | Servers, through Node-API | A native addon |
| Swift | Apple platforms | A Swift package, from GitHub releases |
| Kotlin | Android | A binding, from GitHub releases |
| Amalgamation | Any C or C++ project | One C file and one header, in the style of SQLite |
Every build speaks the same host protocol: requests and replies as messages through the packet and scratch buffers.