-
Notifications
You must be signed in to change notification settings - Fork 1
Basic Concepts
Evi is statically typed. This means, that variables, functions and parameters have their own type declared by the programmer. The compiler automatically resolves type inference and implicit casts when possible, and shows an error when a cast -implicit or not- is invalid. By default, Evi has the following types:
Type | Category | Description |
---|---|---|
i1 | Integer | A 1-bit signed integer |
i4 | Integer | A 4-bit signed integer |
ui4 | Integer | A 4-bit unsigned integer |
i8 | Integer | An 8-bit signed integer |
ui8 | Integer | An 8-bit unsigned integer |
i16 | Integer | A 16-bit signed integer |
ui16 | Integer | A 16-bit unsigned integer |
i32 | Integer | A 32-bit signed integer |
ui32 | Integer | A 32-bit unsigned integer |
i64 | Integer | A 64-bit signed integer |
ui64 | Integer | A 64-bit unsigned integer |
i128 | Integer | A 128-bit signed integer |
ui128 | Integer | A 128-bit unsigned integer |
flt | Floating-Point | A 32-bit single precision floating point number |
dbl | Floating-Point | A 64-bit double precision floating point number |
sze | Integer | An unsigned integral |
bln | Integer | An unsigned 1-bit boolean |
chr | Integer | An unsigned 8-bit character |
nll | Void | The null/void type |
These types can be put in three different categories: integer, floating-point, and void types. The compiler will not have nor make trouble when any two types of the same category are used interchangeably, meaning that -for example- assigning a value of type ui32
to a variable of type i8
will not be a problem. (Though in this particular example 4 bits of data will be lost!) Doing the same with two types of two different categories might result in a warning, or an error when a cast is impossible.
The basic types can be modified using type modifiers. Evi has two of these modifiers: the constant-modifier (prefix !
) that makes a type constant, and the pointer-modifier (suffix *
) that makes for a pointer to the modified type. The constant-modifier can be applied only once to each type, while the pointer-modifier can be applied an abritrary amount of times.
Some examples of correctly modified types are the following:
!i32 (constant i32)
flt* (float pointer)
nll** (pointer to null pointer)
!chr* (constant char pointer)
Note: It is bad practice to use pointers that point to variables declared as constants.
Both arrays and pointers are a feature of Evi, but perhaps not in a way similar to C-like languages. Arrays are the same as pointers. When assigning a normal address to a pointer that address will be stored in the pointer just like in e.g. C. But when assigning an array to a pointer, the array will be allocated in memory and the pointer will be set to the address of the base element. It might help to think of it the same way as strings in C, where after assigning a string literal -which is just an array of characters- to a pointer, that pointer then points to the first character of aforementioned string.
This also means that there are no array types in Evi, but only pointer types. If you want to define a variable that holds an array of -for example- floats, the type of that variable would be a flt*
. This also means that multiple-dimension arrays work the same as pointer-to-pointers. For an example Evi file with arrays and pointers see arrays_and_pointers.evi
in the test/
directory of the Evi github repository.
Next: 4 – The Language
Home | About | Installation | Language Overview | License: MIT 2022 Sjoerd Vermeulen. Terms