https://github.com/akkartik/mu/blob/main/linux/tile/main.mu
  1 fn main args-on-stack: (addr array addr array byte) -> _/ebx: int {
  2   var args/eax: (addr array addr array byte) <- copy args-on-stack
  3   var len/ecx: int <- length args
  4   compare len, 2
  5   {
  6     break-if-!=
  7     # if single arg is 'test', run tests
  8     var tmp/ecx: (addr addr array byte) <- index args, 1
  9     var tmp2/eax: boolean <- string-equal? *tmp, "test"
 10     compare tmp2, 0/false
 11     {
 12       break-if-=
 13       run-tests
 14       return 0  # TODO: get at Num-test-failures somehow
 15     }
 16     # if single arg is 'screen', run in full-screen mode
 17     tmp2 <- string-equal? *tmp, "screen"
 18     compare tmp2, 0/false
 19     {
 20       break-if-=
 21       interactive
 22       return 0
 23     }
 24     # if single arg is 'type', run in typewriter mode
 25     tmp2 <- string-equal? *tmp, "type"
 26     compare tmp2, 0/false
 27     {
 28       break-if-=
 29       repl
 30       return 0
 31     }
 32     # if single arg is 'test' ...
 33     tmp2 <- string-equal? *tmp, "test2"
 34     compare tmp2, 0/false
 35     {
 36       break-if-=
 37       test
 38       return 0
 39     }
 40   }
 41   # otherwise error message
 42   print-string-to-real-screen "usage:\n"
 43   print-string-to-real-screen "  to run tests: tile test\n"
 44   print-string-to-real-screen "  full-screen mode: tile screen\n"
 45   print-string-to-real-screen "  regular REPL: tile type\n"
 46   return 1
 47 }
 48 
 49 fn interactive {
 50   enable-screen-grid-mode
 51   enable-keyboard-immediate-mode
 52   var env-storage: environment
 53   var env/esi: (addr environment) <- address env-storage
 54   initialize-environment env
 55   {
 56     render env
 57     var key/eax: grapheme <- read-key-from-real-keyboard
 58     compare key, 0x11/ctrl-q
 59     break-if-=
 60     process env, key
 61     loop
 62   }
 63   enable-keyboard-type-mode
 64   enable-screen-type-mode
 65 }
 66 
 67 fn test {
 68   var env-storage: environment
 69   var env/esi: (addr environment) <- address env-storage
 70   initialize-environment-with-fake-screen env, 0x20, 0xa0
 71   render env
 72 }
 73 
 74 fn process-all env: (addr environment), cmds: (addr array byte) {
 75   var cmds-stream: (stream byte 0x100)
 76   var cmds-stream-a/esi: (addr stream byte) <- address cmds-stream
 77   write cmds-stream-a, cmds
 78   {
 79     var done?/eax: boolean <- stream-empty? cmds-stream-a
 80     compare done?, 0/false
 81     break-if-!=
 82     var g/eax: grapheme <- read-grapheme cmds-stream-a
 83     process env, g
 84     loop
 85   }
 86 }
 87 
 88 fn repl {
 89   {
 90     # prompt
 91     print-string-to-real-screen "> "
 92     # read
 93     var line-storage: (stream byte 0x100)
 94     var line/ecx: (addr stream byte) <- address line-storage
 95     clear-stream line
 96     read-line-from-real-keyboard line
 97     var done?/eax: boolean <- stream-empty? line
 98     compare done?, 0/false
 99     break-if-!=
100     # parse
101     var env-storage: environment
102     var env/esi: (addr environment) <- address env-storage
103     initialize-environment env
104     {
105       var done?/eax: boolean <- stream-empty? line
106       compare done?, 0/false
107       break-if-!=
108       var g/eax: grapheme <- read-grapheme line
109       process env, g
110       loop
111     }
112     # eval
113     var stack-storage: value-stack
114     var stack/edi: (addr value-stack) <- address stack-storage
115     initialize-value-stack stack, 0x10
116     evaluate-environment env, stack
117     # print
118     var empty?/eax: boolean <- value-stack-empty? stack
119     {
120       compare empty?, 0/false
121       break-if-!=
122       var result/xmm0: float <- pop-number-from-value-stack stack
123       print-float-decimal-approximate 0, result, 3
124       print-string 0, "\n"
125       print-string 0, "width: "
126       var width/eax: int <- float-size result, 3
127       print-int32-decimal 0, width
128       print-string 0, "\n"
129     }
130     #
131     loop
132   }
133 }