From 62151e17c463c640464de752afbd41e279f4ba2a Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 3 Nov 2020 22:40:47 -0800 Subject: 7175 --- html/apps/tile/main.mu.html | 238 ++++++++++++++++++++++---------------------- 1 file changed, 118 insertions(+), 120 deletions(-) (limited to 'html/apps/tile/main.mu.html') diff --git a/html/apps/tile/main.mu.html b/html/apps/tile/main.mu.html index 8e329fff..745ba507 100644 --- a/html/apps/tile/main.mu.html +++ b/html/apps/tile/main.mu.html @@ -60,128 +60,126 @@ if ('onhashchange' in window) { 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 $main-body: { - 5 compare len, 2 - 6 { - 7 break-if-!= - 8 # if single arg is 'test', run tests - 9 var tmp/ecx: (addr addr array byte) <- index args, 1 - 10 var tmp2/eax: boolean <- string-equal? *tmp, "test" - 11 compare tmp2, 0 # false - 12 { - 13 break-if-= - 14 run-tests - 15 return 0 # TODO: get at Num-test-failures somehow - 16 } - 17 # if single arg is 'screen', run in full-screen mode - 18 tmp2 <- string-equal? *tmp, "screen" - 19 compare tmp2, 0 # false - 20 { - 21 break-if-= - 22 interactive - 23 return 0 - 24 } - 25 # if single arg is 'type', run in typewriter mode - 26 tmp2 <- string-equal? *tmp, "type" - 27 compare tmp2, 0 # false - 28 { - 29 break-if-= - 30 repl - 31 return 0 - 32 } - 33 # if single arg is 'test' ... - 34 tmp2 <- string-equal? *tmp, "test2" - 35 compare tmp2, 0 # false - 36 { - 37 break-if-= - 38 test - 39 return 0 - 40 } - 41 } - 42 # otherwise error message - 43 print-string-to-real-screen "usage:\n" - 44 print-string-to-real-screen " to run tests: tile test\n" - 45 print-string-to-real-screen " full-screen mode: tile screen\n" - 46 print-string-to-real-screen " regular REPL: tile type\n" - 47 return 1 - 48 } - 49 } - 50 - 51 fn interactive { - 52 enable-screen-grid-mode - 53 enable-keyboard-immediate-mode - 54 var env-storage: environment - 55 var env/esi: (addr environment) <- address env-storage - 56 initialize-environment env - 57 draw-screen env - 58 { - 59 var key/eax: grapheme <- read-key-from-real-keyboard - 60 compare key, 0x11 # 'ctrl-q' - 61 break-if-= - 62 process env, key - 63 render env - 64 loop - 65 } - 66 enable-keyboard-type-mode - 67 enable-screen-type-mode - 68 } - 69 - 70 fn test { - 71 test-surface-pin-at-origin - 72 #? var env-storage: environment - 73 #? var env/esi: (addr environment) <- address env-storage - 74 #? initialize-environment-with-fake-screen env, 5, 0xa - 75 #? var g/eax: grapheme <- copy 0x22 # '"' + 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 draw-screen env + 56 { + 57 var key/eax: grapheme <- read-key-from-real-keyboard + 58 compare key, 0x11 # 'ctrl-q' + 59 break-if-= + 60 process env, key + 61 render env + 62 loop + 63 } + 64 enable-keyboard-type-mode + 65 enable-screen-type-mode + 66 } + 67 + 68 fn test { + 69 test-surface-pin-at-origin + 70 #? var env-storage: environment + 71 #? var env/esi: (addr environment) <- address env-storage + 72 #? initialize-environment-with-fake-screen env, 5, 0xa + 73 #? var g/eax: grapheme <- copy 0x22 # '"' + 74 #? process env, g + 75 #? g <- copy 0x61 # 'a' 76 #? process env, g - 77 #? g <- copy 0x61 # 'a' + 77 #? g <- copy 0x22 # '"' 78 #? process env, g - 79 #? g <- copy 0x22 # '"' - 80 #? process env, g - 81 #? render env - 82 } - 83 - 84 fn repl { - 85 { - 86 # prompt - 87 print-string-to-real-screen "> " - 88 # read - 89 var line-storage: (stream byte 0x100) - 90 var line/ecx: (addr stream byte) <- address line-storage - 91 clear-stream line - 92 read-line-from-real-keyboard line - 93 var done?/eax: boolean <- stream-empty? line - 94 compare done?, 0 # false - 95 break-if-!= - 96 # parse - 97 var env-storage: environment - 98 var env/esi: (addr environment) <- address env-storage - 99 initialize-environment env -100 { -101 var done?/eax: boolean <- stream-empty? line -102 compare done?, 0 # false -103 break-if-!= -104 var g/eax: grapheme <- read-grapheme line -105 process env, g -106 loop -107 } -108 # eval -109 var stack-storage: value-stack -110 var stack/edi: (addr value-stack) <- address stack-storage -111 initialize-value-stack stack, 0x10 -112 evaluate-environment env, stack -113 # print -114 var empty?/eax: boolean <- value-stack-empty? stack -115 { -116 compare empty?, 0 # false -117 break-if-!= -118 var result/eax: int <- pop-int-from-value-stack stack -119 print-int32-decimal-to-real-screen result -120 print-string-to-real-screen "\n" -121 } -122 # -123 loop -124 } -125 } + 79 #? render env + 80 } + 81 + 82 fn repl { + 83 { + 84 # prompt + 85 print-string-to-real-screen "> " + 86 # read + 87 var line-storage: (stream byte 0x100) + 88 var line/ecx: (addr stream byte) <- address line-storage + 89 clear-stream line + 90 read-line-from-real-keyboard line + 91 var done?/eax: boolean <- stream-empty? line + 92 compare done?, 0 # false + 93 break-if-!= + 94 # parse + 95 var env-storage: environment + 96 var env/esi: (addr environment) <- address env-storage + 97 initialize-environment env + 98 { + 99 var done?/eax: boolean <- stream-empty? line +100 compare done?, 0 # false +101 break-if-!= +102 var g/eax: grapheme <- read-grapheme line +103 process env, g +104 loop +105 } +106 # eval +107 var stack-storage: value-stack +108 var stack/edi: (addr value-stack) <- address stack-storage +109 initialize-value-stack stack, 0x10 +110 evaluate-environment env, stack +111 # print +112 var empty?/eax: boolean <- value-stack-empty? stack +113 { +114 compare empty?, 0 # false +115 break-if-!= +116 var result/eax: int <- pop-int-from-value-stack stack +117 print-int32-decimal-to-real-screen result +118 print-string-to-real-screen "\n" +119 } +120 # +121 loop +122 } +123 } -- cgit 1.4.1-2-gfad0