Mercurial > urweb
comparison src/mono_opt.sml @ 107:bed5cf0b6b75
Optimizing attrification of constants
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 10 Jul 2008 15:58:16 -0400 |
parents | d101cb1efe55 |
children | 6230bdd122e7 |
comparison
equal
deleted
inserted
replaced
106:d101cb1efe55 | 107:bed5cf0b6b75 |
---|---|
30 open Mono | 30 open Mono |
31 structure U = MonoUtil | 31 structure U = MonoUtil |
32 | 32 |
33 fun typ t = t | 33 fun typ t = t |
34 fun decl d = d | 34 fun decl d = d |
35 | |
36 fun attrifyInt n = | |
37 if n < 0 then | |
38 "-" ^ Int64.toString (Int64.~ n) | |
39 else | |
40 Int64.toString n | |
41 | |
42 fun attrifyFloat n = | |
43 if n < 0.0 then | |
44 "-" ^ Real.toString (Real.~ n) | |
45 else | |
46 Real.toString n | |
47 | |
48 val attrifyString = String.translate (fn #"\"" => """ | |
49 | ch => if Char.isPrint ch then | |
50 str ch | |
51 else | |
52 "&#" ^ Int.toString (ord ch) ^ ";") | |
35 | 53 |
36 fun exp e = | 54 fun exp e = |
37 case e of | 55 case e of |
38 EPrim (Prim.String s) => | 56 EPrim (Prim.String s) => |
39 let | 57 let |
83 | 101 |
84 | EWrite (EStrcat (e1, e2), loc) => | 102 | EWrite (EStrcat (e1, e2), loc) => |
85 ESeq ((optExp (EWrite e1, loc), loc), | 103 ESeq ((optExp (EWrite e1, loc), loc), |
86 (optExp (EWrite e2, loc), loc)) | 104 (optExp (EWrite e2, loc), loc)) |
87 | 105 |
106 | EFfiApp ("Basis", "attrifyInt", [(EPrim (Prim.Int n), _)]) => | |
107 EPrim (Prim.String (attrifyInt n)) | |
108 | EWrite (EFfiApp ("Basis", "attrifyInt", [(EPrim (Prim.Int n), _)]), loc) => | |
109 EWrite (EPrim (Prim.String (attrifyInt n)), loc) | |
88 | EWrite (EFfiApp ("Basis", "attrifyInt", [e]), _) => | 110 | EWrite (EFfiApp ("Basis", "attrifyInt", [e]), _) => |
89 EFfiApp ("Basis", "attrifyInt_w", [e]) | 111 EFfiApp ("Basis", "attrifyInt_w", [e]) |
112 | |
113 | EFfiApp ("Basis", "attrifyFloat", [(EPrim (Prim.Float n), _)]) => | |
114 EPrim (Prim.String (attrifyFloat n)) | |
115 | EWrite (EFfiApp ("Basis", "attrifyFloat", [(EPrim (Prim.Float n), _)]), loc) => | |
116 EWrite (EPrim (Prim.String (attrifyFloat n)), loc) | |
90 | EWrite (EFfiApp ("Basis", "attrifyFloat", [e]), _) => | 117 | EWrite (EFfiApp ("Basis", "attrifyFloat", [e]), _) => |
91 EFfiApp ("Basis", "attrifyFloat_w", [e]) | 118 EFfiApp ("Basis", "attrifyFloat_w", [e]) |
119 | |
120 | EFfiApp ("Basis", "attrifyString", [(EPrim (Prim.String s), _)]) => | |
121 EPrim (Prim.String (attrifyString s)) | |
122 | EWrite (EFfiApp ("Basis", "attrifyString", [(EPrim (Prim.String s), _)]), loc) => | |
123 EWrite (EPrim (Prim.String (attrifyString s)), loc) | |
92 | EWrite (EFfiApp ("Basis", "attrifyString", [e]), _) => | 124 | EWrite (EFfiApp ("Basis", "attrifyString", [e]), _) => |
93 EFfiApp ("Basis", "attrifyString_w", [e]) | 125 EFfiApp ("Basis", "attrifyString_w", [e]) |
94 | 126 |
95 | _ => e | 127 | _ => e |
96 | 128 |