From 07bc1eeb90e1ff4e0c9931f4ad568fdd466b4298 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 5 Apr 2021 23:09:05 -0700 Subject: shell: save repl input to disk before running --- shell/main.mu | 4 ++-- shell/sandbox.mu | 51 +++++++++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 24 deletions(-) (limited to 'shell') diff --git a/shell/main.mu b/shell/main.mu index 1fafa42c..b6ceff95 100644 --- a/shell/main.mu +++ b/shell/main.mu @@ -16,7 +16,7 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) compare key, 0 loop-if-= # no way to quit right now; just reboot - edit-sandbox sandbox, key + edit-sandbox sandbox, key, screen, keyboard, data-disk } loop } @@ -36,7 +36,7 @@ fn load-sandbox data-disk: (addr disk), _self: (addr sandbox) { var key/eax: byte <- read-byte s compare key, 0/null break-if-= - edit-sandbox self, key + edit-sandbox self, key, 0/no-screen, 0/no-keyboard, 0/no-disk loop } } diff --git a/shell/sandbox.mu b/shell/sandbox.mu index e419063e..dec1cc94 100644 --- a/shell/sandbox.mu +++ b/shell/sandbox.mu @@ -100,25 +100,35 @@ fn render-sandbox-menu screen: (addr screen) { draw-text-rightward-from-cursor screen, " move to trace ", width, 7/fg, 0/bg } -fn edit-sandbox _self: (addr sandbox), key: byte { +fn edit-sandbox _self: (addr sandbox), key: byte, real-screen: (addr screen), real-keyboard: (addr keyboard), data-disk: (addr disk) { var self/esi: (addr sandbox) <- copy _self var g/edx: grapheme <- copy key - # running code + # ctrl-r { compare g, 0x12/ctrl-r break-if-!= - # ctrl-r: run function outside sandbox + # run function outside sandbox # required: fn (addr screen), (addr keyboard) # Mu will pass in the real screen and keyboard. return } + # ctrl-s { compare g, 0x13/ctrl-s break-if-!= - # ctrl-s: run sandbox(es) + # save to disk var data-ah/eax: (addr handle gap-buffer) <- get self, data var _data/eax: (addr gap-buffer) <- lookup *data-ah var data/ecx: (addr gap-buffer) <- copy _data + { + compare data-disk, 0/no-disk + break-if-= + var stream-storage: (stream byte 0x200) + var stream/esi: (addr stream byte) <- address stream-storage + emit-gap-buffer data, stream + store-sector data-disk, 0/lba, stream + } + # run sandbox var value-ah/eax: (addr handle stream byte) <- get self, value var _value/eax: (addr stream byte) <- lookup *value-ah var value/edx: (addr stream byte) <- copy _value @@ -126,9 +136,6 @@ fn edit-sandbox _self: (addr sandbox), key: byte { var trace/eax: (addr trace) <- lookup *trace-ah clear-trace trace run data, value, trace - # testing write to disk -#? rewind-stream value -#? store-first-sector-to-primary-bus-secondary-drive value return } # tab @@ -195,9 +202,9 @@ fn test-run-integer { var sandbox/esi: (addr sandbox) <- address sandbox-storage initialize-sandbox sandbox # type "1" - edit-sandbox sandbox, 0x31/1 + edit-sandbox sandbox, 0x31/1, 0/no-screen, 0/no-keyboard, 0/no-disk # eval - edit-sandbox sandbox, 0x13/ctrl-s + edit-sandbox sandbox, 0x13/ctrl-s, 0/no-screen, 0/no-keyboard, 0/no-disk # setup: screen var screen-on-stack: screen var screen/edi: (addr screen) <- address screen-on-stack @@ -214,12 +221,12 @@ fn test-run-with-spaces { var sandbox/esi: (addr sandbox) <- address sandbox-storage initialize-sandbox sandbox # type input with whitespace before and after - edit-sandbox sandbox, 0x20/space - edit-sandbox sandbox, 0x31/1 - edit-sandbox sandbox, 0x20/space - edit-sandbox sandbox, 0xa/newline + edit-sandbox sandbox, 0x20/space, 0/no-screen, 0/no-keyboard, 0/no-disk + edit-sandbox sandbox, 0x31/1, 0/no-screen, 0/no-keyboard, 0/no-disk + edit-sandbox sandbox, 0x20/space, 0/no-screen, 0/no-keyboard, 0/no-disk + edit-sandbox sandbox, 0xa/newline, 0/no-screen, 0/no-keyboard, 0/no-disk # eval - edit-sandbox sandbox, 0x13/ctrl-s + edit-sandbox sandbox, 0x13/ctrl-s, 0/no-screen, 0/no-keyboard, 0/no-disk # setup: screen var screen-on-stack: screen var screen/edi: (addr screen) <- address screen-on-stack @@ -237,10 +244,10 @@ fn test-run-error-invalid-integer { var sandbox/esi: (addr sandbox) <- address sandbox-storage initialize-sandbox sandbox # type "1a" - edit-sandbox sandbox, 0x31/1 - edit-sandbox sandbox, 0x61/a + edit-sandbox sandbox, 0x31/1, 0/no-screen, 0/no-keyboard, 0/no-disk + edit-sandbox sandbox, 0x61/a, 0/no-screen, 0/no-keyboard, 0/no-disk # eval - edit-sandbox sandbox, 0x13/ctrl-s + edit-sandbox sandbox, 0x13/ctrl-s, 0/no-screen, 0/no-keyboard, 0/no-disk # setup: screen var screen-on-stack: screen var screen/edi: (addr screen) <- address screen-on-stack @@ -257,10 +264,10 @@ fn test-run-move-cursor-into-trace { var sandbox/esi: (addr sandbox) <- address sandbox-storage initialize-sandbox sandbox # type "12" - edit-sandbox sandbox, 0x31/1 - edit-sandbox sandbox, 0x32/2 + edit-sandbox sandbox, 0x31/1, 0/no-screen, 0/no-keyboard, 0/no-disk + edit-sandbox sandbox, 0x32/2, 0/no-screen, 0/no-keyboard, 0/no-disk # eval - edit-sandbox sandbox, 0x13/ctrl-s + edit-sandbox sandbox, 0x13/ctrl-s, 0/no-screen, 0/no-keyboard, 0/no-disk # setup: screen var screen-on-stack: screen var screen/edi: (addr screen) <- address screen-on-stack @@ -274,7 +281,7 @@ fn test-run-move-cursor-into-trace { check-screen-row screen, 2/y, "=> 12 ", "F - test-run-move-cursor-into-trace/pre-2" check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-move-cursor-into-trace/pre-2/cursor" # move cursor into trace - edit-sandbox sandbox, 9/tab + edit-sandbox sandbox, 9/tab, 0/no-screen, 0/no-keyboard, 0/no-disk # render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height check-screen-row screen, 0/y, "12 ", "F - test-run-move-cursor-into-trace/trace-0" @@ -284,7 +291,7 @@ fn test-run-move-cursor-into-trace { check-screen-row screen, 2/y, "=> 12 ", "F - test-run-move-cursor-into-trace/trace-2" check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-move-cursor-into-trace/trace-2/cursor" # move cursor into input - edit-sandbox sandbox, 9/tab + edit-sandbox sandbox, 9/tab, 0/no-screen, 0/no-keyboard, 0/no-disk # render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height check-screen-row screen, 0/y, "12 ", "F - test-run-move-cursor-into-trace/input-0" -- cgit 1.4.1-2-gfad0 a id='n114' href='#n114'>114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371