@@ -314,6 +314,9 @@ jsSubst var new (JSIndex obj field) =
314jsSubst var new (JSCond conds) =
314jsSubst var new (JSCond conds) =
315 JSCond (map ((jsSubst var new) *** (jsSubst var new)) conds)
315 JSCond (map ((jsSubst var new) *** (jsSubst var new)) conds)
317+jsSubst var new (JSAssign lhs rhs) =
318+ JSAssign (jsSubst var new lhs) (jsSubst var new rhs)
317jsSubst _ _ js = js
320jsSubst _ _ js = js
@@ -328,16 +331,24 @@ isJSConstant js
328 | otherwise = False
331 | otherwise = False
330inlineJS :: JS -> JS
333inlineJS :: JS -> JS
334+inlineJS (JSReturn (JSApp (JSFunction ["cse"] body) [val@(JSVar _)])) =
335+ inlineJS $ jsSubst "cse" val body
337+inlineJS (JSReturn (JSApp (JSFunction [arg] cond@(JSCond _)) [val])) =
338+ JSSeq [ JSAlloc arg (Just (inlineJS val))
331inlineJS (JSApp (JSProj (JSFunction args (JSReturn body)) "apply") [
342inlineJS (JSApp (JSProj (JSFunction args (JSReturn body)) "apply") [
332− JSThis,JSProj (JSIdent var) "vars"
343+ JSThis,JSProj var "vars"
334− | var /= "cse" =
345+ | var /= JSIdent "cse" =
335− inlineApply args body 0
346+ inlineApply args body 0
337− inlineApply [] body _ = body
348+ inlineApply [] body _ = inlineJS body
338 inlineApply (a:as) body n =
349 inlineApply (a:as) body n =
339 inlineApply as (
350 inlineApply as (
340− jsSubst a (JSIndex (JSProj (JSIdent var) "vars") (JSNum (JSInt n))) body
351+ jsSubst a (JSIndex (JSProj var "vars") (JSNum (JSInt n))) body
341 ) (n + 1)
352 ) (n + 1)
343inlineJS (JSApp (JSIdent "__IDR__mEVAL0") [val])
354inlineJS (JSApp (JSIdent "__IDR__mEVAL0") [val])
@@ -348,9 +359,6 @@ inlineJS (JSApp (JSIdent "__IDRRT__tailcall") [
349 | isJSConstant val = val
360 | isJSConstant val = val
351−inlineJS (JSApp (JSFunction [] (JSSeq ret)) []) =
352− JSApp (JSFunction [] (JSSeq (map inlineJS ret))) []
354inlineJS (JSApp (JSFunction [arg] (JSReturn ret)) [val])
362inlineJS (JSApp (JSFunction [arg] (JSReturn ret)) [val])
355 | JSNew con [tag, vals] <- ret
363 | JSNew con [tag, vals] <- ret
356 , opt <- inlineJS val =
364 , opt <- inlineJS val =