shell: reenable the trace

We now have a couple of protections:
  - if we get close to running out of space in the trace we drop in an
    error
  - if we run out of space in the trace we stop trying to append
  - if there are errors we cancel future evaluations

This is already much nicer. You can't do much on the Mu computer, but at
least it gracefully gives up and shows its limitations. On my computer
the Mu shell tries to run computations for about 20s before giving up.
That seems at the outer limit of what interactivity supports. If things
take too long, test smaller chunks.
This commit is contained in:
Kartik K. Agaram 2021-04-17 22:28:38 -07:00
parent 60cab88ace
commit c026dba006
3 changed files with 22 additions and 1 deletions

View File

@ -2,6 +2,15 @@
# we never modify `in` or `env`
# ignore 'screen-cell' on a first reading; it's a hack for sandboxes
fn evaluate _in: (addr handle 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) {
# errors? skip
{
compare trace, 0
break-if-=
var error?/eax: boolean <- has-errors? trace
compare error?, 0/false
break-if-=
return
}
var in/esi: (addr handle cell) <- copy _in
#? dump-cell in
#? {

View File

@ -29,7 +29,7 @@ fn initialize-sandbox _self: (addr sandbox), screen-and-keyboard?: boolean {
}
#
var trace-ah/eax: (addr handle trace) <- get self, trace
#? allocate trace-ah
allocate trace-ah
var trace/eax: (addr trace) <- lookup *trace-ah
initialize-trace trace, 0x8000/lines, 0x80/visible-lines
var cursor-in-data?/eax: (addr boolean) <- get self, cursor-in-data?

View File

@ -89,11 +89,23 @@ fn trace _self: (addr trace), label: (addr array byte), message: (addr stream by
var data-ah/eax: (addr handle array trace-line) <- get self, data
var data/eax: (addr array trace-line) <- lookup *data-ah
var index-addr/edi: (addr int) <- get self, first-free
{
compare *index-addr, 0x8000/lines
break-if-<
return
}
var index/ecx: int <- copy *index-addr
var offset/ecx: (offset trace-line) <- compute-offset data, index
var dest/eax: (addr trace-line) <- index data, offset
var depth/ecx: (addr int) <- get self, curr-depth
rewind-stream message
{
compare *index-addr, 0x7ffe/lines
break-if-<
initialize-trace-line 0/depth, "error", message, dest
increment *index-addr
return
}
initialize-trace-line *depth, label, message, dest
increment *index-addr
}