-
Notifications
You must be signed in to change notification settings - Fork 1
Data Types
ParaVM supports a number of fundamental data types that can be used to build more complex data structures. All types have a total ordering, so the relational instructions can be used on all types.
The nil type is a type that represents nothing. It can be compared to NULL
in C or nil
in Lua. There is only ever one instance of the nil type and it is always equal to itself. All registers are initially set to the nil value.
The integer data type represents an arbitrarily-large natural number, either positive or negative. They work much like integers in most programming languages, other than having no limitations in representable range.
All arithmetic and logical instructions are supported on these.
A float represents a 64-bit IEEE 754 floating point number. It works similarly to double
in C-like languages. All operations involving floats are done in 64-bit precision.
All arithmetic instructions are supported on these.
An atom can be thought of as an interned string. On the surface, an atom is just a string, but when actually loaded into a register, it is looked up in a global hash table that maps atoms to unique word-sized integers. This makes atom comparisons extremely fast.
A binary is a contiguous sequence of bits. They are useful for representing encoded, untyped data such as strings, network packets, etc.
An address points to a particular task running in the virtual machine. Addresses are primarily used for task identification purposes and for sending messages. They are mostly opaque.
A function value is simply a pointer to a function in a module. It can optionally contain a tuple of upvalues that are passed as the first argument to the target function when invoked.
Tuples can be thought of as immutable arrays. They have a fixed length and a sequence of elements matching that length. Looking up elements by index in a tuple is O(1)
, as is computing a tuple's length.
A list is a singly-linked sequence of elements. They are made up of cons cells where the first pointer is to the element and the second pointer points to the next cons cell or to the tail of the list. Looking up an element by index in a list is O(n)
, as is computing its length.
A map is a data structure that maps keys to values. A given key can only map to one value. Looking up a value by its key in a map is very fast (almost O(1)
). Computing a map's length is O(1)
. In addition to being key-value stores, maps are also useful for representing records (or struct
s in C lingo).
A set is a collection of unique values; there can be no duplicates in it. Looking up an item in a set is close to O(1)
as with maps, while computing its length is O(1)
.
A resource is a handle to a native resource of some kind. Resources are completely opaque and can only be created and destroyed in native code (such as in native upcalls). They are useful to represent things like file handles, sockets, etc.