Types - BBpezsgo/BBLang GitHub Wiki
Types
Built-in Types
| Keyword | Size | Signed? | Kind |
|---|---|---|---|
u8 |
8 bit | No | Integer |
i8 |
8 bit | Yes | Integer |
u16 |
16 bit | No | Integer |
i16 |
16 bit | Yes | Integer |
u32 |
32 bit | No | Integer |
i32 |
32 bit | Yes | Integer |
f32 |
32 bit | Yes | Floating |
Booleans
There is no boolean type defined explicitly. Any non-zero value is interpreted as true.
Pointers
Yeah there are also pointers.
[!NOTE] Pointers technically aint supported in brainfuck, but you can still pass a variable as a reference to a function anyway.
You can declare a pointer type like this:
i32* yeah;
This will declare a variable "yeah" that points to a 32 bit signed integer.
You can also declare a pointer that points to a struct like this:
struct Vector2
{
f32 X;
f32 Y;
}
Vector2* point;
... and you can access its fields like normally you do:
f32 x = point.X;
[!NOTE] If you try to access a field of a zero pointer, depending on the
--no-nullcheckargument a runtime exception will be thrown.
You can set the value where the pointer points to like this:
*yeah = 44;
[!NOTE] I want to make a better syntax for field dereferencing, because what if the field is a pointer type and you want to set the pointer's value or the value where the pointer points to? Idk man, I will implement it when I feel like to.
Arrays
You can define array types like this:
var values = i32[6]; // This will make an array of length 6
All array types are value types, so the variable above will allocate 4 * 6 bytes on the stack. You can access each elements using the indexer:
values[0] = 564;
values[4] = 1;
i32 v = values[4];
If you define a pointer to an array, indexing it will dereferene the pointer. In other languages, you can also use the indexer on simple pointer types like this:
int *buffer;
buffer[3] = 7;
However in this language, this is not allowed since you can only index an array. You can convert the code above into BBL:
int[]* buffer;
buffer[3] = 7;
Structs
You can define a struct as follows:
struct Point
{
i32 x;
i32 y;
}
And use it like this:
Point point;
point.x = 37; // Set the "x" field to 37
point.y = 81;
Generics
I will explain it when I feel like to.
Read more:
Aliases
You can alias any type with a name like this:
alias int i32;
alias string u16[]*;
And you can use the alias name like any other type:
int number;
string text;