-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathgc_struct_list01.wat
43 lines (40 loc) · 1.02 KB
/
gc_struct_list01.wat
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
;; INNER_CALIBRATION = 650
(module
(type $st (struct (field $f (ref null $st))))
(func $main (export "main")
(local $y i32)
(local $z (ref null $st))
(local.set $z (call $alloc (ref.null $st) (i32.const 65)))
(local.set $y (i32.const __INNER_ITERATIONS__))
(loop $l
(call $walk (local.get $z))
drop
(local.tee $y (i32.sub (local.get $y) (i32.const 1)))
(br_if $l)
)
)
(func $alloc (param (ref null $st) i32) (result (ref null $st))
(block $done
(loop $l
(br_if $done
(i32.eqz (local.get 1)))
(local.set 0 (struct.new $st (local.get 0)))
(local.set 1 (i32.sub (local.get 1) (i32.const 1)))
(br $l)
)
)
(local.get 0)
)
(func $walk (param (ref null $st)) (result i32)
(local $len i32)
(block $done
(loop $l
(br_if $done (ref.is_null (local.get 0)))
(local.set 0 (struct.get $st $f (local.get 0)))
(local.set $len (i32.add (local.get $len) (i32.const 1)))
(br $l)
)
)
(local.get $len)
)
)