mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
add tail call test
This commit is contained in:
parent
e6cf992af7
commit
48e569c65a
7
makefile
7
makefile
@ -585,6 +585,11 @@ ifeq ($(continuations),true)
|
|||||||
extra.DynamicWind
|
extra.DynamicWind
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(tails),true)
|
||||||
|
tail-tests = \
|
||||||
|
extra.Tails
|
||||||
|
endif
|
||||||
|
|
||||||
class-name = $(patsubst $(1)/%.class,%,$(2))
|
class-name = $(patsubst $(1)/%.class,%,$(2))
|
||||||
class-names = $(foreach x,$(2),$(call class-name,$(1),$(x)))
|
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 \
|
$(library-path) /bin/sh $(test)/test.sh 2>/dev/null \
|
||||||
$(test-executable) $(mode) "$(test-flags)" \
|
$(test-executable) $(mode) "$(test-flags)" \
|
||||||
$(call class-names,$(test-build),$(test-classes)) \
|
$(call class-names,$(test-build),$(test-classes)) \
|
||||||
$(continuation-tests)
|
$(continuation-tests) $(tail-tests)
|
||||||
|
|
||||||
.PHONY: tarball
|
.PHONY: tarball
|
||||||
tarball:
|
tarball:
|
||||||
|
49
test/extra/Tails.java
Normal file
49
test/extra/Tails.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user