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