add some checks
Even if they duplicate lower-level ones, we have an opportunity for better error messages. Any time I see a hard-to-debug error message, I should be asking myself, "what higher-level primitive should catch and improve this error?"
This commit is contained in:
parent
f5ece0451b
commit
8e38b86ab0
|
@ -151,13 +151,29 @@ fn draw-code-point screen: (addr screen), c: code-point, x: int, y: int, color:
|
|||
# not really needed for a real screen, though it shouldn't do any harm
|
||||
fn screen-cell-index _screen: (addr screen), x: int, y: int -> _/ecx: int {
|
||||
var screen/esi: (addr screen) <- copy _screen
|
||||
# only one bounds check isn't automatically handled
|
||||
{
|
||||
compare x, 0
|
||||
break-if->=
|
||||
abort "screen-cell-index: negative x"
|
||||
}
|
||||
{
|
||||
var xmax/eax: (addr int) <- get screen, width
|
||||
var xcurr/ecx: int <- copy x
|
||||
compare xcurr, *xmax
|
||||
break-if-<
|
||||
abort "tried to print out of screen bounds"
|
||||
abort "screen-cell-index: x too high"
|
||||
}
|
||||
{
|
||||
compare y, 0
|
||||
break-if->=
|
||||
abort "screen-cell-index: negative y"
|
||||
}
|
||||
{
|
||||
var ymax/eax: (addr int) <- get screen, width
|
||||
var ycurr/ecx: int <- copy y
|
||||
compare ycurr, *ymax
|
||||
break-if-<
|
||||
abort "screen-cell-index: y too high"
|
||||
}
|
||||
var width-addr/eax: (addr int) <- get screen, width
|
||||
var result/ecx: int <- copy y
|
||||
|
|
Loading…
Reference in New Issue