Hop til hovedindhold

How a program runs

A Runeweave program runs in transactions. In each transaction, the nodes that have something to do run once, in a fixed order, and then the transaction ends. On a microcontroller one transaction runs per pass of the main loop; on an FPGA one runs per clock cycle.

Order​

Before the program runs, Runeweave flattens every patch into one list of native nodes and sorts it so each node comes after the nodes it reads from. That order never changes, so a program does the same thing every time.

Which nodes run​

A node runs in a transaction when:

  • it's the first transaction, when every node runs once to set up;
  • a node it reads from emitted a new value or a pulse earlier in the same transaction;
  • its timer ran out (the clock and delay nodes use this).

Everything else sits still, which is why Runeweave programs are cheap to run and easy to reason about: nothing happens unless something caused it.

Loops​

A wire can't lead back into a node that feeds it, because then there'd be no order. To make feedback, put a defer node (sdp/core/defer) in the loop. It holds the value and delivers it at the start of the next transaction, so a value goes round the loop once per transaction.

Errors​

When a native node fails, for example a sensor that doesn't answer, it puts its outputs in error. The error flows down the wires: nodes reading an output in error don't run, and their own outputs are in error too. A node that wants to handle errors can catch them and carry on.