From 9ee9f37dc78430ca32e00d4d4223b178150c5fee Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 2 Aug 2020 17:45:46 -0700 Subject: 6708 --- 403stream.mu | 46 ---------- 404screen.mu | 288 ----------------------------------------------------------- 404stream.mu | 46 ++++++++++ 405screen.mu | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 334 insertions(+), 334 deletions(-) delete mode 100644 403stream.mu delete mode 100644 404screen.mu create mode 100644 404stream.mu create mode 100644 405screen.mu diff --git a/403stream.mu b/403stream.mu deleted file mode 100644 index bf4ae883..00000000 --- a/403stream.mu +++ /dev/null @@ -1,46 +0,0 @@ -# Tests for Mu's stream primitives. - -fn test-stream { - # - write an int to a stream, then read it back - # step 1: initialize - var s: (stream int 4) - var s2/ecx: (addr stream int 4) <- address s - var tmp/eax: boolean <- stream-empty? s2 - check-true tmp, "F - test-stream/empty?/0" - tmp <- stream-full? s2 - check-false tmp, "F - test-stream/full?/0" - # step 2: write to stream - var x: int - copy-to x, 0x34 - var x2/edx: (addr int) <- address x - write-to-stream s2, x2 - tmp <- stream-empty? s2 - check-false tmp, "F - test-stream/empty?/1" - tmp <- stream-full? s2 - check-false tmp, "F - test-stream/full?/1" - # step 3: modify the value written (should make no difference) - copy-to x, 0 - # step 4: read back - var y: int - var y2/ebx: (addr int) <- address y - read-from-stream s2, y2 - tmp <- stream-empty? s2 - check-true tmp, "F - test-stream/empty?/2" - tmp <- stream-full? s2 - check-false tmp, "F - test-stream/full?/2" - # we read back what was written - check-ints-equal y, 0x34, "F - test-stream" -} - -fn test-stream-full { - # write an int to a stream of capacity 1 - var s: (stream int 1) - var s2/ecx: (addr stream int 1) <- address s - var tmp/eax: boolean <- stream-full? s2 - check-false tmp, "F - test-stream-full?/pre" - var x: int - var x2/edx: (addr int) <- address x - write-to-stream s2, x2 - tmp <- stream-full? s2 - check-true tmp, "F - test-stream-full?" -} diff --git a/404screen.mu b/404screen.mu deleted file mode 100644 index 8165e50f..00000000 --- a/404screen.mu +++ /dev/null @@ -1,288 +0,0 @@ -# Wrappers for real screen primitives that can be passed in a fake screen. - -type screen { - num-rows: int - num-cols: int - data: (handle array screen-cell) - pending-scroll?: boolean - top-index: int - cursor-row: int - cursor-col: int - cursor-hide?: boolean - curr-attributes: screen-cell -} - -type screen-cell { - color: int - background-color: int - bold?: boolean - underline?: boolean - reverse?: boolean - blink?: boolean -} - -fn initialize-screen screen: (addr screen), nrows: int, ncols: int { - var screen-addr/esi: (addr screen) <- copy screen - var tmp/eax: int <- copy 0 - var dest/edi: (addr int) <- copy 0 - # screen->num-rows = nrows - dest <- get screen-addr, num-rows - tmp <- copy nrows - copy-to *dest, tmp - # screen->num-cols = ncols - dest <- get screen-addr, num-cols - tmp <- copy ncols - copy-to *dest, tmp - # screen->data = new screen-cell[nrows*ncols] - { - var data-addr/edi: (addr handle array screen-cell) <- get screen-addr, data - tmp <- multiply nrows - populate data-addr, tmp - } - # screen->cursor-row = 1 - dest <- get screen-addr, cursor-row - copy-to *dest, 1 - # screen->cursor-col = 1 - dest <- get screen-addr, cursor-col - copy-to *dest, 1 - # screen->curr-attributes->background-color = 7 (simulate light background) - var tmp2/eax: (addr screen-cell) <- get screen-addr, curr-attributes - dest <- get tmp2, background-color - copy-to *dest, 7 -} - -fn screen-size screen: (addr screen) -> nrows/eax: int, ncols/ecx: int { -$screen-size:body: { - compare screen, 0 - { - break-if-!= - nrows, ncols <- real-screen-size - break $screen-size:body - } - { - break-if-= - # fake screen - var screen-addr/esi: (addr screen) <- copy screen - var tmp/edx: (addr int) <- get screen-addr, num-rows - nrows <- copy *tmp - tmp <- get screen-addr, num-cols - ncols <- copy *tmp - } -} -} - -fn clear-screen screen: (addr screen) { -$clear-screen:body: { - compare screen, 0 - { - break-if-!= - clear-real-screen - break $clear-screen:body - } - { - break-if-= - # fake screen - var space/edi: grapheme <- copy 0x20 - move-cursor screen, 1, 1 - var screen-addr/esi: (addr screen) <- copy screen - var i/eax: int <- copy 1 - var nrows/ecx: (addr int) <- get screen-addr, num-rows - { - compare i, *nrows - break-if-> - var j/edx: int <- copy 1 - var ncols/ebx: (addr int) <- get screen-addr, num-cols - { - compare j, *ncols - break-if-> - print-grapheme screen, space - j <- increment - loop - } - i <- increment - loop - } - move-cursor screen, 1, 1 - } -} -} - -fn move-cursor screen: (addr screen), row: int, column: int { -$move-cursor:body: { - compare screen, 0 - { - break-if-!= - move-cursor-on-real-screen row, column - break $move-cursor:body - } - { - break-if-= - # fake screen - } -} -} - -fn print-string screen: (addr screen), s: (addr array byte) { -$print-string:body: { - compare screen, 0 - { - break-if-!= - print-string-to-real-screen s - break $print-string:body - } - { - break-if-= - # fake screen - } -} -} - -fn print-grapheme screen: (addr screen), c: grapheme { -$print-grapheme:body: { - compare screen, 0 - { - break-if-!= - print-grapheme-to-real-screen c - break $print-grapheme:body - } - { - break-if-= - # fake screen - } -} -} - -fn print-int32-hex screen: (addr screen), n: int { -$print-int32-hex:body: { - compare screen, 0 - { - break-if-!= - print-int32-hex-to-real-screen n - break $print-int32-hex:body - } - { - break-if-= - # fake screen - } -} -} - -fn reset-formatting screen: (addr screen) { -$reset-formatting:body: { - compare screen, 0 - { - break-if-!= - reset-formatting-on-real-screen - break $reset-formatting:body - } - { - break-if-= - # fake screen - } -} -} - -fn start-color screen: (addr screen), fg: int, bg: int { -$start-color:body: { - compare screen, 0 - { - break-if-!= - start-color-on-real-screen fg, bg - break $start-color:body - } - { - break-if-= - # fake screen - } -} -} - -fn start-bold screen: (addr screen) { -$start-bold:body: { - compare screen, 0 - { - break-if-!= - start-bold-on-real-screen - break $start-bold:body - } - { - break-if-= - # fake screen - } -} -} - -fn start-underline screen: (addr screen) { -$start-underline:body: { - compare screen, 0 - { - break-if-!= - start-underline-on-real-screen - break $start-underline:body - } - { - break-if-= - # fake screen - } -} -} - -fn start-reverse-video screen: (addr screen) { -$start-reverse-video:body: { - compare screen, 0 - { - break-if-!= - start-reverse-video-on-real-screen - break $start-reverse-video:body - } - { - break-if-= - # fake screen - } -} -} - -fn start-blinking screen: (addr screen) { -$start-blinking:body: { - compare screen, 0 - { - break-if-!= - start-blinking-on-real-screen - break $start-blinking:body - } - { - break-if-= - # fake screen - } -} -} - -fn hide-cursor screen: (addr screen) { -$hide-cursor:body: { - compare screen, 0 - { - break-if-!= - hide-cursor-on-real-screen - break $hide-cursor:body - } - { - break-if-= - # fake screen - } -} -} - -fn show-cursor screen: (addr screen) { -$show-cursor:body: { - compare screen, 0 - { - break-if-!= - show-cursor-on-real-screen - break $show-cursor:body - } - { - break-if-= - # fake screen - } -} -} diff --git a/404stream.mu b/404stream.mu new file mode 100644 index 00000000..bf4ae883 --- /dev/null +++ b/404stream.mu @@ -0,0 +1,46 @@ +# Tests for Mu's stream primitives. + +fn test-stream { + # - write an int to a stream, then read it back + # step 1: initialize + var s: (stream int 4) + var s2/ecx: (addr stream int 4) <- address s + var tmp/eax: boolean <- stream-empty? s2 + check-true tmp, "F - test-stream/empty?/0" + tmp <- stream-full? s2 + check-false tmp, "F - test-stream/full?/0" + # step 2: write to stream + var x: int + copy-to x, 0x34 + var x2/edx: (addr int) <- address x + write-to-stream s2, x2 + tmp <- stream-empty? s2 + check-false tmp, "F - test-stream/empty?/1" + tmp <- stream-full? s2 + check-false tmp, "F - test-stream/full?/1" + # step 3: modify the value written (should make no difference) + copy-to x, 0 + # step 4: read back + var y: int + var y2/ebx: (addr int) <- address y + read-from-stream s2, y2 + tmp <- stream-empty? s2 + check-true tmp, "F - test-stream/empty?/2" + tmp <- stream-full? s2 + check-false tmp, "F - test-stream/full?/2" + # we read back what was written + check-ints-equal y, 0x34, "F - test-stream" +} + +fn test-stream-full { + # write an int to a stream of capacity 1 + var s: (stream int 1) + var s2/ecx: (addr stream int 1) <- address s + var tmp/eax: boolean <- stream-full? s2 + check-false tmp, "F - test-stream-full?/pre" + var x: int + var x2/edx: (addr int) <- address x + write-to-stream s2, x2 + tmp <- stream-full? s2 + check-true tmp, "F - test-stream-full?" +} diff --git a/405screen.mu b/405screen.mu new file mode 100644 index 00000000..8165e50f --- /dev/null +++ b/405screen.mu @@ -0,0 +1,288 @@ +# Wrappers for real screen primitives that can be passed in a fake screen. + +type screen { + num-rows: int + num-cols: int + data: (handle array screen-cell) + pending-scroll?: boolean + top-index: int + cursor-row: int + cursor-col: int + cursor-hide?: boolean + curr-attributes: screen-cell +} + +type screen-cell { + color: int + background-color: int + bold?: boolean + underline?: boolean + reverse?: boolean + blink?: boolean +} + +fn initialize-screen screen: (addr screen), nrows: int, ncols: int { + var screen-addr/esi: (addr screen) <- copy screen + var tmp/eax: int <- copy 0 + var dest/edi: (addr int) <- copy 0 + # screen->num-rows = nrows + dest <- get screen-addr, num-rows + tmp <- copy nrows + copy-to *dest, tmp + # screen->num-cols = ncols + dest <- get screen-addr, num-cols + tmp <- copy ncols + copy-to *dest, tmp + # screen->data = new screen-cell[nrows*ncols] + { + var data-addr/edi: (addr handle array screen-cell) <- get screen-addr, data + tmp <- multiply nrows + populate data-addr, tmp + } + # screen->cursor-row = 1 + dest <- get screen-addr, cursor-row + copy-to *dest, 1 + # screen->cursor-col = 1 + dest <- get screen-addr, cursor-col + copy-to *dest, 1 + # screen->curr-attributes->background-color = 7 (simulate light background) + var tmp2/eax: (addr screen-cell) <- get screen-addr, curr-attributes + dest <- get tmp2, background-color + copy-to *dest, 7 +} + +fn screen-size screen: (addr screen) -> nrows/eax: int, ncols/ecx: int { +$screen-size:body: { + compare screen, 0 + { + break-if-!= + nrows, ncols <- real-screen-size + break $screen-size:body + } + { + break-if-= + # fake screen + var screen-addr/esi: (addr screen) <- copy screen + var tmp/edx: (addr int) <- get screen-addr, num-rows + nrows <- copy *tmp + tmp <- get screen-addr, num-cols + ncols <- copy *tmp + } +} +} + +fn clear-screen screen: (addr screen) { +$clear-screen:body: { + compare screen, 0 + { + break-if-!= + clear-real-screen + break $clear-screen:body + } + { + break-if-= + # fake screen + var space/edi: grapheme <- copy 0x20 + move-cursor screen, 1, 1 + var screen-addr/esi: (addr screen) <- copy screen + var i/eax: int <- copy 1 + var nrows/ecx: (addr int) <- get screen-addr, num-rows + { + compare i, *nrows + break-if-> + var j/edx: int <- copy 1 + var ncols/ebx: (addr int) <- get screen-addr, num-cols + { + compare j, *ncols + break-if-> + print-grapheme screen, space + j <- increment + loop + } + i <- increment + loop + } + move-cursor screen, 1, 1 + } +} +} + +fn move-cursor screen: (addr screen), row: int, column: int { +$move-cursor:body: { + compare screen, 0 + { + break-if-!= + move-cursor-on-real-screen row, column + break $move-cursor:body + } + { + break-if-= + # fake screen + } +} +} + +fn print-string screen: (addr screen), s: (addr array byte) { +$print-string:body: { + compare screen, 0 + { + break-if-!= + print-string-to-real-screen s + break $print-string:body + } + { + break-if-= + # fake screen + } +} +} + +fn print-grapheme screen: (addr screen), c: grapheme { +$print-grapheme:body: { + compare screen, 0 + { + break-if-!= + print-grapheme-to-real-screen c + break $print-grapheme:body + } + { + break-if-= + # fake screen + } +} +} + +fn print-int32-hex screen: (addr screen), n: int { +$print-int32-hex:body: { + compare screen, 0 + { + break-if-!= + print-int32-hex-to-real-screen n + break $print-int32-hex:body + } + { + break-if-= + # fake screen + } +} +} + +fn reset-formatting screen: (addr screen) { +$reset-formatting:body: { + compare screen, 0 + { + break-if-!= + reset-formatting-on-real-screen + break $reset-formatting:body + } + { + break-if-= + # fake screen + } +} +} + +fn start-color screen: (addr screen), fg: int, bg: int { +$start-color:body: { + compare screen, 0 + { + break-if-!= + start-color-on-real-screen fg, bg + break $start-color:body + } + { + break-if-= + # fake screen + } +} +} + +fn start-bold screen: (addr screen) { +$start-bold:body: { + compare screen, 0 + { + break-if-!= + start-bold-on-real-screen + break $start-bold:body + } + { + break-if-= + # fake screen + } +} +} + +fn start-underline screen: (addr screen) { +$start-underline:body: { + compare screen, 0 + { + break-if-!= + start-underline-on-real-screen + break $start-underline:body + } + { + break-if-= + # fake screen + } +} +} + +fn start-reverse-video screen: (addr screen) { +$start-reverse-video:body: { + compare screen, 0 + { + break-if-!= + start-reverse-video-on-real-screen + break $start-reverse-video:body + } + { + break-if-= + # fake screen + } +} +} + +fn start-blinking screen: (addr screen) { +$start-blinking:body: { + compare screen, 0 + { + break-if-!= + start-blinking-on-real-screen + break $start-blinking:body + } + { + break-if-= + # fake screen + } +} +} + +fn hide-cursor screen: (addr screen) { +$hide-cursor:body: { + compare screen, 0 + { + break-if-!= + hide-cursor-on-real-screen + break $hide-cursor:body + } + { + break-if-= + # fake screen + } +} +} + +fn show-cursor screen: (addr screen) { +$show-cursor:body: { + compare screen, 0 + { + break-if-!= + show-cursor-on-real-screen + break $show-cursor:body + } + { + break-if-= + # fake screen + } +} +} -- cgit 1.4.1-2-gfad0