Cairn · module

Cairn.Runtime.Abi

lean/Cairn/Runtime/Abi.lean

The Lean side of the app ABI. The host (workstream G) loads one app per binary and calls three exported functions; each app file defines them by applying these generic functions to its App, a Config and a Boundary:

@[export cairn_app_init]
def appInit (w h scalePercent : UInt32) : Runtime.State MyApp.State :=
  Runtime.initState MyApp.app cfg w h scalePercent
@[export cairn_app_step]
def appStep (s : Runtime.State MyApp.State) (events : ByteArray) : Runtime.State MyApp.State :=
  Runtime.stepBytes MyApp.app cfg boundary s events
@[export cairn_app_frame]
def appFrame (s : Runtime.State MyApp.State) : ByteArray := Runtime.frameBytes boundary s

Lean 4.35 rejects @& on @[export], so every argument is owned: the host passes its reference to the state into cairn_app_step and keeps the one that comes back, and calls lean_inc on the state before cairn_app_frame if it keeps using it. See docs/runtime.md.

Imports Cairn.Runtime.Step, Cairn.Frame, Cairn.Frame.Menu

Order

Structures 1

structure

Cairn.Runtime.Boundary

lean/Cairn/Runtime/Abi.lean:32
Boundary : Type

The byte formats at the boundary: Cairn.Frame.boundary (Frame.ofLaid and the v1 encoding, docs/frame.md).

Fields
decode : List Event

Host event bytes → events, in order.

render : Canvas

The draws, accessibility nodes and text input of a laid tree. It reads the UI for the surface's size and focus (the caret, AxNode.focused, textInput). The runtime fills in the cursor, the other surfaces and the effects.

encode : ByteArray

Definitions 6

def

Cairn.Runtime.initState

lean/Cairn/Runtime/Abi.lean:43
initState {S : Type} (app : App S) (cfg : Config)
  (w h scalePercent : UInt32) : State S
def

Cairn.Runtime.stepBytes

lean/Cairn/Runtime/Abi.lean:47
stepBytes {S : Type} (app : App S) (cfg : Config) (b : Boundary) (s : State S)
  (events : ByteArray) : State S

Run a batch of events. The state's effects become this batch's effects.

def

Cairn.Runtime.panelUI

lean/Cairn/Runtime/Abi.lean:53
panelUI (size : Size) : UI

A panel's UI: its size, and nothing focused, hovered or pressed (it takes no input).

def

Cairn.Runtime.surfaceFrame

lean/Cairn/Runtime/Abi.lean:56
surfaceFrame {S : Type} (b : Boundary) (s : State S) : Shown → SurfaceFrame

One surface's record. The window shows the state's laid tree; a panel its own.

def

Cairn.Runtime.frame

lean/Cairn/Runtime/Abi.lean:71
frame {S : Type} (b : Boundary) (s : State S) : Frame
def

Cairn.Runtime.frameBytes

lean/Cairn/Runtime/Abi.lean:75
frameBytes {S : Type} (b : Boundary) (s : State S) : ByteArray