comparison src/jscomp.sml @ 577:3d56940120b1

Setting a source server-side
author Adam Chlipala <adamc@hcoop.net>
date Tue, 30 Dec 2008 10:49:42 -0500
parents ac947e2f29ff
children 1e589a60b86f
comparison
equal deleted inserted replaced
576:813f1e78d9d0 577:3d56940120b1
119 fun unsupported s = 119 fun unsupported s =
120 (EM.errorAt loc (s ^ " in code to be compiled to JavaScript"); 120 (EM.errorAt loc (s ^ " in code to be compiled to JavaScript");
121 (str "ERROR", st)) 121 (str "ERROR", st))
122 122
123 val strcat = strcat loc 123 val strcat = strcat loc
124
125 fun quoteExp (t : typ) e =
126 case #1 t of
127 TSource => strcat [str "s",
128 (EFfiApp ("Basis", "htmlifyInt", [e]), loc)]
129 | _ => (EM.errorAt loc "Don't know how to embed type in JavaScript";
130 str "ERROR")
124 in 131 in
125 case #1 e of 132 case #1 e of
126 EPrim (Prim.String s) => 133 EPrim (Prim.String s) =>
127 (str ("\"" 134 (str ("\""
128 ^ String.translate (fn #"'" => 135 ^ String.translate (fn #"'" =>
129 if mode = Attribute then 136 if mode = Attribute then
130 "\\047" 137 "\\047"
131 else 138 else
132 "'" 139 "'"
140 | #"\"" => "\\\""
133 | #"<" => 141 | #"<" =>
134 if mode = Script then 142 if mode = Script then
135 "<" 143 "<"
136 else 144 else
137 "\\074" 145 "\\074"
141 | EPrim p => (str (Prim.toString p), st) 149 | EPrim p => (str (Prim.toString p), st)
142 | ERel n => 150 | ERel n =>
143 if n < inner then 151 if n < inner then
144 (str ("uwr" ^ var n), st) 152 (str ("uwr" ^ var n), st)
145 else 153 else
146 (str ("uwo" ^ var n), st) 154 let
155 val n = n - inner
156 in
157 (quoteExp (List.nth (outer, n)) (ERel n, loc), st)
158 end
147 | ENamed _ => raise Fail "Named" 159 | ENamed _ => raise Fail "Named"
148 | ECon (_, pc, NONE) => (patCon pc, st) 160 | ECon (_, pc, NONE) => (patCon pc, st)
149 | ECon (_, pc, SOME e) => 161 | ECon (_, pc, SOME e) =>
150 let 162 let
151 val (s, st) = jsE inner (e, st) 163 val (s, st) = jsE inner (e, st)