forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcarray.ts
More file actions
26 lines (18 loc) · 707 Bytes
/
carray.ts
File metadata and controls
26 lines (18 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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);