https://github.com/akkartik/mu/blob/main/apps/tile/int-stack.mu
 1 type int-stack {
 2   data: (handle array int)
 3   top: int
 4 }
 5 
 6 fn initialize-int-stack _self: (addr int-stack), n: int {
 7   var self/esi: (addr int-stack) <- copy _self
 8   var d/edi: (addr handle array int) <- get self, data
 9   populate d, n
10   var top/eax: (addr int) <- get self, top
11   copy-to *top, 0
12 }
13 
14 fn clear-int-stack _self: (addr int-stack) {
15   var self/esi: (addr int-stack) <- copy _self
16   var top/eax: (addr int) <- get self, top
17   copy-to *top, 0
18 }
19 
20 fn push-int-stack _self: (addr int-stack), _val: int {
21   var self/esi: (addr int-stack) <- copy _self
22   var top-addr/ecx: (addr int) <- get self, top
23   var data-ah/edx: (addr handle array int) <- get self, data
24   var data/eax: (addr array int) <- lookup *data-ah
25   var top/edx: int <- copy *top-addr
26   var dest-addr/edx: (addr int) <- index data, top
27   var val/eax: int <- copy _val
28   copy-to *dest-addr, val
29   add-to *top-addr, 1
30 }
31 
32 fn pop-int-stack _self: (addr int-stack) -> _/eax: int {
33   var self/esi: (addr int-stack) <- copy _self
34   var top-addr/ecx: (addr int) <- get self, top
35   {
36     compare *top-addr, 0
37     break-if->
38     return 0
39   }
40   subtract-from *top-addr, 1
41   var data-ah/edx: (addr handle array int) <- get self, data
42   var data/eax: (addr array int) <- lookup *data-ah
43   var top/edx: int <- copy *top-addr
44   var result-addr/eax: (addr int) <- index data, top
45   return *result-addr
46 }
47 
48 fn int-stack-empty? _self: (addr int-stack) -> _/eax: boolean {
49   var self/esi: (addr int-stack) <- copy _self
50   var top-addr/eax: (addr int) <- get self, top
51   compare *top-addr, 0
52   {
53     break-if-!=
54     return 1  # true
55   }
56   return 0  # false
57 }
58 
59 fn int-stack-length _self: (addr int-stack) -> _/eax: int {
60   var self/esi: (addr int-stack) <- copy _self
61   var top-addr/eax: (addr int) <- get self, top
62   return *top-addr
63 }