add tail call test

This commit is contained in:
Joel Dice 2011-03-15 17:51:32 -06:00
parent e6cf992af7
commit 48e569c65a
2 changed files with 55 additions and 1 deletions

View File

@ -585,6 +585,11 @@ ifeq ($(continuations),true)
extra.DynamicWind
endif
ifeq ($(tails),true)
tail-tests = \
extra.Tails
endif
class-name = $(patsubst $(1)/%.class,%,$(2))
class-names = $(foreach x,$(2),$(call class-name,$(1),$(x)))
@ -617,7 +622,7 @@ test: build
$(library-path) /bin/sh $(test)/test.sh 2>/dev/null \
$(test-executable) $(mode) "$(test-flags)" \
$(call class-names,$(test-build),$(test-classes)) \
$(continuation-tests)
$(continuation-tests) $(tail-tests)
.PHONY: tarball
tarball:

49
test/extra/Tails.java Normal file
View File

@ -0,0 +1,49 @@
package extra;
public class Tails {
private static final int Limit = 1000000;
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
private static int staticMethod(Interface i, int n) {
if (n < Limit) {
return i.interfaceMethod(n + 1);
} else {
return leafMethod(n);
}
}
private static int leafMethod(int n) {
expect(new Throwable().getStackTrace().length == 2);
return n;
}
public static void main(String[] args) {
expect(staticMethod(new Foo(), 0) == Limit);
}
private interface Interface {
public int interfaceMethod(int n);
}
private static class Foo implements Interface {
public int interfaceMethod(int n) {
if (n < Limit) {
return virtualMethod(n + 1, 1, 2, 3, 4, 5);
} else {
return leafMethod(n);
}
}
public int virtualMethod(int n, int a, int b, int c, int d, int e) {
if (n < Limit) {
return staticMethod(this, n + 1);
} else {
return leafMethod(n);
}
}
}
}