on master help sign in
javascript: substitute more
f7fc73braichoo
src/IRTS/CodegenJavaScript.hs+18
@@ -222,9 +222,27 @@ jsSubst :: String -> JS -> JS -> JS
222jsSubst var new (JSVar old)
222jsSubst var new (JSVar old)
223 | var == translateVariableName old = new
223 | var == translateVariableName old = new
224
224
225+jsSubst var new (JSRaw old)
226+ | var == old = new
227+
225jsSubst var new (JSArray fields) =
228jsSubst var new (JSArray fields) =
226 JSArray (map (jsSubst var new) fields)
229 JSArray (map (jsSubst var new) fields)
227
230
231+jsSubst var new (JSNew con [tag, vals]) =
232+ JSNew con [tag, jsSubst var new vals]
233+
234+jsSubst var new (JSNew con [JSFunction [] (JSReturn (JSApp fun vars))]) =
235+ JSNew con [JSFunction [] (
236+ JSReturn $ JSApp fun (map (jsSubst var new) vars)
237+ )]
238+
239+jsSubst var new (JSApp (JSRaw "__IDRRT__tailcall") [JSFunction [] (
240+ JSReturn (JSApp fun args)
241+ )]) =
242+ JSApp (JSRaw "__IDRRT__tailcall") [JSFunction [] (
243+ JSReturn $ JSApp fun (map (jsSubst var new) args)
244+ )]
245+
228jsSubst _ _ js = js
246jsSubst _ _ js = js
229
247
230optimizeJS :: JS -> JS
248optimizeJS :: JS -> JS