diff options
author | Adam Chlipala <adam@chlipala.net> | 2011-12-03 09:44:07 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2011-12-03 09:44:07 -0500 |
commit | 7136358c17f8193173e8a0a9469821039212d879 (patch) | |
tree | 55e7ce9758b2233896d59392e6b86614abab533a /src/cjr_print.sml | |
parent | d35896d2f29d23c3cd4c180f9249e44ebf7ed208 (diff) |
Catching integer divisions by zero
Diffstat (limited to 'src/cjr_print.sml')
-rw-r--r-- | src/cjr_print.sml | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml index ddeb8ea5..2c4f7b36 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -1655,7 +1655,7 @@ fun p_exp' par tail env (e, loc) = 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 @@ fun p_exp' par tail env (e, loc) = 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]) |