]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.cfg.tco: teach TCO about safepoints
authorJoe Groff <arcata@gmail.com>
Wed, 19 Oct 2011 20:04:43 +0000 (13:04 -0700)
committerJoe Groff <arcata@gmail.com>
Fri, 28 Oct 2011 04:14:46 +0000 (21:14 -0700)
basis/compiler/cfg/tco/tco.factor

index bd8a7cf7540e53a4a4835d5c7beb24860ef730f2..7751aa5b0343f88fa885feb4ca8bbf3e58355f3c 100644 (file)
@@ -15,9 +15,14 @@ IN: compiler.cfg.tco
 : return? ( bb -- ? )
     skip-empty-blocks
     instructions>> {
-        [ length 2 = ]
-        [ first ##epilogue? ]
-        [ second ##return? ]
+        [ length 3 = ]
+        [ first ##safepoint? ]
+        [ second ##epilogue? ]
+        [ third ##return? ]
+
+        ! [ length 2 = ]
+        ! [ first ##epilogue? ]
+        ! [ second ##return? ]
     } 1&& ;
 
 : tail-call? ( bb -- ? )
@@ -33,8 +38,9 @@ IN: compiler.cfg.tco
     '[
         instructions>>
         [ pop* ] [ pop ] [ ] tri
+        [ [ \ ##safepoint new-insn ] dip push ]
         [ [ \ ##epilogue new-insn ] dip push ]
-        [ _ dip push ] bi
+        [ _ dip push ] tri
     ]
     [ successors>> delete-all ]
     bi ; inline
@@ -48,7 +54,14 @@ IN: compiler.cfg.tco
 
 : convert-loop-tail-call ( bb -- )
     ! If a word calls itself, this becomes a loop in the CFG.
-    [ instructions>> [ pop* ] [ pop* ] [ [ \ ##branch new-insn ] dip push ] tri ]
+    [
+        instructions>> {
+            [ pop* ]
+            [ pop* ]
+            [ [ \ ##safepoint new-insn ] dip push ]
+            [ [ \ ##branch new-insn ] dip push ]
+        } cleave
+    ]
     [ successors>> delete-all ]
     [ [ cfg get entry>> successors>> first ] dip successors>> push ]
     tri ;