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 | |
parent | d35896d2f29d23c3cd4c180f9249e44ebf7ed208 (diff) |
Catching integer divisions by zero
Diffstat (limited to 'src')
-rw-r--r-- | src/cjr_print.sml | 42 | ||||
-rw-r--r-- | src/jscomp.sml | 2 | ||||
-rw-r--r-- | src/monoize.sml | 2 |
3 files changed, 43 insertions, 3 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]) diff --git a/src/jscomp.sml b/src/jscomp.sml index 43c16cc3..3e475899 100644 --- a/src/jscomp.sml +++ b/src/jscomp.sml @@ -706,6 +706,8 @@ fun process file = | "*" => "times" | "/" => (case bi of Int => "divInt" | NotInt => "div") | "%" => (case bi of Int => "modInt" | NotInt => "mod") + | "fdiv" => "div" + | "fmod" => "mod" | "<" => "lt" | "<=" => "le" | "strcmp" => "strcmp" diff --git a/src/monoize.sml b/src/monoize.sml index 4a70c012..e4ed6562 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -1031,7 +1031,7 @@ fun monoExp (env, st, fm) (all as (e, loc)) = floatBin "+", floatBin "-", floatBin "*", - floatBin "/", + floatBin "fdiv", floatBin "fmod") end |