Fixing array code generation

This commit is contained in:
Krzosa Karol
2022-07-28 13:29:25 +02:00
parent 78a0f54319
commit b806bafb51
2 changed files with 36 additions and 8 deletions

View File

@@ -17,11 +17,28 @@ main :: (): int
// We can get size of array using length_of builtin
#assert(length_of(static_array) == 8)
element: int = static_array[0]
assert(static_array[1] == 0)
assert(element == 0)
// Accessing values is like in C
// Variables are zeroed by default
// assert(static_array[7] == 0)
assert(static_array[1] == 0)
element2 := static_array[2]
element0: int = static_array[0]
assert(element0 == 0 && element2 == 0)
// We can loop through arrays
// this implicitly defines 'it' variable
for static_array
*it = 1
// We set all variables to 1 so
assert(static_array[6] == 1)
// This is how slice is defined, no [] index in between brackets
// slice is array pointer + length
// Other then that it works exactly like regular array
slice: []int = static_array
// We can't do a compile time assert anymore
assert(length_of(slice) == 8)
// for static_array
// it = 1