-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy patharray.int
More file actions
45 lines (34 loc) · 862 Bytes
/
Copy patharray.int
File metadata and controls
45 lines (34 loc) · 862 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//@check
static a: &[i32] = [1, 2, 3];
static b: [i32; 3] = [1, 2, 3];
static c: i32 = a[1];
static a_ref: &i32 = &a[1];
static a_ref_val: i32 = *a_ref;
static empty: &[i32] = [];
function sum() -> i32 {
let sum: i32 = 0;
let i: u32 = 0;
loop {
if i >= 3 {
break;
}
sum = sum + a[i];
i = i + 1;
}
return sum;
}
static d: i32 = sum();
function array_ref(idx: i32) -> &[i32] {
let view: &[i32] = &a[1 + idx];
return &view[0];
}
function array_modification(idx: i32) -> &[i32] {
let values: &[i32] = [1, 2, 3];
let view: &[i32] = &values[idx];
view[0] = values[0];
// This return of course isn't valid C, but the
// interpreter uses reference counting so it's
// valid during compile time.
return values;
}
static new_arr: &[i32] = array_modification(1);