Packages

A Virdant design may be split across multiple files. When doing so, each file is a Virdant package.

One Virdant package may import another using the import keyword:

top.vir
 1import buffer
 2
 3mod Top {
 4    incoming clock : Clock
 5    outgoing out : Word[4]
 6
 7    reg counter : Word[4] on clock
 8    counter <= counter + 1
 9
10    mod buffer of buffer::Buffer
11    buffer.clock := clock
12    buffer.inp := counter
13
14    wire counter_is_zero : Bit
15    counter_is_zero := counter == 0
16
17    out := if counter_is_zero {
18        0
19    } else {
20        buffer.out
21    }
22}

The first line, import buffer, tells Virdant that it needs to import the buffer package. That package is located in another file, buffer.vir:

buffer.vir
 1mod Buffer {
 2    incoming clock : Clock
 3    incoming inp : Word[4]
 4    outgoing out : Word[4]
 5
 6    reg queue : Word[4] on clock
 7    queue <= inp
 8
 9    out := queue
10}

When we want to use a module definition, type definition, or other declaration from another package, we refer to it by its fully-qualified name.

In this example, we see:

    mod buffer of buffer::Buffer

The module definition is named with the fully-qualified name buffer::Buffer.