From a5d946734a5d53ed191982d7aa0e65dc6e06bb6a Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Fri, 6 Apr 2018 13:24:04 +0100 Subject: [PATCH] Add more tests. Apparently our algorithm does not do a good job. --- tests/SixtyPical Fallthru.md | 83 ++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/tests/SixtyPical Fallthru.md b/tests/SixtyPical Fallthru.md index 7f50462..ec88370 100644 --- a/tests/SixtyPical Fallthru.md +++ b/tests/SixtyPical Fallthru.md @@ -81,7 +81,7 @@ through to it. = ] = ] -If main does a `goto foo`, then it can fall through to `foo`. +If `main` does a `goto foo`, then it can fall through to `foo`. | define foo routine trashes a, z, n | { @@ -102,9 +102,6 @@ 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. -Also note, `main` is always serialized first, so that the entry -point of the entire program appears at the beginning of the code. - | define foo routine trashes a, z, n | { | ld a, 0 @@ -130,6 +127,29 @@ point of the entire program appears at the beginning of the code. = ] = ] +Because `main` is always serialized first (so that the entry +point of the entire program appears at the beginning of the code), +nothing ever falls through to `main`. + + | define foo routine trashes a, z, n + | { + | ld a, 0 + | goto main + | } + | + | define main routine trashes a, z, n + | { + | ld a, 1 + | } + = [ + = [ + = "main" + = ], + = [ + = "foo" + = ] + = ] + There is nothing stopping two routines from tail-calling each other, but we will only be able to make one of them, at most, fall through to the other. @@ -226,6 +246,61 @@ because we don't necessarily know what actual routine the vector contains. = ] = ] +Our algorithm might not be strictly optimal, but it does a good job. + + | define r1 routine trashes a, z, n + | { + | ld a, 0 + | goto r2 + | } + | + | define r2 routine trashes a, z, n + | { + | ld a, 0 + | goto r3 + | } + | + | define r3 routine trashes a, z, n + | { + | ld a, 0 + | goto r4 + | } + | + | define r4 routine trashes a, z, n + | { + | ld a, 0 + | } + | + | define r5 routine trashes a, z, n + | { + | ld a, 0 + | goto r6 + | } + | + | define r6 routine trashes a, z, n + | { + | ld a, 0 + | goto r3 + | } + | + | define main routine trashes a, z, n + | { + | goto r1 + | } + = [ + = [ + = "main", + = "r1", + = "r2", + = "r3", + = "r4" + = ], + = [ + = "r5", + = "r6" + = ] + = ] + -> Tests for functionality "Compile SixtyPical program with fallthru optimization" Basic test for actually applying this optimization when compiling SixtyPical programs.