Skip to content

Basic Concepts

Sjoerd Vermeulen edited this page Mar 31, 2022 · 1 revision

3 – Basic Concepts

3.1 – Types And Values

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.

3.2 – Type Modifiers

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.

3.3 – Arrays And Pointers

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

Contents

Home

1 – Introduction

2 – Hello World

3 – Basic Concepts

  3.1 – Types And Values

  3.2 – Type Modifiers

  3.3 – Arrays And Pointers

4 – The Language

  4.1 – Lexical Conventions

  4.2 – Variables And Parameters

  4.3 – Statements

    4.3.1 – Blocks

    4.3.2 – Assignment

    4.3.3 – Control Flow

    4.3.4 – Loops

    4.3.5 – Variable Declarations

  4.4 – Expressions

    4.4.1 – Arithmetic Operators

    4.4.2 – Bitwise Operators

    4.4.3 – Relational Operators

    4.4.5 – Logical Operators

    4.4.6 – The SizeOf Operator

    4.4.7 – The Casting Operator

    4.4.8 – Function Calls

    4.4.9 – Precedence

  4.5 – Visibility Rules

5 – The Standard Library

  5.1 – The Std Library

    5.1.1 – Input And Output

    5.1.2 – Mathematics

    5.1.3 – Memory Management

6 – The Preprocessor

  6.1 – Including Files

  6.2 – Setting Flags

  6.3 – Conditional Directives

  6.4 – Macros

  6.5 – Pragma Directives

  6.6 – Miscellaneous Directives

7 – The Compiler

  7.1 – Installation

  7.2 – Compilation

  7.3 – Execution

8 – The Complete Syntax

9 – Miscellaneous Information

  9.1 – Coding Conventions

    9.1.1 – Naming Conventions

    9.1.2 – Commenting Conventions

    9.1.3 – Miscellaneous Conventions

  9.2 – Credits

  9.3 – License

Clone this wiki locally