Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
1618:705cb41ac7d0 | 1619:15e0c935c91b |
---|---|
1653 parenIf par (box [string s, | 1653 parenIf par (box [string s, |
1654 space, | 1654 space, |
1655 p_exp' true false env e1]) | 1655 p_exp' true false env e1]) |
1656 | 1656 |
1657 | EBinop (s, e1, e2) => | 1657 | EBinop (s, e1, e2) => |
1658 if Char.isAlpha (String.sub (s, size s - 1)) then | 1658 if s <> "fdiv" andalso Char.isAlpha (String.sub (s, size s - 1)) then |
1659 box [string s, | 1659 box [string s, |
1660 string "(", | 1660 string "(", |
1661 p_exp' false false env e1, | 1661 p_exp' false false env e1, |
1662 string ",", | 1662 string ",", |
1663 space, | 1663 space, |
1664 p_exp' false false env e2, | 1664 p_exp' false false env e2, |
1665 string ")"] | 1665 string ")"] |
1666 else if s = "/" orelse s = "%" then | |
1667 box [string "({", | |
1668 newline, | |
1669 string "uw_Basis_int", | |
1670 space, | |
1671 string "dividend", | |
1672 space, | |
1673 string "=", | |
1674 space, | |
1675 p_exp env e1, | |
1676 string ",", | |
1677 space, | |
1678 string "divisor", | |
1679 space, | |
1680 string "=", | |
1681 space, | |
1682 p_exp env e2, | |
1683 string ";", | |
1684 newline, | |
1685 string "if", | |
1686 space, | |
1687 string "(divisor", | |
1688 space, | |
1689 string "==", | |
1690 space, | |
1691 string "0)", | |
1692 newline, | |
1693 box [string "uw_error(ctx, FATAL, \"", | |
1694 string (ErrorMsg.spanToString loc), | |
1695 string ": division by zero\");", | |
1696 newline], | |
1697 string "dividend", | |
1698 space, | |
1699 string s, | |
1700 space, | |
1701 string "divisor;", | |
1702 newline, | |
1703 string "})"] | |
1666 else | 1704 else |
1667 parenIf par (box [p_exp' true false env e1, | 1705 parenIf par (box [p_exp' true false env e1, |
1668 space, | 1706 space, |
1669 string s, | 1707 string (if s = "fdiv" then "/" else s), |
1670 space, | 1708 space, |
1671 p_exp' true false env e2]) | 1709 p_exp' true false env e2]) |
1672 | 1710 |
1673 | ERecord (0, _) => string "0" | 1711 | ERecord (0, _) => string "0" |
1674 | 1712 |