Remove do keyword from test/

This commit is contained in:
Scott Lawrence 2014-01-27 18:29:50 -05:00
parent bb22ace3f0
commit 3dbc1c34e6
92 changed files with 191 additions and 499 deletions

View file

@ -12,8 +12,8 @@ use std::task;
pub fn foo<T:Send + Clone>(x: T) -> Port<T> {
let (p, c) = Chan::new();
do task::spawn() {
task::spawn(proc() {
c.send(x.clone());
}
});
p
}

View file

@ -64,17 +64,17 @@ fn run(args: &[~str]) {
let to_child = to_child.clone();
let mut builder = task::task();
worker_results.push(builder.future_result());
do builder.spawn {
builder.spawn(proc() {
for _ in range(0u, size / workers) {
//error!("worker {:?}: sending {:?} bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
}
//error!("worker {:?} exiting", i);
}
});
}
do task::spawn || {
task::spawn(proc() {
server(&from_parent, &to_parent);
}
});
for r in worker_results.iter() {
r.recv();

View file

@ -58,13 +58,13 @@ fn run(args: &[~str]) {
let (from_parent, to_child) = Chan::new();
let mut builder = task::task();
worker_results.push(builder.future_result());
do builder.spawn {
builder.spawn(proc() {
for _ in range(0u, size / workers) {
//error!("worker {:?}: sending {:?} bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
}
//error!("worker {:?} exiting", i);
};
});
from_parent
} else {
let (from_parent, to_child) = SharedChan::new();
@ -72,19 +72,19 @@ fn run(args: &[~str]) {
let to_child = to_child.clone();
let mut builder = task::task();
worker_results.push(builder.future_result());
do builder.spawn {
builder.spawn(proc() {
for _ in range(0u, size / workers) {
//error!("worker {:?}: sending {:?} bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
}
//error!("worker {:?} exiting", i);
};
});
}
from_parent
};
do task::spawn || {
task::spawn(proc() {
server(&from_parent, &to_parent);
}
});
for r in worker_results.iter() {
r.recv();

View file

@ -91,9 +91,9 @@ fn main() {
//error!("spawning %?", i);
let (new_chan, num_port) = init();
let num_chan_2 = num_chan.clone();
let new_future = do Future::spawn() {
let new_future = Future::spawn(proc() {
thread_ring(i, msg_per_task, num_chan_2, num_port)
};
});
futures.push(new_future);
num_chan = new_chan;
};

View file

@ -87,9 +87,9 @@ fn main() {
//error!("spawning %?", i);
let (new_chan, num_port) = init();
let num_chan_2 = num_chan.clone();
let new_future = do Future::spawn {
let new_future = Future::spawn(proc() {
thread_ring(i, msg_per_task, num_chan_2, num_port)
};
});
futures.push(new_future);
num_chan = new_chan;
};

View file

@ -26,23 +26,23 @@ fn ping_pong_bench(n: uint, m: uint) {
// Create a stream B->A
let (pb,cb) = Chan::<()>::new();
do spawn() || {
spawn(proc() {
let chan = ca;
let port = pb;
n.times(|| {
chan.send(());
port.recv();
})
}
});
do spawn() || {
spawn(proc() {
let chan = cb;
let port = pa;
n.times(|| {
port.recv();
chan.send(());
})
}
});
}
m.times(|| {

View file

@ -23,9 +23,9 @@ fn parfib(n: uint) -> uint {
}
let (port,chan) = Chan::new();
do spawn {
spawn(proc() {
chan.send(parfib(n-1));
};
});
let m2 = parfib(n-2);
return (port.recv() + m2);
}

View file

@ -27,7 +27,7 @@ fn main() {
};
n.times(|| {
do spawn || {};
spawn(proc() {});
})
}

View file

@ -64,7 +64,7 @@ fn main() {
let mut messages = range_step(min_depth, max_depth + 1, 2).map(|depth| {
use std::num::pow;
let iterations = pow(2, (max_depth - depth + min_depth) as uint);
do Future::spawn {
Future::spawn(proc() {
let mut chk = 0;
for i in range(1, iterations + 1) {
let arena = TypedArena::new();
@ -74,7 +74,7 @@ fn main() {
}
format!("{}\t trees of depth {}\t check: {}",
iterations * 2, depth, chk)
}
})
}).to_owned_vec();
for message in messages.mut_iter() {

View file

@ -152,13 +152,13 @@ fn rendezvous(nn: uint, set: ~[color]) {
let to_rendezvous = to_rendezvous.clone();
let to_rendezvous_log = to_rendezvous_log.clone();
let (from_rendezvous, to_creature) = Chan::new();
do task::spawn {
task::spawn(proc() {
creature(ii,
col,
from_rendezvous,
to_rendezvous.clone(),
to_rendezvous_log.clone());
}
});
to_creature
}).collect();

View file

@ -168,9 +168,9 @@ fn main() {
let (from_parent, to_child) = Chan::new();
do spawn {
spawn(proc() {
make_sequence_processor(sz, &from_parent, &to_parent_);
}
});
to_child
}).collect::<~[Chan<~[u8]>]>();

View file

@ -79,9 +79,9 @@ fn stress(num_tasks: int) {
for i in range(0, num_tasks) {
let mut builder = task::task();
results.push(builder.future_result());
do builder.spawn {
builder.spawn(proc() {
stress_task(i);
}
});
}
for r in results.iter() {
r.recv();

View file

@ -41,13 +41,13 @@ fn mult(v: RWArc<~[f64]>, out: RWArc<~[f64]>, f: fn(&~[f64], uint) -> f64) {
let w = wait.clone();
let v = v.clone();
let out = out.clone();
do spawn {
spawn(proc() {
for i in range(chk, min(len, chk + chunk)) {
let val = v.read(|v| f(v, i));
out.write(|out| out[i] = val);
}
let _ = w;
}
});
}
let _ = wait.unwrap();
}

View file

@ -23,17 +23,17 @@ fn start(n_tasks: int, token: int) {
let (next_p, ch) = Chan::new();
let imm_i = i;
let imm_p = p;
do spawn {
spawn(proc() {
roundtrip(imm_i, n_tasks, &imm_p, &ch);
};
});
p = next_p;
i += 1;
}
let imm_p = p;
let imm_ch = ch1;
do spawn {
spawn(proc() {
roundtrip(1, n_tasks, &imm_p, &imm_ch);
}
});
}
fn roundtrip(id: int, n_tasks: int, p: &Port<int>, ch: &Chan<int>) {

View file

@ -11,6 +11,6 @@
// Useful smoketest for scheduler performance.
fn main() {
for _ in range(1, 100_000) {
do spawn { }
spawn(proc() {})
}
}

View file

@ -10,5 +10,5 @@
// Useful for checking syscall usage of baseline scheduler usage
fn main() {
do spawn { }
spawn(proc() {});
}

View file

@ -34,9 +34,9 @@ fn main() {
fn run(repeat: int, depth: int) {
for _ in range(0, repeat) {
info!("starting {:.4f}", precise_time_s());
do task::try {
task::try(proc() {
recurse_or_fail(depth, None)
};
});
info!("stopping {:.4f}", precise_time_s());
}
}

View file

@ -26,7 +26,7 @@ fn child_generation(gens_left: uint, c: comm::Chan<()>) {
// This used to be O(n^2) in the number of generations that ever existed.
// With this code, only as many generations are alive at a time as tasks
// alive at a time,
do spawn {
spawn(proc() {
if gens_left & 1 == 1 {
task::deschedule(); // shake things up a bit
}
@ -35,7 +35,7 @@ fn child_generation(gens_left: uint, c: comm::Chan<()>) {
} else {
c.send(())
}
}
});
}
fn main() {

View file

@ -36,11 +36,11 @@ fn grandchild_group(num_tasks: uint) {
for _ in range(0, num_tasks) {
let ch = ch.clone();
let mut t = task::task();
do t.spawn { // linked
t.spawn(proc() { // linked
ch.send(());
let (p, _c) = stream::<()>();
p.recv(); // block forever
}
});
}
error!("Grandchild group getting started");
for _ in range(0, num_tasks) {
@ -77,17 +77,17 @@ fn main() {
// Main group #0 waits for unsupervised group #1.
// Grandparent group #1 waits for middle group #2, then fails, killing #3.
// Middle group #2 creates grandchild_group #3, waits for it to be ready, exits.
let x: result::Result<(), ~Any> = do task::try { // unlinked
do spawn_supervised_blocking("grandparent") {
do spawn_supervised_blocking("middle") {
let x: result::Result<(), ~Any> = task::try(proc() { // unlinked
spawn_supervised_blocking("grandparent", proc() {
spawn_supervised_blocking("middle", proc() {
grandchild_group(num_tasks);
}
});
// When grandchild group is ready to go, make the middle group exit.
error!("Middle group wakes up and exits");
}
});
// Grandparent group waits for middle group to be gone, then fails
error!("Grandparent group wakes up and fails");
fail!();
};
});
assert!(x.is_err());
}

View file

@ -21,9 +21,9 @@ fn calc(children: uint, parent_wait_chan: &Chan<Chan<Chan<int>>>) {
let wait_ports: ~[Port<Chan<Chan<int>>>] = vec::from_fn(children, |_| {
let (wait_port, wait_chan) = stream::<Chan<Chan<int>>>();
do task::spawn {
task::spawn(proc() {
calc(children / 2, &wait_chan);
}
});
wait_port
});
@ -58,9 +58,9 @@ fn main() {
let children = from_str::<uint>(args[1]).unwrap();
let (wait_port, wait_chan) = stream();
do task::spawn {
task::spawn(proc() {
calc(children, &wait_chan);
};
});
let start_chan = wait_port.recv();
let (sum_port, sum_chan) = stream::<int>();

View file

@ -19,5 +19,5 @@ fn main() {
});
y.unwrap();
// Adding this line causes a method unification failure instead
// do (&option::unwrap(y)).read |state| { assert!(*state == 1); }
// (&option::unwrap(y)).read(|state| { assert!(*state == 1); })
}

View file

@ -17,5 +17,5 @@ fn main() {
x.write_downgrade(|write_mode| y = Some(write_mode));
y.unwrap();
// Adding this line causes a method unification failure instead
// do (&option::unwrap(y)).write |state| { assert!(*state == 1); }
// (&option::unwrap(y)).write(|state| { assert!(*state == 1); })
}

View file

@ -17,10 +17,10 @@ fn borrow(v: &int, f: |x: &int|) {
fn box_imm() {
let v = ~3;
let _w = &v;
do task::spawn {
task::spawn(proc() {
info!("v={}", *v);
//~^ ERROR cannot move `v` into closure
}
});
let v = ~3;
let _w = &v;

View file

@ -1,15 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
do something
|x| do somethingelse //~ ERROR: expected `{` but found `do`
|y| say(x, y)
}

View file

@ -1,13 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let x = do y; //~ ERROR: expected `{` but found
}

View file

@ -1,16 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: proc(int) -> bool) -> bool { f(10i) }
fn main() {
assert!(do f() |i| { i == 10i } == 10i);
//~^ ERROR: expected `bool` but found `int`
}

View file

@ -10,9 +10,9 @@
fn main() {
let needlesArr: ~[char] = ~['a', 'f'];
do needlesArr.iter().fold() |x, y| {
}
//~^^ ERROR 1 parameter was supplied (including the closure passed by the `do` keyword)
needlesArr.iter().fold(|x, y| {
});
//~^^ ERROR this function takes 2 parameters but 1 parameter was supplied
//
// the first error is, um, non-ideal.
}

View file

@ -1,15 +0,0 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This file was auto-generated using 'src/etc/generate-keyword-tests.py do'
fn main() {
let do = "foo"; //~ error: ident
}

View file

@ -2,8 +2,8 @@ use std::task;
fn main() {
let x = ~"Hello world!";
do task::spawn {
task::spawn(proc() {
println!("{}", x);
}
});
println!("{}", x); //~ ERROR use of moved value
}

View file

@ -17,10 +17,10 @@ fn test_mutex_arc_nested() {
let arc = ~MutexArc::new(1);
let arc2 = ~MutexArc::new(*arc);
do task::spawn || {
task::spawn(proc() {
(*arc2).access(|mutex| { //~ ERROR instantiating a type parameter with an incompatible type
})
};
});
}
fn main() {}

View file

@ -19,10 +19,10 @@ fn main() {
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::Arc::new(v);
do task::spawn() {
task::spawn(proc() {
let v = arc_v.get();
assert_eq!(v[3], 4);
};
});
assert_eq!((arc_v.get())[2], 3);

View file

@ -17,10 +17,10 @@ fn main() {
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::Arc::new(v);
do task::spawn() {
task::spawn(proc() {
let v = arc_v.get();
assert_eq!(v[3], 4);
};
});
assert_eq!((arc_v.get())[2], 3); //~ ERROR use of moved value: `arc_v`

View file

@ -32,8 +32,8 @@ fn main() {
let x = foo(Port(@()));
do task::spawn {
task::spawn(proc() {
let y = x; //~ ERROR does not fulfill `Send`
error!("{:?}", y);
}
});
}

View file

@ -22,8 +22,8 @@ fn foo(blk: proc()) {
fn main() {
let x = arc::Arc::new(true);
do foo {
foo(proc() {
assert!(*x.get());
drop(x);
}
});
}

View file

@ -18,5 +18,5 @@ fn main() {
y = Some(x.downgrade(write_mode));
})
// Adding this line causes a method unification failure instead
// do (&option::unwrap(y)).read { }
// (&option::unwrap(y)).read(proc() { });
}

View file

@ -18,5 +18,5 @@ fn main() {
y = Some(write_mode);
});
// Adding this line causes a method unification failure instead
// do (&option::unwrap(y)).write { }
// (&option::unwrap(y)).write(proc() { })
}

View file

@ -41,11 +41,11 @@ fn count(n: uint) -> uint {
}
fn main() {
do 10u.times {
do task::spawn {
10u.times(proc() {
task::spawn(proc() {
let result = count(5u);
info!("result = %?", result);
fail!();
};
}
});
});
}

View file

@ -13,8 +13,8 @@
use std::task;
fn main() {
do task::try {
task::try(proc() {
fail!("test");
1
}.unwrap()
}).unwrap()
}

View file

@ -15,8 +15,8 @@ use std::task;
fn main() {
let mut t = task::task();
t.name(~"owned name");
do t.try {
t.try(proc() {
fail!("test");
1
}.unwrap()
}).unwrap()
}

View file

@ -13,8 +13,8 @@
fn main() {
let mut t = ::std::task::task();
t.name("send name".to_send_str());
do t.try {
t.try(proc() {
fail!("test");
3
}.unwrap()
}).unwrap()
}

View file

@ -13,7 +13,7 @@
fn main() {
let mut t = ::std::task::task();
t.name("static name");
do t.try {
t.try(proc() {
fail!("test");
}.unwrap()
}).unwrap()
}

View file

@ -62,8 +62,8 @@ fn and_then_get_big_again(x:int) -> and_then_get_big_again {
}
fn main() {
do task::spawn {
task::spawn(proc() {
let r = and_then_get_big_again(4);
getbig_call_c_and_fail(10000);
};
});
}

View file

@ -48,7 +48,7 @@ fn and_then_get_big_again(x:int) -> and_then_get_big_again {
}
fn main() {
do task::spawn {
task::spawn(proc() {
getbig_and_fail(400);
};
});
}

View file

@ -41,7 +41,7 @@ fn and_then_get_big_again(x:int) -> and_then_get_big_again {
}
fn main() {
do task::spawn {
task::spawn(proc() {
getbig_and_fail(1);
};
});
}

View file

@ -17,7 +17,7 @@ extern mod native;
#[start]
fn start(argc: int, argv: **u8) -> int {
do native::start(argc, argv) {
native::start(argc, argv, proc() {
fail!();
}
})
}

View file

@ -34,8 +34,8 @@ fn r(x:int) -> r {
fn main() {
error!("whatever");
do task::spawn {
task::spawn(proc() {
let _i = r(5);
};
});
fail!();
}

View file

@ -17,9 +17,9 @@ extern mod green;
#[no_mangle] // this needs to get called from C
pub extern "C" fn foo(argc: int, argv: **u8) -> int {
do green::start(argc, argv) {
do spawn {
green::start(argc, argv, proc() {
spawn(proc() {
println!("hello");
}
}
});
})
}

View file

@ -16,9 +16,9 @@ extern mod native;
#[no_mangle] // this needs to get called from C
pub extern "C" fn foo(argc: int, argv: **u8) -> int {
do native::start(argc, argv) {
do spawn {
native::start(argc, argv, proc() {
spawn(proc() {
println!("hello");
}
}
});
})
}

View file

@ -12,11 +12,11 @@ impl Drop for A {
}
fn main() {
do task::try {
task::try(proc() {
let _a = A;
lib::callback(|| fail!());
1
};
});
unsafe {
assert!(lib::statik == 1);

View file

@ -75,11 +75,11 @@ fn main() {
fn check_pp<T>(cx: fake_ext_ctxt,
expr: T, f: |pprust::ps, T|, expect: ~str) {
let s = do io::with_str_writer |wr| {
let s = io::with_str_writer(|wr| {
let pp = pprust::rust_printer(wr, cx.parse_sess().interner);
f(pp, expr);
pp::eof(pp.s);
};
});
stdout().write_line(s);
if expect != ~"" {
error!("expect: '%s', got: '%s'", expect, s);

View file

@ -1,20 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn add(x: proc(f64) -> f64) -> f64 {
x(10.0)
}
pub fn main() {
// Trailing expressions don't require parentheses:
let y = do add |x| { x + 10.0 } + 10.0;
assert_eq!(y, 30.0);
}

View file

@ -1,17 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(_: proc()) -> proc(proc() -> uint) {
proc(_: proc() -> uint) {}
}
pub fn main() {
do do f {} { 20 };
}

View file

@ -1,18 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(_: proc()) -> proc(uint) -> uint {
proc(x: uint) { x }
}
pub fn main() {
let z = do f {} (22u);
assert_eq!(z, 22u);
}

View file

@ -1,38 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(_: proc(int, int) -> int) -> int {
10
}
fn w_semi() {
// the semicolon causes compiler not to
// complain about the ignored return value:
do f |x, y| { x+y };
}
fn w_paren1() -> int {
(do f |x, y| { x+y }) - 10
}
fn w_paren2() -> int {
(do f |x, y| { x+y } - 10)
}
fn w_ret() -> int {
return do f |x, y| { x+y } - 10;
}
pub fn main() {
w_semi();
w_paren1();
w_paren2();
w_ret();
}

View file

@ -1,18 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn call_any(f: proc() -> uint) -> uint {
return f();
}
pub fn main() {
let x_r = do call_any { 22u };
assert_eq!(x_r, 22u);
}

View file

@ -25,49 +25,4 @@ pub fn main() {
info!("{:?}", *i);
}
// Usable at all:
do inty |x| { x };
// Higher precedence than assignments:
let result = do inty |e| { e };
assert_eq!(result, 100);
// Higher precedence than unary operations:
let stringy = do inty |e| { e }.to_str();
assert!(do booly |_| { true });
assert!(!do booly |_| { false });
// Usable in funny statement-like forms:
if !do booly |_| { true } {
assert!(false);
}
match do booly |_| { false } {
true => { fail!("incorrect answer."); }
false => { }
}
match 3 {
_ if do booly |_| { true } => {
}
_ => {
fail!("wrong answer.");
}
}
// Lower precedence than binary operations:
let w = do inty |_| { 10 } + 10;
let y = do inty |_| { 10 } + 10;
let z = 10 + do inty |_| { 10 };
assert_eq!(w, y);
assert_eq!(y, z);
// In the tail of a block
let w = if true {
do booly |_| {
true
}
} else {
false
};
assert!(w);
}

View file

@ -28,9 +28,9 @@ use std::task;
fn foo(x: ()) -> Port<()> {
let (p, c) = Chan::<()>::new();
do task::spawn() {
task::spawn(proc() {
c.send(x);
}
});
p
}

View file

@ -30,18 +30,18 @@ impl Logger for MyWriter {
#[start]
fn start(argc: int, argv: **u8) -> int {
do native::start(argc, argv) {
native::start(argc, argv, proc() {
main();
}
})
}
fn main() {
let (p, c) = Chan::new();
let (mut r, w) = (PortReader::new(p), ChanWriter::new(c));
do spawn {
spawn(proc() {
set_logger(~MyWriter(w) as ~Logger);
debug!("debug");
info!("info");
}
});
assert_eq!(r.read_to_str(), ~"info\n");
}

View file

@ -16,8 +16,8 @@ fn foo(blk: proc()) {
pub fn main() {
let (p,c) = Chan::new();
do foo {
foo(proc() {
c.send(());
}
});
p.recv();
}

View file

@ -38,11 +38,6 @@ fn call_bare_again(f: extern "Rust" fn(&str)) {
pub fn main() {
// Procs
let greeting = ~"Hi ";
do call_it |s| {
greeting + s
}
let greeting = ~"Hello ";
call_it(proc(s) {
greeting + s

View file

@ -1,23 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// no-reformat
// Testing various forms of `do` with empty arg lists
fn f(_f: proc() -> bool) -> bool {
true
}
pub fn main() {
do f() || { true };
do f() { true };
do f || { true };
do f { true };
}

View file

@ -1,19 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Testing that we can drop the || in do exprs
fn f(_f: proc() -> bool) -> bool { true }
fn d(_f: proc()) { }
pub fn main() {
do d { }
}

View file

@ -1,15 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: proc(int)) { f(10) }
pub fn main() {
do f() |i| { assert!(i == 10) }
}

View file

@ -1,15 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: proc(int) -> int) -> int { f(10) }
pub fn main() {
assert_eq!(do f() |i| { i }, 10);
}

View file

@ -1,15 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: proc(int) -> int) -> int { f(10) }
pub fn main() {
assert_eq!(do f |i| { i }, 10);
}

View file

@ -40,9 +40,9 @@ fn count(n: uint) -> uint {
pub fn main() {
// Make sure we're on a task with small Rust stacks (main currently
// has a large stack)
do task::spawn {
task::spawn(proc() {
let result = count(1000u);
info!("result = {}", result);
assert_eq!(result, 1000u);
};
});
}

View file

@ -44,9 +44,9 @@ fn count(n: uint) -> uint {
pub fn main() {
// Make sure we're on a task with small Rust stacks (main currently
// has a large stack)
do task::spawn {
task::spawn(proc() {
let result = count(12u);
info!("result = {}", result);
assert_eq!(result, 2048u);
};
});
}

View file

@ -42,8 +42,8 @@ fn count(n: uint) -> uint {
pub fn main() {
100u.times(|| {
do task::spawn {
task::spawn(proc() {
assert_eq!(count(5u), 16u);
};
});
})
}

View file

@ -39,10 +39,10 @@ fn count(n: uint) -> uint {
pub fn main() {
10u.times(|| {
do task::spawn {
task::spawn(proc() {
let result = count(5u);
info!("result = {}", result);
assert_eq!(result, 16u);
};
});
})
}

View file

@ -33,9 +33,9 @@ impl Drop for B {
}
pub fn main() {
let ret = do task::try {
let ret = task::try(proc() {
let _a = A { b: B { foo: 3 } };
};
});
assert!(ret.is_err());
unsafe { assert!(dropped); }
}

View file

@ -10,10 +10,10 @@ extern {
pub fn main() {
unsafe {
do run_in_bare_thread() {
run_in_bare_thread(proc() {
let i = &100;
rust_dbg_call(callback, cast::transmute(i));
}
});
}
}

View file

@ -17,7 +17,7 @@
extern mod extra;
fn loopy(n: int) {
if n > 0 { do spawn { loopy(n - 1) }; do spawn { loopy(n - 1) }; }
if n > 0 { spawn(proc() { loopy(n - 1) }); spawn(proc() { loopy(n - 1) }); }
loop { }
}
@ -25,5 +25,5 @@ pub fn main() {
// Commenting this out, as this will hang forever otherwise.
// Even after seeing the comment above, I'm not sure what the
// intention of this test is.
// do spawn { loopy(5) };
// spawn(proc() { loopy(5) });
}

View file

@ -51,16 +51,16 @@ impl iterable<uint> for 'static ||uint|| {
}
fn filter<A,IA:iterable<A>>(self: IA, prd: 'static |A| -> bool, blk: |A|) {
do self.iter |a| {
self.iter(|a| {
if prd(a) { blk(a) }
}
});
}
fn foldl<A,B,IA:iterable<A>>(self: IA, b0: B, blk: |B, A| -> B) -> B {
let mut b = b0;
do self.iter |a| {
self.iter(|a| {
b = blk(b, a);
}
});
b
}

View file

@ -16,19 +16,19 @@ use std::task;
pub fn main() {
let (p,c) = comm::stream();
do task::try || {
task::try(|| {
let (p2,c2) = comm::stream();
do task::spawn || {
task::spawn(|| {
p2.recv();
error!("sibling fails");
fail!();
}
});
let (p3,c3) = comm::stream();
c.send(c3);
c2.send(());
error!("child blocks");
p3.recv();
};
});
error!("parent tries");
assert!(!p.recv().try_send(()));
error!("all done!");

View file

@ -12,8 +12,7 @@ enum Msg
}
fn foo(name: ~str, samples_chan: Chan<Msg>) {
do task::spawn
{
task::spawn(proc() {
let mut samples_chan = samples_chan;
let callback: SamplesFn = proc(buffer) {
for i in range(0u, buffer.len()) {
@ -21,7 +20,7 @@ fn foo(name: ~str, samples_chan: Chan<Msg>) {
}
};
samples_chan.send(GetSamples(name.clone(), callback));
};
});
}
pub fn main() {}

View file

@ -45,13 +45,13 @@ priv fn parse_data(len: uint, io: @io::Reader) -> Result {
priv fn parse_list(len: uint, io: @io::Reader) -> Result {
let mut list: ~[Result] = ~[];
do len.times {
len.times(proc() {
let v =
match io.read_char() {
'$' => parse_bulk(io),
':' => parse_int(io),
_ => fail!()
};
});
list.push(v);
}
return List(list);
@ -119,11 +119,11 @@ fn query(cmd: ~[~str], sb: TcpSocketBuf) -> Result {
fn query2(cmd: ~[~str]) -> Result {
let _cmd = cmd_to_str(cmd);
do io::with_str_reader(~"$3\r\nXXX\r\n") |sb| {
io::with_str_reader(~"$3\r\nXXX\r\n")(|sb| {
let res = parse_response(@sb as @io::Reader);
println!("{:?}", res);
res
}
});
}

View file

@ -13,9 +13,9 @@ use std::io::println;
pub fn main() {
let (port, chan) = Chan::new();
do spawn {
spawn(proc() {
println(port.recv());
}
});
chan.send("hello, world");
}

View file

@ -13,9 +13,9 @@ use std::task;
pub fn main() {
let (port, chan) = Chan::<&'static str>::new();
do task::spawn {
task::spawn(proc() {
assert_eq!(port.recv(), "hello, world");
}
});
chan.send("hello, world");
}

View file

@ -16,10 +16,10 @@ fn foo() {
// Here, i is *copied* into the proc (heap closure).
// Requires allocation. The proc's copy is not mutable.
let mut i = 0;
do task::spawn {
task::spawn(proc() {
user(i);
println!("spawned {}", i)
}
});
i += 1;
println!("original {}", i)
}
@ -29,9 +29,9 @@ fn bar() {
// mutable outside of the proc.
let mut i = 0;
while i < 10 {
do task::spawn {
task::spawn(proc() {
user(i);
}
});
i += 1;
}
}
@ -40,11 +40,11 @@ fn car() {
// Here, i must be shadowed in the proc to be mutable.
let mut i = 0;
while i < 10 {
do task::spawn {
task::spawn(proc() {
let mut i = i;
i += 1;
user(i);
}
});
i += 1;
}
}

View file

@ -26,12 +26,12 @@ impl fmt::Default for Foo {
pub fn main() {
let (p,c) = Chan::new();
do spawn {
spawn(proc() {
let mut f = Foo(Cell::new(0));
debug!("{}", f);
let Foo(ref mut f) = f;
assert!(f.get() == 1);
c.send(());
}
});
p.recv();
}

View file

@ -2,7 +2,7 @@ use std::task;
pub fn main() {
let x = ~"Hello world!";
do task::spawn {
task::spawn(proc() {
println!("{}", x);
}
});
}

View file

@ -18,11 +18,11 @@ static mut set: bool = false;
#[start]
fn start(argc: int, argv: **u8) -> int {
// make sure that native::start always waits for all children to finish
do native::start(argc, argv) {
do spawn {
native::start(argc, argv, proc() {
spawn(proc() {
unsafe { set = true; }
}
};
});
});
// if we didn't set the global, then return a nonzero code
if unsafe {set} {0} else {1}

View file

@ -24,9 +24,9 @@ impl Drop for A {
}
fn main() {
do task::try::<()> {
task::try::<()>(proc() {
let _a = A;
fail!();
};
});
assert!(unsafe { !HIT });
}

View file

@ -22,8 +22,8 @@ fn foo(blk: proc()) {
pub fn main() {
let x = arc::Arc::new(true);
do foo {
foo(proc() {
assert!(*x.get());
drop(x);
}
});
}

View file

@ -29,9 +29,9 @@ pub fn main() {
let (port, chan) = stream();
info!("main started");
do spawn {
spawn(proc() {
starve_main(port);
};
});
let mut i: int = 0;
info!("main waiting for alive signal");
chan.send(i);

View file

@ -27,12 +27,12 @@ fn test(f: int) -> test {
pub fn main() {
let (p, c) = Chan::new();
do task::spawn() {
task::spawn(proc() {
let (pp, cc) = Chan::new();
c.send(cc);
let _r = pp.recv();
}
});
p.recv().send(test(42));
}

View file

@ -20,9 +20,9 @@ fn test00() {
let i: int = 0;
let mut builder = task::task();
let mut result = builder.future_result();
do builder.spawn {
builder.spawn(proc() {
start(i)
}
});
// Sleep long enough for the task to finish.
let mut i = 0;

View file

@ -31,21 +31,21 @@ fn test00() {
let number_of_messages: int = 10;
let c = ch.clone();
do task::spawn || {
task::spawn(proc() {
test00_start(&c, number_of_messages * 0, number_of_messages);
}
});
let c = ch.clone();
do task::spawn || {
task::spawn(proc() {
test00_start(&c, number_of_messages * 1, number_of_messages);
}
});
let c = ch.clone();
do task::spawn || {
task::spawn(proc() {
test00_start(&c, number_of_messages * 2, number_of_messages);
}
});
let c = ch.clone();
do task::spawn || {
task::spawn(proc() {
test00_start(&c, number_of_messages * 3, number_of_messages);
}
});
let mut i: int = 0;
while i < number_of_messages {

View file

@ -29,10 +29,10 @@ fn test00() {
let mut builder = task::task();
let result = builder.future_result();
do builder.spawn {
builder.spawn(proc() {
let mut ch = ch;
test00_start(&mut ch, number_of_messages);
}
});
let mut i: int = 0;
while i < number_of_messages {

View file

@ -56,10 +56,10 @@ fn joinable(f: proc()) -> Port<bool> {
*b = true;
}
let (p, c) = stream();
do task::spawn_unlinked {
task::spawn_unlinked(proc() {
let ccc = c;
wrapper(ccc, f)
}
});
p
}

View file

@ -71,13 +71,13 @@ pub fn main() {
~dogge2 as ~Pet:Freeze+Send]);
let (p1,c1) = Chan::new();
let arc1 = arc.clone();
do task::spawn { check_legs(arc1); c1.send(()); }
task::spawn(proc() { check_legs(arc1); c1.send(()); });
let (p2,c2) = Chan::new();
let arc2 = arc.clone();
do task::spawn { check_names(arc2); c2.send(()); }
task::spawn(proc() { check_names(arc2); c2.send(()); });
let (p3,c3) = Chan::new();
let arc3 = arc.clone();
do task::spawn { check_pedigree(arc3); c3.send(()); }
task::spawn(proc() { check_pedigree(arc3); c3.send(()); });
p1.recv();
p2.recv();
p3.recv();

View file

@ -21,9 +21,9 @@ impl Drop for Foo {
}
pub fn main() {
let x = do task::try {
let x = task::try(proc() {
let _b = Foo;
};
});
let s = x.unwrap_err().move::<&'static str>().unwrap();
assert_eq!(s.as_slice(), "This failure should happen.");