Summary

Topics: Release 0.9.0 - Explicit register set specifiers - Void register - Text handling (and source code encoding) - Deferred calls and Communication timeouts

On Sunday 25th, version 0.9.0 of Viua VM was released into the world. This issue of Viua VM weekly is a commentary of this release.


Release 0.9.0

This release is the biggest one in the history of Viua VM, and spans 1287 commits. It is not that surprising, given that previous version (0.8.4) of the VM was released 10 months ago.

Notable changes in this release are discussed in sub-sections below. New features are discussed in their own sections.

iota compile-time keyword

The new compile-time iota keyword generated an ever-increasing integer starting from 1. It can be used to automatically assign register indexes:

    .name: %iota answer     ; will be compiled as '.name: %1 answer'
    istore %answer local 42
    print %answer local

It is especially useful when code is changed, as the assembler will reindex the registers automatically and free the programmer from this task.

Explicit register set specifiers

The tmpri and tmpro instructions are no longer needed as the VM supports explicit register set specifiers for register operands. This means that to move a value from local register set to the static register set the following instruction can be used:

    ; move <target> <source>
    move %1 static %1 local

...instead of this sequence:

    ress local
    tmpri %1
    ress static
    tmpro %1

Explicit register set specifiers make code shorter and more efficient.

Void register

The new void keyword can be used as a target register. Using void register as the target register will drop the value that would by normally produced by the instruction. Some examples:

    ; drop the result of function call (if any)
    call void foo/0

    ; delete the value
    move void %1 local

Having void register in the VM means that the old hacks (i.e. using register 0 as "drop the result" register) are no longer necessary.

Text handling (and source code encoding)

Starting with this release, Viua uses UTF-8 as its internal character set for text values. What is more, a special text type was added to the VM's list of primitive types. Text values must always be valid UTF-8.

A text* family of instructions was introduced to distinguish text values from a "string of bytes" values produced by strstore instruction.

    strstore %1 local "Hello World!"    ; old way of creating text values
    text %2 local "Hello World!"        ; new way of creating text values

As an additional feature, all values can be casted to text using the text instruction:

    istore %1 local 42
    text %2 local %1 local      ; register 2 will contain text "42"

Deferred calls

A very useful feature. Deferred calls may be registered to be called when the frame they were registered in is popped off the stack (during unwinding, normal returns, or tail calls). They are useful as a debugging aid, and can be used to implement resource management schemes.

Deferred calls were discussed in previous Viua VM Weekly posts, so they are given less text in this entry.

Communication timeouts

Blocking operations (join and receive) can now specify a timeout for how long they should block a process. The timeout may be specified in seconds, milliseconds, or as the infinity token.

Some examples:

    receive %1 local 1s     ; wait at least 1s for a message to arrive

    join void 100ms         ; wait at least 100ms for a process to
                            ; become joinable
    receive %1 local infinity   ; wait indefinitely

It is important to note that timeout durations are not exact, and represent the least amount of time the VM will wait before aborting the operation. The VM will abort the operation as soon as the process gets assigned a time slice, and the timeout has passed.