1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
use experimental:effects;
use test;
effect NestedEff {
effect Int fork();
}
handler NestedHandler(Int) for NestedEff {
handle fork(), k {
Int a = k.call(1);
Int b = k.call(10);
a + b;
}
}
handler OuterHandler(Int) for NestedEff {
handle fork(), k {
Int a = k.call(5);
Int b = k.call(50);
a + b;
}
}
test NestedTest1 {
Counter innerTimes;
Counter outerTimes;
// This is fairly logical:
Int result = handle (a = OuterHandler) {
Int intermediate = handle (b = NestedHandler) {
Int x = a.fork();
Int y = b.fork();
innerTimes.count++;
// print("Inner: ${x} ${y}");
x + y + 1000;
};
outerTimes.count++;
// print("Outer!");
intermediate + 10;
};
check result == 4152;
check innerTimes.count == 4;
check outerTimes.count == 2;
}
test NestedTest2 {
Counter innerTimes;
Counter outerTimes;
// Good luck tracing this. I do, however, believe it behaves correctly (verified in Pyret).
Int result = handle (a = OuterHandler) {
Int intermediate = handle (b = NestedHandler) {
Int x = b.fork();
Int y = a.fork();
innerTimes.count++;
// print("Inner: ${x} ${y}");
x + y + 1000;
};
outerTimes.count++;
// print("Outer!");
intermediate + 10;
};
check result == 8304;
check innerTimes.count == 6; // !
check outerTimes.count == 4;
}
|