From 6392f1fde9a1177085954e42b9517f73acac88fe Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 15 Apr 2021 22:51:08 -0700 Subject: first session programming _within_ the Mu computer I tried building a function to draw a horizontal line across the screen. Here's what I have in data.txt: ( (globals . ( (horline . (fn () (screen y) (horline_1 screen y 0 (width screen)))) (horline_1 . (fn () (screen y lo hi) (if (>= lo hi) () ((fn () (pixel screen lo y 12) (horline_1 screen y (+ lo 1) hi)))))) )) (sandbox . (horline_1 screen 0 0 20)) ) $ dd if=/dev/zero of=data.img count=20160 $ cat data.txt |dd of=data.img conv=notrunc $ ./translate shell/*.mu && qemu-system-i386 -hda disk.img -hdb data.img Result: I can't call (horline screen 0) over a fake screen of width 40. Some stream overflows somewhere after all the tweaks to various fixed-size buffers scattered throughout the app. Calling horline_1 gets to a 'hi' column of 20, but not to 30. --- shell/evaluate.mu | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'shell/evaluate.mu') diff --git a/shell/evaluate.mu b/shell/evaluate.mu index 3aedb7c7..ebdbe486 100644 --- a/shell/evaluate.mu +++ b/shell/evaluate.mu @@ -27,6 +27,7 @@ fn evaluate _in: (addr handle cell), out: (addr handle cell), env-h: (handle cel var nil?/eax: boolean <- nil? in-addr compare nil?, 0/false break-if-= +#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "nil|", 7/fg, 0/bg # nil is a literal trace-text trace, "eval", "nil" copy-object _in, out @@ -38,6 +39,7 @@ fn evaluate _in: (addr handle cell), out: (addr handle cell), env-h: (handle cel { break-if-!= # numbers are literals +#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "number|", 7/fg, 0/bg trace-text trace, "eval", "number" copy-object _in, out trace-higher trace @@ -47,7 +49,9 @@ fn evaluate _in: (addr handle cell), out: (addr handle cell), env-h: (handle cel { break-if-!= trace-text trace, "eval", "symbol" +#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "syma|", 7/fg, 0/bg lookup-symbol in-addr, out, env-h, globals, trace, screen-cell, keyboard-cell +#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "symz|", 7/fg, 0/bg trace-higher trace return } @@ -90,6 +94,7 @@ fn evaluate _in: (addr handle cell), out: (addr handle cell), env-h: (handle cel break-if-= # trace-text trace, "eval", "quote" +#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "quote|", 7/fg, 0/bg copy-object rest-ah, out trace-higher trace return @@ -110,6 +115,7 @@ fn evaluate _in: (addr handle cell), out: (addr handle cell), env-h: (handle cel compare set?, 0/false break-if-= # +#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "set|", 7/fg, 0/bg trace-text trace, "eval", "set" trace-text trace, "eval", "evaluating second arg" var rest/eax: (addr cell) <- lookup *rest-ah @@ -208,13 +214,13 @@ fn evaluate _in: (addr handle cell), out: (addr handle cell), env-h: (handle cel var evaluated-list/eax: (addr cell) <- lookup *evaluated-list-ah var function-ah/ecx: (addr handle cell) <- get evaluated-list, left var args-ah/edx: (addr handle cell) <- get evaluated-list, right -#? dump-cell args-ah -#? abort "aaa" +#? set-cursor-position 0/screen, 0, 0 +#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "a", 7/fg, 0/bg apply function-ah, args-ah, out, globals, trace, screen-cell, keyboard-cell trace-higher trace # trace "=> " out {{{ { - var stream-storage: (stream byte 0x40) + var stream-storage: (stream byte 0x100) var stream/ecx: (addr stream byte) <- address stream-storage write stream, "=> " print-cell out, stream, 0/no-trace @@ -290,7 +296,9 @@ fn apply-function params-ah: (addr handle cell), args-ah: (addr handle cell), _b # evaluate each expression, writing result to `out` { var curr-ah/eax: (addr handle cell) <- get body, left +#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "before call|", 7/fg, 0/bg evaluate curr-ah, out, *new-env-ah, globals, trace, screen-cell, keyboard-cell +#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "y", 7/fg, 0/bg } # body-ah <- get body, right @@ -386,7 +394,7 @@ fn push-bindings _params-ah: (addr handle cell), _args-ah: (addr handle cell), o fn lookup-symbol sym: (addr cell), out: (addr handle cell), env-h: (handle cell), globals: (addr global-table), trace: (addr trace), screen-cell: (addr handle cell), keyboard-cell: (addr handle cell) { # trace sym { - var stream-storage: (stream byte 0x40) + var stream-storage: (stream byte 0x100) var stream/ecx: (addr stream byte) <- address stream-storage write stream, "look up " var sym2/eax: (addr cell) <- copy sym @@ -423,7 +431,7 @@ fn lookup-symbol sym: (addr cell), out: (addr handle cell), env-h: (handle cell) var error?/eax: boolean <- has-errors? trace compare error?, 0/false break-if-!= - var stream-storage: (stream byte 0x40) + var stream-storage: (stream byte 0x100) var stream/ecx: (addr stream byte) <- address stream-storage write stream, "=> " print-cell out, stream, 0/no-trace @@ -473,7 +481,7 @@ fn lookup-symbol sym: (addr cell), out: (addr handle cell), env-h: (handle cell) var error?/eax: boolean <- has-errors? trace compare error?, 0/false break-if-!= - var stream-storage: (stream byte 0x40) + var stream-storage: (stream byte 0x200) var stream/ecx: (addr stream byte) <- address stream-storage write stream, "=> " print-cell out, stream, 0/no-trace @@ -495,7 +503,7 @@ fn lookup-symbol sym: (addr cell), out: (addr handle cell), env-h: (handle cell) var error?/eax: boolean <- has-errors? trace compare error?, 0/false break-if-!= - var stream-storage: (stream byte 0x40) + var stream-storage: (stream byte 0x100) var stream/ecx: (addr stream byte) <- address stream-storage write stream, "=> " print-cell out, stream, 0/no-trace -- cgit 1.4.1-2-gfad0