docs of Viua virtual machine
a bytecode virtual machine for highly concurrent software

ISA reference

This document explains the instruction set architecture of Viua virtual machine, its execution model and rationale behind it, and provides descriptions of all available instructions (and pseudoinstructions provided by the assembler).

Execution model

Programs written for Viua VM are organised into functions and data. Functions are sequences of instructions operating on data stored in registers. A register is a slot which may contain a value (a valueless, empty register is said to be void).

At runtime, functions are invoked and their instructions executed. A function invocation comes in two flavours - synchronous and concurrent. Synchronous invocation is a simple function call which suspends the caller until the callee finishes execution. Concurrent invocation involves an actor ie, an independent, isolated process to run the callee.

In both cases the arguments (actual parameters) are passed to the callee via the arguments register set, and the value produced by the callee is returned to the called as a return value. Details of how this is achieved in each case are different, though.

The synchronous inocation is the simpler case. The call instruction suspends the caller and produces a value in the output register.

The concurrent inocation's return value is available indirectly. In this case the call instruction returns a PID of the spawned process. This PID can be queried about the callee actor's state and, eventually, read its return value. This is a concept similar to a future when considering its usefulness in fetching return values of asynchronous function calls.

The PID also serves as a means of communication. It can be used to send messages to the process associated with it. This message exchange is the only means of communication between running actors.

Register sets

Viua is a register-based virtual machine. The values its instructions operate on are stored (at least conceptually) in registers.

Built-in data types

The VM provides several built-in data types, which can be used to solve common problems. These data types are explained in this section.

Integers

Signed and unsigned.

Floating-point numbers

Single- and double-precision.

Bitstrings

For arbitrary-precision integer arithmetic, or bitwise operations.

Atoms

For symbols and struct keys.

Strings

Sequences of bytes.

Structs

Mappings from atoms to arbitrary values.

Buffers

Sequences of values.

References

Values referencing other values (used for indirection).

Instructions

The instructions available to programmers are listed below. Some of them are real instructions ie, are implemented by the VM, and some are pseudoinstructions ie, are provided by the assembler and may expand to different sequences of real instructions. If an instruction is a pseudoinstruction it is marked as such in its description page.