-
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 |
Truthiness is the property of a value to be treated as true
or false
. Values equal to 0
, nil
or '\0'
are false. All other values (non-null values) are true. Truthiness plays a major role in control flow and other parts of programs and is a code feature of most programming languages.
CSpydr has no pre-defined naming conventions as Rust, for example. Following are the naming conventions I used for developing CSpydr, which I advise you to follow to keep the Code clean:
PascalCase
: Used for type definitions.
snake_case
: Used for functions, variables, function arguments and namespaces.
UPPER_SNAKE_CASE
: Used for enum members, constants and macros.
Identifiers starting with __
(two underscores) are meant for internal use and should not be accessed by the user (although they can).
Note: Identifiers starting with
__csp_
should not be used as they are reserved for internal functions of the C transpiler.
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