diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index c842402c70b..5853e6e0e87 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -27,7 +27,10 @@ fn print_complements() { enum color { Red, Yellow, Blue } -type creature_info = { name: uint, color: color }; +struct CreatureInfo { + name: uint, + color: color +} fn show_color(cc: color) -> ~str { match (cc) { @@ -95,8 +98,8 @@ fn transform(aa: color, bb: color) -> color { fn creature( name: uint, color: color, - from_rendezvous: oldcomm::Port>, - to_rendezvous: oldcomm::Chan, + from_rendezvous: oldcomm::Port>, + to_rendezvous: oldcomm::Chan, to_rendezvous_log: oldcomm::Chan<~str> ) { let mut color = color; @@ -105,7 +108,7 @@ fn creature( loop { // ask for a pairing - oldcomm::send(to_rendezvous, {name: name, color: color}); + oldcomm::send(to_rendezvous, CreatureInfo {name: name, color: color}); let resp = oldcomm::recv(from_rendezvous); // log and change, or print and quit @@ -145,7 +148,7 @@ fn rendezvous(nn: uint, set: ~[color]) { } // these ports will allow us to hear from the creatures - let from_creatures: oldcomm::Port = oldcomm::Port(); + let from_creatures: oldcomm::Port = oldcomm::Port(); let from_creatures_log: oldcomm::Port<~str> = oldcomm::Port(); // these channels will be passed to the creatures so they can talk to us @@ -153,7 +156,7 @@ fn rendezvous(nn: uint, set: ~[color]) { let to_rendezvous_log = oldcomm::Chan(&from_creatures_log); // these channels will allow us to talk to each creature by 'name'/index - let to_creature: ~[oldcomm::Chan>] = + let to_creature: ~[oldcomm::Chan>] = vec::mapi(set, |ii, col| { // create each creature as a listener with a port, and // give us a channel to talk to each @@ -169,8 +172,8 @@ fn rendezvous(nn: uint, set: ~[color]) { // set up meetings... for nn.times { - let fst_creature: creature_info = oldcomm::recv(from_creatures); - let snd_creature: creature_info = oldcomm::recv(from_creatures); + let fst_creature: CreatureInfo = oldcomm::recv(from_creatures); + let snd_creature: CreatureInfo = oldcomm::recv(from_creatures); creatures_met += 2; diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index ffb32181dc4..da2f2d5c3d2 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -20,25 +20,33 @@ use io::WriterUtil; fn LINE_LENGTH() -> uint { return 60u; } -type myrandom = @{mut last: u32}; +struct MyRandom { + mut last: u32 +} -fn myrandom_next(r: myrandom, mx: u32) -> u32 { +fn myrandom_next(r: @MyRandom, mx: u32) -> u32 { r.last = (r.last * 3877u32 + 29573u32) % 139968u32; mx * r.last / 139968u32 } -type aminoacids = {ch: char, prob: u32}; +struct AminoAcids { + ch: char, + prob: u32 +} -fn make_cumulative(aa: ~[aminoacids]) -> ~[aminoacids] { +fn make_cumulative(aa: ~[AminoAcids]) -> ~[AminoAcids] { let mut cp: u32 = 0u32; - let mut ans: ~[aminoacids] = ~[]; - for aa.each |a| { cp += a.prob; ans += ~[{ch: a.ch, prob: cp}]; } + let mut ans: ~[AminoAcids] = ~[]; + for aa.each |a| { + cp += a.prob; + ans += ~[AminoAcids {ch: a.ch, prob: cp}]; + } return ans; } -fn select_random(r: u32, genelist: ~[aminoacids]) -> char { +fn select_random(r: u32, genelist: ~[AminoAcids]) -> char { if r < genelist[0].prob { return genelist[0].ch; } - fn bisect(v: ~[aminoacids], lo: uint, hi: uint, target: u32) -> char { + fn bisect(v: ~[AminoAcids], lo: uint, hi: uint, target: u32) -> char { if hi > lo + 1u { let mid: uint = lo + (hi - lo) / 2u; if target < v[mid].prob { @@ -46,12 +54,12 @@ fn select_random(r: u32, genelist: ~[aminoacids]) -> char { } else { return bisect(v, mid, hi, target); } } else { return v[hi].ch; } } - return bisect(copy genelist, 0, vec::len::(genelist) - 1, r); + return bisect(copy genelist, 0, vec::len::(genelist) - 1, r); } -fn make_random_fasta(wr: io::Writer, id: ~str, desc: ~str, genelist: ~[aminoacids], n: int) { +fn make_random_fasta(wr: io::Writer, id: ~str, desc: ~str, genelist: ~[AminoAcids], n: int) { wr.write_line(~">" + id + ~" " + desc); - let rng = @{mut last: rand::Rng().next()}; + let rng = @MyRandom {mut last: rand::Rng().next()}; let mut op: ~str = ~""; for uint::range(0u, n as uint) |_i| { str::push_char(&mut op, select_random(myrandom_next(rng, 100u32), @@ -80,7 +88,9 @@ fn make_repeat_fasta(wr: io::Writer, id: ~str, desc: ~str, s: ~str, n: int) { } } -fn acid(ch: char, prob: u32) -> aminoacids { return {ch: ch, prob: prob}; } +fn acid(ch: char, prob: u32) -> AminoAcids { + return AminoAcids {ch: ch, prob: prob}; +} fn main() { let args = os::args(); @@ -102,13 +112,13 @@ fn main() { let n = int::from_str(args[1]).get(); - let iub: ~[aminoacids] = + let iub: ~[AminoAcids] = make_cumulative(~[acid('a', 27u32), acid('c', 12u32), acid('g', 12u32), acid('t', 27u32), acid('B', 2u32), acid('D', 2u32), acid('H', 2u32), acid('K', 2u32), acid('M', 2u32), acid('N', 2u32), acid('R', 2u32), acid('S', 2u32), acid('V', 2u32), acid('W', 2u32), acid('Y', 2u32)]); - let homosapiens: ~[aminoacids] = + let homosapiens: ~[AminoAcids] = make_cumulative(~[acid('a', 30u32), acid('c', 20u32), acid('g', 20u32), acid('t', 30u32)]); let alu: ~str = diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 75e277e3379..c915820a45a 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -36,7 +36,7 @@ fn main() { args }; let n = int::from_str(args[1]).get(); - let mut bodies: ~[Body::props] = NBodySystem::make(); + let mut bodies: ~[Body::Props] = NBodySystem::make(); io::println(fmt!("%f", NBodySystem::energy(bodies))); let mut i = 0; while i < n { @@ -49,8 +49,8 @@ fn main() { mod NBodySystem { use Body; - pub fn make() -> ~[Body::props] { - let mut bodies: ~[Body::props] = + pub fn make() -> ~[Body::Props] { + let mut bodies: ~[Body::Props] = ~[Body::sun(), Body::jupiter(), Body::saturn(), @@ -76,7 +76,7 @@ mod NBodySystem { return bodies; } - pub fn advance(bodies: &mut [Body::props], dt: float) { + pub fn advance(bodies: &mut [Body::Props], dt: float) { let mut i = 0; while i < 5 { let mut j = i + 1; @@ -96,8 +96,8 @@ mod NBodySystem { } } - pub fn advance_one(bi: &mut Body::props, - bj: &mut Body::props, + pub fn advance_one(bi: &mut Body::Props, + bj: &mut Body::Props, dt: float) { unsafe { let dx = bi.x - bj.x; @@ -119,13 +119,13 @@ mod NBodySystem { } } - pub fn move_(b: &mut Body::props, dt: float) { + pub fn move_(b: &mut Body::Props, dt: float) { b.x += dt * b.vx; b.y += dt * b.vy; b.z += dt * b.vz; } - pub fn energy(bodies: &[Body::props]) -> float { + pub fn energy(bodies: &[Body::Props]) -> float { unsafe { let mut dx; let mut dy; @@ -171,17 +171,17 @@ mod Body { // was 4 * PI * PI originally pub const DAYS_PER_YEAR: float = 365.24; - pub type props = + pub struct Props {mut x: float, mut y: float, mut z: float, mut vx: float, mut vy: float, mut vz: float, - mass: float}; + mass: float} - pub fn jupiter() -> Body::props { - return {mut x: 4.84143144246472090e+00, + pub fn jupiter() -> Body::Props { + return Props {mut x: 4.84143144246472090e+00, mut y: -1.16032004402742839e+00, mut z: -1.03622044471123109e-01, mut vx: 1.66007664274403694e-03 * DAYS_PER_YEAR, @@ -190,8 +190,8 @@ mod Body { mass: 9.54791938424326609e-04 * SOLAR_MASS}; } - pub fn saturn() -> Body::props { - return {mut x: 8.34336671824457987e+00, + pub fn saturn() -> Body::Props { + return Props {mut x: 8.34336671824457987e+00, mut y: 4.12479856412430479e+00, mut z: -4.03523417114321381e-01, mut vx: -2.76742510726862411e-03 * DAYS_PER_YEAR, @@ -200,8 +200,8 @@ mod Body { mass: 2.85885980666130812e-04 * SOLAR_MASS}; } - pub fn uranus() -> Body::props { - return {mut x: 1.28943695621391310e+01, + pub fn uranus() -> Body::Props { + return Props {mut x: 1.28943695621391310e+01, mut y: -1.51111514016986312e+01, mut z: -2.23307578892655734e-01, mut vx: 2.96460137564761618e-03 * DAYS_PER_YEAR, @@ -210,8 +210,8 @@ mod Body { mass: 4.36624404335156298e-05 * SOLAR_MASS}; } - pub fn neptune() -> Body::props { - return {mut x: 1.53796971148509165e+01, + pub fn neptune() -> Body::Props { + return Props {mut x: 1.53796971148509165e+01, mut y: -2.59193146099879641e+01, mut z: 1.79258772950371181e-01, mut vx: 2.68067772490389322e-03 * DAYS_PER_YEAR, @@ -220,8 +220,8 @@ mod Body { mass: 5.15138902046611451e-05 * SOLAR_MASS}; } - pub fn sun() -> Body::props { - return {mut x: 0.0, + pub fn sun() -> Body::Props { + return Props {mut x: 0.0, mut y: 0.0, mut z: 0.0, mut vx: 0.0, @@ -230,7 +230,7 @@ mod Body { mass: SOLAR_MASS}; } - pub fn offset_momentum(props: &mut Body::props, + pub fn offset_momentum(props: &mut Body::Props, px: float, py: float, pz: float) { props.vx = -px / SOLAR_MASS; props.vy = -py / SOLAR_MASS; diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 80bcb834054..b56552d46fe 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -55,15 +55,19 @@ fn fib(n: int) -> int { p.recv() } -type config = {stress: bool}; +struct Config { + stress: bool +} -fn parse_opts(argv: ~[~str]) -> config { +fn parse_opts(argv: ~[~str]) -> Config { let opts = ~[getopts::optflag(~"stress")]; - let opt_args = vec::slice(argv, 1u, vec::len(argv)); + let opt_args = vec::slice(argv, 1, argv.len()); match getopts::getopts(opt_args, opts) { - Ok(ref m) => { return {stress: getopts::opt_present(m, ~"stress")} } + Ok(ref m) => { + return Config {stress: getopts::opt_present(m, ~"stress")} + } Err(_) => { fail; } } } diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index 992162f98bf..52826752922 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -38,16 +38,15 @@ fn run(repeat: int, depth: int) { 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), - vec: ~[@nillist], - res: r - }) + +struct State { + box: @nillist, + unique: ~nillist, + fn_box: fn@() -> @nillist, + fn_unique: fn~() -> ~nillist, + tuple: (@nillist, ~nillist), + vec: ~[@nillist], + res: r } struct r { @@ -64,7 +63,7 @@ fn r(l: @nillist) -> r { } } -fn recurse_or_fail(depth: int, st: Option) { +fn recurse_or_fail(depth: int, st: Option) { if depth == 0 { debug!("unwinding %.4f", precise_time_s()); fail; @@ -73,7 +72,7 @@ fn recurse_or_fail(depth: int, st: Option) { let st = match st { None => { - st_({ + State { box: @Nil, unique: ~Nil, fn_box: fn@() -> @nillist { @Nil::<()> }, @@ -81,13 +80,13 @@ fn recurse_or_fail(depth: int, st: Option) { tuple: (@Nil, ~Nil), vec: ~[@Nil], res: r(@Nil) - }) + } } Some(st) => { let fn_box = st.fn_box; let fn_unique = copy st.fn_unique; - st_({ + State { box: @Cons((), st.box), unique: ~Cons((), @*st.unique), fn_box: fn@() -> @nillist { @Cons((), fn_box()) }, @@ -97,7 +96,7 @@ fn recurse_or_fail(depth: int, st: Option) { ~Cons((), @*st.tuple.second())), vec: st.vec + ~[@Cons((), st.vec.last())], res: r(@Cons((), st.res._l)) - }) + } } };