mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
make --enforce-mut-vars always on, add mut annotations to remaining files
This commit is contained in:
parent
ea6030878a
commit
dc07280b08
29
doc/rust.md
29
doc/rust.md
@ -1003,7 +1003,7 @@ fn iter<T>(seq: [T], f: fn(T)) {
|
|||||||
for elt: T in seq { f(elt); }
|
for elt: T in seq { f(elt); }
|
||||||
}
|
}
|
||||||
fn map<T, U>(seq: [T], f: fn(T) -> U) -> [U] {
|
fn map<T, U>(seq: [T], f: fn(T) -> U) -> [U] {
|
||||||
let acc = [];
|
let mut acc = [];
|
||||||
for elt in seq { acc += [f(elt)]; }
|
for elt in seq { acc += [f(elt)]; }
|
||||||
acc
|
acc
|
||||||
}
|
}
|
||||||
@ -1104,7 +1104,7 @@ enum animal {
|
|||||||
cat
|
cat
|
||||||
}
|
}
|
||||||
|
|
||||||
let a: animal = dog;
|
let mut a: animal = dog;
|
||||||
a = cat;
|
a = cat;
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
@ -1254,7 +1254,7 @@ not given, and the name is mandatory.
|
|||||||
~~~~
|
~~~~
|
||||||
impl uint_loops for uint {
|
impl uint_loops for uint {
|
||||||
fn times(f: fn(uint)) {
|
fn times(f: fn(uint)) {
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < self { f(i); i += 1u; }
|
while i < self { f(i); i += 1u; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1775,7 +1775,7 @@ expression. No allocation or destruction is entailed.
|
|||||||
An example of three different move expressions:
|
An example of three different move expressions:
|
||||||
|
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
# let x = [mut 0];
|
# let mut x = [mut 0];
|
||||||
# let a = [mut 0];
|
# let a = [mut 0];
|
||||||
# let b = 0;
|
# let b = 0;
|
||||||
# let y = {mut z: 0};
|
# let y = {mut z: 0};
|
||||||
@ -1804,8 +1804,8 @@ expression. No allocation or destruction is entailed.
|
|||||||
An example of three different swap expressions:
|
An example of three different swap expressions:
|
||||||
|
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
# let x = [mut 0];
|
# let mut x = [mut 0];
|
||||||
# let a = [mut 0];
|
# let mut a = [mut 0];
|
||||||
# let i = 0;
|
# let i = 0;
|
||||||
# let y = {mut z: 0};
|
# let y = {mut z: 0};
|
||||||
# let b = {mut c: 0};
|
# let b = {mut c: 0};
|
||||||
@ -1827,7 +1827,7 @@ expression](#unary-copy-expressions). For example, the following two
|
|||||||
expressions have the same effect:
|
expressions have the same effect:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
# let x = 0;
|
# let mut x = 0;
|
||||||
# let y = 0;
|
# let y = 0;
|
||||||
|
|
||||||
x = y;
|
x = y;
|
||||||
@ -2015,7 +2015,7 @@ loop body. If it evaluates to `false`, control exits the loop.
|
|||||||
An example of a simple `while` expression:
|
An example of a simple `while` expression:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
# let i = 0;
|
# let mut i = 0;
|
||||||
# let println = io::println;
|
# let println = io::println;
|
||||||
|
|
||||||
while i < 10 {
|
while i < 10 {
|
||||||
@ -2027,7 +2027,7 @@ while i < 10 {
|
|||||||
An example of a `do`-`while` expression:
|
An example of a `do`-`while` expression:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
# let i = 0;
|
# let mut i = 0;
|
||||||
# let println = io::println;
|
# let println = io::println;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -2053,7 +2053,7 @@ For example, the following (contrived) function uses a `loop` with a
|
|||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
fn count() -> bool {
|
fn count() -> bool {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
loop {
|
loop {
|
||||||
i += 1;
|
i += 1;
|
||||||
if i == 20 { ret true; }
|
if i == 20 { ret true; }
|
||||||
@ -2801,7 +2801,7 @@ fn add(x: int, y: int) -> int {
|
|||||||
ret x + y;
|
ret x + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
let x = add(5,7);
|
let mut x = add(5,7);
|
||||||
|
|
||||||
type binop = fn(int,int) -> int;
|
type binop = fn(int,int) -> int;
|
||||||
let bo: binop = add;
|
let bo: binop = add;
|
||||||
@ -2880,7 +2880,7 @@ has a set of points before and after it in the implied control flow.
|
|||||||
For example, this code:
|
For example, this code:
|
||||||
|
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
# let s;
|
# let mut s;
|
||||||
|
|
||||||
s = "hello, world";
|
s = "hello, world";
|
||||||
io::println(s);
|
io::println(s);
|
||||||
@ -3154,7 +3154,10 @@ A _reference_ references a value outside the frame. It may refer to a
|
|||||||
value allocated in another frame *or* a boxed value in the heap. The
|
value allocated in another frame *or* a boxed value in the heap. The
|
||||||
reference-formation rules ensure that the referent will outlive the reference.
|
reference-formation rules ensure that the referent will outlive the reference.
|
||||||
|
|
||||||
Local variables are always implicitly mutable.
|
Local variables are immutable unless declared with `let mut`. The
|
||||||
|
`mut` keyword applies to all local variables declared within that
|
||||||
|
declaration (so `let mut x, y` declares two mutable variables, `x` and
|
||||||
|
`y`).
|
||||||
|
|
||||||
Local variables are not initialized when allocated; the entire frame worth of
|
Local variables are not initialized when allocated; the entire frame worth of
|
||||||
local variables are allocated at once, on frame-entry, in an uninitialized
|
local variables are allocated at once, on frame-entry, in an uninitialized
|
||||||
|
@ -26,7 +26,7 @@ a curly-brace language in the tradition of C, C++, and JavaScript.
|
|||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
fn fac(n: int) -> int {
|
fn fac(n: int) -> int {
|
||||||
let result = 1, i = 1;
|
let mut result = 1, i = 1;
|
||||||
while i <= n {
|
while i <= n {
|
||||||
result *= i;
|
result *= i;
|
||||||
i += 1;
|
i += 1;
|
||||||
@ -286,16 +286,19 @@ fn this_doesnt(_x: int) {}
|
|||||||
|
|
||||||
## Variable declaration
|
## Variable declaration
|
||||||
|
|
||||||
The `let` keyword, as we've seen, introduces a local variable. Global
|
The `let` keyword, as we've seen, introduces a local variable. Local
|
||||||
constants can be defined with `const`:
|
variables are immutable by default: `let mut` can be used to introduce
|
||||||
|
a local variable that can be reassigned. Global constants can be
|
||||||
|
defined with `const`:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
use std;
|
use std;
|
||||||
const repeat: uint = 5u;
|
const repeat: uint = 5u;
|
||||||
fn main() {
|
fn main() {
|
||||||
let count = 0u;
|
let hi = "Hi!";
|
||||||
|
let mut count = 0u;
|
||||||
while count < repeat {
|
while count < repeat {
|
||||||
io::println("Hi!");
|
io::println(hi);
|
||||||
count += 1u;
|
count += 1u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,7 +323,7 @@ annotation:
|
|||||||
~~~~
|
~~~~
|
||||||
// The type of this vector will be inferred based on its use.
|
// The type of this vector will be inferred based on its use.
|
||||||
let x = [];
|
let x = [];
|
||||||
# x = [3];
|
# vec::map(x, fn&(&&_y:int) -> int { _y });
|
||||||
// Explicitly say this is a vector of integers.
|
// Explicitly say this is a vector of integers.
|
||||||
let y: [int] = [];
|
let y: [int] = [];
|
||||||
~~~~
|
~~~~
|
||||||
@ -665,7 +668,7 @@ keyword `break` can be used to abort the loop, and `cont` can be used
|
|||||||
to abort the current iteration and continue with the next.
|
to abort the current iteration and continue with the next.
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
let x = 5;
|
let mut x = 5;
|
||||||
while true {
|
while true {
|
||||||
x += x - 3;
|
x += x - 3;
|
||||||
if x % 5 == 0 { break; }
|
if x % 5 == 0 { break; }
|
||||||
@ -761,7 +764,7 @@ failure otherwise. It is typically used to double-check things that
|
|||||||
*should* hold at a certain point in a program.
|
*should* hold at a certain point in a program.
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
let x = 100;
|
let mut x = 100;
|
||||||
while (x > 10) { x -= 10; }
|
while (x > 10) { x -= 10; }
|
||||||
assert x == 10;
|
assert x == 10;
|
||||||
~~~~
|
~~~~
|
||||||
@ -933,7 +936,7 @@ of integers backwards:
|
|||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
fn for_rev(v: [int], act: fn(int)) {
|
fn for_rev(v: [int], act: fn(int)) {
|
||||||
let i = vec::len(v);
|
let mut i = vec::len(v);
|
||||||
while (i > 0u) {
|
while (i > 0u) {
|
||||||
i -= 1u;
|
i -= 1u;
|
||||||
act(v[i]);
|
act(v[i]);
|
||||||
@ -1273,7 +1276,7 @@ The `+` operator means concatenation when applied to vector types.
|
|||||||
Growing a vector in Rust is not as inefficient as it looks :
|
Growing a vector in Rust is not as inefficient as it looks :
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
let myvec = [], i = 0;
|
let mut myvec = [], i = 0;
|
||||||
while i < 100 {
|
while i < 100 {
|
||||||
myvec += [i];
|
myvec += [i];
|
||||||
i += 1;
|
i += 1;
|
||||||
@ -1376,7 +1379,7 @@ in `main`, so we're good. But the call could also look like this:
|
|||||||
~~~~
|
~~~~
|
||||||
# fn myfunc(a: int, b: fn()) {}
|
# fn myfunc(a: int, b: fn()) {}
|
||||||
# fn get_another_record() -> int { 1 }
|
# fn get_another_record() -> int { 1 }
|
||||||
# let x = 1;
|
# let mut x = 1;
|
||||||
myfunc(x, {|| x = get_another_record(); });
|
myfunc(x, {|| x = get_another_record(); });
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
@ -1436,7 +1439,7 @@ very cheap, but you'll occasionally have to copy them to ensure
|
|||||||
safety.
|
safety.
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
let my_rec = {a: 4, b: [1, 2, 3]};
|
let mut my_rec = {a: 4, b: [1, 2, 3]};
|
||||||
alt my_rec {
|
alt my_rec {
|
||||||
{a, b} {
|
{a, b} {
|
||||||
log(info, b); // This is okay
|
log(info, b); // This is okay
|
||||||
@ -1497,7 +1500,7 @@ Thus, Rust allows functions and datatypes to have type parameters.
|
|||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
fn for_rev<T>(v: [T], act: fn(T)) {
|
fn for_rev<T>(v: [T], act: fn(T)) {
|
||||||
let i = vec::len(v);
|
let mut i = vec::len(v);
|
||||||
while i > 0u {
|
while i > 0u {
|
||||||
i -= 1u;
|
i -= 1u;
|
||||||
act(v[i]);
|
act(v[i]);
|
||||||
@ -1505,7 +1508,7 @@ fn for_rev<T>(v: [T], act: fn(T)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn map<T, U>(v: [T], f: fn(T) -> U) -> [U] {
|
fn map<T, U>(v: [T], f: fn(T) -> U) -> [U] {
|
||||||
let acc = [];
|
let mut acc = [];
|
||||||
for elt in v { acc += [f(elt)]; }
|
for elt in v { acc += [f(elt)]; }
|
||||||
ret acc;
|
ret acc;
|
||||||
}
|
}
|
||||||
@ -1548,7 +1551,7 @@ programs that just can't be typed.
|
|||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
let n = option::none;
|
let n = option::none;
|
||||||
# n = option::some(1);
|
# option::may(n, fn&(&&x:int) {})
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
If you never do anything else with `n`, the compiler will not be able
|
If you never do anything else with `n`, the compiler will not be able
|
||||||
@ -1982,7 +1985,7 @@ parameters.
|
|||||||
~~~~
|
~~~~
|
||||||
# iface to_str { fn to_str() -> str; }
|
# iface to_str { fn to_str() -> str; }
|
||||||
fn comma_sep<T: to_str>(elts: [T]) -> str {
|
fn comma_sep<T: to_str>(elts: [T]) -> str {
|
||||||
let result = "", first = true;
|
let mut result = "", first = true;
|
||||||
for elt in elts {
|
for elt in elts {
|
||||||
if first { first = false; }
|
if first { first = false; }
|
||||||
else { result += ", "; }
|
else { result += ", "; }
|
||||||
@ -2094,7 +2097,7 @@ to leave off the `of` clause.
|
|||||||
# fn mk_currency(x: int, s: str) {}
|
# fn mk_currency(x: int, s: str) {}
|
||||||
impl int_util for int {
|
impl int_util for int {
|
||||||
fn times(b: fn(int)) {
|
fn times(b: fn(int)) {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
while i < self { b(i); i += 1; }
|
while i < self { b(i); i += 1; }
|
||||||
}
|
}
|
||||||
fn dollars() -> currency {
|
fn dollars() -> currency {
|
||||||
@ -2450,7 +2453,7 @@ Here is the function which implements the child task:
|
|||||||
~~~~
|
~~~~
|
||||||
fn stringifier(from_parent: comm::port<uint>,
|
fn stringifier(from_parent: comm::port<uint>,
|
||||||
to_parent: comm::chan<str>) {
|
to_parent: comm::chan<str>) {
|
||||||
let value: uint;
|
let mut value: uint;
|
||||||
do {
|
do {
|
||||||
value = comm::recv(from_parent);
|
value = comm::recv(from_parent);
|
||||||
comm::send(to_parent, uint::to_str(value, 10u));
|
comm::send(to_parent, uint::to_str(value, 10u));
|
||||||
|
18
mk/target.mk
18
mk/target.mk
@ -11,13 +11,6 @@
|
|||||||
USE_SNAPSHOT_RUNTIME=0
|
USE_SNAPSHOT_RUNTIME=0
|
||||||
USE_SNAPSHOT_CORELIB=0
|
USE_SNAPSHOT_CORELIB=0
|
||||||
|
|
||||||
# Do not use --enforce-mut-vars in stage0, for now, as the snapshot
|
|
||||||
# has an older version of the check.
|
|
||||||
ENFORCE_MUT_VARS_0=
|
|
||||||
ENFORCE_MUT_VARS_1=--enforce-mut-vars
|
|
||||||
ENFORCE_MUT_VARS_2=--enforce-mut-vars
|
|
||||||
ENFORCE_MUT_VARS_3=--enforce-mut-vars
|
|
||||||
|
|
||||||
define TARGET_STAGE_N
|
define TARGET_STAGE_N
|
||||||
|
|
||||||
$$(TLIB$(1)_T_$(2)_H_$(3))/intrinsics.ll: \
|
$$(TLIB$(1)_T_$(2)_H_$(3))/intrinsics.ll: \
|
||||||
@ -41,8 +34,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB): \
|
|||||||
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
|
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
|
||||||
$$(TSREQ$(1)_T_$(2)_H_$(3))
|
$$(TSREQ$(1)_T_$(2)_H_$(3))
|
||||||
@$$(call E, compile_and_link: $$@)
|
@$$(call E, compile_and_link: $$@)
|
||||||
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(ENFORCE_MUT_VARS_$(1)) \
|
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
|
||||||
-o $$@ $$< && touch $$@
|
|
||||||
|
|
||||||
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM): \
|
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM): \
|
||||||
rustllvm/$(2)/$$(CFG_RUSTLLVM)
|
rustllvm/$(2)/$$(CFG_RUSTLLVM)
|
||||||
@ -53,8 +45,7 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X): \
|
|||||||
$$(RUSTC_INPUTS) \
|
$$(RUSTC_INPUTS) \
|
||||||
$$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
|
$$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
|
||||||
@$$(call E, compile_and_link: $$@)
|
@$$(call E, compile_and_link: $$@)
|
||||||
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(ENFORCE_MUT_VARS_$(1)) \
|
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$<
|
||||||
-o $$@ $$<
|
|
||||||
|
|
||||||
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
|
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
|
||||||
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
|
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
|
||||||
@ -63,8 +54,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
|
|||||||
$$(TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
|
$$(TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
|
||||||
$$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3))
|
$$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3))
|
||||||
@$$(call E, compile_and_link: $$@)
|
@$$(call E, compile_and_link: $$@)
|
||||||
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(ENFORCE_MUT_VARS_$(1)) \
|
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
|
||||||
-o $$@ $$< && touch $$@
|
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
@ -127,7 +117,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB): \
|
|||||||
$$(CORELIB_CRATE) $$(CORELIB_INPUTS) \
|
$$(CORELIB_CRATE) $$(CORELIB_INPUTS) \
|
||||||
$$(TSREQ$(1)_T_$(2)_H_$(3))
|
$$(TSREQ$(1)_T_$(2)_H_$(3))
|
||||||
@$$(call E, compile_and_link: $$@)
|
@$$(call E, compile_and_link: $$@)
|
||||||
$$(STAGE$(1)_T_$(2)_H_$(3)) --enforce-mut-vars -o $$@ $$< && touch $$@
|
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
@ -93,9 +93,9 @@ fn error(msg: str) {
|
|||||||
fn load_link(mis: [@ast::meta_item]) -> (option<str>,
|
fn load_link(mis: [@ast::meta_item]) -> (option<str>,
|
||||||
option<str>,
|
option<str>,
|
||||||
option<str>) {
|
option<str>) {
|
||||||
let name = none;
|
let mut name = none;
|
||||||
let vers = none;
|
let mut vers = none;
|
||||||
let uuid = none;
|
let mut uuid = none;
|
||||||
for a: @ast::meta_item in mis {
|
for a: @ast::meta_item in mis {
|
||||||
alt a.node {
|
alt a.node {
|
||||||
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
|
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
|
||||||
@ -124,12 +124,12 @@ fn load_pkg(filename: str) -> option<pkg> {
|
|||||||
};
|
};
|
||||||
let c = parser::parse_crate_from_crate_file(filename, [], sess);
|
let c = parser::parse_crate_from_crate_file(filename, [], sess);
|
||||||
|
|
||||||
let name = none;
|
let mut name = none;
|
||||||
let vers = none;
|
let mut vers = none;
|
||||||
let uuid = none;
|
let mut uuid = none;
|
||||||
let desc = none;
|
let mut desc = none;
|
||||||
let sigs = none;
|
let mut sigs = none;
|
||||||
let crate_type = none;
|
let mut crate_type = none;
|
||||||
|
|
||||||
for a in c.node.attrs {
|
for a in c.node.attrs {
|
||||||
alt a.node.value.node {
|
alt a.node.value.node {
|
||||||
@ -273,7 +273,7 @@ fn load_one_source_package(&src: source, p: map::hashmap<str, json::json>) {
|
|||||||
_ { none }
|
_ { none }
|
||||||
};
|
};
|
||||||
|
|
||||||
let tags = [];
|
let mut tags = [];
|
||||||
alt p.find("tags") {
|
alt p.find("tags") {
|
||||||
some(json::list(js)) {
|
some(json::list(js)) {
|
||||||
for j in js {
|
for j in js {
|
||||||
@ -390,7 +390,7 @@ fn configure(opts: options) -> cargo {
|
|||||||
let sources = map::str_hash::<source>();
|
let sources = map::str_hash::<source>();
|
||||||
try_parse_sources(path::connect(syscargo, "sources.json"), sources);
|
try_parse_sources(path::connect(syscargo, "sources.json"), sources);
|
||||||
try_parse_sources(path::connect(syscargo, "local-sources.json"), sources);
|
try_parse_sources(path::connect(syscargo, "local-sources.json"), sources);
|
||||||
let c = {
|
let mut c = {
|
||||||
pgp: pgp::supported(),
|
pgp: pgp::supported(),
|
||||||
root: p,
|
root: p,
|
||||||
bindir: path::connect(p, "bin"),
|
bindir: path::connect(p, "bin"),
|
||||||
@ -408,7 +408,7 @@ fn configure(opts: options) -> cargo {
|
|||||||
need_dir(c.bindir);
|
need_dir(c.bindir);
|
||||||
|
|
||||||
sources.keys { |k|
|
sources.keys { |k|
|
||||||
let s = sources.get(k);
|
let mut s = sources.get(k);
|
||||||
load_source_packages(c, s);
|
load_source_packages(c, s);
|
||||||
sources.insert(k, s);
|
sources.insert(k, s);
|
||||||
};
|
};
|
||||||
@ -597,7 +597,7 @@ fn cargo_suggestion(c: cargo, syncing: bool, fallback: fn())
|
|||||||
ret;
|
ret;
|
||||||
}
|
}
|
||||||
if !syncing {
|
if !syncing {
|
||||||
let npkg = 0u;
|
let mut npkg = 0u;
|
||||||
c.sources.values({ |v| npkg += vec::len(v.packages) });
|
c.sources.values({ |v| npkg += vec::len(v.packages) });
|
||||||
if npkg == 0u {
|
if npkg == 0u {
|
||||||
error("No packages known. You may wish to run " +
|
error("No packages known. You may wish to run " +
|
||||||
@ -609,7 +609,7 @@ fn cargo_suggestion(c: cargo, syncing: bool, fallback: fn())
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn install_uuid(c: cargo, wd: str, uuid: str) {
|
fn install_uuid(c: cargo, wd: str, uuid: str) {
|
||||||
let ps = [];
|
let mut ps = [];
|
||||||
for_each_package(c, { |s, p|
|
for_each_package(c, { |s, p|
|
||||||
info(#fmt["%s ? %s", p.uuid, uuid]);
|
info(#fmt["%s ? %s", p.uuid, uuid]);
|
||||||
if p.uuid == uuid {
|
if p.uuid == uuid {
|
||||||
@ -631,7 +631,7 @@ fn install_uuid(c: cargo, wd: str, uuid: str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn install_named(c: cargo, wd: str, name: str) {
|
fn install_named(c: cargo, wd: str, name: str) {
|
||||||
let ps = [];
|
let mut ps = [];
|
||||||
for_each_package(c, { |s, p|
|
for_each_package(c, { |s, p|
|
||||||
if p.name == name {
|
if p.name == name {
|
||||||
vec::grow(ps, 1u, (s, p));
|
vec::grow(ps, 1u, (s, p));
|
||||||
@ -698,7 +698,7 @@ fn cmd_install(c: cargo) unsafe {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if str::starts_with(target, "uuid:") {
|
if str::starts_with(target, "uuid:") {
|
||||||
let uuid = rest(target, 5u);
|
let mut uuid = rest(target, 5u);
|
||||||
alt str::find_char(uuid, '/') {
|
alt str::find_char(uuid, '/') {
|
||||||
option::some(idx) {
|
option::some(idx) {
|
||||||
let source = str::slice(uuid, 0u, idx);
|
let source = str::slice(uuid, 0u, idx);
|
||||||
@ -710,7 +710,7 @@ fn cmd_install(c: cargo) unsafe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let name = target;
|
let mut name = target;
|
||||||
alt str::find_char(name, '/') {
|
alt str::find_char(name, '/') {
|
||||||
option::some(idx) {
|
option::some(idx) {
|
||||||
let source = str::slice(name, 0u, idx);
|
let source = str::slice(name, 0u, idx);
|
||||||
@ -820,7 +820,7 @@ fn cmd_init(c: cargo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn print_pkg(s: source, p: package) {
|
fn print_pkg(s: source, p: package) {
|
||||||
let m = s.name + "/" + p.name + " (" + p.uuid + ")";
|
let mut m = s.name + "/" + p.name + " (" + p.uuid + ")";
|
||||||
if vec::len(p.tags) > 0u {
|
if vec::len(p.tags) > 0u {
|
||||||
m = m + " [" + str::connect(p.tags, ", ") + "]";
|
m = m + " [" + str::connect(p.tags, ", ") + "]";
|
||||||
}
|
}
|
||||||
@ -842,7 +842,7 @@ fn cmd_search(c: cargo) {
|
|||||||
cmd_usage();
|
cmd_usage();
|
||||||
ret;
|
ret;
|
||||||
}
|
}
|
||||||
let n = 0;
|
let mut n = 0;
|
||||||
let name = c.opts.free[2];
|
let name = c.opts.free[2];
|
||||||
let tags = vec::slice(c.opts.free, 3u, vec::len(c.opts.free));
|
let tags = vec::slice(c.opts.free, 3u, vec::len(c.opts.free));
|
||||||
for_each_package(c, { |s, p|
|
for_each_package(c, { |s, p|
|
||||||
|
@ -126,7 +126,7 @@ fn test_opts(config: config) -> test::test_opts {
|
|||||||
|
|
||||||
fn make_tests(config: config) -> [test::test_desc] {
|
fn make_tests(config: config) -> [test::test_desc] {
|
||||||
#debug("making tests from %s", config.src_base);
|
#debug("making tests from %s", config.src_base);
|
||||||
let tests = [];
|
let mut tests = [];
|
||||||
for file: str in os::list_dir(config.src_base) {
|
for file: str in os::list_dir(config.src_base) {
|
||||||
let file = file;
|
let file = file;
|
||||||
#debug("inspecting file %s", file);
|
#debug("inspecting file %s", file);
|
||||||
@ -144,7 +144,7 @@ fn is_test(config: config, testfile: str) -> bool {
|
|||||||
let invalid_prefixes = [".", "#", "~"];
|
let invalid_prefixes = [".", "#", "~"];
|
||||||
let name = path::basename(testfile);
|
let name = path::basename(testfile);
|
||||||
|
|
||||||
let valid = false;
|
let mut valid = false;
|
||||||
|
|
||||||
for ext in valid_extensions {
|
for ext in valid_extensions {
|
||||||
if str::ends_with(name, ext) { valid = true; }
|
if str::ends_with(name, ext) { valid = true; }
|
||||||
|
@ -9,9 +9,9 @@ type expected_error = { line: uint, kind: str, msg: str };
|
|||||||
|
|
||||||
// Load any test directives embedded in the file
|
// Load any test directives embedded in the file
|
||||||
fn load_errors(testfile: str) -> [expected_error] {
|
fn load_errors(testfile: str) -> [expected_error] {
|
||||||
let error_patterns = [];
|
let mut error_patterns = [];
|
||||||
let rdr = result::get(io::file_reader(testfile));
|
let rdr = result::get(io::file_reader(testfile));
|
||||||
let line_num = 1u;
|
let mut line_num = 1u;
|
||||||
while !rdr.eof() {
|
while !rdr.eof() {
|
||||||
let ln = rdr.read_line();
|
let ln = rdr.read_line();
|
||||||
error_patterns += parse_expected(line_num, ln);
|
error_patterns += parse_expected(line_num, ln);
|
||||||
@ -22,7 +22,7 @@ fn load_errors(testfile: str) -> [expected_error] {
|
|||||||
|
|
||||||
fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
|
fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
|
||||||
let error_tag = "//!";
|
let error_tag = "//!";
|
||||||
let idx;
|
let mut idx;
|
||||||
alt str::find_str(line, error_tag) {
|
alt str::find_str(line, error_tag) {
|
||||||
option::none { ret []; }
|
option::none { ret []; }
|
||||||
option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
|
option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
|
||||||
@ -30,7 +30,7 @@ fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
|
|||||||
|
|
||||||
// "//!^^^ kind msg" denotes a message expected
|
// "//!^^^ kind msg" denotes a message expected
|
||||||
// three lines above current line:
|
// three lines above current line:
|
||||||
let adjust_line = 0u;
|
let mut adjust_line = 0u;
|
||||||
let len = str::len(line);
|
let len = str::len(line);
|
||||||
while idx < len && line[idx] == ('^' as u8) {
|
while idx < len && line[idx] == ('^' as u8) {
|
||||||
adjust_line += 1u;
|
adjust_line += 1u;
|
||||||
|
@ -22,10 +22,10 @@ type test_props = {
|
|||||||
|
|
||||||
// Load any test directives embedded in the file
|
// Load any test directives embedded in the file
|
||||||
fn load_props(testfile: str) -> test_props {
|
fn load_props(testfile: str) -> test_props {
|
||||||
let error_patterns = [];
|
let mut error_patterns = [];
|
||||||
let aux_builds = [];
|
let mut aux_builds = [];
|
||||||
let compile_flags = option::none;
|
let mut compile_flags = option::none;
|
||||||
let pp_exact = option::none;
|
let mut pp_exact = option::none;
|
||||||
iter_header(testfile) {|ln|
|
iter_header(testfile) {|ln|
|
||||||
alt parse_error_pattern(ln) {
|
alt parse_error_pattern(ln) {
|
||||||
option::some(ep) { error_patterns += [ep]; }
|
option::some(ep) { error_patterns += [ep]; }
|
||||||
@ -53,7 +53,7 @@ fn load_props(testfile: str) -> test_props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_test_ignored(config: config, testfile: str) -> bool {
|
fn is_test_ignored(config: config, testfile: str) -> bool {
|
||||||
let found = false;
|
let mut found = false;
|
||||||
iter_header(testfile) {|ln|
|
iter_header(testfile) {|ln|
|
||||||
// FIXME: Can't return or break from iterator
|
// FIXME: Can't return or break from iterator
|
||||||
// (Fix when Issue #1619 is resolved)
|
// (Fix when Issue #1619 is resolved)
|
||||||
|
@ -60,9 +60,9 @@ fn run(lib_path: str, prog: str, args: [str],
|
|||||||
comm::send(ch, (1, output));
|
comm::send(ch, (1, output));
|
||||||
};
|
};
|
||||||
let status = run::waitpid(pid);
|
let status = run::waitpid(pid);
|
||||||
let errs = "";
|
let mut errs = "";
|
||||||
let outs = "";
|
let mut outs = "";
|
||||||
let count = 2;
|
let mut count = 2;
|
||||||
while count > 0 {
|
while count > 0 {
|
||||||
let stream = comm::recv(p);
|
let stream = comm::recv(p);
|
||||||
alt check stream {
|
alt check stream {
|
||||||
@ -91,7 +91,7 @@ fn readclose(fd: c_int) -> str {
|
|||||||
// Copied from run::program_output
|
// Copied from run::program_output
|
||||||
let file = os::fdopen(fd);
|
let file = os::fdopen(fd);
|
||||||
let reader = io::FILE_reader(file, false);
|
let reader = io::FILE_reader(file, false);
|
||||||
let buf = "";
|
let mut buf = "";
|
||||||
while !reader.eof() {
|
while !reader.eof() {
|
||||||
let bytes = reader.read_bytes(4096u);
|
let bytes = reader.read_bytes(4096u);
|
||||||
buf += str::from_bytes(bytes);
|
buf += str::from_bytes(bytes);
|
||||||
|
@ -47,7 +47,7 @@ fn run_cfail_test(config: config, props: test_props, testfile: str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_rfail_test(config: config, props: test_props, testfile: str) {
|
fn run_rfail_test(config: config, props: test_props, testfile: str) {
|
||||||
let procres = compile_test(config, props, testfile);
|
let mut procres = compile_test(config, props, testfile);
|
||||||
|
|
||||||
if procres.status != 0 { fatal_procres("compilation failed!", procres); }
|
if procres.status != 0 { fatal_procres("compilation failed!", procres); }
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ fn check_correct_failure_status(procres: procres) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_rpass_test(config: config, props: test_props, testfile: str) {
|
fn run_rpass_test(config: config, props: test_props, testfile: str) {
|
||||||
let procres = compile_test(config, props, testfile);
|
let mut procres = compile_test(config, props, testfile);
|
||||||
|
|
||||||
if procres.status != 0 { fatal_procres("compilation failed!", procres); }
|
if procres.status != 0 { fatal_procres("compilation failed!", procres); }
|
||||||
|
|
||||||
@ -93,9 +93,9 @@ fn run_pretty_test(config: config, props: test_props, testfile: str) {
|
|||||||
let rounds =
|
let rounds =
|
||||||
alt props.pp_exact { option::some(_) { 1 } option::none { 2 } };
|
alt props.pp_exact { option::some(_) { 1 } option::none { 2 } };
|
||||||
|
|
||||||
let srcs = [result::get(io::read_whole_file_str(testfile))];
|
let mut srcs = [result::get(io::read_whole_file_str(testfile))];
|
||||||
|
|
||||||
let round = 0;
|
let mut round = 0;
|
||||||
while round < rounds {
|
while round < rounds {
|
||||||
logv(config, #fmt["pretty-printing round %d", round]);
|
logv(config, #fmt["pretty-printing round %d", round]);
|
||||||
let procres = print_source(config, testfile, srcs[round]);
|
let procres = print_source(config, testfile, srcs[round]);
|
||||||
@ -109,7 +109,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: str) {
|
|||||||
round += 1;
|
round += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let expected =
|
let mut expected =
|
||||||
alt props.pp_exact {
|
alt props.pp_exact {
|
||||||
option::some(file) {
|
option::some(file) {
|
||||||
let filepath = path::connect(path::dirname(testfile), file);
|
let filepath = path::connect(path::dirname(testfile), file);
|
||||||
@ -117,7 +117,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: str) {
|
|||||||
}
|
}
|
||||||
option::none { srcs[vec::len(srcs) - 2u] }
|
option::none { srcs[vec::len(srcs) - 2u] }
|
||||||
};
|
};
|
||||||
let actual = srcs[vec::len(srcs) - 1u];
|
let mut actual = srcs[vec::len(srcs) - 1u];
|
||||||
|
|
||||||
if option::is_some(props.pp_exact) {
|
if option::is_some(props.pp_exact) {
|
||||||
// Now we have to care about line endings
|
// Now we have to care about line endings
|
||||||
@ -176,7 +176,7 @@ actual:\n\
|
|||||||
|
|
||||||
fn make_typecheck_args(config: config, _testfile: str) -> procargs {
|
fn make_typecheck_args(config: config, _testfile: str) -> procargs {
|
||||||
let prog = config.rustc_path;
|
let prog = config.rustc_path;
|
||||||
let args = ["-", "--no-trans", "--lib", "-L", config.build_base];
|
let mut args = ["-", "--no-trans", "--lib", "-L", config.build_base];
|
||||||
args += split_maybe_args(config.rustcflags);
|
args += split_maybe_args(config.rustcflags);
|
||||||
ret {prog: prog, args: args};
|
ret {prog: prog, args: args};
|
||||||
}
|
}
|
||||||
@ -193,8 +193,8 @@ fn check_error_patterns(props: test_props,
|
|||||||
fatal("process did not return an error status");
|
fatal("process did not return an error status");
|
||||||
}
|
}
|
||||||
|
|
||||||
let next_err_idx = 0u;
|
let mut next_err_idx = 0u;
|
||||||
let next_err_pat = props.error_patterns[next_err_idx];
|
let mut next_err_pat = props.error_patterns[next_err_idx];
|
||||||
for line: str in str::split_char(procres.stderr, '\n') {
|
for line: str in str::split_char(procres.stderr, '\n') {
|
||||||
if str::contains(line, next_err_pat) {
|
if str::contains(line, next_err_pat) {
|
||||||
#debug("found error pattern %s", next_err_pat);
|
#debug("found error pattern %s", next_err_pat);
|
||||||
@ -244,7 +244,7 @@ fn check_expected_errors(expected_errors: [errors::expected_error],
|
|||||||
// where line1:col1: is the starting point, line2:col2:
|
// where line1:col1: is the starting point, line2:col2:
|
||||||
// is the ending point, and * represents ANSI color codes.
|
// is the ending point, and * represents ANSI color codes.
|
||||||
for line: str in str::split_char(procres.stderr, '\n') {
|
for line: str in str::split_char(procres.stderr, '\n') {
|
||||||
let was_expected = false;
|
let mut was_expected = false;
|
||||||
vec::iteri(expected_errors) {|i, ee|
|
vec::iteri(expected_errors) {|i, ee|
|
||||||
if !found_flags[i] {
|
if !found_flags[i] {
|
||||||
#debug["prefix=%s ee.kind=%s ee.msg=%s line=%s",
|
#debug["prefix=%s ee.kind=%s ee.msg=%s line=%s",
|
||||||
@ -321,8 +321,8 @@ fn make_compile_args(config: config, props: test_props, extras: [str],
|
|||||||
xform: fn(config, str) -> str, testfile: str) ->
|
xform: fn(config, str) -> str, testfile: str) ->
|
||||||
procargs {
|
procargs {
|
||||||
let prog = config.rustc_path;
|
let prog = config.rustc_path;
|
||||||
let args = [testfile, "-o", xform(config, testfile),
|
let mut args = [testfile, "-o", xform(config, testfile),
|
||||||
"-L", config.build_base] + extras;
|
"-L", config.build_base] + extras;
|
||||||
args += split_maybe_args(config.rustcflags);
|
args += split_maybe_args(config.rustcflags);
|
||||||
args += split_maybe_args(props.compile_flags);
|
args += split_maybe_args(props.compile_flags);
|
||||||
ret {prog: prog, args: args};
|
ret {prog: prog, args: args};
|
||||||
|
@ -217,7 +217,7 @@ fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty, tm: test_mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn under(n: uint, it: fn(uint)) {
|
fn under(n: uint, it: fn(uint)) {
|
||||||
let i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
while i < n { it(i); i += 1u; }
|
while i < n { it(i); i += 1u; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,9 +487,9 @@ fn file_might_not_converge(filename: str) -> bool {
|
|||||||
|
|
||||||
fn check_roundtrip_convergence(code: @str, maxIters: uint) {
|
fn check_roundtrip_convergence(code: @str, maxIters: uint) {
|
||||||
|
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
let newv = code;
|
let mut newv = code;
|
||||||
let oldv = code;
|
let mut oldv = code;
|
||||||
|
|
||||||
while i < maxIters {
|
while i < maxIters {
|
||||||
oldv = newv;
|
oldv = newv;
|
||||||
@ -576,7 +576,7 @@ fn main(args: [str]) {
|
|||||||
#error("usage: %s <testdir>", args[0]);
|
#error("usage: %s <testdir>", args[0]);
|
||||||
ret;
|
ret;
|
||||||
}
|
}
|
||||||
let files = [];
|
let mut files = [];
|
||||||
let root = args[1];
|
let root = args[1];
|
||||||
|
|
||||||
find_rust_files(files, root);
|
find_rust_files(files, root);
|
||||||
|
@ -332,8 +332,8 @@ fn test_select2_stress() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let as = 0;
|
let mut as = 0;
|
||||||
let bs = 0;
|
let mut bs = 0;
|
||||||
iter::repeat(msgs * times * 2u) {||
|
iter::repeat(msgs * times * 2u) {||
|
||||||
alt check select2(po_a, po_b) {
|
alt check select2(po_a, po_b) {
|
||||||
either::left("a") { as += 1 }
|
either::left("a") { as += 1 }
|
||||||
|
@ -715,7 +715,7 @@ mod tests {
|
|||||||
assert(vec::slice(ivals, 0u, vec::len(res)) ==
|
assert(vec::slice(ivals, 0u, vec::len(res)) ==
|
||||||
vec::map(res, {|x| x as int}));
|
vec::map(res, {|x| x as int}));
|
||||||
}
|
}
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < 8u {
|
while i < 8u {
|
||||||
check_read_ln(i, wide_test, ivals);
|
check_read_ln(i, wide_test, ivals);
|
||||||
i += 1u;
|
i += 1u;
|
||||||
|
@ -232,7 +232,7 @@ fn test_flat_map_with_option() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_flat_map_with_list() {
|
fn test_flat_map_with_list() {
|
||||||
fn repeat(&&i: int) -> [int] {
|
fn repeat(&&i: int) -> [int] {
|
||||||
let r = [];
|
let mut r = [];
|
||||||
int::range(0, i) {|_j| r += [i]; }
|
int::range(0, i) {|_j| r += [i]; }
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
@ -246,8 +246,7 @@ fn test_flat_map_with_list() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_repeat() {
|
fn test_repeat() {
|
||||||
let c = [],
|
let mut c = [], i = 0u;
|
||||||
i = 0u;
|
|
||||||
repeat(5u) {||
|
repeat(5u) {||
|
||||||
c += [(i * i)];
|
c += [(i * i)];
|
||||||
i += 1u;
|
i += 1u;
|
||||||
|
@ -617,8 +617,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore(reason = "fails periodically on mac")]
|
#[ignore(reason = "fails periodically on mac")]
|
||||||
fn test_getenv_big() {
|
fn test_getenv_big() {
|
||||||
let s = "";
|
let mut s = "";
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
while i < 100 { s += "aaaaaaaaaa"; i += 1; }
|
while i < 100 { s += "aaaaaaaaaa"; i += 1; }
|
||||||
let n = make_rand_name();
|
let n = make_rand_name();
|
||||||
setenv(n, s);
|
setenv(n, s);
|
||||||
@ -659,7 +659,7 @@ mod tests {
|
|||||||
fn test_env_setenv() {
|
fn test_env_setenv() {
|
||||||
let n = make_rand_name();
|
let n = make_rand_name();
|
||||||
|
|
||||||
let e = env();
|
let mut e = env();
|
||||||
setenv(n, "VALUE");
|
setenv(n, "VALUE");
|
||||||
assert !vec::contains(e, (n, "VALUE"));
|
assert !vec::contains(e, (n, "VALUE"));
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ mod tests {
|
|||||||
// Copied from run::program_output
|
// Copied from run::program_output
|
||||||
let file = os::fdopen(fd);
|
let file = os::fdopen(fd);
|
||||||
let reader = io::FILE_reader(file, false);
|
let reader = io::FILE_reader(file, false);
|
||||||
let buf = "";
|
let mut buf = "";
|
||||||
while !reader.eof() {
|
while !reader.eof() {
|
||||||
let bytes = reader.read_bytes(4096u);
|
let bytes = reader.read_bytes(4096u);
|
||||||
buf += str::from_bytes(bytes);
|
buf += str::from_bytes(bytes);
|
||||||
|
@ -1675,7 +1675,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pop_char() {
|
fn test_pop_char() {
|
||||||
let data = "ประเทศไทย中华";
|
let mut data = "ประเทศไทย中华";
|
||||||
let cc = pop_char(data);
|
let cc = pop_char(data);
|
||||||
assert "ประเทศไทย中" == data;
|
assert "ประเทศไทย中" == data;
|
||||||
assert '华' == cc;
|
assert '华' == cc;
|
||||||
@ -1683,7 +1683,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pop_char_2() {
|
fn test_pop_char_2() {
|
||||||
let data2 = "华";
|
let mut data2 = "华";
|
||||||
let cc2 = pop_char(data2);
|
let cc2 = pop_char(data2);
|
||||||
assert "" == data2;
|
assert "" == data2;
|
||||||
assert '华' == cc2;
|
assert '华' == cc2;
|
||||||
@ -1693,7 +1693,7 @@ mod tests {
|
|||||||
#[should_fail]
|
#[should_fail]
|
||||||
#[ignore(cfg(target_os = "win32"))]
|
#[ignore(cfg(target_os = "win32"))]
|
||||||
fn test_pop_char_fail() {
|
fn test_pop_char_fail() {
|
||||||
let data = "";
|
let mut data = "";
|
||||||
let _cc3 = pop_char(data);
|
let _cc3 = pop_char(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1887,7 +1887,7 @@ mod tests {
|
|||||||
assert find_str_between(data, "ab", 2u, 6u) == some(3u);
|
assert find_str_between(data, "ab", 2u, 6u) == some(3u);
|
||||||
assert find_str_between(data, "ab", 2u, 4u) == none;
|
assert find_str_between(data, "ab", 2u, 4u) == none;
|
||||||
|
|
||||||
let data = "ประเทศไทย中华Việt Nam";
|
let mut data = "ประเทศไทย中华Việt Nam";
|
||||||
data += data;
|
data += data;
|
||||||
assert find_str_between(data, "", 0u, 43u) == some(0u);
|
assert find_str_between(data, "", 0u, 43u) == some(0u);
|
||||||
assert find_str_between(data, "", 6u, 43u) == some(6u);
|
assert find_str_between(data, "", 6u, 43u) == some(6u);
|
||||||
@ -1959,14 +1959,14 @@ mod tests {
|
|||||||
assert (eq("bc", unsafe::slice_bytes("abc", 1u, 3u)));
|
assert (eq("bc", unsafe::slice_bytes("abc", 1u, 3u)));
|
||||||
assert (eq("", unsafe::slice_bytes("abc", 1u, 1u)));
|
assert (eq("", unsafe::slice_bytes("abc", 1u, 1u)));
|
||||||
fn a_million_letter_a() -> str {
|
fn a_million_letter_a() -> str {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
let rs = "";
|
let mut rs = "";
|
||||||
while i < 100000 { rs += "aaaaaaaaaa"; i += 1; }
|
while i < 100000 { rs += "aaaaaaaaaa"; i += 1; }
|
||||||
ret rs;
|
ret rs;
|
||||||
}
|
}
|
||||||
fn half_a_million_letter_a() -> str {
|
fn half_a_million_letter_a() -> str {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
let rs = "";
|
let mut rs = "";
|
||||||
while i < 100000 { rs += "aaaaa"; i += 1; }
|
while i < 100000 { rs += "aaaaa"; i += 1; }
|
||||||
ret rs;
|
ret rs;
|
||||||
}
|
}
|
||||||
@ -2068,14 +2068,14 @@ mod tests {
|
|||||||
assert "华" == slice(data, 30u, 33u);
|
assert "华" == slice(data, 30u, 33u);
|
||||||
|
|
||||||
fn a_million_letter_X() -> str {
|
fn a_million_letter_X() -> str {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
let rs = "";
|
let mut rs = "";
|
||||||
while i < 100000 { rs += "华华华华华华华华华华"; i += 1; }
|
while i < 100000 { rs += "华华华华华华华华华华"; i += 1; }
|
||||||
ret rs;
|
ret rs;
|
||||||
}
|
}
|
||||||
fn half_a_million_letter_X() -> str {
|
fn half_a_million_letter_X() -> str {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
let rs = "";
|
let mut rs = "";
|
||||||
while i < 100000 { rs += "华华华华华"; i += 1; }
|
while i < 100000 { rs += "华华华华华"; i += 1; }
|
||||||
ret rs;
|
ret rs;
|
||||||
}
|
}
|
||||||
@ -2164,7 +2164,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_shift_byte() unsafe {
|
fn test_shift_byte() unsafe {
|
||||||
let s = "ABC";
|
let mut s = "ABC";
|
||||||
let b = unsafe::shift_byte(s);
|
let b = unsafe::shift_byte(s);
|
||||||
assert (s == "BC");
|
assert (s == "BC");
|
||||||
assert (b == 65u8);
|
assert (b == 65u8);
|
||||||
@ -2172,7 +2172,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pop_byte() unsafe {
|
fn test_pop_byte() unsafe {
|
||||||
let s = "ABC";
|
let mut s = "ABC";
|
||||||
let b = unsafe::pop_byte(s);
|
let b = unsafe::pop_byte(s);
|
||||||
assert (s == "AB");
|
assert (s == "AB");
|
||||||
assert (b == 67u8);
|
assert (b == 67u8);
|
||||||
@ -2264,7 +2264,7 @@ mod tests {
|
|||||||
|
|
||||||
let v: [u8] = bytes(s1);
|
let v: [u8] = bytes(s1);
|
||||||
let s2: str = from_bytes(v);
|
let s2: str = from_bytes(v);
|
||||||
let i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
let n1: uint = len(s1);
|
let n1: uint = len(s1);
|
||||||
let n2: uint = vec::len::<u8>(v);
|
let n2: uint = vec::len::<u8>(v);
|
||||||
assert (n1 == n2);
|
assert (n1 == n2);
|
||||||
@ -2297,7 +2297,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chars_iter() {
|
fn test_chars_iter() {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
chars_iter("x\u03c0y") {|ch|
|
chars_iter("x\u03c0y") {|ch|
|
||||||
alt check i {
|
alt check i {
|
||||||
0 { assert ch == 'x'; }
|
0 { assert ch == 'x'; }
|
||||||
@ -2312,7 +2312,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bytes_iter() {
|
fn test_bytes_iter() {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
|
|
||||||
bytes_iter("xyz") {|bb|
|
bytes_iter("xyz") {|bb|
|
||||||
alt check i {
|
alt check i {
|
||||||
@ -2330,7 +2330,7 @@ mod tests {
|
|||||||
fn test_split_char_iter() {
|
fn test_split_char_iter() {
|
||||||
let data = "\nMary had a little lamb\nLittle lamb\n";
|
let data = "\nMary had a little lamb\nLittle lamb\n";
|
||||||
|
|
||||||
let ii = 0;
|
let mut ii = 0;
|
||||||
|
|
||||||
split_char_iter(data, ' ') {|xx|
|
split_char_iter(data, ' ') {|xx|
|
||||||
alt ii {
|
alt ii {
|
||||||
@ -2348,7 +2348,7 @@ mod tests {
|
|||||||
fn test_splitn_char_iter() {
|
fn test_splitn_char_iter() {
|
||||||
let data = "\nMary had a little lamb\nLittle lamb\n";
|
let data = "\nMary had a little lamb\nLittle lamb\n";
|
||||||
|
|
||||||
let ii = 0;
|
let mut ii = 0;
|
||||||
|
|
||||||
splitn_char_iter(data, ' ', 2u) {|xx|
|
splitn_char_iter(data, ' ', 2u) {|xx|
|
||||||
alt ii {
|
alt ii {
|
||||||
@ -2365,7 +2365,7 @@ mod tests {
|
|||||||
fn test_words_iter() {
|
fn test_words_iter() {
|
||||||
let data = "\nMary had a little lamb\nLittle lamb\n";
|
let data = "\nMary had a little lamb\nLittle lamb\n";
|
||||||
|
|
||||||
let ii = 0;
|
let mut ii = 0;
|
||||||
|
|
||||||
words_iter(data) {|ww|
|
words_iter(data) {|ww|
|
||||||
alt ii {
|
alt ii {
|
||||||
@ -2385,7 +2385,7 @@ mod tests {
|
|||||||
fn test_lines_iter () {
|
fn test_lines_iter () {
|
||||||
let lf = "\nMary had a little lamb\nLittle lamb\n";
|
let lf = "\nMary had a little lamb\nLittle lamb\n";
|
||||||
|
|
||||||
let ii = 0;
|
let mut ii = 0;
|
||||||
|
|
||||||
lines_iter(lf) {|x|
|
lines_iter(lf) {|x|
|
||||||
alt ii {
|
alt ii {
|
||||||
|
@ -790,7 +790,7 @@ fn test_spawn_sched_blocking() {
|
|||||||
comm::recv(start_po);
|
comm::recv(start_po);
|
||||||
|
|
||||||
fn pingpong(po: comm::port<int>, ch: comm::chan<int>) {
|
fn pingpong(po: comm::port<int>, ch: comm::chan<int>) {
|
||||||
let val = 20;
|
let mut val = 20;
|
||||||
while val > 0 {
|
while val > 0 {
|
||||||
val = comm::recv(po);
|
val = comm::recv(po);
|
||||||
comm::send(ch, val - 1);
|
comm::send(ch, val - 1);
|
||||||
|
@ -1017,7 +1017,7 @@ mod tests {
|
|||||||
fn test_unsafe_ptrs() unsafe {
|
fn test_unsafe_ptrs() unsafe {
|
||||||
// Test on-stack copy-from-buf.
|
// Test on-stack copy-from-buf.
|
||||||
let a = [1, 2, 3];
|
let a = [1, 2, 3];
|
||||||
let ptr = unsafe::to_ptr(a);
|
let mut ptr = unsafe::to_ptr(a);
|
||||||
let b = unsafe::from_buf(ptr, 3u);
|
let b = unsafe::from_buf(ptr, 3u);
|
||||||
assert (len(b) == 3u);
|
assert (len(b) == 3u);
|
||||||
assert (b[0] == 1);
|
assert (b[0] == 1);
|
||||||
@ -1039,7 +1039,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_from_fn() {
|
fn test_from_fn() {
|
||||||
// Test on-stack from_fn.
|
// Test on-stack from_fn.
|
||||||
let v = from_fn(3u, square);
|
let mut v = from_fn(3u, square);
|
||||||
assert (len(v) == 3u);
|
assert (len(v) == 3u);
|
||||||
assert (v[0] == 0u);
|
assert (v[0] == 0u);
|
||||||
assert (v[1] == 1u);
|
assert (v[1] == 1u);
|
||||||
@ -1058,7 +1058,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_from_elem() {
|
fn test_from_elem() {
|
||||||
// Test on-stack from_elem.
|
// Test on-stack from_elem.
|
||||||
let v = from_elem(2u, 10u);
|
let mut v = from_elem(2u, 10u);
|
||||||
assert (len(v) == 2u);
|
assert (len(v) == 2u);
|
||||||
assert (v[0] == 10u);
|
assert (v[0] == 10u);
|
||||||
assert (v[1] == 10u);
|
assert (v[1] == 10u);
|
||||||
@ -1093,7 +1093,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tail() {
|
fn test_tail() {
|
||||||
let a = [11];
|
let mut a = [11];
|
||||||
assert (tail(a) == []);
|
assert (tail(a) == []);
|
||||||
|
|
||||||
a = [11, 12];
|
a = [11, 12];
|
||||||
@ -1102,7 +1102,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_last() {
|
fn test_last() {
|
||||||
let n = last_opt([]);
|
let mut n = last_opt([]);
|
||||||
assert (n == none);
|
assert (n == none);
|
||||||
n = last_opt([1, 2, 3]);
|
n = last_opt([1, 2, 3]);
|
||||||
assert (n == some(3));
|
assert (n == some(3));
|
||||||
@ -1113,7 +1113,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_slice() {
|
fn test_slice() {
|
||||||
// Test on-stack -> on-stack slice.
|
// Test on-stack -> on-stack slice.
|
||||||
let v = slice([1, 2, 3], 1u, 3u);
|
let mut v = slice([1, 2, 3], 1u, 3u);
|
||||||
assert (len(v) == 2u);
|
assert (len(v) == 2u);
|
||||||
assert (v[0] == 2);
|
assert (v[0] == 2);
|
||||||
assert (v[1] == 3);
|
assert (v[1] == 3);
|
||||||
@ -1138,8 +1138,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_pop() {
|
fn test_pop() {
|
||||||
// Test on-stack pop.
|
// Test on-stack pop.
|
||||||
let v = [1, 2, 3];
|
let mut v = [1, 2, 3];
|
||||||
let e = pop(v);
|
let mut e = pop(v);
|
||||||
assert (len(v) == 2u);
|
assert (len(v) == 2u);
|
||||||
assert (v[0] == 1);
|
assert (v[0] == 1);
|
||||||
assert (v[1] == 2);
|
assert (v[1] == 2);
|
||||||
@ -1159,7 +1159,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_push() {
|
fn test_push() {
|
||||||
// Test on-stack push().
|
// Test on-stack push().
|
||||||
let v = [];
|
let mut v = [];
|
||||||
push(v, 1);
|
push(v, 1);
|
||||||
assert (len(v) == 1u);
|
assert (len(v) == 1u);
|
||||||
assert (v[0] == 1);
|
assert (v[0] == 1);
|
||||||
@ -1174,7 +1174,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_grow() {
|
fn test_grow() {
|
||||||
// Test on-stack grow().
|
// Test on-stack grow().
|
||||||
let v = [];
|
let mut v = [];
|
||||||
grow(v, 2u, 1);
|
grow(v, 2u, 1);
|
||||||
assert (len(v) == 2u);
|
assert (len(v) == 2u);
|
||||||
assert (v[0] == 1);
|
assert (v[0] == 1);
|
||||||
@ -1192,7 +1192,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_grow_fn() {
|
fn test_grow_fn() {
|
||||||
let v = [];
|
let mut v = [];
|
||||||
grow_fn(v, 3u, square);
|
grow_fn(v, 3u, square);
|
||||||
assert (len(v) == 3u);
|
assert (len(v) == 3u);
|
||||||
assert (v[0] == 0u);
|
assert (v[0] == 0u);
|
||||||
@ -1202,7 +1202,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_grow_set() {
|
fn test_grow_set() {
|
||||||
let v = [mutable 1, 2, 3];
|
let mut v = [mutable 1, 2, 3];
|
||||||
grow_set(v, 4u, 4, 5);
|
grow_set(v, 4u, 4, 5);
|
||||||
assert (len(v) == 5u);
|
assert (len(v) == 5u);
|
||||||
assert (v[0] == 1);
|
assert (v[0] == 1);
|
||||||
@ -1215,8 +1215,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_map() {
|
fn test_map() {
|
||||||
// Test on-stack map.
|
// Test on-stack map.
|
||||||
let v = [1u, 2u, 3u];
|
let mut v = [1u, 2u, 3u];
|
||||||
let w = map(v, square_ref);
|
let mut w = map(v, square_ref);
|
||||||
assert (len(w) == 3u);
|
assert (len(w) == 3u);
|
||||||
assert (w[0] == 1u);
|
assert (w[0] == 1u);
|
||||||
assert (w[1] == 4u);
|
assert (w[1] == 4u);
|
||||||
@ -1240,15 +1240,15 @@ mod tests {
|
|||||||
let v0 = [1, 2, 3, 4, 5];
|
let v0 = [1, 2, 3, 4, 5];
|
||||||
let v1 = [5, 4, 3, 2, 1];
|
let v1 = [5, 4, 3, 2, 1];
|
||||||
let u = map2::<int, int, int>(v0, v1, f);
|
let u = map2::<int, int, int>(v0, v1, f);
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
while i < 5 { assert (v0[i] * v1[i] == u[i]); i += 1; }
|
while i < 5 { assert (v0[i] * v1[i] == u[i]); i += 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_filter_map() {
|
fn test_filter_map() {
|
||||||
// Test on-stack filter-map.
|
// Test on-stack filter-map.
|
||||||
let v = [1u, 2u, 3u];
|
let mut v = [1u, 2u, 3u];
|
||||||
let w = filter_map(v, square_if_odd);
|
let mut w = filter_map(v, square_if_odd);
|
||||||
assert (len(w) == 2u);
|
assert (len(w) == 2u);
|
||||||
assert (w[0] == 1u);
|
assert (w[0] == 1u);
|
||||||
assert (w[1] == 9u);
|
assert (w[1] == 9u);
|
||||||
@ -1287,8 +1287,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_foldl() {
|
fn test_foldl() {
|
||||||
// Test on-stack fold.
|
// Test on-stack fold.
|
||||||
let v = [1u, 2u, 3u];
|
let mut v = [1u, 2u, 3u];
|
||||||
let sum = foldl(0u, v, add);
|
let mut sum = foldl(0u, v, add);
|
||||||
assert (sum == 6u);
|
assert (sum == 6u);
|
||||||
|
|
||||||
// Test on-heap fold.
|
// Test on-heap fold.
|
||||||
@ -1302,7 +1302,7 @@ mod tests {
|
|||||||
fn sub(&&a: int, &&b: int) -> int {
|
fn sub(&&a: int, &&b: int) -> int {
|
||||||
a - b
|
a - b
|
||||||
}
|
}
|
||||||
let v = [1, 2, 3, 4];
|
let mut v = [1, 2, 3, 4];
|
||||||
let sum = foldl(0, v, sub);
|
let sum = foldl(0, v, sub);
|
||||||
assert sum == -10;
|
assert sum == -10;
|
||||||
}
|
}
|
||||||
@ -1312,28 +1312,28 @@ mod tests {
|
|||||||
fn sub(&&a: int, &&b: int) -> int {
|
fn sub(&&a: int, &&b: int) -> int {
|
||||||
a - b
|
a - b
|
||||||
}
|
}
|
||||||
let v = [1, 2, 3, 4];
|
let mut v = [1, 2, 3, 4];
|
||||||
let sum = foldr(v, 0, sub);
|
let sum = foldr(v, 0, sub);
|
||||||
assert sum == -2;
|
assert sum == -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_iter_empty() {
|
fn test_iter_empty() {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
iter::<int>([], { |_v| i += 1 });
|
iter::<int>([], { |_v| i += 1 });
|
||||||
assert i == 0;
|
assert i == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_iter_nonempty() {
|
fn test_iter_nonempty() {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
iter([1, 2, 3], { |v| i += v });
|
iter([1, 2, 3], { |v| i += v });
|
||||||
assert i == 6;
|
assert i == 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_iteri() {
|
fn test_iteri() {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
iteri([1, 2, 3], { |j, v|
|
iteri([1, 2, 3], { |j, v|
|
||||||
if i == 0 { assert v == 1; }
|
if i == 0 { assert v == 1; }
|
||||||
assert j + 1u == v as uint;
|
assert j + 1u == v as uint;
|
||||||
@ -1344,14 +1344,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_riter_empty() {
|
fn test_riter_empty() {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
riter::<int>([], { |_v| i += 1 });
|
riter::<int>([], { |_v| i += 1 });
|
||||||
assert i == 0;
|
assert i == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_riter_nonempty() {
|
fn test_riter_nonempty() {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
riter([1, 2, 3], { |v|
|
riter([1, 2, 3], { |v|
|
||||||
if i == 0 { assert v == 3; }
|
if i == 0 { assert v == 3; }
|
||||||
i += v
|
i += v
|
||||||
@ -1361,7 +1361,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_riteri() {
|
fn test_riteri() {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
riteri([0, 1, 2], { |j, v|
|
riteri([0, 1, 2], { |j, v|
|
||||||
if i == 0 { assert v == 2; }
|
if i == 0 { assert v == 2; }
|
||||||
assert j == v as uint;
|
assert j == v as uint;
|
||||||
@ -1372,7 +1372,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_permute() {
|
fn test_permute() {
|
||||||
let results: [[int]];
|
let mut results: [[int]];
|
||||||
|
|
||||||
results = [];
|
results = [];
|
||||||
permute([]) {|v| results += [v]; }
|
permute([]) {|v| results += [v]; }
|
||||||
@ -1464,7 +1464,7 @@ mod tests {
|
|||||||
assert position_between([], 0u, 0u, f) == none;
|
assert position_between([], 0u, 0u, f) == none;
|
||||||
|
|
||||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||||
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||||
|
|
||||||
assert position_between(v, 0u, 0u, f) == none;
|
assert position_between(v, 0u, 0u, f) == none;
|
||||||
assert position_between(v, 0u, 1u, f) == none;
|
assert position_between(v, 0u, 1u, f) == none;
|
||||||
@ -1493,7 +1493,7 @@ mod tests {
|
|||||||
|
|
||||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||||
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
|
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
|
||||||
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||||
|
|
||||||
assert find(v, f) == some((1, 'b'));
|
assert find(v, f) == some((1, 'b'));
|
||||||
assert find(v, g) == none;
|
assert find(v, g) == none;
|
||||||
@ -1504,7 +1504,7 @@ mod tests {
|
|||||||
assert find_between([], 0u, 0u, f) == none;
|
assert find_between([], 0u, 0u, f) == none;
|
||||||
|
|
||||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||||
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||||
|
|
||||||
assert find_between(v, 0u, 0u, f) == none;
|
assert find_between(v, 0u, 0u, f) == none;
|
||||||
assert find_between(v, 0u, 1u, f) == none;
|
assert find_between(v, 0u, 1u, f) == none;
|
||||||
@ -1533,7 +1533,7 @@ mod tests {
|
|||||||
|
|
||||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||||
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
|
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
|
||||||
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||||
|
|
||||||
assert position(v, f) == some(1u);
|
assert position(v, f) == some(1u);
|
||||||
assert position(v, g) == none;
|
assert position(v, g) == none;
|
||||||
@ -1544,7 +1544,7 @@ mod tests {
|
|||||||
assert rposition_between([], 0u, 0u, f) == none;
|
assert rposition_between([], 0u, 0u, f) == none;
|
||||||
|
|
||||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||||
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||||
|
|
||||||
assert rposition_between(v, 0u, 0u, f) == none;
|
assert rposition_between(v, 0u, 0u, f) == none;
|
||||||
assert rposition_between(v, 0u, 1u, f) == none;
|
assert rposition_between(v, 0u, 1u, f) == none;
|
||||||
@ -1573,7 +1573,7 @@ mod tests {
|
|||||||
|
|
||||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||||
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
|
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
|
||||||
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||||
|
|
||||||
assert rfind(v, f) == some((3, 'b'));
|
assert rfind(v, f) == some((3, 'b'));
|
||||||
assert rfind(v, g) == none;
|
assert rfind(v, g) == none;
|
||||||
@ -1584,7 +1584,7 @@ mod tests {
|
|||||||
assert rfind_between([], 0u, 0u, f) == none;
|
assert rfind_between([], 0u, 0u, f) == none;
|
||||||
|
|
||||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||||
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||||
|
|
||||||
assert rfind_between(v, 0u, 0u, f) == none;
|
assert rfind_between(v, 0u, 0u, f) == none;
|
||||||
assert rfind_between(v, 0u, 1u, f) == none;
|
assert rfind_between(v, 0u, 1u, f) == none;
|
||||||
@ -1740,7 +1740,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unshift() {
|
fn test_unshift() {
|
||||||
let x = [1, 2, 3];
|
let mut x = [1, 2, 3];
|
||||||
unshift(x, 0);
|
unshift(x, 0);
|
||||||
assert x == [0, 1, 2, 3];
|
assert x == [0, 1, 2, 3];
|
||||||
}
|
}
|
||||||
|
@ -234,8 +234,8 @@ fn eq_vec(v0: bitv, v1: [uint]) -> bool {
|
|||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_0_elements() {
|
fn test_0_elements() {
|
||||||
let act;
|
let mut act;
|
||||||
let exp;
|
let mut exp;
|
||||||
act = bitv(0u, false);
|
act = bitv(0u, false);
|
||||||
exp = vec::from_elem::<uint>(0u, 0u);
|
exp = vec::from_elem::<uint>(0u, 0u);
|
||||||
assert (eq_vec(act, exp));
|
assert (eq_vec(act, exp));
|
||||||
@ -243,7 +243,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_1_element() {
|
fn test_1_element() {
|
||||||
let act;
|
let mut act;
|
||||||
act = bitv(1u, false);
|
act = bitv(1u, false);
|
||||||
assert (eq_vec(act, [0u]));
|
assert (eq_vec(act, [0u]));
|
||||||
act = bitv(1u, true);
|
act = bitv(1u, true);
|
||||||
@ -252,7 +252,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_10_elements() {
|
fn test_10_elements() {
|
||||||
let act;
|
let mut act;
|
||||||
// all 0
|
// all 0
|
||||||
|
|
||||||
act = bitv(10u, false);
|
act = bitv(10u, false);
|
||||||
@ -291,7 +291,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_31_elements() {
|
fn test_31_elements() {
|
||||||
let act;
|
let mut act;
|
||||||
// all 0
|
// all 0
|
||||||
|
|
||||||
act = bitv(31u, false);
|
act = bitv(31u, false);
|
||||||
@ -364,7 +364,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_32_elements() {
|
fn test_32_elements() {
|
||||||
let act;
|
let mut act;
|
||||||
// all 0
|
// all 0
|
||||||
|
|
||||||
act = bitv(32u, false);
|
act = bitv(32u, false);
|
||||||
@ -439,7 +439,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_33_elements() {
|
fn test_33_elements() {
|
||||||
let act;
|
let mut act;
|
||||||
// all 0
|
// all 0
|
||||||
|
|
||||||
act = bitv(33u, false);
|
act = bitv(33u, false);
|
||||||
|
@ -126,7 +126,7 @@ mod tests {
|
|||||||
assert (d.peek_front() == 42);
|
assert (d.peek_front() == 42);
|
||||||
log(debug, d.peek_back());
|
log(debug, d.peek_back());
|
||||||
assert (d.peek_back() == 137);
|
assert (d.peek_back() == 137);
|
||||||
let i: int = d.pop_front();
|
let mut i: int = d.pop_front();
|
||||||
log(debug, i);
|
log(debug, i);
|
||||||
assert (i == 42);
|
assert (i == 42);
|
||||||
i = d.pop_back();
|
i = d.pop_back();
|
||||||
|
@ -453,7 +453,7 @@ mod tests {
|
|||||||
let eqer_uint: map::eqfn<uint> = eq_uint;
|
let eqer_uint: map::eqfn<uint> = eq_uint;
|
||||||
let hm_uu: map::hashmap<uint, uint> =
|
let hm_uu: map::hashmap<uint, uint> =
|
||||||
map::hashmap::<uint, uint>(hasher_uint, eqer_uint);
|
map::hashmap::<uint, uint>(hasher_uint, eqer_uint);
|
||||||
let i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
while i < num_to_insert {
|
while i < num_to_insert {
|
||||||
assert (hm_uu.insert(i, i * i));
|
assert (hm_uu.insert(i, i * i));
|
||||||
#debug("inserting %u -> %u", i, i*i);
|
#debug("inserting %u -> %u", i, i*i);
|
||||||
@ -533,7 +533,7 @@ mod tests {
|
|||||||
let eqer: map::eqfn<uint> = eq;
|
let eqer: map::eqfn<uint> = eq;
|
||||||
let hm: map::hashmap<uint, uint> =
|
let hm: map::hashmap<uint, uint> =
|
||||||
map::hashmap::<uint, uint>(hasher, eqer);
|
map::hashmap::<uint, uint>(hasher, eqer);
|
||||||
let i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
while i < num_to_insert {
|
while i < num_to_insert {
|
||||||
assert (hm.insert(i, i * i));
|
assert (hm.insert(i, i * i));
|
||||||
#debug("inserting %u -> %u", i, i*i);
|
#debug("inserting %u -> %u", i, i*i);
|
||||||
|
@ -1281,18 +1281,18 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn of_string2() {
|
fn of_string2() {
|
||||||
let buf = @ mutable "1234567890";
|
let buf = @ mutable "1234567890";
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
while i < 10 { *buf = *buf + *buf; i+=1;}
|
while i < 10 { *buf = *buf + *buf; i+=1;}
|
||||||
let sample = @*buf;
|
let sample = @*buf;
|
||||||
let r = of_str(sample);
|
let r = of_str(sample);
|
||||||
assert char_len(r) == str::char_len(*sample);
|
assert char_len(r) == str::char_len(*sample);
|
||||||
assert rope_to_string(r) == *sample;
|
assert rope_to_string(r) == *sample;
|
||||||
|
|
||||||
let string_iter = 0u;
|
let mut string_iter = 0u;
|
||||||
let string_len = str::len(*sample);
|
let string_len = str::len(*sample);
|
||||||
let rope_iter = iterator::char::start(r);
|
let rope_iter = iterator::char::start(r);
|
||||||
let equal = true;
|
let mut equal = true;
|
||||||
let pos = 0u;
|
let mut pos = 0u;
|
||||||
while equal {
|
while equal {
|
||||||
alt(node::char_iterator::next(rope_iter)) {
|
alt(node::char_iterator::next(rope_iter)) {
|
||||||
option::none {
|
option::none {
|
||||||
@ -1314,12 +1314,12 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn iter1() {
|
fn iter1() {
|
||||||
let buf = @ mutable "1234567890";
|
let buf = @ mutable "1234567890";
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
while i < 10 { *buf = *buf + *buf; i+=1;}
|
while i < 10 { *buf = *buf + *buf; i+=1;}
|
||||||
let sample = @*buf;
|
let sample = @*buf;
|
||||||
let r = of_str(sample);
|
let r = of_str(sample);
|
||||||
|
|
||||||
let len = 0u;
|
let mut len = 0u;
|
||||||
let it = iterator::char::start(r);
|
let it = iterator::char::start(r);
|
||||||
loop {
|
loop {
|
||||||
alt(node::char_iterator::next(it)) {
|
alt(node::char_iterator::next(it)) {
|
||||||
@ -1335,11 +1335,11 @@ mod tests {
|
|||||||
fn bal1() {
|
fn bal1() {
|
||||||
let init = @ "1234567890";
|
let init = @ "1234567890";
|
||||||
let buf = @ mutable * init;
|
let buf = @ mutable * init;
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
while i < 8 { *buf = *buf + *buf; i+=1;}
|
while i < 8 { *buf = *buf + *buf; i+=1;}
|
||||||
let sample = @*buf;
|
let sample = @*buf;
|
||||||
let r1 = of_str(sample);
|
let r1 = of_str(sample);
|
||||||
let r2 = of_str(init);
|
let mut r2 = of_str(init);
|
||||||
i = 0;
|
i = 0;
|
||||||
while i < 8 { r2 = append_rope(r2, r2); i+= 1;}
|
while i < 8 { r2 = append_rope(r2, r2); i+= 1;}
|
||||||
|
|
||||||
@ -1354,19 +1354,19 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn char_at1() {
|
fn char_at1() {
|
||||||
//Generate a large rope
|
//Generate a large rope
|
||||||
let r = of_str(@ "123456789");
|
let mut r = of_str(@ "123456789");
|
||||||
uint::range(0u, 10u){|_i|
|
uint::range(0u, 10u){|_i|
|
||||||
r = append_rope(r, r);
|
r = append_rope(r, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Copy it in the slowest possible way
|
//Copy it in the slowest possible way
|
||||||
let r2 = empty();
|
let mut r2 = empty();
|
||||||
uint::range(0u, char_len(r)){|i|
|
uint::range(0u, char_len(r)){|i|
|
||||||
r2 = append_char(r2, char_at(r, i));
|
r2 = append_char(r2, char_at(r, i));
|
||||||
}
|
}
|
||||||
assert eq(r, r2);
|
assert eq(r, r2);
|
||||||
|
|
||||||
let r3 = empty();
|
let mut r3 = empty();
|
||||||
uint::range(0u, char_len(r)){|i|
|
uint::range(0u, char_len(r)){|i|
|
||||||
r3 = prepend_char(r3, char_at(r, char_len(r) - i - 1u));
|
r3 = prepend_char(r3, char_at(r, char_len(r) - i - 1u));
|
||||||
}
|
}
|
||||||
@ -1387,7 +1387,7 @@ mod tests {
|
|||||||
fn concat1() {
|
fn concat1() {
|
||||||
//Generate a reasonable rope
|
//Generate a reasonable rope
|
||||||
let chunk = of_str(@ "123456789");
|
let chunk = of_str(@ "123456789");
|
||||||
let r = empty();
|
let mut r = empty();
|
||||||
uint::range(0u, 10u){|_i|
|
uint::range(0u, 10u){|_i|
|
||||||
r = append_rope(r, chunk);
|
r = append_rope(r, chunk);
|
||||||
}
|
}
|
||||||
|
@ -264,8 +264,8 @@ mod tests {
|
|||||||
type test = {input: str, output: [u8]};
|
type test = {input: str, output: [u8]};
|
||||||
|
|
||||||
fn a_million_letter_a() -> str {
|
fn a_million_letter_a() -> str {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
let rs = "";
|
let mut rs = "";
|
||||||
while i < 100000 { rs += "aaaaaaaaaa"; i += 1; }
|
while i < 100000 { rs += "aaaaaaaaaa"; i += 1; }
|
||||||
ret rs;
|
ret rs;
|
||||||
}
|
}
|
||||||
@ -316,7 +316,7 @@ mod tests {
|
|||||||
fn check_vec_eq(v0: [u8], v1: [u8]) {
|
fn check_vec_eq(v0: [u8], v1: [u8]) {
|
||||||
assert (vec::len::<u8>(v0) == vec::len::<u8>(v1));
|
assert (vec::len::<u8>(v0) == vec::len::<u8>(v1));
|
||||||
let len = vec::len::<u8>(v0);
|
let len = vec::len::<u8>(v0);
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < len {
|
while i < len {
|
||||||
let a = v0[i];
|
let a = v0[i];
|
||||||
let b = v1[i];
|
let b = v1[i];
|
||||||
@ -338,7 +338,7 @@ mod tests {
|
|||||||
// Test that it works when accepting the message in pieces
|
// Test that it works when accepting the message in pieces
|
||||||
for t: test in tests {
|
for t: test in tests {
|
||||||
let len = str::len(t.input);
|
let len = str::len(t.input);
|
||||||
let left = len;
|
let mut left = len;
|
||||||
while left > 0u {
|
while left > 0u {
|
||||||
let take = (left + 1u) / 2u;
|
let take = (left + 1u) / 2u;
|
||||||
sh.input_str(str::slice(t.input, len - left,
|
sh.input_str(str::slice(t.input, len - left,
|
||||||
|
@ -167,7 +167,7 @@ mod test_qsort3 {
|
|||||||
let f1 = lt;
|
let f1 = lt;
|
||||||
let f2 = equal;
|
let f2 = equal;
|
||||||
quick_sort3::<int>(f1, f2, v1);
|
quick_sort3::<int>(f1, f2, v1);
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < len {
|
while i < len {
|
||||||
log(debug, v2[i]);
|
log(debug, v2[i]);
|
||||||
assert (v2[i] == v1[i]);
|
assert (v2[i] == v1[i]);
|
||||||
@ -208,7 +208,7 @@ mod test_qsort {
|
|||||||
fn leual(&&a: int, &&b: int) -> bool { ret a <= b; }
|
fn leual(&&a: int, &&b: int) -> bool { ret a <= b; }
|
||||||
let f = leual;
|
let f = leual;
|
||||||
quick_sort::<int>(f, v1);
|
quick_sort::<int>(f, v1);
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < len {
|
while i < len {
|
||||||
log(debug, v2[i]);
|
log(debug, v2[i]);
|
||||||
assert (v2[i] == v1[i]);
|
assert (v2[i] == v1[i]);
|
||||||
@ -266,7 +266,7 @@ mod tests {
|
|||||||
fn le(&&a: int, &&b: int) -> bool { ret a <= b; }
|
fn le(&&a: int, &&b: int) -> bool { ret a <= b; }
|
||||||
let f = le;
|
let f = le;
|
||||||
let v3 = merge_sort::<int>(f, v1);
|
let v3 = merge_sort::<int>(f, v1);
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < len {
|
while i < len {
|
||||||
log(debug, v3[i]);
|
log(debug, v3[i]);
|
||||||
assert (v3[i] == v2[i]);
|
assert (v3[i] == v2[i]);
|
||||||
|
@ -491,7 +491,7 @@ mod tests {
|
|||||||
let tests =
|
let tests =
|
||||||
{
|
{
|
||||||
let testfn = fn~() { };
|
let testfn = fn~() { };
|
||||||
let tests = [];
|
let mut tests = [];
|
||||||
for name: str in names {
|
for name: str in names {
|
||||||
let test = {name: name, fn: testfn, ignore: false,
|
let test = {name: name, fn: testfn, ignore: false,
|
||||||
should_fail: false};
|
should_fail: false};
|
||||||
|
@ -422,7 +422,6 @@ fn build_session_options(match: getopts::match,
|
|||||||
let cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
|
let cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
|
||||||
let test = opt_present(match, "test");
|
let test = opt_present(match, "test");
|
||||||
let warn_unused_imports = opt_present(match, "warn-unused-imports");
|
let warn_unused_imports = opt_present(match, "warn-unused-imports");
|
||||||
let enforce_mut_vars = opt_present(match, "enforce-mut-vars");
|
|
||||||
let sopts: @session::options =
|
let sopts: @session::options =
|
||||||
@{crate_type: crate_type,
|
@{crate_type: crate_type,
|
||||||
static: static,
|
static: static,
|
||||||
@ -444,8 +443,7 @@ fn build_session_options(match: getopts::match,
|
|||||||
parse_only: parse_only,
|
parse_only: parse_only,
|
||||||
no_trans: no_trans,
|
no_trans: no_trans,
|
||||||
no_asm_comments: no_asm_comments,
|
no_asm_comments: no_asm_comments,
|
||||||
warn_unused_imports: warn_unused_imports,
|
warn_unused_imports: warn_unused_imports};
|
||||||
enforce_mut_vars: enforce_mut_vars};
|
|
||||||
ret sopts;
|
ret sopts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,8 +45,7 @@ type options =
|
|||||||
parse_only: bool,
|
parse_only: bool,
|
||||||
no_trans: bool,
|
no_trans: bool,
|
||||||
no_asm_comments: bool,
|
no_asm_comments: bool,
|
||||||
warn_unused_imports: bool,
|
warn_unused_imports: bool};
|
||||||
enforce_mut_vars: bool};
|
|
||||||
|
|
||||||
type crate_metadata = {name: str, data: [u8]};
|
type crate_metadata = {name: str, data: [u8]};
|
||||||
|
|
||||||
@ -154,7 +153,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn make_crate(with_bin: bool, with_lib: bool) -> @ast::crate {
|
fn make_crate(with_bin: bool, with_lib: bool) -> @ast::crate {
|
||||||
let attrs = [];
|
let mut attrs = [];
|
||||||
if with_bin { attrs += [make_crate_type_attr("bin")]; }
|
if with_bin { attrs += [make_crate_type_attr("bin")]; }
|
||||||
if with_lib { attrs += [make_crate_type_attr("lib")]; }
|
if with_lib { attrs += [make_crate_type_attr("lib")]; }
|
||||||
@ast_util::respan(ast_util::dummy_sp(), {
|
@ast_util::respan(ast_util::dummy_sp(), {
|
||||||
|
@ -305,7 +305,7 @@ fn is_illegal_to_modify_def(cx: @ctx, def: def, msg: msg) -> option<str> {
|
|||||||
// variables are assigned at most once. But this requires a new kind of
|
// variables are assigned at most once. But this requires a new kind of
|
||||||
// propagation (def. not assigned), so I didn't do that.
|
// propagation (def. not assigned), so I didn't do that.
|
||||||
def_local(_, false) if msg == msg_move_out { none }
|
def_local(_, false) if msg == msg_move_out { none }
|
||||||
def_local(_, false) if cx.tcx.sess.opts.enforce_mut_vars {
|
def_local(_, false) {
|
||||||
some("immutable local variable")
|
some("immutable local variable")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1134,6 +1134,13 @@ fn print_decl(s: ps, decl: @ast::decl) {
|
|||||||
space_if_not_bol(s);
|
space_if_not_bol(s);
|
||||||
ibox(s, indent_unit);
|
ibox(s, indent_unit);
|
||||||
word_nbsp(s, "let");
|
word_nbsp(s, "let");
|
||||||
|
|
||||||
|
// if any are mutable, all are mutable
|
||||||
|
if vec::any(locs) {|l| l.node.is_mutbl } {
|
||||||
|
assert vec::all(locs) {|l| l.node.is_mutbl };
|
||||||
|
word_nbsp(s, "mut");
|
||||||
|
}
|
||||||
|
|
||||||
fn print_local(s: ps, &&loc: @ast::local) {
|
fn print_local(s: ps, &&loc: @ast::local) {
|
||||||
ibox(s, indent_unit);
|
ibox(s, indent_unit);
|
||||||
print_local_decl(s, loc);
|
print_local_decl(s, loc);
|
||||||
|
@ -77,7 +77,7 @@ fn act(po: comm::port<msg>, source: str, parse: parser) {
|
|||||||
ignore_errors
|
ignore_errors
|
||||||
);
|
);
|
||||||
|
|
||||||
let keep_going = true;
|
let mut keep_going = true;
|
||||||
while keep_going {
|
while keep_going {
|
||||||
alt comm::recv(po) {
|
alt comm::recv(po) {
|
||||||
handle_request(f) {
|
handle_request(f) {
|
||||||
@ -147,8 +147,7 @@ fn build_session() -> (session::session, @mutable bool) {
|
|||||||
parse_only: false,
|
parse_only: false,
|
||||||
no_trans: false,
|
no_trans: false,
|
||||||
no_asm_comments: false,
|
no_asm_comments: false,
|
||||||
warn_unused_imports: false,
|
warn_unused_imports: false
|
||||||
enforce_mut_vars: false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let codemap = codemap::new_codemap();
|
let codemap = codemap::new_codemap();
|
||||||
|
@ -131,7 +131,7 @@ fn first_sentence(s: str) -> option<str> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn first_sentence_(s: str) -> str {
|
fn first_sentence_(s: str) -> str {
|
||||||
let dotcount = 0;
|
let mut dotcount = 0;
|
||||||
// The index of the character following a single dot. This allows
|
// The index of the character following a single dot. This allows
|
||||||
// Things like [0..1) to appear in the brief description
|
// Things like [0..1) to appear in the brief description
|
||||||
let idx = str::find(s) {|ch|
|
let idx = str::find(s) {|ch|
|
||||||
@ -163,10 +163,10 @@ fn first_sentence_(s: str) -> str {
|
|||||||
|
|
||||||
fn paragraphs(s: str) -> [str] {
|
fn paragraphs(s: str) -> [str] {
|
||||||
let lines = str::lines_any(s);
|
let lines = str::lines_any(s);
|
||||||
let whitespace_lines = 0;
|
let mut whitespace_lines = 0;
|
||||||
let accum = "";
|
let mut accum = "";
|
||||||
let paras = vec::foldl([], lines) {|paras, line|
|
let paras = vec::foldl([], lines) {|paras, line|
|
||||||
let res = paras;
|
let mut res = paras;
|
||||||
|
|
||||||
if str::is_whitespace(line) {
|
if str::is_whitespace(line) {
|
||||||
whitespace_lines += 1;
|
whitespace_lines += 1;
|
||||||
|
@ -127,7 +127,7 @@ fn readclose(fd: libc::c_int) -> str {
|
|||||||
// Copied from run::program_output
|
// Copied from run::program_output
|
||||||
let file = os::fdopen(fd);
|
let file = os::fdopen(fd);
|
||||||
let reader = io::FILE_reader(file, false);
|
let reader = io::FILE_reader(file, false);
|
||||||
let buf = "";
|
let mut buf = "";
|
||||||
while !reader.eof() {
|
while !reader.eof() {
|
||||||
let bytes = reader.read_bytes(4096u);
|
let bytes = reader.read_bytes(4096u);
|
||||||
buf += str::from_bytes(bytes);
|
buf += str::from_bytes(bytes);
|
||||||
@ -138,8 +138,8 @@ fn readclose(fd: libc::c_int) -> str {
|
|||||||
|
|
||||||
fn generic_writer(process: fn~(markdown: str)) -> writer {
|
fn generic_writer(process: fn~(markdown: str)) -> writer {
|
||||||
let ch = task::spawn_listener {|po: comm::port<writeinstr>|
|
let ch = task::spawn_listener {|po: comm::port<writeinstr>|
|
||||||
let markdown = "";
|
let mut markdown = "";
|
||||||
let keep_going = true;
|
let mut keep_going = true;
|
||||||
while keep_going {
|
while keep_going {
|
||||||
alt comm::recv(po) {
|
alt comm::recv(po) {
|
||||||
write(s) { markdown += s; }
|
write(s) { markdown += s; }
|
||||||
@ -281,7 +281,7 @@ fn future_writer() -> (writer, future::future<str>) {
|
|||||||
comm::send(chan, copy instr);
|
comm::send(chan, copy instr);
|
||||||
};
|
};
|
||||||
let future = future::from_fn {||
|
let future = future::from_fn {||
|
||||||
let res = "";
|
let mut res = "";
|
||||||
loop {
|
loop {
|
||||||
alt comm::recv(port) {
|
alt comm::recv(port) {
|
||||||
write(s) { res += s }
|
write(s) { res += s }
|
||||||
|
@ -46,7 +46,7 @@ fn to_assoc_list<K:copy, V:copy>(
|
|||||||
map: map::hashmap<K, V>
|
map: map::hashmap<K, V>
|
||||||
) -> [(K, V)] {
|
) -> [(K, V)] {
|
||||||
|
|
||||||
let vec = [];
|
let mut vec = [];
|
||||||
map.items {|k, v|
|
map.items {|k, v|
|
||||||
vec += [(k, v)];
|
vec += [(k, v)];
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ fn build_reexport_path_map(srv: astsrv::srv, -def_map: def_map) -> path_map {
|
|||||||
};
|
};
|
||||||
let modpath = ast_map::path_to_str(vec::init(*path));
|
let modpath = ast_map::path_to_str(vec::init(*path));
|
||||||
|
|
||||||
let reexportdocs = [];
|
let mut reexportdocs = [];
|
||||||
for def in defs {
|
for def in defs {
|
||||||
if !def.reexp { cont; }
|
if !def.reexp { cont; }
|
||||||
alt def_map.find(def.id) {
|
alt def_map.find(def.id) {
|
||||||
|
@ -30,7 +30,7 @@ fn run_passes(
|
|||||||
original through each pass"
|
original through each pass"
|
||||||
)];
|
)];
|
||||||
|
|
||||||
let passno = 0;
|
let mut passno = 0;
|
||||||
vec::foldl(doc, passes) {|doc, pass|
|
vec::foldl(doc, passes) {|doc, pass|
|
||||||
log(debug, #fmt("pass #%d", passno));
|
log(debug, #fmt("pass #%d", passno));
|
||||||
passno += 1;
|
passno += 1;
|
||||||
|
@ -90,9 +90,9 @@ fn sectionalize(desc: option<str>) -> (option<str>, [doc::section]) {
|
|||||||
|
|
||||||
let lines = str::lines(option::get(desc));
|
let lines = str::lines(option::get(desc));
|
||||||
|
|
||||||
let new_desc = none;
|
let mut new_desc = none;
|
||||||
let current_section = none;
|
let mut current_section = none;
|
||||||
let sections = [];
|
let mut sections = [];
|
||||||
|
|
||||||
for line in lines {
|
for line in lines {
|
||||||
alt parse_header(line) {
|
alt parse_header(line) {
|
||||||
|
@ -19,8 +19,8 @@ fn mk_pass() -> pass {
|
|||||||
|
|
||||||
fn unindent(s: str) -> str {
|
fn unindent(s: str) -> str {
|
||||||
let lines = str::lines_any(s);
|
let lines = str::lines_any(s);
|
||||||
let saw_first_line = false;
|
let mut saw_first_line = false;
|
||||||
let saw_second_line = false;
|
let mut saw_second_line = false;
|
||||||
let min_indent = vec::foldl(uint::max_value, lines) {|min_indent, line|
|
let min_indent = vec::foldl(uint::max_value, lines) {|min_indent, line|
|
||||||
|
|
||||||
// After we see the first non-whitespace line, look at
|
// After we see the first non-whitespace line, look at
|
||||||
@ -46,7 +46,7 @@ fn unindent(s: str) -> str {
|
|||||||
min_indent
|
min_indent
|
||||||
} else {
|
} else {
|
||||||
saw_first_line = true;
|
saw_first_line = true;
|
||||||
let spaces = 0u;
|
let mut spaces = 0u;
|
||||||
str::all(line) {|char|
|
str::all(line) {|char|
|
||||||
// Only comparing against space because I wouldn't
|
// Only comparing against space because I wouldn't
|
||||||
// know what to do with mixed whitespace chars
|
// know what to do with mixed whitespace chars
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
impl helpers for uint {
|
impl helpers for uint {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to(v: uint, f: fn(uint)) {
|
fn to(v: uint, f: fn(uint)) {
|
||||||
let i = self;
|
let mut i = self;
|
||||||
while i < v {
|
while i < v {
|
||||||
f(i);
|
f(i);
|
||||||
i += 1u;
|
i += 1u;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn iter<T>(v: [T], f: fn(T)) {
|
fn iter<T>(v: [T], f: fn(T)) {
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
let n = vec::len(v);
|
let n = vec::len(v);
|
||||||
while i < n {
|
while i < n {
|
||||||
f(v[i]);
|
f(v[i]);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// same as cci_iter_lib, more-or-less, but not marked inline
|
// same as cci_iter_lib, more-or-less, but not marked inline
|
||||||
fn iter(v: [uint], f: fn(uint)) {
|
fn iter(v: [uint], f: fn(uint)) {
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
let n = vec::len(v);
|
let n = vec::len(v);
|
||||||
while i < n {
|
while i < n {
|
||||||
f(v[i]);
|
f(v[i]);
|
||||||
|
@ -23,9 +23,9 @@ fn b8() -> str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn sub(t: str, n: int) -> str unsafe {
|
fn sub(t: str, n: int) -> str unsafe {
|
||||||
let b: str = "";
|
let mut b: str = "";
|
||||||
let i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
let ns: str;
|
let mut ns: str;
|
||||||
alt n {
|
alt n {
|
||||||
0 { ns = "no more bottles"; }
|
0 { ns = "no more bottles"; }
|
||||||
1 { ns = "1 bottle"; }
|
1 { ns = "1 bottle"; }
|
||||||
@ -42,7 +42,7 @@ fn sub(t: str, n: int) -> str unsafe {
|
|||||||
|
|
||||||
/* Using an interator */
|
/* Using an interator */
|
||||||
fn ninetynine(it: fn(int)) {
|
fn ninetynine(it: fn(int)) {
|
||||||
let n: int = 100;
|
let mut n: int = 100;
|
||||||
while n > 1 { n -= 1; it(n); }
|
while n > 1 { n -= 1; it(n); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ fn next(b: bottle) -> bottle {
|
|||||||
fn more(b: bottle) -> bool { alt b { none { ret false; } _ { ret true; } } }
|
fn more(b: bottle) -> bool { alt b { none { ret false; } _ { ret true; } } }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let b: bottle = multiple(99);
|
let mut b: bottle = multiple(99);
|
||||||
let running: bool = true;
|
let mut running: bool = true;
|
||||||
while running { show(b); #debug(""); running = more(b); b = next(b); }
|
while running { show(b); #debug(""); running = more(b); b = next(b); }
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ fn b8() -> str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn sub(t: str, n: int) -> str unsafe {
|
fn sub(t: str, n: int) -> str unsafe {
|
||||||
let b: str = "";
|
let mut b: str = "";
|
||||||
let i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
let ns: str;
|
let mut ns: str;
|
||||||
alt n {
|
alt n {
|
||||||
0 { ns = "no more bottles"; }
|
0 { ns = "no more bottles"; }
|
||||||
1 { ns = "1 bottle"; }
|
1 { ns = "1 bottle"; }
|
||||||
@ -42,7 +42,7 @@ fn sub(t: str, n: int) -> str unsafe {
|
|||||||
|
|
||||||
/* Straightforward counter */
|
/* Straightforward counter */
|
||||||
fn main() {
|
fn main() {
|
||||||
let n: int = 99;
|
let mut n: int = 99;
|
||||||
while n > 0 {
|
while n > 0 {
|
||||||
log(debug, sub(b1(), n));
|
log(debug, sub(b1(), n));
|
||||||
log(debug, sub(b2(), n - 1));
|
log(debug, sub(b2(), n - 1));
|
||||||
|
@ -15,8 +15,8 @@ enum request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn server(requests: comm::port<request>, responses: comm::chan<uint>) {
|
fn server(requests: comm::port<request>, responses: comm::chan<uint>) {
|
||||||
let count = 0u;
|
let mut count = 0u;
|
||||||
let done = false;
|
let mut done = false;
|
||||||
while !done {
|
while !done {
|
||||||
alt comm::recv(requests) {
|
alt comm::recv(requests) {
|
||||||
get_count { comm::send(responses, copy count); }
|
get_count { comm::send(responses, copy count); }
|
||||||
@ -37,7 +37,7 @@ fn run(args: [str]) {
|
|||||||
let workers = option::get(uint::from_str(args[2]));
|
let workers = option::get(uint::from_str(args[2]));
|
||||||
let start = std::time::precise_time_s();
|
let start = std::time::precise_time_s();
|
||||||
let to_child = to_child;
|
let to_child = to_child;
|
||||||
let worker_results = [];
|
let mut worker_results = [];
|
||||||
uint::range(0u, workers) {|_i|
|
uint::range(0u, workers) {|_i|
|
||||||
let builder = task::task_builder();
|
let builder = task::task_builder();
|
||||||
worker_results += [task::future_result(builder)];
|
worker_results += [task::future_result(builder)];
|
||||||
|
@ -25,7 +25,7 @@ fn main(args: [str]) {
|
|||||||
8
|
8
|
||||||
};
|
};
|
||||||
let min_depth = 4;
|
let min_depth = 4;
|
||||||
let max_depth;
|
let mut max_depth;
|
||||||
if min_depth + 2 > n {
|
if min_depth + 2 > n {
|
||||||
max_depth = min_depth + 2;
|
max_depth = min_depth + 2;
|
||||||
} else { max_depth = n; }
|
} else { max_depth = n; }
|
||||||
@ -35,13 +35,13 @@ fn main(args: [str]) {
|
|||||||
stretch_depth,
|
stretch_depth,
|
||||||
item_check(stretch_tree)));
|
item_check(stretch_tree)));
|
||||||
let long_lived_tree = bottom_up_tree(0, max_depth);
|
let long_lived_tree = bottom_up_tree(0, max_depth);
|
||||||
let depth = min_depth;
|
let mut depth = min_depth;
|
||||||
while depth <= max_depth {
|
while depth <= max_depth {
|
||||||
let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
|
let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
|
||||||
let chk = 0;
|
let mut chk = 0;
|
||||||
let i = 1;
|
let mut i = 1;
|
||||||
while i <= iterations {
|
while i <= iterations {
|
||||||
let temp_tree = bottom_up_tree(i, depth);
|
let mut temp_tree = bottom_up_tree(i, depth);
|
||||||
chk += item_check(temp_tree);
|
chk += item_check(temp_tree);
|
||||||
temp_tree = bottom_up_tree(-i, depth);
|
temp_tree = bottom_up_tree(-i, depth);
|
||||||
chk += item_check(temp_tree);
|
chk += item_check(temp_tree);
|
||||||
|
@ -9,13 +9,13 @@ fn fannkuch(n: int) -> int {
|
|||||||
let perm = vec::to_mut(vec::from_elem(n as uint, 0));
|
let perm = vec::to_mut(vec::from_elem(n as uint, 0));
|
||||||
let perm1 = vec::to_mut(vec::from_fn(n as uint, perm1init));
|
let perm1 = vec::to_mut(vec::from_fn(n as uint, perm1init));
|
||||||
let count = vec::to_mut(vec::from_elem(n as uint, 0));
|
let count = vec::to_mut(vec::from_elem(n as uint, 0));
|
||||||
let f = 0;
|
let mut f = 0;
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
let k = 0;
|
let mut k = 0;
|
||||||
let r = 0;
|
let mut r = 0;
|
||||||
let flips = 0;
|
let mut flips = 0;
|
||||||
let nperm = 0;
|
let mut nperm = 0;
|
||||||
let checksum = 0;
|
let mut checksum = 0;
|
||||||
r = n;
|
r = n;
|
||||||
while r > 0 {
|
while r > 0 {
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -40,7 +40,7 @@ fn fannkuch(n: int) -> int {
|
|||||||
if nperm & 0x1 == 0 { checksum += f; } else { checksum -= f; }
|
if nperm & 0x1 == 0 { checksum += f; } else { checksum -= f; }
|
||||||
// Use incremental change to generate another permutation
|
// Use incremental change to generate another permutation
|
||||||
|
|
||||||
let go = true;
|
let mut go = true;
|
||||||
while go {
|
while go {
|
||||||
if r == n {
|
if r == n {
|
||||||
io::println(#fmt("%d", checksum));
|
io::println(#fmt("%d", checksum));
|
||||||
|
@ -23,8 +23,8 @@ fn myrandom_next(r: myrandom, mx: u32) -> u32 {
|
|||||||
type aminoacids = {ch: char, prob: u32};
|
type aminoacids = {ch: char, prob: u32};
|
||||||
|
|
||||||
fn make_cumulative(aa: [aminoacids]) -> [aminoacids] {
|
fn make_cumulative(aa: [aminoacids]) -> [aminoacids] {
|
||||||
let cp: u32 = 0u32;
|
let mut cp: u32 = 0u32;
|
||||||
let ans: [aminoacids] = [];
|
let mut ans: [aminoacids] = [];
|
||||||
for a: aminoacids in aa { cp += a.prob; ans += [{ch: a.ch, prob: cp}]; }
|
for a: aminoacids in aa { cp += a.prob; ans += [{ch: a.ch, prob: cp}]; }
|
||||||
ret ans;
|
ret ans;
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ fn select_random(r: u32, genelist: [aminoacids]) -> char {
|
|||||||
fn make_random_fasta(id: str, desc: str, genelist: [aminoacids], n: int) {
|
fn make_random_fasta(id: str, desc: str, genelist: [aminoacids], n: int) {
|
||||||
log(debug, ">" + id + " " + desc);
|
log(debug, ">" + id + " " + desc);
|
||||||
let rng = @{mutable last: std::rand::rng().next()};
|
let rng = @{mutable last: std::rand::rng().next()};
|
||||||
let op: str = "";
|
let mut op: str = "";
|
||||||
uint::range(0u, n as uint) {|_i|
|
uint::range(0u, n as uint) {|_i|
|
||||||
str::push_char(op, select_random(myrandom_next(rng, 100u32),
|
str::push_char(op, select_random(myrandom_next(rng, 100u32),
|
||||||
genelist));
|
genelist));
|
||||||
@ -59,7 +59,7 @@ fn make_random_fasta(id: str, desc: str, genelist: [aminoacids], n: int) {
|
|||||||
|
|
||||||
fn make_repeat_fasta(id: str, desc: str, s: str, n: int) unsafe {
|
fn make_repeat_fasta(id: str, desc: str, s: str, n: int) unsafe {
|
||||||
log(debug, ">" + id + " " + desc);
|
log(debug, ">" + id + " " + desc);
|
||||||
let op: str = "";
|
let mut op: str = "";
|
||||||
let sl: uint = str::len(s);
|
let sl: uint = str::len(s);
|
||||||
uint::range(0u, n as uint) {|i|
|
uint::range(0u, n as uint) {|i|
|
||||||
str::unsafe::push_byte(op, s[i % sl]);
|
str::unsafe::push_byte(op, s[i % sl]);
|
||||||
|
@ -36,9 +36,9 @@ pure fn cabs(x: cmplx) -> f64
|
|||||||
|
|
||||||
fn mb(x: cmplx) -> bool
|
fn mb(x: cmplx) -> bool
|
||||||
{
|
{
|
||||||
let z = {re: 0., im: 0.};
|
let mut z = {re: 0., im: 0.};
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
let in = true;
|
let mut in = true;
|
||||||
while i < 50 {
|
while i < 50 {
|
||||||
z = z*z + x;
|
z = z*z + x;
|
||||||
if cabs(z) >= 4. {
|
if cabs(z) >= 4. {
|
||||||
@ -51,8 +51,8 @@ fn mb(x: cmplx) -> bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fillbyte(x: cmplx, incr: f64) -> u8 {
|
fn fillbyte(x: cmplx, incr: f64) -> u8 {
|
||||||
let rv = 0_u8;
|
let mut rv = 0_u8;
|
||||||
let i = 0_u8;
|
let mut i = 0_u8;
|
||||||
while i < 8_u8 {
|
while i < 8_u8 {
|
||||||
let z = {re: x.re + (i as f64)*incr, im: x.im};
|
let z = {re: x.re + (i as f64)*incr, im: x.im};
|
||||||
if mb(z) {
|
if mb(z) {
|
||||||
@ -65,7 +65,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
|
|||||||
|
|
||||||
fn chanmb(i: uint, size: uint, ch: comm::chan<line>) -> ()
|
fn chanmb(i: uint, size: uint, ch: comm::chan<line>) -> ()
|
||||||
{
|
{
|
||||||
let crv = [];
|
let mut crv = [];
|
||||||
let incr = 2./(size as f64);
|
let incr = 2./(size as f64);
|
||||||
let y = incr*(i as f64) - 1.;
|
let y = incr*(i as f64) - 1.;
|
||||||
let xincr = 8.*incr;
|
let xincr = 8.*incr;
|
||||||
@ -107,15 +107,15 @@ fn writer(path: str, writech: comm::chan<comm::chan<line>>, size: uint)
|
|||||||
cout.write_line("P4");
|
cout.write_line("P4");
|
||||||
cout.write_line(#fmt("%u %u", size, size));
|
cout.write_line(#fmt("%u %u", size, size));
|
||||||
let lines = std::map::uint_hash();
|
let lines = std::map::uint_hash();
|
||||||
let done = 0_u;
|
let mut done = 0_u;
|
||||||
let i = 0_u;
|
let mut i = 0_u;
|
||||||
while i < size {
|
while i < size {
|
||||||
let aline = comm::recv(p);
|
let aline = comm::recv(p);
|
||||||
if aline.i == done {
|
if aline.i == done {
|
||||||
#debug("W %u", aline.i);
|
#debug("W %u", aline.i);
|
||||||
cout.write(aline.b);
|
cout.write(aline.b);
|
||||||
done += 1_u;
|
done += 1_u;
|
||||||
let prev = done;
|
let mut prev = done;
|
||||||
while prev <= i {
|
while prev <= i {
|
||||||
if lines.contains_key(prev) {
|
if lines.contains_key(prev) {
|
||||||
#debug("WS %u", prev);
|
#debug("WS %u", prev);
|
||||||
|
@ -21,7 +21,7 @@ fn main(args: [str]) {
|
|||||||
};
|
};
|
||||||
let bodies: [Body::props] = NBodySystem::MakeNBodySystem();
|
let bodies: [Body::props] = NBodySystem::MakeNBodySystem();
|
||||||
io::println(#fmt("%f", NBodySystem::energy(bodies)));
|
io::println(#fmt("%f", NBodySystem::energy(bodies)));
|
||||||
let i: int = 0;
|
let mut i: int = 0;
|
||||||
while i < n { NBodySystem::advance(bodies, 0.01); i += 1; }
|
while i < n { NBodySystem::advance(bodies, 0.01); i += 1; }
|
||||||
io::println(#fmt("%f", NBodySystem::energy(bodies)));
|
io::println(#fmt("%f", NBodySystem::energy(bodies)));
|
||||||
}
|
}
|
||||||
@ -37,11 +37,11 @@ mod NBodySystem {
|
|||||||
[Body::sun(), Body::jupiter(), Body::saturn(), Body::uranus(),
|
[Body::sun(), Body::jupiter(), Body::saturn(), Body::uranus(),
|
||||||
Body::neptune()];
|
Body::neptune()];
|
||||||
|
|
||||||
let px: float = 0.0;
|
let mut px: float = 0.0;
|
||||||
let py: float = 0.0;
|
let mut py: float = 0.0;
|
||||||
let pz: float = 0.0;
|
let mut pz: float = 0.0;
|
||||||
|
|
||||||
let i: int = 0;
|
let mut i: int = 0;
|
||||||
while i < 5 {
|
while i < 5 {
|
||||||
px += bodies[i].vx * bodies[i].mass;
|
px += bodies[i].vx * bodies[i].mass;
|
||||||
py += bodies[i].vy * bodies[i].mass;
|
py += bodies[i].vy * bodies[i].mass;
|
||||||
@ -58,9 +58,9 @@ mod NBodySystem {
|
|||||||
|
|
||||||
fn advance(bodies: [Body::props], dt: float) {
|
fn advance(bodies: [Body::props], dt: float) {
|
||||||
|
|
||||||
let i: int = 0;
|
let mut i: int = 0;
|
||||||
while i < 5 {
|
while i < 5 {
|
||||||
let j: int = i + 1;
|
let mut j: int = i + 1;
|
||||||
while j < 5 { advance_one(bodies[i], bodies[j], dt); j += 1; }
|
while j < 5 { advance_one(bodies[i], bodies[j], dt); j += 1; }
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
@ -96,20 +96,20 @@ mod NBodySystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn energy(bodies: [Body::props]) -> float unsafe {
|
fn energy(bodies: [Body::props]) -> float unsafe {
|
||||||
let dx: float;
|
let mut dx: float;
|
||||||
let dy: float;
|
let mut dy: float;
|
||||||
let dz: float;
|
let mut dz: float;
|
||||||
let distance: float;
|
let mut distance: float;
|
||||||
let e: float = 0.0;
|
let mut e: float = 0.0;
|
||||||
|
|
||||||
let i: int = 0;
|
let mut i: int = 0;
|
||||||
while i < 5 {
|
while i < 5 {
|
||||||
e +=
|
e +=
|
||||||
0.5 * bodies[i].mass *
|
0.5 * bodies[i].mass *
|
||||||
(bodies[i].vx * bodies[i].vx + bodies[i].vy * bodies[i].vy
|
(bodies[i].vx * bodies[i].vx + bodies[i].vy * bodies[i].vy
|
||||||
+ bodies[i].vz * bodies[i].vz);
|
+ bodies[i].vz * bodies[i].vz);
|
||||||
|
|
||||||
let j: int = i + 1;
|
let mut j: int = i + 1;
|
||||||
while j < 5 {
|
while j < 5 {
|
||||||
dx = bodies[i].x - bodies[j].x;
|
dx = bodies[i].x - bodies[j].x;
|
||||||
dy = bodies[i].y - bodies[j].y;
|
dy = bodies[i].y - bodies[j].y;
|
||||||
|
@ -59,7 +59,7 @@ fn parse_opts(argv: [str]) -> config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn stress_task(&&id: int) {
|
fn stress_task(&&id: int) {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
loop {
|
loop {
|
||||||
let n = 15;
|
let n = 15;
|
||||||
assert (fib(n) == fib(n));
|
assert (fib(n) == fib(n));
|
||||||
@ -69,7 +69,7 @@ fn stress_task(&&id: int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn stress(num_tasks: int) {
|
fn stress(num_tasks: int) {
|
||||||
let results = [];
|
let mut results = [];
|
||||||
range(0, num_tasks) {|i|
|
range(0, num_tasks) {|i|
|
||||||
let builder = task::task_builder();
|
let builder = task::task_builder();
|
||||||
results += [task::future_result(builder)];
|
results += [task::future_result(builder)];
|
||||||
|
@ -8,10 +8,10 @@ fn eval_A(i: uint, j: uint) -> float {
|
|||||||
|
|
||||||
fn eval_A_times_u(u: [const float], Au: [mutable float]) {
|
fn eval_A_times_u(u: [const float], Au: [mutable float]) {
|
||||||
let N = vec::len(u);
|
let N = vec::len(u);
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < N {
|
while i < N {
|
||||||
Au[i] = 0.0;
|
Au[i] = 0.0;
|
||||||
let j = 0u;
|
let mut j = 0u;
|
||||||
while j < N {
|
while j < N {
|
||||||
Au[i] += eval_A(i, j) * u[j];
|
Au[i] += eval_A(i, j) * u[j];
|
||||||
j += 1u;
|
j += 1u;
|
||||||
@ -22,10 +22,10 @@ fn eval_A_times_u(u: [const float], Au: [mutable float]) {
|
|||||||
|
|
||||||
fn eval_At_times_u(u: [const float], Au: [mutable float]) {
|
fn eval_At_times_u(u: [const float], Au: [mutable float]) {
|
||||||
let N = vec::len(u);
|
let N = vec::len(u);
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < N {
|
while i < N {
|
||||||
Au[i] = 0.0;
|
Au[i] = 0.0;
|
||||||
let j = 0u;
|
let mut j = 0u;
|
||||||
while j < N {
|
while j < N {
|
||||||
Au[i] += eval_A(j, i) * u[j];
|
Au[i] += eval_A(j, i) * u[j];
|
||||||
j += 1u;
|
j += 1u;
|
||||||
@ -50,16 +50,16 @@ fn main(args: [str]) {
|
|||||||
|
|
||||||
let u = vec::to_mut(vec::from_elem(N, 1.0));
|
let u = vec::to_mut(vec::from_elem(N, 1.0));
|
||||||
let v = vec::to_mut(vec::from_elem(N, 0.0));
|
let v = vec::to_mut(vec::from_elem(N, 0.0));
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < 10u {
|
while i < 10u {
|
||||||
eval_AtA_times_u(u, v);
|
eval_AtA_times_u(u, v);
|
||||||
eval_AtA_times_u(v, u);
|
eval_AtA_times_u(v, u);
|
||||||
i += 1u;
|
i += 1u;
|
||||||
}
|
}
|
||||||
|
|
||||||
let vBv = 0.0;
|
let mut vBv = 0.0;
|
||||||
let vv = 0.0;
|
let mut vv = 0.0;
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < N {
|
while i < N {
|
||||||
vBv += u[i] * v[i];
|
vBv += u[i] * v[i];
|
||||||
vv += v[i] * v[i];
|
vv += v[i] * v[i];
|
||||||
|
@ -59,7 +59,7 @@ fn solve_grid(g: grid_t) {
|
|||||||
drop_colors(g, avail, row, col);
|
drop_colors(g, avail, row, col);
|
||||||
|
|
||||||
// find first remaining color that is available
|
// find first remaining color that is available
|
||||||
let i = 1 as uint;
|
let mut i = 1 as uint;
|
||||||
while i < (10 as uint) { /* FIXME llvm ctlhd */
|
while i < (10 as uint) { /* FIXME llvm ctlhd */
|
||||||
if bitv::get(avail, i) {
|
if bitv::get(avail, i) {
|
||||||
g[row][col] = i as u8;
|
g[row][col] = i as u8;
|
||||||
@ -94,7 +94,7 @@ fn solve_grid(g: grid_t) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let work: [(u8, u8)] = []; /* queue of uncolored fields */
|
let mut work: [(u8, u8)] = []; /* queue of uncolored fields */
|
||||||
u8::range(0u8, 9u8) { |row|
|
u8::range(0u8, 9u8) { |row|
|
||||||
u8::range(0u8, 9u8) { |col|
|
u8::range(0u8, 9u8) { |col|
|
||||||
let color = (*g)[row][col];
|
let color = (*g)[row][col];
|
||||||
@ -102,7 +102,7 @@ fn solve_grid(g: grid_t) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ptr = 0u;
|
let mut ptr = 0u;
|
||||||
let end = vec::len(work);
|
let end = vec::len(work);
|
||||||
while (ptr < end) {
|
while (ptr < end) {
|
||||||
let (row, col) = work[ptr];
|
let (row, col) = work[ptr];
|
||||||
|
@ -9,8 +9,8 @@ enum msg {
|
|||||||
fn calc(children: uint, parent_ch: comm::chan<msg>) {
|
fn calc(children: uint, parent_ch: comm::chan<msg>) {
|
||||||
let port = comm::port();
|
let port = comm::port();
|
||||||
let chan = comm::chan(port);
|
let chan = comm::chan(port);
|
||||||
let child_chs = [];
|
let mut child_chs = [];
|
||||||
let sum = 0;
|
let mut sum = 0;
|
||||||
|
|
||||||
iter::repeat (children) {||
|
iter::repeat (children) {||
|
||||||
task::spawn {||
|
task::spawn {||
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
fn f(&&n: uint) {
|
fn f(&&n: uint) {
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < n {
|
while i < n {
|
||||||
task::try {|| g() };
|
task::try {|| g() };
|
||||||
i += 1u;
|
i += 1u;
|
||||||
@ -13,6 +13,6 @@ fn main(args: [str]) {
|
|||||||
if vec::len(args) < 2u {
|
if vec::len(args) < 2u {
|
||||||
10u
|
10u
|
||||||
} else { option::get(uint::parse_buf(str::bytes(args[1]), 10u)) };
|
} else { option::get(uint::parse_buf(str::bytes(args[1]), 10u)) };
|
||||||
let i = 0u;
|
let mut i = 0u;
|
||||||
while i < n { task::spawn {|| f(n); }; i += 1u; }
|
while i < n { task::spawn {|| f(n); }; i += 1u; }
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
fn f(&&n: uint) {
|
fn f(&&n: uint) {
|
||||||
uint::range(0u, n) {|i|
|
uint::range(0u, n) {|i|
|
||||||
let v: [u8] = [];
|
let mut v: [u8] = [];
|
||||||
vec::reserve(v, 1000u);
|
vec::reserve(v, 1000u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ fn map(input: str, emit: map_reduce::putter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn reduce(_word: str, get: map_reduce::getter) {
|
fn reduce(_word: str, get: map_reduce::getter) {
|
||||||
let count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
loop { alt get() { some(_) { count += 1; } none { break; } } }
|
loop { alt get() { some(_) { count += 1; } none { break; } } }
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ mod map_reduce {
|
|||||||
|
|
||||||
fn start_mappers(ctrl: chan<ctrl_proto>, -inputs: [str]) ->
|
fn start_mappers(ctrl: chan<ctrl_proto>, -inputs: [str]) ->
|
||||||
[future::future<task::task_result>] {
|
[future::future<task::task_result>] {
|
||||||
let results = [];
|
let mut results = [];
|
||||||
for i: str in inputs {
|
for i: str in inputs {
|
||||||
let builder = task::task_builder();
|
let builder = task::task_builder();
|
||||||
results += [task::future_result(builder)];
|
results += [task::future_result(builder)];
|
||||||
@ -75,7 +75,7 @@ mod map_reduce {
|
|||||||
|
|
||||||
fn emit(im: map::hashmap<str, chan<reduce_proto>>,
|
fn emit(im: map::hashmap<str, chan<reduce_proto>>,
|
||||||
ctrl: chan<ctrl_proto>, key: str, val: int) {
|
ctrl: chan<ctrl_proto>, key: str, val: int) {
|
||||||
let c;
|
let mut c;
|
||||||
alt im.find(key) {
|
alt im.find(key) {
|
||||||
some(_c) {
|
some(_c) {
|
||||||
c = _c;
|
c = _c;
|
||||||
@ -134,12 +134,12 @@ mod map_reduce {
|
|||||||
// This task becomes the master control task. It task::_spawns
|
// This task becomes the master control task. It task::_spawns
|
||||||
// to do the rest.
|
// to do the rest.
|
||||||
|
|
||||||
let reducers: map::hashmap<str, chan<reduce_proto>>;
|
let mut reducers: map::hashmap<str, chan<reduce_proto>>;
|
||||||
|
|
||||||
reducers = map::str_hash();
|
reducers = map::str_hash();
|
||||||
|
|
||||||
let num_mappers = vec::len(inputs) as int;
|
let mut num_mappers = vec::len(inputs) as int;
|
||||||
let results = start_mappers(chan(ctrl), inputs);
|
let mut results = start_mappers(chan(ctrl), inputs);
|
||||||
|
|
||||||
while num_mappers > 0 {
|
while num_mappers > 0 {
|
||||||
alt recv(ctrl) {
|
alt recv(ctrl) {
|
||||||
@ -148,7 +148,7 @@ mod map_reduce {
|
|||||||
num_mappers -= 1;
|
num_mappers -= 1;
|
||||||
}
|
}
|
||||||
find_reducer(k, cc) {
|
find_reducer(k, cc) {
|
||||||
let c;
|
let mut c;
|
||||||
// log(error, "finding reducer for " + k);
|
// log(error, "finding reducer for " + k);
|
||||||
alt reducers.find(k) {
|
alt reducers.find(k) {
|
||||||
some(_c) {
|
some(_c) {
|
||||||
@ -191,7 +191,7 @@ fn main(argv: [str]) {
|
|||||||
map_reduce::map_reduce(inputs);
|
map_reduce::map_reduce(inputs);
|
||||||
let stop = time::precise_time_ns();
|
let stop = time::precise_time_ns();
|
||||||
|
|
||||||
let elapsed = stop - start;
|
let mut elapsed = stop - start;
|
||||||
elapsed /= 1000000u64;
|
elapsed /= 1000000u64;
|
||||||
|
|
||||||
log(error, "MapReduce completed in "
|
log(error, "MapReduce completed in "
|
||||||
@ -199,7 +199,7 @@ fn main(argv: [str]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_word(r: io::reader) -> option<str> {
|
fn read_word(r: io::reader) -> option<str> {
|
||||||
let w = "";
|
let mut w = "";
|
||||||
|
|
||||||
while !r.eof() {
|
while !r.eof() {
|
||||||
let c = r.read_char();
|
let c = r.read_char();
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
// error-pattern:wooooo
|
// error-pattern:wooooo
|
||||||
fn main() { let a = 1; if 1 == 1 { a = 2; } fail "woooo" + "o"; }
|
fn main() {
|
||||||
|
let mut a = 1; if 1 == 1 { a = 2; } fail "woooo" + "o";
|
||||||
|
}
|
||||||
|
@ -16,7 +16,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let map = map::hashmap(hash, eq);
|
let map = map::hashmap(hash, eq);
|
||||||
let arr = [];
|
let mut arr = [];
|
||||||
uint::range(0u, 10u) {|i|
|
uint::range(0u, 10u) {|i|
|
||||||
arr += [@"key stuff"];
|
arr += [@"key stuff"];
|
||||||
map.insert(arr, arr + [@"value stuff"]);
|
map.insert(arr, arr + [@"value stuff"]);
|
||||||
|
@ -3,8 +3,8 @@ use std;
|
|||||||
import option;
|
import option;
|
||||||
|
|
||||||
fn foo<T>(y: option<T>) {
|
fn foo<T>(y: option<T>) {
|
||||||
let x: int;
|
let mut x: int;
|
||||||
let rs: [int] = [];
|
let mut rs: [int] = [];
|
||||||
/* tests that x doesn't get put in the precondition for the
|
/* tests that x doesn't get put in the precondition for the
|
||||||
entire if expression */
|
entire if expression */
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ enum thing { a, b, c, }
|
|||||||
fn foo(it: fn(int)) { it(10); }
|
fn foo(it: fn(int)) { it(10); }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = true;
|
let mut x = true;
|
||||||
alt a {
|
alt a {
|
||||||
a { x = true; foo {|_i|} }
|
a { x = true; foo {|_i|} }
|
||||||
b { x = false; }
|
b { x = false; }
|
||||||
|
@ -9,7 +9,7 @@ enum color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn process(c: color) -> int {
|
fn process(c: color) -> int {
|
||||||
let x: int;
|
let mut x: int;
|
||||||
alt c {
|
alt c {
|
||||||
rgb(r, _, _) { #debug("rgb"); log(debug, r); x = r; }
|
rgb(r, _, _) { #debug("rgb"); log(debug, r); x = r; }
|
||||||
rgba(_, _, _, a) { #debug("rgba"); log(debug, a); x = a; }
|
rgba(_, _, _, a) { #debug("rgba"); log(debug, a); x = a; }
|
||||||
|
@ -9,7 +9,7 @@ fn f1(a: {mutable x: int}, &b: int, -c: int) -> int {
|
|||||||
fn f2(a: int, f: fn(int)) -> int { f(1); ret a; }
|
fn f2(a: int, f: fn(int)) -> int { f(1); ret a; }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = {mutable x: 1}, b = 2, c = 3;
|
let mut a = {mutable x: 1}, b = 2, c = 3;
|
||||||
assert (f1(a, b, c) == 6);
|
assert (f1(a, b, c) == 6);
|
||||||
assert (a.x == 0);
|
assert (a.x == 0);
|
||||||
assert (b == 10);
|
assert (b == 10);
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
// Issue 483 - Assignment expressions result in nil
|
// Issue 483 - Assignment expressions result in nil
|
||||||
fn test_assign() {
|
fn test_assign() {
|
||||||
let x: int;
|
let mut x: int;
|
||||||
let y: () = x = 10;
|
let mut y: () = x = 10;
|
||||||
assert (x == 10);
|
assert (x == 10);
|
||||||
let z = x = 11;
|
let mut z = x = 11;
|
||||||
assert (x == 11);
|
assert (x == 11);
|
||||||
z = x = 12;
|
z = x = 12;
|
||||||
assert (x == 12);
|
assert (x == 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_assign_op() {
|
fn test_assign_op() {
|
||||||
let x: int = 0;
|
let mut x: int = 0;
|
||||||
let y: () = x += 10;
|
let mut y: () = x += 10;
|
||||||
assert (x == 10);
|
assert (x == 10);
|
||||||
let z = x += 11;
|
let mut z = x += 11;
|
||||||
assert (x == 21);
|
assert (x == 21);
|
||||||
z = x += 12;
|
z = x += 12;
|
||||||
assert (x == 33);
|
assert (x == 33);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let sum = 0;
|
let mut sum = 0;
|
||||||
for x in [1, 2, 3, 4, 5] { sum += x; }
|
for x in [1, 2, 3, 4, 5] { sum += x; }
|
||||||
assert (sum == 15);
|
assert (sum == 15);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ fn main() {
|
|||||||
let ch = chan(p);
|
let ch = chan(p);
|
||||||
task::spawn {|| a(ch); };
|
task::spawn {|| a(ch); };
|
||||||
task::spawn {|| a(ch); };
|
task::spawn {|| a(ch); };
|
||||||
let n: int = 0;
|
let mut n: int = 0;
|
||||||
n = recv(p);
|
n = recv(p);
|
||||||
n = recv(p);
|
n = recv(p);
|
||||||
// #debug("Finished.");
|
// #debug("Finished.");
|
||||||
|
@ -15,7 +15,7 @@ fn main() {
|
|||||||
let ch = chan(p);
|
let ch = chan(p);
|
||||||
task::spawn {|| a(ch); };
|
task::spawn {|| a(ch); };
|
||||||
task::spawn {|| b(ch); };
|
task::spawn {|| b(ch); };
|
||||||
let n: int = 0;
|
let mut n: int = 0;
|
||||||
n = recv(p);
|
n = recv(p);
|
||||||
n = recv(p);
|
n = recv(p);
|
||||||
#debug("Finished.");
|
#debug("Finished.");
|
||||||
|
@ -28,13 +28,13 @@ fn g(x: int, y: str) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let n: int = 2 + 3 * 7;
|
let mut n: int = 2 + 3 * 7;
|
||||||
let s: str = "hello there";
|
let s: str = "hello there";
|
||||||
let p = comm::port();
|
let p = comm::port();
|
||||||
let ch = comm::chan(p);
|
let ch = comm::chan(p);
|
||||||
task::spawn {|| a(ch); };
|
task::spawn {|| a(ch); };
|
||||||
task::spawn {|| b(ch); };
|
task::spawn {|| b(ch); };
|
||||||
let x: int = 10;
|
let mut x: int = 10;
|
||||||
x = g(n, s);
|
x = g(n, s);
|
||||||
log(debug, x);
|
log(debug, x);
|
||||||
n = recv(p);
|
n = recv(p);
|
||||||
|
@ -11,8 +11,8 @@ fn target() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn general() {
|
fn general() {
|
||||||
let a: int = 1;
|
let mut a: int = 1;
|
||||||
let b: int = 2;
|
let mut b: int = 2;
|
||||||
a ^= b;
|
a ^= b;
|
||||||
b ^= a;
|
b ^= a;
|
||||||
a = a ^ b;
|
a = a ^ b;
|
||||||
|
@ -8,7 +8,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Usable at all:
|
// Usable at all:
|
||||||
let any_negative = vec::any(v) { |e| float::is_negative(e) };
|
let mut any_negative = vec::any(v) { |e| float::is_negative(e) };
|
||||||
assert any_negative;
|
assert any_negative;
|
||||||
|
|
||||||
// Higher precedence than assignments:
|
// Higher precedence than assignments:
|
||||||
|
@ -2,7 +2,7 @@ fn iter_vec<T>(v: [T], f: fn(T)) { for x: T in v { f(x); } }
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let v = [1, 2, 3, 4, 5, 6, 7];
|
let v = [1, 2, 3, 4, 5, 6, 7];
|
||||||
let odds = 0;
|
let mut odds = 0;
|
||||||
iter_vec(v, {|i|
|
iter_vec(v, {|i|
|
||||||
log(error, i);
|
log(error, i);
|
||||||
if i % 2 == 1 {
|
if i % 2 == 1 {
|
||||||
|
@ -2,7 +2,7 @@ fn iter_vec<T>(v: [T], f: fn(T)) { for x: T in v { f(x); } }
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let v = [1, 2, 3, 4, 5];
|
let v = [1, 2, 3, 4, 5];
|
||||||
let sum = 0;
|
let mut sum = 0;
|
||||||
iter_vec(v, {|i|
|
iter_vec(v, {|i|
|
||||||
iter_vec(v, {|j|
|
iter_vec(v, {|j|
|
||||||
log(error, i * j);
|
log(error, i * j);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
while i < 20 { i += 1; if i == 10 { break; } }
|
while i < 20 { i += 1; if i == 10 { break; } }
|
||||||
assert (i == 10);
|
assert (i == 10);
|
||||||
do { i += 1; if i == 20 { break; } } while i < 30
|
do { i += 1; if i == 20 { break; } } while i < 30
|
||||||
|
@ -15,7 +15,7 @@ type ctx = chan<request>;
|
|||||||
fn request_task(c: chan<ctx>) {
|
fn request_task(c: chan<ctx>) {
|
||||||
let p = port();
|
let p = port();
|
||||||
send(c, chan(p));
|
send(c, chan(p));
|
||||||
let req: request;
|
let mut req: request;
|
||||||
req = recv(p);
|
req = recv(p);
|
||||||
// Need to drop req before receiving it again
|
// Need to drop req before receiving it again
|
||||||
req = recv(p);
|
req = recv(p);
|
||||||
@ -25,7 +25,7 @@ fn new_cx() -> ctx {
|
|||||||
let p = port();
|
let p = port();
|
||||||
let ch = chan(p);
|
let ch = chan(p);
|
||||||
let t = task::spawn {|| request_task(ch); };
|
let t = task::spawn {|| request_task(ch); };
|
||||||
let cx: ctx;
|
let mut cx: ctx;
|
||||||
cx = recv(p);
|
cx = recv(p);
|
||||||
ret cx;
|
ret cx;
|
||||||
}
|
}
|
||||||
|
@ -9,17 +9,17 @@ fn nothing() { }
|
|||||||
fn putstr(s: str) { }
|
fn putstr(s: str) { }
|
||||||
|
|
||||||
fn putint(i: int) {
|
fn putint(i: int) {
|
||||||
let i: int = 33;
|
let mut i: int = 33;
|
||||||
while i < 36 { putstr("hi"); i = i + 1; }
|
while i < 36 { putstr("hi"); i = i + 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn zerg(i: int) -> int { ret i; }
|
fn zerg(i: int) -> int { ret i; }
|
||||||
|
|
||||||
fn foo(x: int) -> int {
|
fn foo(x: int) -> int {
|
||||||
let y: t = x + 2;
|
let mut y: t = x + 2;
|
||||||
putstr("hello");
|
putstr("hello");
|
||||||
while y < 10 { putint(y); if y * 3 == 4 { y = y + 2; nothing(); } }
|
while y < 10 { putint(y); if y * 3 == 4 { y = y + 2; nothing(); } }
|
||||||
let z: t;
|
let mut z: t;
|
||||||
z = 0x55;
|
z = 0x55;
|
||||||
foo(z);
|
foo(z);
|
||||||
ret 0;
|
ret 0;
|
||||||
|
@ -3,7 +3,7 @@ fn main() unsafe {
|
|||||||
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
|
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
|
||||||
let a: uint = 1u;
|
let a: uint = 1u;
|
||||||
let b: uint = 4u;
|
let b: uint = 4u;
|
||||||
let c: uint = 17u;
|
let mut c: uint = 17u;
|
||||||
check (uint::le(a, b));
|
check (uint::le(a, b));
|
||||||
c <- a;
|
c <- a;
|
||||||
log(debug, foo(c, b));
|
log(debug, foo(c, b));
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
fn main() unsafe {
|
fn main() unsafe {
|
||||||
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
|
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
|
||||||
let a: uint = 4u;
|
let mut a: uint = 4u;
|
||||||
let b: uint = 1u;
|
let mut b: uint = 1u;
|
||||||
check (uint::le(b, a));
|
check (uint::le(b, a));
|
||||||
b <-> a;
|
b <-> a;
|
||||||
log(debug, foo(a, b));
|
log(debug, foo(a, b));
|
||||||
|
@ -5,14 +5,14 @@
|
|||||||
|
|
||||||
// Tests for using alt as an expression
|
// Tests for using alt as an expression
|
||||||
fn test_basic() {
|
fn test_basic() {
|
||||||
let rs: bool = alt true { true { true } false { false } };
|
let mut rs: bool = alt true { true { true } false { false } };
|
||||||
assert (rs);
|
assert (rs);
|
||||||
rs = alt false { true { false } false { true } };
|
rs = alt false { true { false } false { true } };
|
||||||
assert (rs);
|
assert (rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_inferrence() {
|
fn test_inferrence() {
|
||||||
let rs = alt true { true { true } false { false } };
|
let mut rs = alt true { true { true } false { false } };
|
||||||
assert (rs);
|
assert (rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ fn test_basic() { let rs: bool = { true }; assert (rs); }
|
|||||||
fn test_rec() { let rs = { {v1: 10, v2: 20} }; assert (rs.v2 == 20); }
|
fn test_rec() { let rs = { {v1: 10, v2: 20} }; assert (rs.v2 == 20); }
|
||||||
|
|
||||||
fn test_filled_with_stuff() {
|
fn test_filled_with_stuff() {
|
||||||
let rs = { let a = 0; while a < 10 { a += 1; } a };
|
let rs = { let mut a = 0; while a < 10 { a += 1; } a };
|
||||||
assert (rs == 10);
|
assert (rs == 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ fn g(f: native fn(int, &bool), &called: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let called = false;
|
let mut called = false;
|
||||||
let h = f;
|
let h = f;
|
||||||
g(h, called);
|
g(h, called);
|
||||||
assert called == true;
|
assert called == true;
|
||||||
|
@ -6,7 +6,7 @@ fn two(it: fn(int)) { it(0); it(1); }
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a: [mutable int] = [mutable -1, -1, -1, -1];
|
let a: [mutable int] = [mutable -1, -1, -1, -1];
|
||||||
let p: int = 0;
|
let mut p: int = 0;
|
||||||
two {|i|
|
two {|i|
|
||||||
two {|j| a[p] = 10 * i + j; p += 1; };
|
two {|j| a[p] = 10 * i + j; p += 1; };
|
||||||
};
|
};
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
|
|
||||||
|
|
||||||
fn pairs(it: fn((int, int))) {
|
fn pairs(it: fn((int, int))) {
|
||||||
let i: int = 0;
|
let mut i: int = 0;
|
||||||
let j: int = 0;
|
let mut j: int = 0;
|
||||||
while i < 10 { it((i, j)); i += 1; j += i; }
|
while i < 10 { it((i, j)); i += 1; j += i; }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let i: int = 10;
|
let mut i: int = 10;
|
||||||
let j: int = 0;
|
let mut j: int = 0;
|
||||||
pairs() {|p|
|
pairs() {|p|
|
||||||
let (_0, _1) = p;
|
let (_0, _1) = p;
|
||||||
log(debug, _0);
|
log(debug, _0);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
fn main() {
|
fn main() {
|
||||||
let sum: int = 0;
|
let mut sum: int = 0;
|
||||||
first_ten {|i| #debug("main"); log(debug, i); sum = sum + i; };
|
first_ten {|i| #debug("main"); log(debug, i); sum = sum + i; };
|
||||||
#debug("sum");
|
#debug("sum");
|
||||||
log(debug, sum);
|
log(debug, sum);
|
||||||
@ -11,6 +11,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn first_ten(it: fn(int)) {
|
fn first_ten(it: fn(int)) {
|
||||||
let i: int = 0;
|
let mut i: int = 0;
|
||||||
while i < 10 { #debug("first_ten"); it(i); i = i + 1; }
|
while i < 10 { #debug("first_ten"); it(i); i = i + 1; }
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@ fn id<T: copy>(x: T) -> T { ret x; }
|
|||||||
type triple = {x: int, y: int, z: int};
|
type triple = {x: int, y: int, z: int};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 62;
|
let mut x = 62;
|
||||||
let y = 63;
|
let mut y = 63;
|
||||||
let a = 'a';
|
let a = 'a';
|
||||||
let b = 'b';
|
let mut b = 'b';
|
||||||
let p: triple = {x: 65, y: 66, z: 67};
|
let p: triple = {x: 65, y: 66, z: 67};
|
||||||
let q: triple = {x: 68, y: 69, z: 70};
|
let mut q: triple = {x: 68, y: 69, z: 70};
|
||||||
y = id::<int>(x);
|
y = id::<int>(x);
|
||||||
log(debug, y);
|
log(debug, y);
|
||||||
assert (x == y);
|
assert (x == y);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
enum foo<T> { arm(T), }
|
enum foo<T> { arm(T), }
|
||||||
|
|
||||||
fn altfoo<T>(f: foo<T>) {
|
fn altfoo<T>(f: foo<T>) {
|
||||||
let hit = false;
|
let mut hit = false;
|
||||||
alt f { arm::<T>(x) { #debug("in arm"); hit = true; } }
|
alt f { arm::<T>(x) { #debug("in arm"); hit = true; } }
|
||||||
assert (hit);
|
assert (hit);
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
enum option<T> { some(@T), none, }
|
enum option<T> { some(@T), none, }
|
||||||
|
|
||||||
fn main() { let a: option<int> = some::<int>(@10); a = none::<int>; }
|
fn main() { let mut a: option<int> = some::<int>(@10); a = none::<int>; }
|
||||||
|
@ -44,7 +44,7 @@ mod map_reduce {
|
|||||||
|
|
||||||
fn emit(im: map::hashmap<str, int>, ctrl: chan<ctrl_proto>, key: str,
|
fn emit(im: map::hashmap<str, int>, ctrl: chan<ctrl_proto>, key: str,
|
||||||
val: str) {
|
val: str) {
|
||||||
let c;
|
let mut c;
|
||||||
alt im.find(key) {
|
alt im.find(key) {
|
||||||
some(_c) { c = _c }
|
some(_c) { c = _c }
|
||||||
none {
|
none {
|
||||||
@ -69,19 +69,19 @@ mod map_reduce {
|
|||||||
// This task becomes the master control task. It spawns others
|
// This task becomes the master control task. It spawns others
|
||||||
// to do the rest.
|
// to do the rest.
|
||||||
|
|
||||||
let reducers: map::hashmap<str, int>;
|
let mut reducers: map::hashmap<str, int>;
|
||||||
|
|
||||||
reducers = map::str_hash();
|
reducers = map::str_hash();
|
||||||
|
|
||||||
start_mappers(chan(ctrl), inputs);
|
start_mappers(chan(ctrl), inputs);
|
||||||
|
|
||||||
let num_mappers = vec::len(inputs) as int;
|
let mut num_mappers = vec::len(inputs) as int;
|
||||||
|
|
||||||
while num_mappers > 0 {
|
while num_mappers > 0 {
|
||||||
alt recv(ctrl) {
|
alt recv(ctrl) {
|
||||||
mapper_done { num_mappers -= 1; }
|
mapper_done { num_mappers -= 1; }
|
||||||
find_reducer(k, cc) {
|
find_reducer(k, cc) {
|
||||||
let c;
|
let mut c;
|
||||||
alt reducers.find(str::from_bytes(k)) {
|
alt reducers.find(str::from_bytes(k)) {
|
||||||
some(_c) { c = _c; }
|
some(_c) { c = _c; }
|
||||||
none { c = 0; }
|
none { c = 0; }
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
|
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
fn main() { let x: i32 = -400_i32; x = 0_i32 - x; assert (x == 400_i32); }
|
fn main() { let mut x: i32 = -400_i32; x = 0_i32 - x; assert (x == 400_i32); }
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: i8 = -12i8;
|
let mut x: i8 = -12i8;
|
||||||
let y: i8 = -12i8;
|
let y: i8 = -12i8;
|
||||||
x = x + 1i8;
|
x = x + 1i8;
|
||||||
x = x - 1i8;
|
x = x - 1i8;
|
||||||
|
@ -16,7 +16,7 @@ iface map<T> {
|
|||||||
}
|
}
|
||||||
impl <T> of map<T> for [T] {
|
impl <T> of map<T> for [T] {
|
||||||
fn map<U>(f: fn(T) -> U) -> [U] {
|
fn map<U>(f: fn(T) -> U) -> [U] {
|
||||||
let r = [];
|
let mut r = [];
|
||||||
for x in self { r += [f(x)]; }
|
for x in self { r += [f(x)]; }
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use std;
|
|||||||
import vec::*;
|
import vec::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let v = from_elem(0u, 0);
|
let mut v = from_elem(0u, 0);
|
||||||
v += [4, 2];
|
v += [4, 2];
|
||||||
assert (reversed(v) == [2, 4]);
|
assert (reversed(v) == [2, 4]);
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,11 @@ native mod rusti {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() unsafe {
|
fn main() unsafe {
|
||||||
let v: [int] = [];
|
let mut v: [int] = [];
|
||||||
assert (vec_len(v) == 0u); // zero-length
|
assert (vec_len(v) == 0u); // zero-length
|
||||||
let x = [1, 2];
|
let mut x = [1, 2];
|
||||||
assert (vec_len(x) == 2u); // on stack
|
assert (vec_len(x) == 2u); // on stack
|
||||||
let y = [1, 2, 3, 4, 5];
|
let mut y = [1, 2, 3, 4, 5];
|
||||||
assert (vec_len(y) == 5u); // on heap
|
assert (vec_len(y) == 5u); // on heap
|
||||||
|
|
||||||
v += [];
|
v += [];
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
fn main () {
|
fn main () {
|
||||||
let line = "";
|
let mut line = "";
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
do {
|
do {
|
||||||
line = if i == 9 { "exit" } else { "notexit" };
|
line = if i == 9 { "exit" } else { "notexit" };
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -13,7 +13,7 @@ fn a() {
|
|||||||
spawn {|| b(ch); };
|
spawn {|| b(ch); };
|
||||||
recv(p);
|
recv(p);
|
||||||
}
|
}
|
||||||
let i = 0;
|
let mut i = 0;
|
||||||
while i < 100 {
|
while i < 100 {
|
||||||
doit();
|
doit();
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -33,16 +33,16 @@ fn test_heap_add() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_append() {
|
fn test_append() {
|
||||||
let s = "";
|
let mut s = "";
|
||||||
s += "a";
|
s += "a";
|
||||||
assert (s == "a");
|
assert (s == "a");
|
||||||
|
|
||||||
let s = "a";
|
let mut s = "a";
|
||||||
s += "b";
|
s += "b";
|
||||||
log(debug, s);
|
log(debug, s);
|
||||||
assert (s == "ab");
|
assert (s == "ab");
|
||||||
|
|
||||||
let s = "c";
|
let mut s = "c";
|
||||||
s += "offee";
|
s += "offee";
|
||||||
assert (s == "coffee");
|
assert (s == "coffee");
|
||||||
|
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
fn range(a: int, b: int, it: fn(int)) {
|
fn range(a: int, b: int, it: fn(int)) {
|
||||||
assert (a < b);
|
assert (a < b);
|
||||||
let i: int = a;
|
let mut i: int = a;
|
||||||
while i < b { it(i); i += 1; }
|
while i < b { it(i); i += 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let sum: int = 0;
|
let mut sum: int = 0;
|
||||||
range(0, 100) {|x| sum += x; }
|
range(0, 100) {|x| sum += x; }
|
||||||
log(debug, sum);
|
log(debug, sum);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ fn double<T: copy>(a: T) -> [T] { ret [a] + [a]; }
|
|||||||
fn double_int(a: int) -> [int] { ret [a] + [a]; }
|
fn double_int(a: int) -> [int] { ret [a] + [a]; }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let d = double(1);
|
let mut d = double(1);
|
||||||
assert (d[0] == 1);
|
assert (d[0] == 1);
|
||||||
assert (d[1] == 1);
|
assert (d[1] == 1);
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ fn main() {
|
|||||||
call_me({|| *q}, q);
|
call_me({|| *q}, q);
|
||||||
|
|
||||||
// Check that no false positives are found in loops.
|
// Check that no false positives are found in loops.
|
||||||
let q = ~40, p = 10;
|
let mut q = ~40, p = 10;
|
||||||
loop {
|
loop {
|
||||||
let i = q;
|
let i = q;
|
||||||
p += *i;
|
p += *i;
|
||||||
|
@ -5,7 +5,7 @@ fn incr(&x: int) -> bool { x += 1; assert (false); ret false; }
|
|||||||
fn main() {
|
fn main() {
|
||||||
let x = 1 == 2 || 3 == 3;
|
let x = 1 == 2 || 3 == 3;
|
||||||
assert (x);
|
assert (x);
|
||||||
let y: int = 10;
|
let mut y: int = 10;
|
||||||
log(debug, x || incr(y));
|
log(debug, x || incr(y));
|
||||||
assert (y == 10);
|
assert (y == 10);
|
||||||
if true && x { assert (true); } else { assert (false); }
|
if true && x { assert (true); } else { assert (false); }
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
fn foo(x: int) { log(debug, x); }
|
fn foo(x: int) { log(debug, x); }
|
||||||
|
|
||||||
fn main() { let x: int; if 1 > 2 { x = 12; } else { x = 10; } foo(x); }
|
fn main() { let mut x: int; if 1 > 2 { x = 12; } else { x = 10; } foo(x); }
|
||||||
|
@ -7,7 +7,7 @@ import comm::*;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let p = port();
|
let p = port();
|
||||||
let ch = chan(p);
|
let ch = chan(p);
|
||||||
let y: int;
|
let mut y: int;
|
||||||
|
|
||||||
task::spawn {|| child(ch); };
|
task::spawn {|| child(ch); };
|
||||||
y = recv(p);
|
y = recv(p);
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
enum t { a, b(@int), }
|
enum t { a, b(@int), }
|
||||||
|
|
||||||
fn main() { let x = b(@10); x = a; }
|
fn main() { let mut x = b(@10); x = a; }
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user