diff --git a/src/sixtypical/fallthru.py b/src/sixtypical/fallthru.py index 8a72e77..5913410 100644 --- a/src/sixtypical/fallthru.py +++ b/src/sixtypical/fallthru.py @@ -73,7 +73,7 @@ class FallthruAnalyzer(object): if routine.name not in self.fall_out_map: self.fall_out_map[routine.name] = None - routine_list = [] + roster = [] pending_routines = copy(self.fall_out_map) while pending_routines: # Pick a routine that is still pending to be serialized. @@ -87,13 +87,11 @@ class FallthruAnalyzer(object): chains.sort(key=len, reverse=True) routines = chains[0] - # Remove (r1,r2,...,rn) from R and append them to L in that order. - # Mark (r1,r2,...rn-1) as "will have their final goto removed." + # Append (r1,r2,...,rn) to the roster and remove r1,r2,...rn from R. + # A sublist like this appearing in the roster has meaning + # "optimize the final goto out of all but the last routine in the sublist". for r in routines: del pending_routines[r] - if r == routines[-1]: - routine_list.append(['retain', r]) - else: - routine_list.append(['fallthru', r]) + roster.append(routines) - return routine_list + return roster diff --git a/tests/SixtyPical Fallthru.md b/tests/SixtyPical Fallthru.md index f6b4ae9..ef0e40b 100644 --- a/tests/SixtyPical Fallthru.md +++ b/tests/SixtyPical Fallthru.md @@ -73,7 +73,6 @@ through to it. = *** serialization: = [ = [ - = "retain", = "main" = ] = ] @@ -97,18 +96,13 @@ If main does a `goto foo`, then it can fall through to `foo`. = *** serialization: = [ = [ - = "fallthru", - = "main" - = ], - = [ - = "retain", + = "main", = "foo" = ] = ] -More than one routine can fall through to a routine. - -If main does a `goto foo`, then it can fall through to `foo`. +More than one routine can fall through to a routine. We pick one +of them to fall through, when selecting the order of routines. | define foo routine trashes a, z, n | { @@ -134,15 +128,10 @@ If main does a `goto foo`, then it can fall through to `foo`. = *** serialization: = [ = [ - = "fallthru", - = "main" - = ], - = [ - = "retain", + = "main", = "foo" = ], = [ - = "retain", = "bar" = ] = ] @@ -188,15 +177,10 @@ fall through to the other. = *** serialization: = [ = [ - = "retain", = "main" = ], = [ - = "fallthru", - = "bar" - = ], - = [ - = "retain", + = "bar", = "foo" = ] = ] @@ -227,15 +211,12 @@ routine. = *** serialization: = [ = [ - = "retain", = "main" = ], = [ - = "retain", = "bar" = ], = [ - = "retain", = "foo" = ] = ] @@ -265,15 +246,12 @@ because we don't necessarily know what actual routine the vector contains. = *** serialization: = [ = [ - = "retain", = "main" = ], = [ - = "retain", = "bar" = ], = [ - = "retain", = "foo" = ] = ]