Mercurial > urweb
changeset 107:bed5cf0b6b75
Optimizing attrification of constants
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 10 Jul 2008 15:58:16 -0400 |
parents | d101cb1efe55 |
children | f59553dc1b6a |
files | src/mono_opt.sml |
diffstat | 1 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/mono_opt.sml Thu Jul 10 15:49:14 2008 -0400 +++ b/src/mono_opt.sml Thu Jul 10 15:58:16 2008 -0400 @@ -33,6 +33,24 @@ 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 #"\"" => """ + | 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 @@ 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])