diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-04-19 10:30:21 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-04-19 10:47:30 -0700 |
commit | 8e38b86ab01603b67eb563a5e909b9317f4dd700 (patch) | |
tree | 919fc3ec9e22a2d94508d0c4058188b02c364da4 | |
parent | f5ece0451b7de213ebe989ba90c95e4781b2c26b (diff) | |
download | mu-8e38b86ab01603b67eb563a5e909b9317f4dd700.tar.gz |
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?"
-rw-r--r-- | 500fake-screen.mu | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/500fake-screen.mu b/500fake-screen.mu index 4aefc694..5cf925a9 100644 --- a/500fake-screen.mu +++ b/500fake-screen.mu @@ -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 |