2012-06-02 19:42:48 -05:00
|
|
|
// xfail-win32
|
|
|
|
|
|
|
|
use std;
|
|
|
|
|
|
|
|
import std::list::{list, cons, nil};
|
|
|
|
import std::time::precise_time_s;
|
|
|
|
|
|
|
|
fn main() {
|
2012-07-14 00:57:48 -05:00
|
|
|
let (repeat, depth) = if os::getenv(~"RUST_BENCH").is_some() {
|
2012-06-02 19:42:48 -05:00
|
|
|
(50, 1000)
|
|
|
|
} else {
|
|
|
|
(10, 10)
|
|
|
|
};
|
|
|
|
|
|
|
|
run(repeat, depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(repeat: int, depth: int) {
|
2012-07-04 14:04:28 -05:00
|
|
|
for iter::repeat(repeat as uint) {
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"starting %.4f", precise_time_s()};
|
2012-07-04 14:04:28 -05:00
|
|
|
do task::try {
|
2012-06-02 19:42:48 -05:00
|
|
|
recurse_or_fail(depth, none)
|
|
|
|
};
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"stopping %.4f", precise_time_s()};
|
2012-06-02 19:42:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type nillist = list<()>;
|
|
|
|
|
|
|
|
// Filled with things that have to be unwound
|
|
|
|
enum st {
|
|
|
|
st_({
|
|
|
|
box: @nillist,
|
|
|
|
unique: ~nillist,
|
|
|
|
fn_box: fn@() -> @nillist,
|
|
|
|
fn_unique: fn~() -> ~nillist,
|
|
|
|
tuple: (@nillist, ~nillist),
|
2012-06-29 18:26:56 -05:00
|
|
|
vec: ~[@nillist],
|
2012-06-02 19:42:48 -05:00
|
|
|
res: r
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2012-08-15 20:46:55 -05:00
|
|
|
struct r {
|
2012-06-22 15:11:29 -05:00
|
|
|
let _l: @nillist;
|
|
|
|
new(l: @nillist) { self._l = l; }
|
|
|
|
drop {}
|
2012-06-02 19:42:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn recurse_or_fail(depth: int, st: option<st>) {
|
|
|
|
if depth == 0 {
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"unwinding %.4f", precise_time_s()};
|
2012-06-02 19:42:48 -05:00
|
|
|
fail;
|
|
|
|
} else {
|
|
|
|
let depth = depth - 1;
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let st = match st {
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2012-06-02 19:42:48 -05:00
|
|
|
st_({
|
|
|
|
box: @nil,
|
|
|
|
unique: ~nil,
|
|
|
|
fn_box: fn@() -> @nillist { @nil::<()> },
|
|
|
|
fn_unique: fn~() -> ~nillist { ~nil::<()> },
|
|
|
|
tuple: (@nil, ~nil),
|
2012-06-29 18:26:56 -05:00
|
|
|
vec: ~[@nil],
|
2012-06-02 19:42:48 -05:00
|
|
|
res: r(@nil)
|
|
|
|
})
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
some(st) => {
|
2012-06-02 19:42:48 -05:00
|
|
|
let fn_box = st.fn_box;
|
|
|
|
let fn_unique = st.fn_unique;
|
|
|
|
|
|
|
|
st_({
|
|
|
|
box: @cons((), st.box),
|
|
|
|
unique: ~cons((), @*st.unique),
|
|
|
|
fn_box: fn@() -> @nillist { @cons((), fn_box()) },
|
|
|
|
fn_unique: fn~() -> ~nillist { ~cons((), @*fn_unique()) },
|
2012-07-16 16:32:59 -05:00
|
|
|
tuple: (@cons((), st.tuple.first()),
|
|
|
|
~cons((), @*st.tuple.second())),
|
2012-06-29 18:26:56 -05:00
|
|
|
vec: st.vec + ~[@cons((), st.vec.last())],
|
2012-06-25 14:20:51 -05:00
|
|
|
res: r(@cons((), st.res._l))
|
2012-06-02 19:42:48 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
recurse_or_fail(depth, some(st));
|
|
|
|
}
|
|
|
|
}
|