comparison src/mono_opt.sml @ 105:da760c34f5ed

Stringifying attributes
author Adam Chlipala <adamc@hcoop.net>
date Thu, 10 Jul 2008 15:19:06 -0400
parents 82aaa1c406d3
children d101cb1efe55
comparison
equal deleted inserted replaced
104:b1e5398a7f30 105:da760c34f5ed
50 (false, []) s 50 (false, []) s
51 in 51 in
52 EPrim (Prim.String (String.implode (rev chs))) 52 EPrim (Prim.String (String.implode (rev chs)))
53 end 53 end
54 54
55
56 | EStrcat ((EPrim (Prim.String s1), loc), (EPrim (Prim.String s2), _)) => 55 | EStrcat ((EPrim (Prim.String s1), loc), (EPrim (Prim.String s2), _)) =>
57 let 56 let
58 val s = 57 val s =
59 if size s1 > 0 andalso size s2 > 0 58 if size s1 > 0 andalso size s2 > 0
60 andalso Char.isSpace (String.sub (s1, size s1 - 1)) 59 andalso Char.isSpace (String.sub (s1, size s1 - 1))
63 else 62 else
64 s1 ^ s2 63 s1 ^ s2
65 in 64 in
66 EPrim (Prim.String s) 65 EPrim (Prim.String s)
67 end 66 end
67
68 | EStrcat ((EPrim (Prim.String s1), loc), (EStrcat ((EPrim (Prim.String s2), _), rest), _)) =>
69 let
70 val s =
71 if size s1 > 0 andalso size s2 > 0
72 andalso Char.isSpace (String.sub (s1, size s1 - 1))
73 andalso Char.isSpace (String.sub (s2, 0)) then
74 s1 ^ String.extract (s2, 1, NONE)
75 else
76 s1 ^ s2
77 in
78 EStrcat ((EPrim (Prim.String s), loc), rest)
79 end
80
81 | EStrcat ((EStrcat (e1, e2), loc), e3) =>
82 optExp (EStrcat (e1, (EStrcat (e2, e3), loc)), loc)
83
68 | _ => e 84 | _ => e
85
86 and optExp e = #1 (U.Exp.map {typ = typ, exp = exp} e)
69 87
70 val optimize = U.File.map {typ = typ, exp = exp, decl = decl} 88 val optimize = U.File.map {typ = typ, exp = exp, decl = decl}
71 89
72 end 90 end