https://github.com/akkartik/mu/blob/main/shell/life.mu
1 fn state _grid: (addr array boolean), x: int, y: int -> _/eax: boolean {
2
3 compare x, 0
4 {
5 break-if->=
6 return 0/false
7 }
8 compare y, 0
9 {
10 break-if->=
11 return 0/false
12 }
13 compare x, 0x100/width
14 {
15 break-if-<
16 return 0/false
17 }
18 compare y, 0xc0/height
19 {
20 break-if-<
21 return 0/false
22 }
23 var idx/eax: int <- copy y
24 idx <- shift-left 8/log2width
25 idx <- add x
26 var grid/esi: (addr array boolean) <- copy _grid
27 var result/eax: (addr boolean) <- index grid, idx
28 return *result
29 }
30
31 fn set-state _grid: (addr array boolean), x: int, y: int, val: boolean {
32
33 var idx/eax: int <- copy y
34 idx <- shift-left 8/log2width
35 idx <- add x
36 var grid/esi: (addr array boolean) <- copy _grid
37 var result/eax: (addr boolean) <- index grid, idx
38 var src/ecx: boolean <- copy val
39 copy-to *result, src
40 }
41
42 fn num-live-neighbors grid: (addr array boolean), x: int, y: int -> _/eax: int {
43 var result/edi: int <- copy 0
44
45 decrement y
46 decrement x
47 var s/eax: boolean <- state grid, x, y
48 {
49 compare s, 0/false
50 break-if-=
51 result <- increment
52 }
53 increment x
54 s <- state grid, x, y
55 {
56 compare s, 0/false
57 break-if-=
58 result <- increment
59 }
60 increment x
61 s <- state grid, x, y
62 {
63 compare s, 0/false
64 break-if-=
65 result <- increment
66 }
67
68 increment y
69 s <- state grid, x, y
70 {
71 compare s, 0/false
72 break-if-=
73 result <- increment
74 }
75 subtract-from x, 2
76 s <- state grid, x, y
77 {
78 compare s, 0/false
79 break-if-=
80 result <- increment
81 }
82
83 increment y
84 s <- state grid, x, y
85 {
86 compare s, 0/false
87 break-if-=
88 result <- increment
89 }
90 increment x
91 s <- state grid, x, y
92 {
93 compare s, 0/false
94 break-if-=
95 result <- increment
96 }
97 increment x
98 s <- state grid, x, y
99 {
100 compare s, 0/false
101 break-if-=
102 result <- increment
103 }
104 return result
105 }
106
107 fn step old-grid: (addr array boolean), new-grid: (addr array boolean) {
108 var y/ecx: int <- cop<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.gui.displayable</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.gui.html"><font color="#ffffff">gui</font></a>.displayable</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/ranger/ranger/gui/displayable.py">/home/hut/ranger/ranger/gui/displayable.py</a></font></td></tr></table>
<p><tt># Copyright (c) 2009, 2010 hut <hut@lavabit.com><br>
#<br>
# Permission to use, copy, modify, and/or distribute this software for any<br>
# purpose with or without fee is hereby granted, provided that the above<br>
# copyright notice and this permission notice appear in all copies.<br>
#<br>
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES<br>
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF<br>
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR<br>
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES<br>
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN<br>
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF<br>
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.</tt></p>
<