git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Better TCO for case statements
commit1074a1a5ed2c23118a2ea657ebbe1da6e2fa3cd1 authorPhil Freeman <paf31@cantab.net> dateWed 14 May 2014, 21:50 (12 years ago) parent9345919
1 file changed+3−2
src/Language/PureScript/CodeGen/JS.hs+3−2
src/Language/PureScript/CodeGen/JS.hs+3−2
@@ -254,9 +254,10 @@ qualifiedToJS _ f (Qualified _ a) = JSVar $ identToJs (f a)
254254bindersToJs :: Options -> ModuleName -> Environment -> [CaseAlternative] -> [JS] -> JS
255255bindersToJs opts m e binders vals = runGen (map identToJs (S.unusedNames usedNames)) $ do
256256 valNames <- replicateM (length vals) fresh
257+ let assignments = zipWith JSVariableIntroduction valNames (map Just vals)
257258 jss <- forM binders $ \(CaseAlternative bs grd result) -> go valNames [JSReturn (valueToJs opts m (bindNames m (concatMap binderNames bs) e) result)] bs grd
258− return $ JSApp (JSFunction Nothing valNames (JSBlock (concat jss ++ [JSThrow (JSStringLiteral "Failed pattern match")])))
259− vals
259+ return $ JSApp (JSFunction Nothing [] (JSBlock (assignments ++ concat jss ++ [JSThrow (JSStringLiteral "Failed pattern match")])))
260+ []
260261 where
261262 usedNames = concatMap usedNamesJS vals ++ concatMap S.usedNamesCaseAlternative binders
262263