7785 - baremetal/shell: trace primitives done

Rendering traces will be an ongoing journey.
This commit is contained in:
Kartik K. Agaram 2021-02-22 20:23:43 -08:00
parent 421ed4651f
commit 2387a8fba4
4 changed files with 88 additions and 5 deletions

View File

@ -121,7 +121,7 @@ fn next-number-token in: (addr gap-buffer), out: (addr stream byte), trace: (add
var digit?/eax: boolean <- is-decimal-digit? g
compare digit?, 0/false
break-if-!=
abort "invalid number"
error trace, "invalid number"
}
var g/eax: grapheme <- read-from-gap-buffer in
write-grapheme out, g

View File

@ -12,6 +12,10 @@ fn initialize-sandbox _self: (addr sandbox) {
initialize-gap-buffer data, 0x1000/4KB
var value-ah/eax: (addr handle stream byte) <- get self, value
populate-stream value-ah, 0x1000/4KB
var trace-ah/eax: (addr handle trace) <- get self, trace
allocate trace-ah
var trace/eax: (addr trace) <- lookup *trace-ah
initialize-trace trace, 0x100/lines
}
## some helpers for tests
@ -48,12 +52,13 @@ fn delete-grapheme-before-cursor _self: (addr sandbox) {
fn render-sandbox screen: (addr screen), _self: (addr sandbox), _x: int, _y: int {
clear-screen screen
var self/esi: (addr sandbox) <- copy _self
# data
var data-ah/eax: (addr handle gap-buffer) <- get self, data
var _data/eax: (addr gap-buffer) <- lookup *data-ah
var data/edx: (addr gap-buffer) <- copy _data
var x/eax: int <- copy _x
var y/ecx: int <- copy _y
x, y <- render-gap-buffer-wrapping-right-then-down screen, data, x, y, 0x20/xmax, 0x20/ymax, x, y, 1/true
x, y <- render-gap-buffer-wrapping-right-then-down screen, data, x, y, 0x20/xmax, 0x20/ymax, x, y, 1/show-cursor
{
var value-ah/eax: (addr handle stream byte) <- get self, value
var value/eax: (addr stream byte) <- lookup *value-ah
@ -63,6 +68,14 @@ fn render-sandbox screen: (addr screen), _self: (addr sandbox), _x: int, _y: int
return
}
y <- increment
# trace
var trace-ah/eax: (addr handle trace) <- get self, trace
var _trace/eax: (addr trace) <- lookup *trace-ah
var trace/edx: (addr trace) <- copy _trace
y <- render-trace screen, trace, _x, y, 0x20/xmax, 0x20/ymax
y <- increment
# value
var x/eax: int <- copy 0
x, y <- draw-text-wrapping-right-then-down screen, "=> ", _x, y, 0x20/xmax, 0x20/ymax, _x, y, 7/fg, 0/bg
var x2/edx: int <- copy x
var value-ah/eax: (addr handle stream byte) <- get self, value
@ -99,6 +112,7 @@ fn edit-sandbox _self: (addr sandbox), key: byte {
var value/edx: (addr stream byte) <- copy _value
var trace-ah/eax: (addr handle trace) <- get self, trace
var trace/eax: (addr trace) <- lookup *trace-ah
clear-trace trace
run data, value, trace
return
}

View File

@ -12,21 +12,88 @@ type trace-line {
data: (handle array byte)
}
fn initialize-trace _self: (addr trace), capacity: int {
var self/eax: (addr trace) <- copy _self
var trace-ah/eax: (addr handle stream trace-line) <- get self, data
populate-stream trace-ah, capacity
}
fn clear-trace _self: (addr trace) {
var self/eax: (addr trace) <- copy _self
var trace-ah/eax: (addr handle stream trace-line) <- get self, data
var trace/eax: (addr stream trace-line) <- lookup *trace-ah
clear-stream trace # leaks memory
}
fn has-errors? _self: (addr trace) -> _/eax: boolean {
var self/eax: (addr trace) <- copy _self
var trace-ah/eax: (addr handle stream trace-line) <- get self, data
var _trace/eax: (addr stream trace-line) <- lookup *trace-ah
var trace/esi: (addr stream trace-line) <- copy _trace
{
var done?/eax: boolean <- stream-empty? trace
compare done?, 0/false
break-if-!=
var curr-storage: trace-line
var curr/eax: (addr trace-line) <- address curr-storage
read-from-stream trace, curr
var curr-label-ah/eax: (addr handle array byte) <- get curr, label
var curr-label/eax: (addr array byte) <- lookup *curr-label-ah
var is-error?/eax: boolean <- string-equal? curr-label, "error"
compare is-error?, 0/false
loop-if-=
return 1/true
}
return 0/false
}
fn trace _self: (addr trace), label: (addr array byte), data: (array stream byte) {
fn trace _self: (addr trace), label: (addr array byte), data: (addr stream byte) {
var self/esi: (addr trace) <- copy _self
var line-storage: trace-line
var line/ecx: (addr trace-line) <- address line-storage
var depth/eax: (addr int) <- get self, curr-depth
initialize-trace-line *depth, label, data, line
var dest-ah/eax: (addr handle stream trace-line) <- get self, data
var dest/eax: (addr stream trace-line) <- lookup *dest-ah
write-to-stream dest, line
}
fn new-trace-line depth: int, label: (addr array byte), data: (array stream byte), out: (addr trace-line) {
fn error self: (addr trace), data: (addr array byte) {
var s: (stream byte 0x100)
var s-a/eax: (addr stream byte) <- address s
write s-a, data
trace self, "error", s-a
}
fn initialize-trace-line depth: int, label: (addr array byte), data: (addr stream byte), _out: (addr trace-line) {
var out/edi: (addr trace-line) <- copy _out
# depth
var src/eax: int <- copy depth
var dest/ecx: (addr int) <- get out, depth
copy-to *dest, src
# label
var dest/eax: (addr handle array byte) <- get out, label
copy-array-object label, dest
# data
var dest/eax: (addr handle array byte) <- get out, data
stream-to-array data, dest
}
fn trace-lower _self: (addr trace) {
var self/esi: (addr trace) <- copy _self
var depth/eax: (addr int) <- get self, curr-depth
increment *depth
}
fn trace-higher _self: (addr trace) {
var self/esi: (addr trace) <- copy _self
var depth/eax: (addr int) <- get self, curr-depth
decrement *depth
}
fn render-trace screen: (addr screen), _self: (addr trace), _x: int, _y: int {
fn render-trace screen: (addr screen), _self: (addr trace), xmin: int, ymin: int, xmax: int, ymax: int -> _/ecx: int {
var x/eax: int <- copy xmin
var y/ecx: int <- copy ymin
x, y <- draw-text-wrapping-right-then-down screen, "...", xmin, ymin, xmax, ymax, x, y, 9/fg=trace, 0/bg
return y
}

2
mu.vim
View File

@ -49,6 +49,8 @@ highlight link muError Error
" sources of action at a distance
syntax match muAssign "<-"
highlight link muAssign SpecialChar
syntax keyword muAssign error
highlight link muAssign Special
" common keywords
syntax match muControl "\<return\>\|\<return-if[^ ]*\>"