pike.git/
src/
testsuite.in
Branch:
Tag:
Non-build tags
All tags
No tags
2001-02-08
2001-02-08 04:04:41 by Martin Stjernholm <mast@lysator.liu.se>
692ebeb7967553bd851bad1c5b366dc9463a750b (
276
lines) (+
275
/-
1
)
[
Show
|
Annotate
]
Branch:
7.9
Added tests for premature stack popping in the tail recursion opcodes.
Rev: src/testsuite.in:1.383
1:
-
test_true([["$Id: testsuite.in,v 1.
382
2001/02/
05
11
:
24
:
16
mirar
Exp $"]]);
+
test_true([["$Id: testsuite.in,v 1.
383
2001/02/
08
04
:
04
:
41
mast
Exp $"]]);
cond([[all_constants()->_verify_internals]], [[
340:
Top(); ]]);
+
// Testing stack popping in the tail recursion opcodes
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
int a()
+
{
+
object key = monitor::lock();
+
return f (1); // F_CALL_LFUN_AND_RETURN
+
};
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
mixed g = f;
+
int a()
+
{
+
object key = monitor::lock();
+
return g (1); // F_CALL_FUNCTION_AND_RETURN
+
}
+
]]);
+
test_program([[
+
Thread.Mutex monitor = Thread.Mutex();
+
int f (int x)
+
{
+
if(monitor->trylock(1))
+
return 0;
+
return x;
+
}
+
int a()
+
{
+
add_constant ("f", f);
+
add_constant ("monitor", monitor);
+
return compile_string(#"
+
int g()
+
{
+
object key = monitor->lock();
+
return f (1); // F_APPLY_AND_RETURN
+
}")()->g();
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (iter == 1) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
object key = monitor::lock();
+
iter = 1;
+
return a (1); // F_COND_RECUR
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
object key = monitor::lock();
+
iter = 2;
+
return a (1); // F_TAIL_RECUR
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
object key = monitor::lock();
+
iter = 2;
+
int res = a (1); // F_RECUR
+
iter = -1;
+
return res;
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
iter = 0;
+
iter = x;
+
}
+
else {
+
object key = monitor::lock();
+
iter = 2;
+
a (1); // F_RECUR_AND_POP
+
return iter;
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
int a()
+
{
+
({monitor::lock(), catch {
+
return f (1); // F_CALL_LFUN_AND_RETURN
+
}});
+
};
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
mixed g = f;
+
int a()
+
{
+
({monitor::lock(), catch {
+
return g (1); // F_CALL_FUNCTION_AND_RETURN
+
}});
+
}
+
]]);
+
test_program([[
+
Thread.Mutex monitor = Thread.Mutex();
+
int f (int x)
+
{
+
if(monitor->trylock(1))
+
return 0;
+
return x;
+
}
+
int a()
+
{
+
add_constant ("f", f);
+
add_constant ("monitor", monitor);
+
return compile_string(#"
+
int g()
+
{
+
({monitor->lock(), catch {
+
return f (1); // F_APPLY_AND_RETURN
+
}});
+
}")()->g();
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (iter == 1) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
iter = 1;
+
({monitor::lock(), catch {
+
return a (1); // F_COND_RECUR
+
}});
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
iter = 2;
+
({monitor::lock(), catch {
+
return a (1); // F_TAIL_RECUR
+
}});
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
iter = 2;
+
int res;
+
({monitor::lock(), catch {
+
res = a (1); // F_RECUR
+
}});
+
return res;
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
iter = 0;
+
iter = x;
+
}
+
else {
+
iter = 2;
+
({monitor::lock(), catch {
+
a (1); // F_RECUR_AND_POP
+
}});
+
return iter;
+
}
+
}
+
]]);
+
test_false([[object_variablep(class X { int y; int z() { return 1; }}(),"foo")]]) test_false([[object_variablep(class X { int y; int z() { return 1; }}(),"z")]]) test_true([[object_variablep(class X { int y; int z() { return 1; }}(),"y")]])