From 3d1c4216ede8c628558c9fe700fb2be1aa08b473 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 2 Nov 2020 21:24:53 -0800 Subject: 7162 --- html/apps/tile/value-stack.mu.html | 285 +++++++++++++++++++++++++++---------- 1 file changed, 213 insertions(+), 72 deletions(-) (limited to 'html/apps/tile/value-stack.mu.html') diff --git a/html/apps/tile/value-stack.mu.html b/html/apps/tile/value-stack.mu.html index 3afd6075..50db3d41 100644 --- a/html/apps/tile/value-stack.mu.html +++ b/html/apps/tile/value-stack.mu.html @@ -86,14 +86,14 @@ if ('onhashchange' in window) { 27 var top/edx: int <- copy *top-addr 28 var dest-offset/edx: (offset value) <- compute-offset data, top 29 var dest-addr/edx: (addr value) <- index data, dest-offset - 30 var dest-addr2/eax: (addr int) <- get dest-addr, scalar-data + 30 var dest-addr2/eax: (addr int) <- get dest-addr, int-data 31 var val/esi: int <- copy _val 32 #? print-int32-hex-to-real-screen val 33 copy-to *dest-addr2, val 34 increment *top-addr 35 } 36 - 37 fn push-value-stack _self: (addr value-stack), val: (addr value) { + 37 fn push-string-to-value-stack _self: (addr value-stack), val: (handle array byte) { 38 var self/esi: (addr value-stack) <- copy _self 39 var top-addr/ecx: (addr int) <- get self, top 40 var data-ah/edx: (addr handle array value) <- get self, data @@ -101,76 +101,217 @@ if ('onhashchange' in window) { 42 var top/edx: int <- copy *top-addr 43 var dest-offset/edx: (offset value) <- compute-offset data, top 44 var dest-addr/edx: (addr value) <- index data, dest-offset - 45 copy-object val, dest-addr - 46 increment *top-addr - 47 } - 48 - 49 fn pop-int-from-value-stack _self: (addr value-stack) -> val/eax: int { - 50 $pop-int-from-value-stack:body: { - 51 var self/esi: (addr value-stack) <- copy _self - 52 var top-addr/ecx: (addr int) <- get self, top - 53 { - 54 compare *top-addr, 0 - 55 break-if-> - 56 val <- copy -1 - 57 break $pop-int-from-value-stack:body - 58 } - 59 decrement *top-addr - 60 var data-ah/edx: (addr handle array value) <- get self, data - 61 var data/eax: (addr array value) <- lookup *data-ah - 62 var top/edx: int <- copy *top-addr - 63 var dest-offset/edx: (offset value) <- compute-offset data, top - 64 var result-addr/eax: (addr value) <- index data, dest-offset - 65 var result-addr2/eax: (addr int) <- get result-addr, scalar-data - 66 val <- copy *result-addr2 - 67 } - 68 } - 69 - 70 fn value-stack-empty? _self: (addr value-stack) -> result/eax: boolean { - 71 $value-stack-empty?:body: { - 72 var self/esi: (addr value-stack) <- copy _self - 73 var top/eax: (addr int) <- get self, top - 74 compare *top, 0 - 75 { - 76 break-if-!= - 77 result <- copy 1 # true - 78 break $value-stack-empty?:body - 79 } - 80 result <- copy 0 # false - 81 } - 82 } - 83 - 84 fn value-stack-length _self: (addr value-stack) -> result/eax: int { - 85 var self/esi: (addr value-stack) <- copy _self - 86 var top-addr/eax: (addr int) <- get self, top - 87 result <- copy *top-addr - 88 } - 89 - 90 fn value-stack-max-width _self: (addr value-stack) -> result/eax: int { - 91 var self/esi: (addr value-stack) <- copy _self - 92 var data-ah/edi: (addr handle array value) <- get self, data - 93 var _data/eax: (addr array value) <- lookup *data-ah - 94 var data/edi: (addr array value) <- copy _data - 95 var top-addr/ecx: (addr int) <- get self, top - 96 var i/ebx: int <- copy 0 - 97 var out: int - 98 { - 99 compare i, *top-addr -100 break-if->= -101 var o/edx: (offset value) <- compute-offset data, i -102 var g/edx: (addr value) <- index data, o -103 var g2/edx: (addr int) <- get g, scalar-data -104 var w/eax: int <- decimal-size *g2 -105 compare w, out -106 { -107 break-if-<= -108 copy-to out, w -109 } -110 i <- increment -111 loop -112 } -113 result <- copy out -114 } + 45 var dest-addr2/eax: (addr handle array byte) <- get dest-addr, text-data + 46 copy-handle val, dest-addr2 + 47 var dest-addr3/eax: (addr int) <- get dest-addr, type + 48 #? print-string 0, "setting type to 1: " + 49 #? { + 50 #? var foo/eax: int <- copy dest-addr3 + 51 #? print-int32-hex 0, foo + 52 #? } + 53 #? print-string 0, "\n" + 54 copy-to *dest-addr3, 1 # type string + 55 increment *top-addr + 56 } + 57 + 58 fn push-array-to-value-stack _self: (addr value-stack), val: (handle array value) { + 59 var self/esi: (addr value-stack) <- copy _self + 60 var top-addr/ecx: (addr int) <- get self, top + 61 var data-ah/edx: (addr handle array value) <- get self, data + 62 var data/eax: (addr array value) <- lookup *data-ah + 63 var top/edx: int <- copy *top-addr + 64 var dest-offset/edx: (offset value) <- compute-offset data, top + 65 var dest-addr/edx: (addr value) <- index data, dest-offset + 66 var dest-addr2/eax: (addr handle array value) <- get dest-addr, array-data + 67 copy-handle val, dest-addr2 + 68 # update type + 69 var dest-addr3/eax: (addr int) <- get dest-addr, type + 70 copy-to *dest-addr3, 2 # type array + 71 increment *top-addr + 72 } + 73 + 74 fn push-value-stack _self: (addr value-stack), val: (addr value) { + 75 var self/esi: (addr value-stack) <- copy _self + 76 var top-addr/ecx: (addr int) <- get self, top + 77 var data-ah/edx: (addr handle array value) <- get self, data + 78 var data/eax: (addr array value) <- lookup *data-ah + 79 var top/edx: int <- copy *top-addr + 80 var dest-offset/edx: (offset value) <- compute-offset data, top + 81 var dest-addr/edx: (addr value) <- index data, dest-offset + 82 copy-object val, dest-addr + 83 increment *top-addr + 84 } + 85 + 86 fn pop-int-from-value-stack _self: (addr value-stack) -> _/eax: int { + 87 var self/esi: (addr value-stack) <- copy _self + 88 var top-addr/ecx: (addr int) <- get self, top + 89 { + 90 compare *top-addr, 0 + 91 break-if-> + 92 return -1 + 93 } + 94 decrement *top-addr + 95 var data-ah/edx: (addr handle array value) <- get self, data + 96 var data/eax: (addr array value) <- lookup *data-ah + 97 var top/edx: int <- copy *top-addr + 98 var dest-offset/edx: (offset value) <- compute-offset data, top + 99 var result-addr/eax: (addr value) <- index data, dest-offset +100 var result-addr2/eax: (addr int) <- get result-addr, int-data +101 return *result-addr2 +102 } +103 +104 fn value-stack-empty? _self: (addr value-stack) -> _/eax: boolean { +105 var self/esi: (addr value-stack) <- copy _self +106 var top/eax: (addr int) <- get self, top +107 compare *top, 0 +108 { +109 break-if-!= +110 return 1 # true +111 } +112 return 0 # false +113 } +114 +115 fn value-stack-length _self: (addr value-stack) -> _/eax: int { +116 var self/esi: (addr value-stack) <- copy _self +117 var top-addr/eax: (addr int) <- get self, top +118 return *top-addr +119 } +120 +121 fn value-stack-max-width _self: (addr value-stack) -> _/eax: int { +122 var self/esi: (addr value-stack) <- copy _self +123 var data-ah/edi: (addr handle array value) <- get self, data +124 var _data/eax: (addr array value) <- lookup *data-ah +125 var data/edi: (addr array value) <- copy _data +126 var top-addr/ecx: (addr int) <- get self, top +127 var i/ebx: int <- copy 0 +128 var result: int +129 { +130 compare i, *top-addr +131 break-if->= +132 var o/edx: (offset value) <- compute-offset data, i +133 var v/edx: (addr value) <- index data, o +134 var w/eax: int <- value-width v, 1 # top-level=true +135 # if (w > result) w = result +136 { +137 compare w, result +138 break-if-<= +139 copy-to result, w +140 } +141 i <- increment +142 loop +143 } +144 return result +145 } +146 +147 fn value-width _v: (addr value), top-level: boolean -> _/eax: int { +148 var v/esi: (addr value) <- copy _v +149 var type/eax: (addr int) <- get v, type +150 { +151 compare *type, 0 # int +152 break-if-!= +153 var v-int/edx: (addr int) <- get v, int-data +154 var result/eax: int <- decimal-size *v-int +155 return result +156 } +157 { +158 compare *type, 1 # string +159 break-if-!= +160 var s-ah/eax: (addr handle array byte) <- get v, text-data +161 var s/eax: (addr array byte) <- lookup *s-ah +162 compare s, 0 +163 break-if-= +164 var result/eax: int <- length s +165 compare result, 0xd # max string size +166 { +167 break-if-<= +168 result <- copy 0xd +169 } +170 # if it's a nested string, include space for quotes +171 # we don't do this for the top-level, where the quotes will overflow +172 # into surrounding padding. +173 compare top-level, 0 # false +174 { +175 break-if-!= +176 result <- add 2 +177 } +178 return result +179 } +180 { +181 compare *type, 2 # array +182 break-if-!= +183 var a-ah/eax: (addr handle array value) <- get v, array-data +184 var a/eax: (addr array value) <- lookup *a-ah +185 compare a, 0 +186 break-if-= +187 var result/eax: int <- array-width a +188 return result +189 } +190 { +191 compare *type, 3 # file handle +192 break-if-!= +193 var f-ah/eax: (addr handle buffered-file) <- get v, file-data +194 var f/eax: (addr buffered-file) <- lookup *f-ah +195 compare f, 0 +196 break-if-= +197 # TODO: visualizing file handles +198 return 4 +199 } +200 return 0 +201 } +202 +203 # keep sync'd with render-array +204 fn array-width _a: (addr array value) -> _/eax: int { +205 var a/esi: (addr array value) <- copy _a +206 var max/ecx: int <- length a +207 var i/eax: int <- copy 0 +208 var result/edi: int <- copy 0 +209 { +210 compare i, max +211 break-if->= +212 { +213 compare i, 0 +214 break-if-= +215 result <- increment # for space +216 } +217 var off/ecx: (offset value) <- compute-offset a, i +218 var x/ecx: (addr value) <- index a, off +219 { +220 var w/eax: int <- value-width x, 0 +221 result <- add w +222 } +223 i <- increment +224 loop +225 } +226 # we won't add 2 for surrounding brackets since we don't surround arrays in +227 # spaces like other value types +228 return result +229 } +230 +231 fn save-lines in-h: (handle array (handle array byte)), _out-ah: (addr handle array value) { +232 var _in/eax: (addr array (handle array byte)) <- lookup in-h +233 var in/esi: (addr array (handle array byte)) <- copy _in +234 var len/ecx: int <- length in +235 var out-ah/edi: (addr handle array value) <- copy _out-ah +236 populate out-ah, len +237 var out/eax: (addr array value) <- lookup *out-ah +238 # copy in into out +239 var i/ebx: int <- copy 0 +240 { +241 compare i, len +242 break-if->= +243 #? print-int32-hex 0, i +244 #? print-string 0, "\n" +245 var src/ecx: (addr handle array byte) <- index in, i +246 var dest-offset/edx: (offset value) <- compute-offset out, i +247 var dest-val/edx: (addr value) <- index out, dest-offset +248 var dest/eax: (addr handle array byte) <- get dest-val, text-data +249 copy-object src, dest +250 var type/edx: (addr int) <- get dest-val, type +251 copy-to *type, 1 # string +252 i <- increment +253 loop +254 } +255 } -- cgit 1.4.1-2-gfad0