summaryrefslogtreecommitdiff
path: root/src/mono_opt.sml
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-07-10 15:58:16 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-07-10 15:58:16 -0400
commit58947e1d10547d4ecc40c41f2466605e0acfd601 (patch)
treec0c63ec819801f31e17053df205c20eacbe76848 /src/mono_opt.sml
parent0e95aa2c802d0a4fa54ebf985133eb2584a1d9ba (diff)
Optimizing attrification of constants
Diffstat (limited to 'src/mono_opt.sml')
-rw-r--r--src/mono_opt.sml32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/mono_opt.sml b/src/mono_opt.sml
index 30b462bf..11e0acef 100644
--- a/src/mono_opt.sml
+++ b/src/mono_opt.sml
@@ -33,6 +33,24 @@ structure U = MonoUtil
fun typ t = t
fun decl d = d
+fun attrifyInt n =
+ if n < 0 then
+ "-" ^ Int64.toString (Int64.~ n)
+ else
+ Int64.toString n
+
+fun attrifyFloat n =
+ if n < 0.0 then
+ "-" ^ Real.toString (Real.~ n)
+ else
+ Real.toString n
+
+val attrifyString = String.translate (fn #"\"" => "&quot;"
+ | ch => if Char.isPrint ch then
+ str ch
+ else
+ "&#" ^ Int.toString (ord ch) ^ ";")
+
fun exp e =
case e of
EPrim (Prim.String s) =>
@@ -85,10 +103,24 @@ fun exp e =
ESeq ((optExp (EWrite e1, loc), loc),
(optExp (EWrite e2, loc), loc))
+ | EFfiApp ("Basis", "attrifyInt", [(EPrim (Prim.Int n), _)]) =>
+ EPrim (Prim.String (attrifyInt n))
+ | EWrite (EFfiApp ("Basis", "attrifyInt", [(EPrim (Prim.Int n), _)]), loc) =>
+ EWrite (EPrim (Prim.String (attrifyInt n)), loc)
| EWrite (EFfiApp ("Basis", "attrifyInt", [e]), _) =>
EFfiApp ("Basis", "attrifyInt_w", [e])
+
+ | EFfiApp ("Basis", "attrifyFloat", [(EPrim (Prim.Float n), _)]) =>
+ EPrim (Prim.String (attrifyFloat n))
+ | EWrite (EFfiApp ("Basis", "attrifyFloat", [(EPrim (Prim.Float n), _)]), loc) =>
+ EWrite (EPrim (Prim.String (attrifyFloat n)), loc)
| EWrite (EFfiApp ("Basis", "attrifyFloat", [e]), _) =>
EFfiApp ("Basis", "attrifyFloat_w", [e])
+
+ | EFfiApp ("Basis", "attrifyString", [(EPrim (Prim.String s), _)]) =>
+ EPrim (Prim.String (attrifyString s))
+ | EWrite (EFfiApp ("Basis", "attrifyString", [(EPrim (Prim.String s), _)]), loc) =>
+ EWrite (EPrim (Prim.String (attrifyString s)), loc)
| EWrite (EFfiApp ("Basis", "attrifyString", [e]), _) =>
EFfiApp ("Basis", "attrifyString_w", [e])