6821 - highlight words clobbered by the next word
Another suggestion from the Future of Software forum.
This commit is contained in:
parent
a1ae40403d
commit
022595a20a
|
@ -303,7 +303,7 @@ test-write-int32-decimal-negative-multiple-digits:
|
|||
# . end
|
||||
c3/return
|
||||
|
||||
is-decimal-digit?: # c: byte -> result/eax: boolean
|
||||
is-decimal-digit?: # c: grapheme -> result/eax: boolean
|
||||
# . prologue
|
||||
55/push-ebp
|
||||
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
|
||||
|
@ -402,7 +402,7 @@ test-is-decimal-digit-above-9:
|
|||
81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp
|
||||
c3/return
|
||||
|
||||
to-decimal-digit: # in: byte -> out/eax: int
|
||||
to-decimal-digit: # in: grapheme -> out/eax: int
|
||||
# . prologue
|
||||
55/push-ebp
|
||||
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
|
||||
|
|
4
400.mu
4
400.mu
|
@ -109,8 +109,8 @@ sig skip-until-close-paren line: (addr stream byte)
|
|||
#sig skip-until-close-paren-in-slice curr: (addr byte), end: (addr byte) -> curr/eax: (addr byte)
|
||||
sig write-stream-data f: (addr buffered-file), s: (addr stream byte)
|
||||
sig write-int32-decimal out: (addr stream byte), n: int
|
||||
sig is-decimal-digit? c: byte -> result/eax: boolean
|
||||
sig to-decimal-digit in: byte -> out/eax: int
|
||||
sig is-decimal-digit? c: grapheme -> result/eax: boolean
|
||||
sig to-decimal-digit in: grapheme -> out/eax: int
|
||||
sig next-word line: (addr stream byte), out: (addr slice)
|
||||
sig has-metadata? word: (addr slice), s: (addr string) -> result/eax: boolean
|
||||
sig is-valid-name? in: (addr slice) -> result/eax: boolean
|
||||
|
|
|
@ -201,15 +201,26 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
|
|||
initialize-int-stack stack-addr, 0x10 # max-words
|
||||
evaluate first-word, final-word, stack-addr
|
||||
# render stack
|
||||
var stack-index/ebx: int <- copy 0
|
||||
var stack-remaining/eax: int <- int-stack-length stack-addr
|
||||
var curr-row/edx: int <- copy botleft-depth
|
||||
curr-row <- add 6 # input-row 3 + stack-margin-top 3
|
||||
curr-row <- subtract stack-remaining
|
||||
# highlight item just added
|
||||
start-color screen, 0, 2
|
||||
{
|
||||
compare stack-remaining, 0
|
||||
break-if-<=
|
||||
move-cursor screen, curr-row, botleft-col
|
||||
# highlight items about to be removed
|
||||
{
|
||||
compare stack-index, 1 # second from top
|
||||
break-if-!=
|
||||
var safe-next-word?/eax: boolean <- next-word-is-number? final-word
|
||||
compare safe-next-word?, 0 # false
|
||||
break-if-!=
|
||||
start-color screen, 0, 1
|
||||
}
|
||||
{
|
||||
var val/eax: int <- pop-int-stack stack-addr
|
||||
print-int32-decimal screen, val
|
||||
|
@ -220,6 +231,7 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
|
|||
}
|
||||
reset-formatting screen
|
||||
curr-row <- increment
|
||||
stack-index <- increment
|
||||
stack-remaining <- decrement
|
||||
loop
|
||||
}
|
||||
|
@ -246,6 +258,29 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
|
|||
right-col <- add 3 # margin-right
|
||||
}
|
||||
|
||||
# gotcha: returns true by default
|
||||
fn next-word-is-number? _w: (addr word) -> result/eax: boolean {
|
||||
$next-word-is-operator?:body: {
|
||||
var w/esi: (addr word) <- copy _w
|
||||
var next-ah/eax: (addr handle word) <- get w, next
|
||||
var next/eax: (addr word) <- lookup *next-ah
|
||||
compare next, 0
|
||||
{
|
||||
break-if-!=
|
||||
result <- copy 1 # true
|
||||
break $next-word-is-operator?:body
|
||||
}
|
||||
var first-grapheme/eax: grapheme <- first-grapheme next
|
||||
compare first-grapheme, -1
|
||||
{
|
||||
break-if-!=
|
||||
result <- copy 1 # true
|
||||
break $next-word-is-operator?:body
|
||||
}
|
||||
result <- is-decimal-digit? first-grapheme
|
||||
}
|
||||
}
|
||||
|
||||
# We could be a little faster by not using 'first-word' (since max is commutative),
|
||||
# but this way the code follows the pattern of 'render'. Let's see if that's a net win.
|
||||
fn compute-max-depth _env: (addr environment) -> result/eax: int {
|
||||
|
|
|
@ -169,6 +169,40 @@ fn gap-index _self: (addr gap-buffer) -> result/eax: int {
|
|||
result <- copy *top-addr
|
||||
}
|
||||
|
||||
fn first-grapheme-in-gap-buffer _self: (addr gap-buffer) -> result/eax: grapheme {
|
||||
$first-grapheme-in-gap-buffer:body: {
|
||||
var self/esi: (addr gap-buffer) <- copy _self
|
||||
# try to read from left
|
||||
var left/eax: (addr grapheme-stack) <- get self, left
|
||||
var top-addr/ecx: (addr int) <- get left, top
|
||||
compare *top-addr, 0
|
||||
{
|
||||
break-if-<=
|
||||
var data-ah/eax: (addr handle array grapheme) <- get left, data
|
||||
var data/eax: (addr array grapheme) <- lookup *data-ah
|
||||
var result-addr/eax: (addr grapheme) <- index data, 0
|
||||
result <- copy *result-addr
|
||||
break $first-grapheme-in-gap-buffer:body
|
||||
}
|
||||
# try to read from right
|
||||
var right/eax: (addr grapheme-stack) <- get self, right
|
||||
top-addr <- get right, top
|
||||
compare *top-addr, 0
|
||||
{
|
||||
break-if-<=
|
||||
var data-ah/eax: (addr handle array grapheme) <- get right, data
|
||||
var data/eax: (addr array grapheme) <- lookup *data-ah
|
||||
var top/ecx: int <- copy *top-addr
|
||||
top <- decrement
|
||||
var result-addr/eax: (addr grapheme) <- index data, top
|
||||
result <- copy *result-addr
|
||||
break $first-grapheme-in-gap-buffer:body
|
||||
}
|
||||
# give up
|
||||
result <- copy -1
|
||||
}
|
||||
}
|
||||
|
||||
fn delete-before-gap _self: (addr gap-buffer) {
|
||||
var self/eax: (addr gap-buffer) <- copy _self
|
||||
var left/eax: (addr grapheme-stack) <- get self, left
|
||||
|
|
|
@ -92,6 +92,12 @@ fn final-word _self: (addr word) -> result/eax: (addr word) {
|
|||
result <- copy out
|
||||
}
|
||||
|
||||
fn first-grapheme _self: (addr word) -> result/eax: grapheme {
|
||||
var self/esi: (addr word) <- copy _self
|
||||
var data/eax: (addr gap-buffer) <- get self, data
|
||||
result <- first-grapheme-in-gap-buffer data
|
||||
}
|
||||
|
||||
fn add-grapheme-to-word _self: (addr word), c: grapheme {
|
||||
var self/esi: (addr word) <- copy _self
|
||||
var data/eax: (addr gap-buffer) <- get self, data
|
||||
|
|
Loading…
Reference in New Issue