Skip to content

4 Basic Concepts

Spydr edited this page Apr 1, 2022 · 8 revisions

4 - Basic Concepts

4.1 - Types and Values

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.

4.2 - Type Modifiers

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: ....

Clone this wiki locally