@@ -332,6 +332,12 @@ codegenJS_all target definitions includes filename outputType = do
332332 ) [ JSIdent "vm"
333333 , JSNum (JSInt 0)
334334 ]
335+ , JSWhile (JSProj (JSProj (JSIdent ("vm")) "callstack") "length") (
336+ JSSeq [ JSAlloc "func" (Just (JSApp (JSProj (JSProj (JSIdent ("vm")) "callstack") "pop") []))
337+ , JSAlloc "args" (Just (JSApp (JSProj (JSProj (JSIdent ("vm")) "callstack") "pop") []))
338+ , JSApp (JSProj (JSIdent "func") "apply") [JSThis, JSIdent "args"]
339+ ]
340+ )
335341 ]
336342 )
337343
@@ -377,8 +383,7 @@ splitFunction (JSAlloc name (Just (JSFunction args body@(JSSeq _)))) = do
377383 put (depth + 1)
378384 new <- splitFunction (newFun rest)
379385 tell [(depth, new)]
380− {-return $ JSSeq (pre ++ [newCall depth, call])-}
381− return $ JSSeq (pre ++ (call : [newCall depth]))
386+ return $ JSSeq (pre ++ (newCall depth : [call]))
382387
383388 splitSequence js = return js
384389