A simple compiler built to learn about compilers and assembly.
- Simple 32 bit unsigned integer type declaration.
uint32 x = 67;- Separate declaration and definition is also supported.
uint32 x;
x = 420;- An array of unsigned 8 bit integers (bytes).
- Currently array literals are not supported.
uint8[5] bytes;- A pointer to x.
- All pointers are 64 bit unsigned integers.
uint32* x_ptr = &x;{
{
uint32 x = 67;
}
// x will be unaccessable here
}- Shadowing
{
uint32 x = 67;
{
uint32 x = 420;
// x will be 420 here
}
}uint32 x = 66;
uint32 y;
if x == 67 {
y = 69;
}
else if x == 66 {
y = 67;
}
else {
y = 420;
}
assert y == 67;- While loops take a condition which must be of type bool and a lopp body.
uint64 i = 0;
while i < 10 {
i = i + 1;
}
assert i == 10;- If assert condition is true the execution continues, if it's not the program aborts.
uint32 x = 67;
assert x == 67;- Arrays are treated as pointers to their first element. However, they are NOT equivalent or can be used as pointers.
uint8[5] bytes; // bytes is a pointer to the first element- Deep copy
uint32[3] xs;
xs[0] = 1;
xs[1] = 2;
xs[2] = 3;
// Here the values of xs are copied over byte by byte into ys.
uint32[3] ys = xs;
ys[1] = 67;
assert xs[1] != 67;- Shallow copy
- You need to create a pointer to the array you want to shallow copy.
uint32[3]* zs = &xs;
(*zs)[1] = 69;
assert xs[1] == 69;
assert (*zs)[1] == 69;- Referencing can be achieved with the & unary operator used on a identifier.
uint32 x = 67;
uint32* x_ptr = &x;- Dereferencing can be achieved by using the * unary operator in a pointer type.
uint32 x = 67;
uint32* x_ptr = &x;
assert *x_ptr == 67;