Components

← WASM
Io

io_embed.wasm is the Io VM built as a WebAssembly component that other programs call. A host written in Python, Rust, Go, JavaScript or C# loads it with a component runtime; another component can import it. Either way the caller gets a typed interface: evaluate code, send messages to Io objects, read and set slots, get values and errors back.

The interface is wit/io.wit, package iolanguage:io@0.1.0. This is a first version: it is new and relatively untested, and the interface may change before 1.0.

Releases from 2026.11.28 on attach a prebuilt io_embed.wasm and io.wit on the releases page.

eval: func(code: string) -> result<value, error>;
lobby: func() -> object;

resource object {
  perform: func(name: string, args: list<arg>) -> result<value, error>;
  get-slot: func(name: string) -> value;
  set-slot: func(name: string, v: arg) -> result<_, error>;
  is-same: func(other: borrow<object>) -> bool;
}

Build and test

make embed               # build/bin/io_embed.wasm (needs wasi-sdk)
make check-embed         # a guest component calls it; needs wasmtime and wac
make check-embed-python  # a Python host calls it; needs `pip install wasmtime`

make check-embed builds a second component from test/guest.c, which imports the interface, joins the two with wac plug, and runs the result under wasmtime. Put wac on your PATH or at deps/wac/wac.

Try it

With a recent wasmtime (the --invoke form needs version 33 or later):

wasmtime run --invoke 'eval("list(1, 2, 3) map(x, x * x) sum")' build/bin/io_embed.wasm
# ok(number(14))
wasmtime run --invoke 'eval("1 foo")' build/bin/io_embed.wasm
# err({message: "Number does not respond to 'foo'", stack: "..."})

The command line can only show plain values. Anything that returns an object handle needs a real host.

From Python

python/iolang.py is a small wrapper over the wasmtime package, and python/example.py uses it:

from iolang import Io

io = Io("io_embed.wasm")
io.eval("1 + 1")                                   # 2.0
io.eval('Dog := Object clone do(name ::= nil; speak := method(name .. " says woof"))')

dog = io.eval("Dog clone")                         # a handle to an Io object
dog.perform("setName", "Rex")
dog.perform("speak")                               # 'Rex says woof'

io.lobby.set("pet", dog)
io.eval("pet name")                                # 'Rex'

A handle is released when Python collects the IoObject, or at once with drop().

From another component

Import the interface in your world and compose with io_embed.wasm:

world my-app {
  import iolanguage:io/vm@0.1.0;
}
wac plug my-app.wasm --plug io_embed.wasm -o app.wasm

test/guest.c is a complete example in C, with bindings generated by wit-bindgen c.

Values

Plain data is copied; everything else crosses as a handle.

IoComes out asNote
nil, true, falsenil, boolean
Numbernumber (f64)
Sequence holding texttextMust be valid Unicode. Non-ASCII strings are transcoded to UTF-8.
Sequence holding other bytesbytes
BigIntbig-intDecimal digits
VectornumbersItem type plus little-endian bytes. A Vector of 64-bit integers comes as a handle.
anything elseobjLists, Maps, blocks and methods included
an exceptionthe error of the resultMessage and Io backtrace

Going in, text becomes what a string literal is in Io (an immutable Sequence), bytes a mutable byte Sequence, numbers a Vector, and obj the object the handle refers to.

  • Handles keep objects alive. An Io object is not collected while a handle to it exists. Drop handles you no longer need.
  • Arguments borrow. Passing a handle as an argument does not give it away: you can keep using it.
  • Lists and Maps are handles. Send them at, size, atPut, keys and so on with perform.
  • A bad argument changes nothing. A big-int that is not a decimal integer, or numbers whose length is not a multiple of the item size, is an error before any message is sent or slot set.
  • get-slot does not activate. A method comes back as a handle. Use perform to call it.

Behaviour to know about

  • One instance is one VM, created on the first call. State persists between calls. Some hosts make a new instance for every call: keep one alive if you want state.
  • Calls block. eval and perform return when the code has finished, including any wait. Coroutines left running in the background make progress only during later calls.
  • System exit ends the VM, not the host. The call that exits returns an error saying so, and so does every later call on that instance. Make a new instance to carry on.
  • Output goes to the component's standard output. println writes to whatever the host connects there, and it is flushed before each call returns, so it stays in order with the host's own output.
  • Sandboxing is the host's job. The component imports the standard WASI interfaces (files, clocks, sockets). Io can reach only what the host grants: give it no directories and no network to confine it.
  • Not here yet: passing callbacks or the host's own objects into Io, copying a whole List or Map in one call, and async. See the plan.

Source

The component lives in embed/ in the repository: the interface, its implementation over the VM, the generated C bindings, the test guest and the Python wrapper. Release builds attach io_embed.wasm and io.wit.