In Cord, I/O is done via blocking channels known as ports. Cores communicate with other cores or devices one 32-bit word at a time.
io opcode
The io opcode initiates I/O. It pops an item from the stack, which
controls how the I/O is carried out.
If bit 5 is set, initiate a recv. Otherwise, a send.
If bit 4 is set, the operation may time out. See below for more on timeouts.
Bits 3–0 indicate whether to communicate with peers to the north, east, south, or west, respectively. If multiple peers are specified, the core will communicate with the first ready peer (or a random one if more than one is ready).
Bits not mentioned here are ignored.
Sends will use the next item on the stack, popping it. Recvs will push the received item to the top of the stack.
Timeouts
Each core has an internal timeout value, defaulting to 0. When timeouts are enabled (see above), an I/O operation will time out after this many milliseconds have elapsed.
Recv and send operations with a timeout will push an additional item
to the stack*. This item will be 0 if the I/O operation times out,
else it will indicate the peer. For instance, if we successfully
communicate with our peer to the east, the top of stack will hold
0b0100, which corresponds to east in the format laid out above.
Setting the timer
Sending to no peers with timeouts enabled will pop the stack and use this as the new duration in milliseconds for future timeouts.
Sleeping
Recving from no peers with timeouts enabled will simply sleep for the timeout duration.
Querying the last peer
Initiating a recv with no peers and no timeout will push the last peer onto the stack, or 0 if none. This is especially useful with blocking (non-timeout) recv and send operations, as they do not push the peer onto the stack when they complete.
Halting
0 io, which initiates a send to no peers and with no timeout, will
immediately halt the core (and is the canonical way to do so).
Incoming
✏ Edited