on master help sign in
javascript: recognize more redundant continuations
commitb98b1f3d4cd7d1c2cf2e6008283d66e3dd8cca2f authorraichoo <raichoo@googlemail.com> dateSun 9 Feb 2014, 16:10 (13 years ago) parent43828d9
1 file changed+26−15
src/IRTS/CodegenJavaScript.hs+26−15
src/IRTS/CodegenJavaScript.hs+26−15
@@ -407,22 +407,32 @@ removeAllocations (JSSeq body) =
407407removeAllocations js = transformJS removeAllocations js
408408
409409
410−isJSConstant :: [String] -> JS -> Bool
411−isJSConstant constants js
412− | JSString _ <- js = True
413− | JSChar _ <- js = True
414− | JSNum _ <- js = True
415− | JSType _ <- js = True
416− | JSNull <- js = True
410+isJSConstant :: JS -> Bool
411+isJSConstant js
412+ | JSString _ <- js = True
413+ | JSChar _ <- js = True
414+ | JSNum _ <- js = True
415+ | JSType _ <- js = True
416+ | JSNull <- js = True
417+ | JSArray vals <- js = all isJSConstant vals
417418
418419 | JSApp (JSIdent "__IDRRT__bigInt") _ <- js = True
419420
420− | JSArray vals <- js = all (isJSConstant constants) vals
421− | JSNew "__IDRRT__Con" args <- js = all (isJSConstant constants) args
421+ | otherwise = False
422422
423+isJSConstantConstructor :: [String] -> JS -> Bool
424+isJSConstantConstructor constants js
425+ | isJSConstant js =
426+ True
427+ | JSArray vals <- js =
428+ all (isJSConstantConstructor constants) vals
429+ | JSNew "__IDRRT__Con" args <- js =
430+ all (isJSConstantConstructor constants) args
431+ | JSIndex (JSProj (JSIdent _) "vars") (JSNum _) <- js =
432+ True
423433 | JSIdent name <- js
424− , name `elem` constants = True
425−
434+ , name `elem` constants =
435+ True
426436 | otherwise = False
427437
428438
@@ -450,12 +460,12 @@ inlineJS (JSApp (JSProj (JSFunction args (JSReturn body)) "apply") [
450460 ) (n + 1)
451461
452462inlineJS (JSApp (JSIdent "__IDR__mEVAL0") [val])
453− | isJSConstant [] val = val
463+ | isJSConstant val = val
454464
455465inlineJS (JSApp (JSIdent "__IDRRT__tailcall") [
456466 JSFunction [] (JSReturn val)
457467 ])
458− | isJSConstant [] val = val
468+ | isJSConstant val = val
459469
460470inlineJS (JSApp (JSFunction [arg] (JSReturn ret)) [val])
461471 | JSNew con [tag, vals] <- ret
@@ -1044,7 +1054,7 @@ extractLocalConstructors js =
10441054 , all isConstant args =
10451055 True
10461056 | otherwise =
1047− isJSConstant globalCons js
1057+ isJSConstantConstructor globalCons js
10481058
10491059 extractLocalConstructors' js = [js]
10501060
@@ -1140,7 +1150,8 @@ evalCons js =
11401150 where
11411151 collapsable :: JS -> Bool
11421152 collapsable (JSIdent _) = True
1143− collapsable js = isJSConstant (map fst cons) js
1153+ collapsable js = isJSConstantConstructor (map fst cons) js
1154+
11441155
11451156 match js = transformJS match js
11461157