mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-14 23:41:30 +00:00
Initial element access compilation; Carefully approaching std array
This commit is contained in:
26
tests/compiler/std/carray.ts
Normal file
26
tests/compiler/std/carray.ts
Normal file
@ -0,0 +1,26 @@
|
||||
// TBD: While this is useful as long as the pointer is just a local or global,
|
||||
// things go haywire, compared to C, as soon as the CArray is a member of a
|
||||
// class. Also, multi dimensional arrays cannot be implemented C-like because
|
||||
// their length isn't known at compile time.
|
||||
|
||||
var arr: CArray<i32> = changetype<CArray<i32>>(HEAP_BASE);
|
||||
|
||||
assert(load<i32>(HEAP_BASE) == 0);
|
||||
assert(load<i32>(HEAP_BASE + 4) == 0);
|
||||
|
||||
assert(arr[0] == 0);
|
||||
assert(arr[1] == 0);
|
||||
|
||||
arr[0] = 42;
|
||||
arr[1] = 24;
|
||||
|
||||
assert(load<i32>(HEAP_BASE) == 42);
|
||||
assert(load<i32>(HEAP_BASE + 4) == 24);
|
||||
|
||||
assert(arr[0] == 42);
|
||||
assert(arr[1] == 24);
|
||||
|
||||
assert((arr[3] = 9000) == 9000);
|
||||
|
||||
assert(load<i32>(HEAP_BASE + 12) == 9000);
|
||||
assert(arr[3] == 9000);
|
Reference in New Issue
Block a user