Mercurial > urweb
diff src/cjr_print.sml @ 1619:15e0c935c91b
Catching integer divisions by zero
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sat, 03 Dec 2011 09:44:07 -0500 |
parents | 4973d31b5fff |
children | 218e2a9a53d0 |
line wrap: on
line diff
--- a/src/cjr_print.sml Wed Nov 30 15:28:56 2011 -0500 +++ b/src/cjr_print.sml Sat Dec 03 09:44:07 2011 -0500 @@ -1655,7 +1655,7 @@ p_exp' true false env e1]) | EBinop (s, e1, e2) => - if Char.isAlpha (String.sub (s, size s - 1)) then + if s <> "fdiv" andalso Char.isAlpha (String.sub (s, size s - 1)) then box [string s, string "(", p_exp' false false env e1, @@ -1663,10 +1663,48 @@ space, p_exp' false false env e2, string ")"] + else if s = "/" orelse s = "%" then + box [string "({", + newline, + string "uw_Basis_int", + space, + string "dividend", + space, + string "=", + space, + p_exp env e1, + string ",", + space, + string "divisor", + space, + string "=", + space, + p_exp env e2, + string ";", + newline, + string "if", + space, + string "(divisor", + space, + string "==", + space, + string "0)", + newline, + box [string "uw_error(ctx, FATAL, \"", + string (ErrorMsg.spanToString loc), + string ": division by zero\");", + newline], + string "dividend", + space, + string s, + space, + string "divisor;", + newline, + string "})"] else parenIf par (box [p_exp' true false env e1, space, - string s, + string (if s = "fdiv" then "/" else s), space, p_exp' true false env e2])