OTIL Datatypes
Primitive Data-types
Bit
- bit
A single true or false / 0 or 1 value. When using many bit values it is highly recommended to use an enumeration or bit-array rather than a list of bits.
Integer
Integer types represent whole numbers and are either signed (sint) or unsigned (uint) with sizes of 8, 16, 32 or 64. Together the list reads:
- sint8
- uint8
- sint16
- uint16
- sint32
- uint32
- sint64
- uint64
The distinction between signed and unsigned is that signed types go support negative values at the expense of half of their positive values.
Values are decimal unless prefixed with 0x to indicate hexadecimal.
Real
Real values are fractions represented in memory using the IEEE-754 floating-point standard. They come in two sizes, 32 and 64 bits.
- real32
- real64
Values can be written in exponent notation.
Textual Data-types
Characters
- char
Alternative name for uint8. Only supports ASCII character set at present.
Strings
- string
An alias for List of uint8. Constant string values have a terminating 0 value added to them.
Note that OTIL strings support C-Style escape characters, e.g. "n" to mean a string containing a new line.
Warning: Using the string type on its own is strongly discouraged. It is recommended to wrap strings in a record that also has a length field whenever possible.
Compound Primitive Data-types
List
Multiple instances of any data-type other than bit or slice.
LIST OF type
Bit-Array
Similar to an array but consisting of bits. This allows for arbitrary lengths unlike enumerations at the expense of syntactic complexity.
Slices
Equivalent to a List of uint8 but with type restrictions disabled. For example two bytes can be re-assigned at once using a 16 bit integer. Unlike with a List of uint16 it will still be addressed byte.
Custom Data-types
Enumerations
Used to alias integer values with contextual meanings.
TYPE name = ( Option-1, Option-2, etcetera );
By default options are numbered in exponents of 2 (1, 2, 4, 8, etcetera). The size of the enumeration will be set to 8, 16, 32, or 64 bits depending on how many options it has.
Alternatively numeric values of options can be hard-coded using the following syntax:
TYPE name = ( Option-1 = value, Option-2 = value, etcetera );
This allows for a far wider range of options at the expense of being able to combine them using bitwise operations.
Records
Used to declare a compound data-type consisting of multiple named fields.
Declaration
TYPE name = record ( field-1 : type, field-2 : type, etcetera );
Initialization
CONST name <- ( field-1 : value; field-1 : value; etcetera );
Note that fields which are not explicitly initialized will be automatically set to zero.
Nested records
Should a field of a record itself be another record the two may be initialised together.
CONST name <- ( field-1 : ( field-1-1 : value; field-1-2 : value; ); field-2 : value );
Accessing fields
field-1 OF name;
Fun Fact: This syntax is taken from the ALGOL language.
Note that there is no syntactic limitation on how deeply records can be nested.