From e2f18e8866bd75669c04bff52c3f8e96d13eeb4e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 28 Jul 2021 23:28:29 -0700 Subject: [PATCH] shell: literal images --- 317abort.subx | 7 ++----- shell/evaluate.mu | 28 ++++++++++++++++++++++++++++ shell/macroexpand.mu | 9 +++++++++ shell/print.mu | 2 +- translate_subx | 2 +- translate_subx_emulated | 2 +- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/317abort.subx b/317abort.subx index 5ee3b37f..2b464658 100644 --- a/317abort.subx +++ b/317abort.subx @@ -81,11 +81,8 @@ load-debug-symbols: # labels: (addr stream {start-address, label-slice}) c7 0/subop/copy *ecx 0/imm32 # write index c7 0/subop/copy *(ecx+4) 0/imm32 # read index c7 0/subop/copy *(ecx+8) 0x01000000/imm32 # stream capacity = 16MB - # load 0x400 sectors starting from sector 10080 = 0x2760 - (read-ata-disk Primary-bus-primary-drive 0x2760 0x100 %ecx) - (read-ata-disk Primary-bus-primary-drive 0x2860 0x100 %ecx) - (read-ata-disk Primary-bus-primary-drive 0x2960 0x100 %ecx) - (read-ata-disk Primary-bus-primary-drive 0x2a60 0x100 %ecx) + # load sectors starting from sector 10080 = 0x2760 + (load-sectors Primary-bus-primary-drive 0x2760 0x800 %ecx) # 0x800 sectors = 1MB # - parse pointers to portions of this stream into labels # var curr/ecx: (addr byte) = s->data 81 0/subop/add %ecx 0xc/imm32 diff --git a/shell/evaluate.mu b/shell/evaluate.mu index 932a0fa5..c78f1e23 100644 --- a/shell/evaluate.mu +++ b/shell/evaluate.mu @@ -171,6 +171,20 @@ fn evaluate _in-ah: (addr handle cell), _out-ah: (addr handle cell), env-h: (han trace-higher trace return } + $evaluate:literal-image: { + # trees starting with "litimg" are literals + var expr/esi: (addr cell) <- copy in + var in/edx: (addr cell) <- copy in + var first-ah/ecx: (addr handle cell) <- get in, left + var first/eax: (addr cell) <- lookup *first-ah + var litimg?/eax: boolean <- litimg? first + compare litimg?, 0/false + break-if-= + trace-text trace, "eval", "literal image" + copy-object _in-ah, _out-ah + trace-higher trace + return + } $evaluate:anonymous-function: { # trees starting with "fn" are anonymous functions var expr/esi: (addr cell) <- copy in @@ -1546,6 +1560,20 @@ fn litmac? _x: (addr cell) -> _/eax: boolean { return result } +fn litimg? _x: (addr cell) -> _/eax: boolean { + var x/esi: (addr cell) <- copy _x + var type/eax: (addr int) <- get x, type + compare *type, 2/symbol + { + break-if-= + return 0/false + } + var contents-ah/eax: (addr handle stream byte) <- get x, text-data + var contents/eax: (addr stream byte) <- lookup *contents-ah + var result/eax: boolean <- stream-data-equal? contents, "litimg" + return result +} + fn test-evaluate-is-well-behaved { var t-storage: trace var t/esi: (addr trace) <- address t-storage diff --git a/shell/macroexpand.mu b/shell/macroexpand.mu index f65ead85..6cfae474 100644 --- a/shell/macroexpand.mu +++ b/shell/macroexpand.mu @@ -103,6 +103,15 @@ fn macroexpand-iter _expr-ah: (addr handle cell), globals: (addr global-table), trace-higher trace return 0/false } + { + var litimg?/eax: boolean <- litimg? first + compare litimg?, 0/false + break-if-= + # litimg is a literal + trace-text trace, "mac", "literal image" + trace-higher trace + return 0/false + } var result/edi: boolean <- copy 0/false # for each builtin, expand only what will later be evaluated $macroexpand-iter:anonymous-function: { diff --git a/shell/print.mu b/shell/print.mu index 470ceae3..90e4a832 100644 --- a/shell/print.mu +++ b/shell/print.mu @@ -235,7 +235,7 @@ fn print-stream _in: (addr cell), out: (addr stream byte), trace: (addr trace) { compare should-trace?, 0/false break-if-= rewind-stream data - var stream-storage: (stream byte 0x40) + var stream-storage: (stream byte 0x400) var stream/ecx: (addr stream byte) <- address stream-storage write stream, "=> stream " write-stream-immutable stream, data diff --git a/translate_subx b/translate_subx index 391a9b43..4970a77a 100755 --- a/translate_subx +++ b/translate_subx @@ -49,7 +49,7 @@ fi # Latter half of disk is for debug info. dd if=labels of=code.img seek=10080 conv=notrunc # keep this sync'd with abort.subx -if [ `stat --printf="%s" labels` -ge 524288 ] # 4 reads * 256 sectors * 512 bytes per sector +if [ `stat --printf="%s" labels` -ge 1048576 ] # 8 reads * 256 sectors * 512 bytes per sector then echo "labels won't all be loaded on abort" exit 1 diff --git a/translate_subx_emulated b/translate_subx_emulated index 6a025e9c..689d1712 100755 --- a/translate_subx_emulated +++ b/translate_subx_emulated @@ -53,7 +53,7 @@ fi # Latter half of disk is for debug info. dd if=labels of=code.img seek=10080 conv=notrunc # keep this sync'd with abort.subx -if [ `stat --printf="%s" labels` -ge 524288 ] # 4 reads * 256 sectors * 512 bytes per sector +if [ `stat --printf="%s" labels` -ge 1048576 ] # 8 reads * 256 sectors * 512 bytes per sector then echo "labels won't all be loaded on abort" exit 1