-
Notifications
You must be signed in to change notification settings - Fork 2
4 Basic Concepts
CSpydr is statically types. This means, that variables, function 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, CSpydr has the following types:
Type | Category | Description |
---|---|---|
i8 | Integer | A 8-bit signed integer (-128 -> 127) |
u8 | Integer | A 8-bit unsigned integer (0 -> 255) |
i16 | Integer | A 16-bit signed integer (-32768 -> 32767) |
u16 | Integer | A 16-bit unsigned integer (0 -> 65535) |
i32 | Integer | A 32-bit signed integer (-2147483648 -> 2147483647) |
u32 | Integer | A 32-bit unsigned integer (0 -> 4294967295) |
i64 | Integer | A 64-bit signed integer (-9223372036854775808 -> 9223372036854775807) |
u64 | Integer | A 64-bit unsigned integer (0 -> 18446744073709551615) |
f32 | Floating-Point | A 32-bit single precision floating point number |
f64 | Floating-Point | A 64-bit double precision floating point number |
f80 | Floating-Point | A 80-bit double precision floating point number |
bool | Integer | A 8-bit boolean value (true , false ) |
void | Void | The void type |
char | Integer | A 8-bit signed integer (-128 -> 127) made for representing ascii characters |
fn | Integer | A 64-bit unsigned integer (pointer) to a function or lambda expression, can have return- and argument types specified: fn<i32>(i32, i32)
|
enum | Integer | A 32-bit signed integer made for defining constants |
These types can be put into three different Categories: integer, floating-point and void. The compiler can convert between types of the same category without problems. Else, there will be errors and/or warnings. Sometimes, data can be lost though, e.g. converting from i64 to i8.
The basic types can be modified using type modifiers. CSpydr has six type modifiers:
Type | Category | Example | Description |
---|---|---|---|
struct | Struct | struct { a: i32, b: char } |
Structs can group multiple types together making one big type |
union | Struct | union { a: i32, b: char } |
Unions can group multiple types together, while keeping the same memory pointer for each entry. This makes it possible to have multiple types for one identifier. |
& | Integer |
&char &void
|
Pointers store memory addresses to the base type. They are 64-bit unsigned integers |
[x] | Array |
i32[4] char[10]
|
Arrays can group multiple indices of a base type together to form one big type |
[] | Integer/Array |
i32[] char[]
|
VLAs (Variable Length Arrays) can be either a pointer or an implicitly-sized array to a base type depending on the context |
typeof | * | typeof x |
the typeof "type" is not a type of its own, it "returns" the type of the right expression |
Next: 5 - The Language
2.1 - Compatibility
2.2 - Obtaining CSpydr
2.3 - Dependencies
2.4 - Building
2.5 - Installation
2.6 - Usage
4.1 - Types and Values
4.2 - Type Modifiers
4.3 - Truthiness
4.4 - Naming Conventions
5.1 - Lexical Conventions
5.2 - Variables, Members and Arguments
5.3 - Statements
5.3.1 - Blocks
5.3.2 - Loops
5.3.3 - Control Flow
5.3.4 - Expression Statements
5.3.5 - Variable Declarations
5.4 - Expressions
5.4.1 - Literals
5.4.2 - Operator Precedence
5.4.3 - Binary Operators
5.4.4 - Unary Operators
5.4.5 - Postfix Operators