From 421ed4651f0f9ceb23f07f8d00797e61d63a29ad Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 22 Feb 2021 19:46:23 -0800 Subject: 7784 - baremetal/shell: start of trace --- baremetal/shell/read.mu | 17 ++++++++++------- baremetal/shell/sandbox.mu | 18 ++++++++++++++---- baremetal/shell/trace.mu | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 baremetal/shell/trace.mu (limited to 'baremetal') diff --git a/baremetal/shell/read.mu b/baremetal/shell/read.mu index d6325c62..5c6014d9 100644 --- a/baremetal/shell/read.mu +++ b/baremetal/shell/read.mu @@ -1,5 +1,5 @@ # out is not allocated -fn read-cell in: (addr gap-buffer), out: (addr handle cell) { +fn read-cell in: (addr gap-buffer), out: (addr handle cell), trace: (addr trace) { # TODO: # tokenize # insert parens @@ -13,13 +13,16 @@ fn read-cell in: (addr gap-buffer), out: (addr handle cell) { var done?/eax: boolean <- gap-buffer-scan-done? in compare done?, 0/false break-if-!= - next-token in, token + next-token in, token, trace + var error?/eax: boolean <- has-errors? trace + compare error?, 0/false + break-if-!= read-symbol token, out loop } } -fn next-token in: (addr gap-buffer), out: (addr stream byte) { +fn next-token in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) { clear-stream out skip-whitespace-from-gap-buffer in var g/eax: grapheme <- peek-from-gap-buffer in @@ -27,13 +30,13 @@ fn next-token in: (addr gap-buffer), out: (addr stream byte) { var digit?/eax: boolean <- is-decimal-digit? g compare digit?, 0/false break-if-= - next-number-token in, out + next-number-token in, out, trace return } - next-symbol-token in, out + next-symbol-token in, out, trace } -fn next-symbol-token in: (addr gap-buffer), out: (addr stream byte) { +fn next-symbol-token in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) { { var done?/eax: boolean <- gap-buffer-scan-done? in compare done?, 0/false @@ -101,7 +104,7 @@ fn is-symbol-grapheme? g: grapheme -> _/eax: boolean { return 1/true } -fn next-number-token in: (addr gap-buffer), out: (addr stream byte) { +fn next-number-token in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) { var done?/eax: boolean <- gap-buffer-scan-done? in compare done?, 0/false break-if-!= diff --git a/baremetal/shell/sandbox.mu b/baremetal/shell/sandbox.mu index c89814d4..6ba2e4ac 100644 --- a/baremetal/shell/sandbox.mu +++ b/baremetal/shell/sandbox.mu @@ -1,6 +1,7 @@ type sandbox { data: (handle gap-buffer) value: (handle stream byte) + trace: (handle trace) } fn initialize-sandbox _self: (addr sandbox) { @@ -94,17 +95,26 @@ fn edit-sandbox _self: (addr sandbox), key: byte { var _data/eax: (addr gap-buffer) <- lookup *data-ah var data/ecx: (addr gap-buffer) <- copy _data var value-ah/eax: (addr handle stream byte) <- get self, value - var value/eax: (addr stream byte) <- lookup *value-ah - run data, value + var _value/eax: (addr stream byte) <- lookup *value-ah + 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 + run data, value, trace return } add-grapheme-to-sandbox self, g } -fn run in: (addr gap-buffer), out: (addr stream byte) { +fn run in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) { var read-result-storage: (handle cell) var read-result/esi: (addr handle cell) <- address read-result-storage - read-cell in, read-result + read-cell in, read-result, trace + var error?/eax: boolean <- has-errors? trace + { + compare error?, 0/false + break-if-= + return + } # TODO: eval print-cell read-result, out } diff --git a/baremetal/shell/trace.mu b/baremetal/shell/trace.mu new file mode 100644 index 00000000..88ee0860 --- /dev/null +++ b/baremetal/shell/trace.mu @@ -0,0 +1,32 @@ +# A trace records the evolution of a computation. +# An integral part of the Mu Shell is facilities for browsing traces. + +type trace { + curr-depth: int + data: (handle stream trace-line) +} + +type trace-line { + depth: int + label: (handle array byte) + data: (handle array byte) +} + +fn has-errors? _self: (addr trace) -> _/eax: boolean { + return 0/false +} + +fn trace _self: (addr trace), label: (addr array byte), data: (array stream byte) { +} + +fn new-trace-line depth: int, label: (addr array byte), data: (array stream byte), out: (addr trace-line) { +} + +fn trace-lower _self: (addr trace) { +} + +fn trace-higher _self: (addr trace) { +} + +fn render-trace screen: (addr screen), _self: (addr trace), _x: int, _y: int { +} -- cgit 1.4.1-2-gfad0