on master help sign in
javascript: loop to reduce constructor
commit24fb37005b0084a092a5a6845505fd7f5f259ae0 authorraichoo <raichoo@googlemail.com> dateSat 12 Oct 2013, 17:02 (13 years ago) parentdd10071
1 file changed+12−5
src/IRTS/CodegenJavaScript.hs+12−5
src/IRTS/CodegenJavaScript.hs+12−5
@@ -332,10 +332,17 @@ inlineJS (JSObject fields) =
332332inlineJS js = js
333333
334334reduceJS :: [JS] -> [JS]
335−reduceJS program =
335+reduceJS js = reduceLoop [] ([], js)
336+
337+reduceLoop :: [String] -> ([JS], [JS]) -> [JS]
338+reduceLoop reduced (cons, program) =
336339 case partition findConstructors program of
337− (candidates, rest) ->
338− map reduce candidates ++ map (reduceCall (map funNames candidates)) rest
340+ ([], js) -> cons ++ js
341+ (candidates, rest) ->
342+ let names = reduced ++ map funName candidates in
343+ reduceLoop names (
344+ cons ++ map reduce candidates, map (reduceCall names) rest
345+ )
339346 where findConstructors :: JS -> Bool
340347 findConstructors js
341348 | (JSAlloc fun (Just (JSFunction _ (JSSeq body)))) <- js =
@@ -356,8 +363,8 @@ reduceJS program =
356363
357364 reduce js = js
358365
359− funNames :: JS -> String
360− funNames (JSAlloc fun _) = fun
366+ funName :: JS -> String
367+ funName (JSAlloc fun _) = fun
361368
362369 reduceCall :: [String] -> JS -> JS
363370 reduceCall funs (JSApp (JSIdent "__IDRRT__tailcall") [JSFunction [] (