annotate libstd and start enforcing mutability

This commit is contained in:
Niko Matsakis 2012-03-14 14:03:56 -04:00
parent 273c5e5f11
commit 6b35875dca
19 changed files with 145 additions and 138 deletions

View file

@ -38,7 +38,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)) -o $$@ $$< && touch $$@ $$(STAGE$(1)_T_$(2)_H_$(3)) --enforce-mut-vars -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)

View file

@ -45,7 +45,7 @@ fn process(v0: t, v1: t, op: fn(uint, uint) -> uint) -> bool {
let len = vec::len(v1.storage); let len = vec::len(v1.storage);
assert (vec::len(v0.storage) == len); assert (vec::len(v0.storage) == len);
assert (v0.nbits == v1.nbits); assert (v0.nbits == v1.nbits);
let changed = false; let mut changed = false;
uint::range(0u, len) {|i| uint::range(0u, len) {|i|
let w0 = v0.storage[i]; let w0 = v0.storage[i];
let w1 = v1.storage[i]; let w1 = v1.storage[i];
@ -113,7 +113,7 @@ fn equal(v0: t, v1: t) -> bool {
// we can eliminate this painful while-loop // we can eliminate this painful while-loop
let len = vec::len(v1.storage); let len = vec::len(v1.storage);
let i = 0u; let mut i = 0u;
while i < len { while i < len {
if v0.storage[i] != v1.storage[i] { ret false; } if v0.storage[i] != v1.storage[i] { ret false; }
i = i + 1u; i = i + 1u;
@ -201,7 +201,7 @@ The resulting string has the same length as the bitvector, and each character
is either '0' or '1'. is either '0' or '1'.
"] "]
fn to_str(v: t) -> str { fn to_str(v: t) -> str {
let rs = ""; let mut rs = "";
for i: uint in to_vec(v) { if i == 1u { rs += "1"; } else { rs += "0"; } } for i: uint in to_vec(v) { if i == 1u { rs += "1"; } else { rs += "0"; } }
ret rs; ret rs;
} }
@ -215,7 +215,7 @@ bitvector and vector must have the same length
fn eq_vec(v0: t, v1: [uint]) -> bool { fn eq_vec(v0: t, v1: [uint]) -> bool {
assert (v0.nbits == vec::len::<uint>(v1)); assert (v0.nbits == vec::len::<uint>(v1));
let len = v0.nbits; let len = v0.nbits;
let i = 0u; let mut i = 0u;
while i < len { while i < len {
let w0 = get(v0, i); let w0 = get(v0, i);
let w1 = v1[i]; let w1 = v1[i];

View file

@ -26,9 +26,9 @@ fn create<T: copy>() -> t<T> {
fn grow<T: copy>(nelts: uint, lo: uint, elts: [mutable cell<T>]) -> fn grow<T: copy>(nelts: uint, lo: uint, elts: [mutable cell<T>]) ->
[mutable cell<T>] { [mutable cell<T>] {
assert (nelts == vec::len(elts)); assert (nelts == vec::len(elts));
let rv = [mutable]; let mut rv = [mutable];
let i = 0u; let mut i = 0u;
let nalloc = uint::next_power_of_two(nelts + 1u); let nalloc = uint::next_power_of_two(nelts + 1u);
while i < nalloc { while i < nalloc {
if i < nelts { if i < nelts {

View file

@ -77,7 +77,7 @@ fn doc_at(data: @[u8], start: uint) -> tagged_doc {
} }
fn maybe_get_doc(d: doc, tg: uint) -> option<doc> { fn maybe_get_doc(d: doc, tg: uint) -> option<doc> {
let pos = d.start; let mut pos = d.start;
while pos < d.end { while pos < d.end {
let elt_tag = vuint_at(*d.data, pos); let elt_tag = vuint_at(*d.data, pos);
let elt_size = vuint_at(*d.data, elt_tag.next); let elt_size = vuint_at(*d.data, elt_tag.next);
@ -100,7 +100,7 @@ fn get_doc(d: doc, tg: uint) -> doc {
} }
fn docs(d: doc, it: fn(uint, doc)) { fn docs(d: doc, it: fn(uint, doc)) {
let pos = d.start; let mut pos = d.start;
while pos < d.end { while pos < d.end {
let elt_tag = vuint_at(*d.data, pos); let elt_tag = vuint_at(*d.data, pos);
let elt_size = vuint_at(*d.data, elt_tag.next); let elt_size = vuint_at(*d.data, elt_tag.next);
@ -110,7 +110,7 @@ fn docs(d: doc, it: fn(uint, doc)) {
} }
fn tagged_docs(d: doc, tg: uint, it: fn(doc)) { fn tagged_docs(d: doc, tg: uint, it: fn(doc)) {
let pos = d.start; let mut pos = d.start;
while pos < d.end { while pos < d.end {
let elt_tag = vuint_at(*d.data, pos); let elt_tag = vuint_at(*d.data, pos);
let elt_size = vuint_at(*d.data, elt_tag.next); let elt_size = vuint_at(*d.data, elt_tag.next);
@ -154,20 +154,19 @@ fn doc_as_i64(d: doc) -> i64 { doc_as_u64(d) as i64 }
type writer = {writer: io::writer, mutable size_positions: [uint]}; type writer = {writer: io::writer, mutable size_positions: [uint]};
fn write_sized_vuint(w: io::writer, n: uint, size: uint) { fn write_sized_vuint(w: io::writer, n: uint, size: uint) {
let buf: [u8]; let buf: [u8] = alt size {
alt size { 1u { [0x80u8 | (n as u8)] }
1u { buf = [0x80u8 | (n as u8)]; } 2u { [0x40u8 | ((n >> 8_u) as u8), n as u8] }
2u { buf = [0x40u8 | ((n >> 8_u) as u8), n as u8]; }
3u { 3u {
buf = [0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8, [0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
n as u8]; n as u8]
} }
4u { 4u {
buf = [0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8, [0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
(n >> 8_u) as u8, n as u8]; (n >> 8_u) as u8, n as u8]
} }
_ { fail #fmt("vint to write too big: %?", n); } _ { fail #fmt("vint to write too big: %?", n); }
} };
w.write(buf); w.write(buf);
} }

View file

@ -171,21 +171,21 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
let n_opts = vec::len::<opt>(opts); let n_opts = vec::len::<opt>(opts);
fn f(_x: uint) -> [optval] { ret []; } fn f(_x: uint) -> [optval] { ret []; }
let vals = vec::to_mut(vec::from_fn(n_opts, f)); let vals = vec::to_mut(vec::from_fn(n_opts, f));
let free: [str] = []; let mut free: [str] = [];
let l = vec::len(args); let l = vec::len(args);
let i = 0u; let mut i = 0u;
while i < l { while i < l {
let cur = args[i]; let cur = args[i];
let curlen = str::len(cur); let curlen = str::len(cur);
if !is_arg(cur) { if !is_arg(cur) {
free += [cur]; free += [cur];
} else if str::eq(cur, "--") { } else if str::eq(cur, "--") {
let j = i + 1u; let mut j = i + 1u;
while j < l { free += [args[j]]; j += 1u; } while j < l { free += [args[j]]; j += 1u; }
break; break;
} else { } else {
let names; let mut names;
let i_arg = option::none::<str>; let mut i_arg = option::none::<str>;
if cur[1] == '-' as u8 { if cur[1] == '-' as u8 {
let tail = str::slice(cur, 2u, curlen); let tail = str::slice(cur, 2u, curlen);
let tail_eq = str::splitn_char(tail, '=', 1u); let tail_eq = str::splitn_char(tail, '=', 1u);
@ -198,7 +198,7 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
option::some::<str>(tail_eq[1]); option::some::<str>(tail_eq[1]);
} }
} else { } else {
let j = 1u; let mut j = 1u;
names = []; names = [];
while j < curlen { while j < curlen {
let range = str::char_range_at(cur, j); let range = str::char_range_at(cur, j);
@ -206,14 +206,13 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
j = range.next; j = range.next;
} }
} }
let name_pos = 0u; let mut name_pos = 0u;
for nm: name in names { for nm: name in names {
name_pos += 1u; name_pos += 1u;
let optid; let optid = alt find_opt(opts, nm) {
alt find_opt(opts, nm) { some(id) { id }
some(id) { optid = id; }
none { ret err(unrecognized_option(name_str(nm))); } none { ret err(unrecognized_option(name_str(nm))); }
} };
alt opts[optid].hasarg { alt opts[optid].hasarg {
no { no {
if !option::is_none::<str>(i_arg) { if !option::is_none::<str>(i_arg) {
@ -289,7 +288,7 @@ Returns a vector of the arguments provided to all matches of the given option.
Used when an option accepts multiple values. Used when an option accepts multiple values.
"] "]
fn opt_strs(m: match, nm: str) -> [str] { fn opt_strs(m: match, nm: str) -> [str] {
let acc: [str] = []; let mut acc: [str] = [];
for v: optval in opt_vals(m, nm) { for v: optval in opt_vals(m, nm) {
alt v { val(s) { acc += [s]; } _ { } } alt v { val(s) { acc += [s]; } _ { } }
} }

View file

@ -46,7 +46,7 @@ fn to_writer(wr: io::writer, j: json) {
num(n) { wr.write_str(float::to_str(n, 6u)); } num(n) { wr.write_str(float::to_str(n, 6u)); }
string(s) { string(s) {
wr.write_char('"'); wr.write_char('"');
let escaped = ""; let mut escaped = "";
str::chars_iter(s) { |c| str::chars_iter(s) { |c|
alt c { alt c {
'"' { escaped += "\\\""; } '"' { escaped += "\\\""; }
@ -67,7 +67,7 @@ fn to_writer(wr: io::writer, j: json) {
} }
list(v) { list(v) {
wr.write_char('['); wr.write_char('[');
let first = true; let mut first = true;
vec::iter(v) { |item| vec::iter(v) { |item|
if !first { if !first {
wr.write_str(", "); wr.write_str(", ");
@ -84,7 +84,7 @@ fn to_writer(wr: io::writer, j: json) {
} }
wr.write_str("{ "); wr.write_str("{ ");
let first = true; let mut first = true;
d.items { |key, value| d.items { |key, value|
if !first { if !first {
wr.write_str(", "); wr.write_str(", ");
@ -189,14 +189,14 @@ impl parser for parser {
} }
fn parse_number() -> result<json, error> { fn parse_number() -> result<json, error> {
let neg = 1f; let mut neg = 1f;
if self.ch == '-' { if self.ch == '-' {
self.bump(); self.bump();
neg = -1f; neg = -1f;
} }
let res = alt self.parse_integer() { let mut res = alt self.parse_integer() {
ok(res) { res } ok(res) { res }
err(e) { ret err(e); } err(e) { ret err(e); }
}; };
@ -219,7 +219,7 @@ impl parser for parser {
} }
fn parse_integer() -> result<float, error> { fn parse_integer() -> result<float, error> {
let res = 0f; let mut res = 0f;
alt self.ch { alt self.ch {
'0' { '0' {
@ -259,8 +259,8 @@ impl parser for parser {
_ { ret self.error("invalid number"); } _ { ret self.error("invalid number"); }
} }
let res = res; let mut res = res;
let dec = 1f; let mut dec = 1f;
while !self.eof() { while !self.eof() {
alt self.ch { alt self.ch {
'0' to '9' { '0' to '9' {
@ -279,9 +279,9 @@ impl parser for parser {
fn parse_exponent(res: float) -> result<float, error> { fn parse_exponent(res: float) -> result<float, error> {
self.bump(); self.bump();
let res = res; let mut res = res;
let exp = 0u; let mut exp = 0u;
let neg_exp = false; let mut neg_exp = false;
alt self.ch { alt self.ch {
'+' { self.bump(); } '+' { self.bump(); }
@ -318,8 +318,8 @@ impl parser for parser {
} }
fn parse_str() -> result<str, error> { fn parse_str() -> result<str, error> {
let escape = false; let mut escape = false;
let res = ""; let mut res = "";
while !self.eof() { while !self.eof() {
self.bump(); self.bump();
@ -336,8 +336,8 @@ impl parser for parser {
't' { str::push_char(res, '\t'); } 't' { str::push_char(res, '\t'); }
'u' { 'u' {
// Parse \u1234. // Parse \u1234.
let i = 0u; let mut i = 0u;
let n = 0u; let mut n = 0u;
while i < 4u { while i < 4u {
alt self.next_char() { alt self.next_char() {
'0' to '9' { '0' to '9' {
@ -346,6 +346,7 @@ impl parser for parser {
} }
_ { ret self.error("invalid \\u escape"); } _ { ret self.error("invalid \\u escape"); }
} }
i += 1u;
} }
// Error out if we didn't parse 4 digits. // Error out if we didn't parse 4 digits.
@ -376,7 +377,7 @@ impl parser for parser {
self.bump(); self.bump();
self.parse_whitespace(); self.parse_whitespace();
let values = []; let mut values = [];
if self.ch == ']' { if self.ch == ']' {
self.bump(); self.bump();
@ -479,7 +480,7 @@ fn eq(value0: json, value1: json) -> bool {
(list(l0), list(l1)) { vec::all2(l0, l1, eq) } (list(l0), list(l1)) { vec::all2(l0, l1, eq) }
(dict(d0), dict(d1)) { (dict(d0), dict(d1)) {
if d0.size() == d1.size() { if d0.size() == d1.size() {
let equal = true; let mut equal = true;
d0.items { |k, v0| d0.items { |k, v0|
alt d1.find(k) { alt d1.find(k) {
some(v1) { some(v1) {

View file

@ -28,7 +28,7 @@ accumulated result.
* f - The function to apply * f - The function to apply
"] "]
fn foldl<T: copy, U>(ls: list<U>, z: T, f: fn(T, U) -> T) -> T { fn foldl<T: copy, U>(ls: list<U>, z: T, f: fn(T, U) -> T) -> T {
let accum: T = z; let mut accum: T = z;
iter(ls) {|elt| accum = f(accum, elt);} iter(ls) {|elt| accum = f(accum, elt);}
accum accum
} }
@ -41,7 +41,7 @@ When function `f` returns true then an option containing the element
is returned. If `f` matches no elements then none is returned. is returned. If `f` matches no elements then none is returned.
"] "]
fn find<T: copy>(ls: list<T>, f: fn(T) -> bool) -> option<T> { fn find<T: copy>(ls: list<T>, f: fn(T) -> bool) -> option<T> {
let ls = ls; let mut ls = ls;
loop { loop {
alt ls { alt ls {
cons(hd, tl) { cons(hd, tl) {
@ -55,7 +55,7 @@ fn find<T: copy>(ls: list<T>, f: fn(T) -> bool) -> option<T> {
#[doc = "Returns true if a list contains an element with the given value"] #[doc = "Returns true if a list contains an element with the given value"]
fn has<T: copy>(ls: list<T>, elt: T) -> bool { fn has<T: copy>(ls: list<T>, elt: T) -> bool {
let ls = ls; let mut ls = ls;
loop { loop {
alt ls { alt ls {
cons(hd, tl) { if elt == hd { ret true; } else { ls = *tl; } } cons(hd, tl) { if elt == hd { ret true; } else { ls = *tl; } }
@ -79,7 +79,7 @@ pure fn is_not_empty<T: copy>(ls: list<T>) -> bool {
#[doc = "Returns the length of a list"] #[doc = "Returns the length of a list"]
fn len<T>(ls: list<T>) -> uint { fn len<T>(ls: list<T>) -> uint {
let count = 0u; let mut count = 0u;
iter(ls) {|_e| count += 1u;} iter(ls) {|_e| count += 1u;}
count count
} }
@ -110,7 +110,7 @@ fn iter<T>(l: list<T>, f: fn(T)) {
alt l { alt l {
cons(hd, tl) { cons(hd, tl) {
f(hd); f(hd);
let cur = tl; let mut cur = tl;
loop { loop {
alt *cur { alt *cur {
cons(hd, tl) { cons(hd, tl) {

View file

@ -94,8 +94,8 @@ mod chained {
fn search_rem<K: copy, V: copy>( fn search_rem<K: copy, V: copy>(
tbl: t<K,V>, k: K, h: uint, idx: uint, tbl: t<K,V>, k: K, h: uint, idx: uint,
e_root: @entry<K,V>) -> search_result<K,V> { e_root: @entry<K,V>) -> search_result<K,V> {
let e0 = e_root; let mut e0 = e_root;
let comp = 1u; // for logging let mut comp = 1u; // for logging
loop { loop {
alt e0.next { alt e0.next {
absent { absent {
@ -207,7 +207,7 @@ mod chained {
fn foreach_entry<K: copy, V: copy>(chain0: chain<K,V>, fn foreach_entry<K: copy, V: copy>(chain0: chain<K,V>,
blk: fn(@entry<K,V>)) { blk: fn(@entry<K,V>)) {
let chain = chain0; let mut chain = chain0;
loop { loop {
alt chain { alt chain {
absent { ret; } absent { ret; }
@ -222,7 +222,8 @@ mod chained {
fn foreach_chain<K: copy, V: copy>(chains: [const chain<K,V>], fn foreach_chain<K: copy, V: copy>(chains: [const chain<K,V>],
blk: fn(@entry<K,V>)) { blk: fn(@entry<K,V>)) {
let i = 0u, n = vec::len(chains); let mut i = 0u;
let n = vec::len(chains);
while i < n { while i < n {
foreach_entry(chains[i], blk); foreach_entry(chains[i], blk);
i += 1u; i += 1u;

View file

@ -5,36 +5,37 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
let orig_len: u64 = (vec::len(msg) * 8u) as u64; let orig_len: u64 = (vec::len(msg) * 8u) as u64;
// pad message // pad message
let msg = msg + [0x80u8]; let mut msg = msg + [0x80u8];
let bitlen = orig_len + 8u64; let mut bitlen = orig_len + 8u64;
while (bitlen + 64u64) % 512u64 > 0u64 { while (bitlen + 64u64) % 512u64 > 0u64 {
msg += [0u8]; msg += [0u8];
bitlen += 8u64; bitlen += 8u64;
} }
// append length // append length
let i = 0u64; let mut i = 0u64;
while i < 8u64 { while i < 8u64 {
msg += [(orig_len >> (i * 8u64)) as u8]; msg += [(orig_len >> (i * 8u64)) as u8];
i += 1u64; i += 1u64;
} }
let a = 0x67452301u32; let mut a = 0x67452301u32;
let b = 0xefcdab89u32; let mut b = 0xefcdab89u32;
let c = 0x98badcfeu32; let mut c = 0x98badcfeu32;
let d = 0x10325476u32; let mut d = 0x10325476u32;
fn rot(r: int, x: u32) -> u32 { fn rot(r: int, x: u32) -> u32 {
let r = r as u32; let r = r as u32;
(x << r) | (x >> (32u32 - r)) (x << r) | (x >> (32u32 - r))
} }
let i = 0u, e = vec::len(msg); let mut i = 0u;
let e = vec::len(msg);
let x = vec::to_mut(vec::from_elem(16u, 0u32)); let x = vec::to_mut(vec::from_elem(16u, 0u32));
while i < e { while i < e {
let aa = a, bb = b, cc = c, dd = d; let aa = a, bb = b, cc = c, dd = d;
let j = 0u, base = i; let mut j = 0u, base = i;
while j < 16u { while j < 16u {
x[j] = (msg[base] as u32) + (msg[base + 1u] as u32 << 8u32) + x[j] = (msg[base] as u32) + (msg[base + 1u] as u32 << 8u32) +
(msg[base + 2u] as u32 << 16u32) + (msg[base + 2u] as u32 << 16u32) +
@ -42,7 +43,7 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
j += 1u; base += 4u; j += 1u; base += 4u;
} }
let j = 0u; let mut j = 0u;
while j < 16u { while j < 16u {
a = rot(3, a + ((b & c) | (!b & d)) + x[j]); a = rot(3, a + ((b & c) | (!b & d)) + x[j]);
j += 1u; j += 1u;
@ -54,7 +55,8 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
j += 1u; j += 1u;
} }
let j = 0u, q = 0x5a827999u32; let mut j = 0u;
let q = 0x5a827999u32;
while j < 4u { while j < 4u {
a = rot(3, a + ((b & c) | ((b & d) | (c & d))) + x[j] + q); a = rot(3, a + ((b & c) | ((b & d) | (c & d))) + x[j] + q);
d = rot(5, d + ((a & b) | ((a & c) | (b & c))) + x[j + 4u] + q); d = rot(5, d + ((a & b) | ((a & c) | (b & c))) + x[j + 4u] + q);
@ -63,7 +65,8 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
j += 1u; j += 1u;
} }
let j = 0u, q = 0x6ed9eba1u32; let mut j = 0u;
let q = 0x6ed9eba1u32;
while j < 8u { while j < 8u {
let jj = if j > 2u { j - 3u } else { j }; let jj = if j > 2u { j - 3u } else { j };
a = rot(3, a + (b ^ c ^ d) + x[jj] + q); a = rot(3, a + (b ^ c ^ d) + x[jj] + q);
@ -84,9 +87,9 @@ fn md4_str(msg: [u8]) -> str {
fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) { fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) {
f(a); f(b); f(c); f(d); f(a); f(b); f(c); f(d);
} }
let result = ""; let mut result = "";
app(a, b, c, d) {|u| app(a, b, c, d) {|u|
let i = 0u32; let mut i = 0u32;
while i < 4u32 { while i < 4u32 {
let byte = (u >> (i * 8u32)) as u8; let byte = (u >> (i * 8u32)) as u8;
if byte <= 16u8 { result += "0"; } if byte <= 16u8 { result += "0"; }

View file

@ -155,7 +155,7 @@ measure to ensure that the result is balanced.
"] "]
fn concat(v: [rope]) -> rope { fn concat(v: [rope]) -> rope {
//Copy `v` into a mutable vector //Copy `v` into a mutable vector
let len = vec::len(v); let mut len = vec::len(v);
if len == 0u { ret node::empty; } if len == 0u { ret node::empty; }
let ropes = vec::to_mut(vec::from_elem(len, v[0])); let ropes = vec::to_mut(vec::from_elem(len, v[0]));
uint::range(1u, len) {|i| uint::range(1u, len) {|i|
@ -684,12 +684,12 @@ mod node {
ret candidate; ret candidate;
} else { } else {
//Firstly, split `str` in slices of hint_max_leaf_char_len //Firstly, split `str` in slices of hint_max_leaf_char_len
let leaves = uint::div_ceil(char_len, hint_max_leaf_char_len); let mut leaves = uint::div_ceil(char_len, hint_max_leaf_char_len);
//Number of leaves //Number of leaves
let nodes = vec::to_mut(vec::from_elem(leaves, candidate)); let nodes = vec::to_mut(vec::from_elem(leaves, candidate));
let i = 0u; let mut i = 0u;
let offset = byte_start; let mut offset = byte_start;
let first_leaf_char_len = let first_leaf_char_len =
if char_len%hint_max_leaf_char_len == 0u { if char_len%hint_max_leaf_char_len == 0u {
hint_max_leaf_char_len hint_max_leaf_char_len
@ -753,17 +753,17 @@ mod node {
execution and should be discarded as meaningless afterwards. execution and should be discarded as meaningless afterwards.
"] "]
fn tree_from_forest_destructive(forest: [mutable @node]) -> @node { fn tree_from_forest_destructive(forest: [mutable @node]) -> @node {
let i = 0u; let mut i = 0u;
let len = vec::len(forest); let mut len = vec::len(forest);
while len > 1u { while len > 1u {
i = 0u; i = 0u;
while i < len - 1u {//Concat nodes 0 with 1, 2 with 3 etc. while i < len - 1u {//Concat nodes 0 with 1, 2 with 3 etc.
let left = forest[i]; let mut left = forest[i];
let right = forest[i+1u]; let mut right = forest[i+1u];
let left_len = char_len(left); let left_len = char_len(left);
let right_len= char_len(right); let right_len= char_len(right);
let left_height= height(left); let mut left_height= height(left);
let right_height=height(right); let mut right_height=height(right);
if left_len + right_len > hint_max_leaf_char_len { if left_len + right_len > hint_max_leaf_char_len {
if left_len <= hint_max_leaf_char_len { if left_len <= hint_max_leaf_char_len {
left = flatten(left); left = flatten(left);
@ -797,16 +797,17 @@ mod node {
} }
fn serialize_node(node: @node) -> str unsafe { fn serialize_node(node: @node) -> str unsafe {
let buf = vec::to_mut(vec::from_elem(byte_len(node), 0u8)); let mut buf = vec::to_mut(vec::from_elem(byte_len(node), 0u8));
let offset = 0u;//Current position in the buffer let mut offset = 0u;//Current position in the buffer
let it = leaf_iterator::start(node); let it = leaf_iterator::start(node);
loop { loop {
alt(leaf_iterator::next(it)) { alt(leaf_iterator::next(it)) {
option::none { break; } option::none { break; }
option::some(x) { option::some(x) {
//TODO: Replace with memcpy or something similar //TODO: Replace with memcpy or something similar
let local_buf: [u8] = unsafe::reinterpret_cast(*x.content); let mut local_buf: [u8] =
let i = x.byte_offset; unsafe::reinterpret_cast(*x.content);
let mut i = x.byte_offset;
while i < x.byte_len { while i < x.byte_len {
buf[offset] = local_buf[i]; buf[offset] = local_buf[i];
offset += 1u; offset += 1u;
@ -860,7 +861,7 @@ mod node {
fn bal(node: @node) -> option<@node> { fn bal(node: @node) -> option<@node> {
if height(node) < hint_max_node_height { ret option::none; } if height(node) < hint_max_node_height { ret option::none; }
//1. Gather all leaves as a forest //1. Gather all leaves as a forest
let forest = [mutable]; let mut forest = [mutable];
let it = leaf_iterator::start(node); let it = leaf_iterator::start(node);
loop { loop {
alt (leaf_iterator::next(it)) { alt (leaf_iterator::next(it)) {
@ -894,8 +895,8 @@ mod node {
valid positions in `node`. valid positions in `node`.
"] "]
fn sub_bytes(node: @node, byte_offset: uint, byte_len: uint) -> @node { fn sub_bytes(node: @node, byte_offset: uint, byte_len: uint) -> @node {
let node = node; let mut node = node;
let byte_offset = byte_offset; let mut byte_offset = byte_offset;
loop { loop {
if byte_offset == 0u && byte_len == node::byte_len(node) { if byte_offset == 0u && byte_len == node::byte_len(node) {
ret node; ret node;
@ -955,8 +956,8 @@ mod node {
valid positions in `node`. valid positions in `node`.
"] "]
fn sub_chars(node: @node, char_offset: uint, char_len: uint) -> @node { fn sub_chars(node: @node, char_offset: uint, char_len: uint) -> @node {
let node = node; let mut node = node;
let char_offset = char_offset; let mut char_offset = char_offset;
loop { loop {
alt(*node) { alt(*node) {
node::leaf(x) { node::leaf(x) {
@ -1018,8 +1019,8 @@ mod node {
fn cmp(a: @node, b: @node) -> int { fn cmp(a: @node, b: @node) -> int {
let ita = char_iterator::start(a); let ita = char_iterator::start(a);
let itb = char_iterator::start(b); let itb = char_iterator::start(b);
let result = 0; let mut result = 0;
let pos = 0u; let mut pos = 0u;
while result == 0 { while result == 0 {
alt((char_iterator::next(ita), char_iterator::next(itb))) { alt((char_iterator::next(ita), char_iterator::next(itb))) {
(option::none, option::none) { (option::none, option::none) {
@ -1063,7 +1064,7 @@ mod node {
that is if `it` returned `false` at any point. that is if `it` returned `false` at any point.
"] "]
fn loop_leaves(node: @node, it: fn(leaf) -> bool) -> bool{ fn loop_leaves(node: @node, it: fn(leaf) -> bool) -> bool{
let current = node; let mut current = node;
loop { loop {
alt(*current) { alt(*current) {
leaf(x) { leaf(x) {
@ -1098,8 +1099,8 @@ mod node {
length of the largest leaf. length of the largest leaf.
"] "]
fn char_at(node: @node, pos: uint) -> char { fn char_at(node: @node, pos: uint) -> char {
let node = node; let mut node = node;
let pos = pos; let mut pos = pos;
loop { loop {
alt *node { alt *node {
leaf(x) { leaf(x) {

View file

@ -82,13 +82,13 @@ fn sha1() -> sha1 {
// FIXME: Make precondition // FIXME: Make precondition
assert (vec::len(st.h) == digest_buf_len); assert (vec::len(st.h) == digest_buf_len);
assert (vec::len(st.work_buf) == work_buf_len); assert (vec::len(st.work_buf) == work_buf_len);
let t: int; // Loop counter let mut t: int; // Loop counter
let w = st.work_buf; let w = st.work_buf;
// Initialize the first 16 words of the vector w // Initialize the first 16 words of the vector w
t = 0; t = 0;
while t < 16 { while t < 16 {
let tmp; let mut tmp;
tmp = (st.msg_block[t * 4] as u32) << 24u32; tmp = (st.msg_block[t * 4] as u32) << 24u32;
tmp = tmp | (st.msg_block[t * 4 + 1] as u32) << 16u32; tmp = tmp | (st.msg_block[t * 4 + 1] as u32) << 16u32;
tmp = tmp | (st.msg_block[t * 4 + 2] as u32) << 8u32; tmp = tmp | (st.msg_block[t * 4 + 2] as u32) << 8u32;
@ -103,12 +103,12 @@ fn sha1() -> sha1 {
w[t] = circular_shift(1u32, val); w[t] = circular_shift(1u32, val);
t += 1; t += 1;
} }
let a = st.h[0]; let mut a = st.h[0];
let b = st.h[1]; let mut b = st.h[1];
let c = st.h[2]; let mut c = st.h[2];
let d = st.h[3]; let mut d = st.h[3];
let e = st.h[4]; let mut e = st.h[4];
let temp: u32; let mut temp: u32;
t = 0; t = 0;
while t < 20 { while t < 20 {
temp = circular_shift(5u32, a) + (b & c | !b & d) + e + w[t] + k0; temp = circular_shift(5u32, a) + (b & c | !b & d) + e + w[t] + k0;
@ -160,7 +160,7 @@ fn sha1() -> sha1 {
} }
fn mk_result(st: sha1state) -> [u8] { fn mk_result(st: sha1state) -> [u8] {
if !st.computed { pad_msg(st); st.computed = true; } if !st.computed { pad_msg(st); st.computed = true; }
let rs: [u8] = []; let mut rs: [u8] = [];
for hpart: u32 in st.h { for hpart: u32 in st.h {
let a = (hpart >> 24u32 & 0xFFu32) as u8; let a = (hpart >> 24u32 & 0xFFu32) as u8;
let b = (hpart >> 16u32 & 0xFFu32) as u8; let b = (hpart >> 16u32 & 0xFFu32) as u8;
@ -237,7 +237,7 @@ fn sha1() -> sha1 {
fn result() -> [u8] { ret mk_result(self); } fn result() -> [u8] { ret mk_result(self); }
fn result_str() -> str { fn result_str() -> str {
let r = mk_result(self); let r = mk_result(self);
let s = ""; let mut s = "";
for b: u8 in r { s += uint::to_str(b as uint, 16u); } for b: u8 in r { s += uint::to_str(b as uint, 16u); }
ret s; ret s;
} }

View file

@ -66,7 +66,7 @@ fn max_key<T>(m: smallintmap<T>) -> uint {
#[doc = "Implements the map::map interface for smallintmap"] #[doc = "Implements the map::map interface for smallintmap"]
impl <V: copy> of map::map<uint, V> for smallintmap<V> { impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn size() -> uint { fn size() -> uint {
let sz = 0u; let mut sz = 0u;
for item in self.v { for item in self.v {
alt item { some(_) { sz += 1u; } _ {} } alt item { some(_) { sz += 1u; } _ {} }
} }
@ -90,7 +90,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn find(&&key: uint) -> option<V> { find(self, key) } fn find(&&key: uint) -> option<V> { find(self, key) }
fn rehash() { fail } fn rehash() { fail }
fn items(it: fn(&&uint, V)) { fn items(it: fn(&&uint, V)) {
let idx = 0u; let mut idx = 0u;
for item in self.v { for item in self.v {
alt item { alt item {
some(elt) { some(elt) {
@ -102,7 +102,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
} }
} }
fn keys(it: fn(&&uint)) { fn keys(it: fn(&&uint)) {
let idx = 0u; let mut idx = 0u;
for item in self.v { for item in self.v {
if item != none { it(idx); } if item != none { it(idx); }
idx += 1u; idx += 1u;

View file

@ -33,12 +33,12 @@ fn merge_sort<T: copy>(le: le<T>, v: [const T]) -> [T] {
} }
fn merge<T: copy>(le: le<T>, a: [T], b: [T]) -> [T] { fn merge<T: copy>(le: le<T>, a: [T], b: [T]) -> [T] {
let rs = []; let mut rs = [];
vec::reserve(rs, len(a) + len(b)); vec::reserve(rs, len(a) + len(b));
let a_len = len(a); let a_len = len(a);
let a_ix = 0u; let mut a_ix = 0u;
let b_len = len(b); let b_len = len(b);
let b_ix = 0u; let mut b_ix = 0u;
while a_ix < a_len && b_ix < b_len { while a_ix < a_len && b_ix < b_len {
if le(a[a_ix], b[b_ix]) { if le(a[a_ix], b[b_ix]) {
rs += [a[a_ix]]; rs += [a[a_ix]];
@ -55,8 +55,8 @@ fn part<T: copy>(compare_func: le<T>, arr: [mutable T], left: uint,
right: uint, pivot: uint) -> uint { right: uint, pivot: uint) -> uint {
let pivot_value = arr[pivot]; let pivot_value = arr[pivot];
arr[pivot] <-> arr[right]; arr[pivot] <-> arr[right];
let storage_index: uint = left; let mut storage_index: uint = left;
let i: uint = left; let mut i: uint = left;
while i < right { while i < right {
if compare_func(copy arr[i], pivot_value) { if compare_func(copy arr[i], pivot_value) {
arr[i] <-> arr[storage_index]; arr[i] <-> arr[storage_index];
@ -96,10 +96,10 @@ fn qsort3<T: copy>(compare_func_lt: le<T>, compare_func_eq: le<T>,
arr: [mutable T], left: int, right: int) { arr: [mutable T], left: int, right: int) {
if right <= left { ret; } if right <= left { ret; }
let v: T = arr[right]; let v: T = arr[right];
let i: int = left - 1; let mut i: int = left - 1;
let j: int = right; let mut j: int = right;
let p: int = i; let mut p: int = i;
let q: int = j; let mut q: int = j;
loop { loop {
i += 1; i += 1;
while compare_func_lt(copy arr[i], v) { i += 1; } while compare_func_lt(copy arr[i], v) { i += 1; }
@ -122,7 +122,7 @@ fn qsort3<T: copy>(compare_func_lt: le<T>, compare_func_eq: le<T>,
arr[i] <-> arr[right]; arr[i] <-> arr[right];
j = i - 1; j = i - 1;
i += 1; i += 1;
let k: int = left; let mut k: int = left;
while k < p { while k < p {
arr[k] <-> arr[j]; arr[k] <-> arr[j];
k += 1; k += 1;

View file

@ -6,7 +6,7 @@ import rand;
fn mkdtemp(prefix: str, suffix: str) -> option<str> { fn mkdtemp(prefix: str, suffix: str) -> option<str> {
let r = rand::rng(); let r = rand::rng();
let i = 0u; let mut i = 0u;
while (i < 1000u) { while (i < 1000u) {
let s = prefix + r.gen_str(16u) + suffix; let s = prefix + r.gen_str(16u) + suffix;
if os::make_dir(s, 0x1c0i32) { // FIXME: u+rwx if os::make_dir(s, 0x1c0i32) { // FIXME: u+rwx

View file

@ -49,7 +49,7 @@ fn color_supported() -> bool {
fn set_color(writer: io::writer, first_char: u8, color: u8) { fn set_color(writer: io::writer, first_char: u8, color: u8) {
assert (color < 16u8); assert (color < 16u8);
esc(writer); esc(writer);
let color = color; let mut color = color;
if color >= 8u8 { writer.write(['1' as u8, ';' as u8]); color -= 8u8; } if color >= 8u8 { writer.write(['1' as u8, ';' as u8]); color -= 8u8; }
writer.write([first_char, ('0' as u8) + color, 'm' as u8]); writer.write([first_char, ('0' as u8) + color, 'm' as u8]);
} }

View file

@ -237,7 +237,7 @@ type monitor_msg = (test_desc, test_result);
fn run_tests(opts: test_opts, tests: [test_desc], fn run_tests(opts: test_opts, tests: [test_desc],
callback: fn@(testevent)) { callback: fn@(testevent)) {
let filtered_tests = filter_tests(opts, tests); let mut filtered_tests = filter_tests(opts, tests);
callback(te_filtered(filtered_tests)); callback(te_filtered(filtered_tests));
// It's tempting to just spawn all the tests at once, but since we have // It's tempting to just spawn all the tests at once, but since we have
@ -246,9 +246,9 @@ fn run_tests(opts: test_opts, tests: [test_desc],
#debug("using %u test tasks", concurrency); #debug("using %u test tasks", concurrency);
let total = vec::len(filtered_tests); let total = vec::len(filtered_tests);
let run_idx = 0u; let mut run_idx = 0u;
let wait_idx = 0u; let mut wait_idx = 0u;
let done_idx = 0u; let mut done_idx = 0u;
let p = comm::port(); let p = comm::port();
let ch = comm::chan(p); let ch = comm::chan(p);
@ -294,7 +294,7 @@ fn get_concurrency() -> uint {
fn filter_tests(opts: test_opts, fn filter_tests(opts: test_opts,
tests: [test_desc]) -> [test_desc] { tests: [test_desc]) -> [test_desc] {
let filtered = tests; let mut filtered = tests;
// Remove tests that don't match the test filter // Remove tests that don't match the test filter
filtered = if option::is_none(opts.filter) { filtered = if option::is_none(opts.filter) {
@ -355,9 +355,8 @@ fn run_test(+test: test_desc, monitor_ch: comm::chan<monitor_msg>) {
} }
task::spawn {|| task::spawn {||
let testfn = test.fn; let testfn = test.fn;
let builder = task::task_builder(); let mut builder = task::task_builder();
let result_future = task::future_result(builder); let result_future = task::future_result(builder);
task::unsupervise(builder); task::unsupervise(builder);
task::run(builder, testfn); task::run(builder, testfn);

View file

@ -12,8 +12,8 @@ Returns the current time as a `timeval` containing the seconds and
microseconds since 1970-01-01T00:00:00Z. microseconds since 1970-01-01T00:00:00Z.
"] "]
fn get_time() -> timeval { fn get_time() -> timeval {
let sec = 0u32; let mut sec = 0u32;
let usec = 0u32; let mut usec = 0u32;
rustrt::get_time(sec, usec); rustrt::get_time(sec, usec);
ret {sec: sec, usec: usec}; ret {sec: sec, usec: usec};
} }
@ -22,7 +22,11 @@ fn get_time() -> timeval {
Returns the current value of a high-resolution performance counter Returns the current value of a high-resolution performance counter
in nanoseconds since an unspecified epoch. in nanoseconds since an unspecified epoch.
"] "]
fn precise_time_ns() -> u64 { let ns = 0u64; rustrt::precise_time_ns(ns); ns } fn precise_time_ns() -> u64 {
let mut ns = 0u64;
rustrt::precise_time_ns(ns);
ns
}
#[doc = " #[doc = "
Returns the current value of a high-resolution performance counter Returns the current value of a high-resolution performance counter

View file

@ -47,6 +47,6 @@ fn set_count(ufnd: ufind) -> uint { ret vec::len::<node>(ufnd.nodes); }
fn prune(ufnd: ufind, n: uint) { fn prune(ufnd: ufind, n: uint) {
// TODO: Use "slice" once we get rid of "const" // TODO: Use "slice" once we get rid of "const"
let len = vec::len::<node>(ufnd.nodes); let mut len = vec::len::<node>(ufnd.nodes);
while len != n { vec::pop::<node>(ufnd.nodes); len -= 1u; } while len != n { vec::pop::<node>(ufnd.nodes); len -= 1u; }
} }

View file

@ -146,8 +146,8 @@ fn loop_new() -> uv_loop unsafe {
// the main loop that this task blocks on. // the main loop that this task blocks on.
// should have the same lifetime as the C libuv // should have the same lifetime as the C libuv
// event loop. // event loop.
let keep_going = true; let mut keep_going = true;
while (keep_going) { while keep_going {
alt comm::recv(rust_loop_port) { alt comm::recv(rust_loop_port) {
msg_run(end_chan) { msg_run(end_chan) {
// start the libuv event loop // start the libuv event loop
@ -339,7 +339,7 @@ fn async_init (
lp: uv_loop, lp: uv_loop,
async_cb: fn~(uv_handle), async_cb: fn~(uv_handle),
after_cb: fn~(uv_handle)) { after_cb: fn~(uv_handle)) {
let msg = msg_async_init(async_cb, after_cb); let mut msg = msg_async_init(async_cb, after_cb);
let loop_chan = get_loop_chan_from_uv_loop(lp); let loop_chan = get_loop_chan_from_uv_loop(lp);
comm::send(loop_chan, msg); comm::send(loop_chan, msg);
} }
@ -363,7 +363,7 @@ fn close(h: uv_handle, cb: fn~()) {
} }
fn timer_init(lp: uv_loop, after_cb: fn~(uv_handle)) { fn timer_init(lp: uv_loop, after_cb: fn~(uv_handle)) {
let msg = msg_timer_init(after_cb); let mut msg = msg_timer_init(after_cb);
let loop_chan = get_loop_chan_from_uv_loop(lp); let loop_chan = get_loop_chan_from_uv_loop(lp);
comm::send(loop_chan, msg); comm::send(loop_chan, msg);
} }
@ -372,7 +372,7 @@ fn timer_start(the_timer: uv_handle, timeout: u32, repeat:u32,
timer_cb: fn~(uv_handle)) { timer_cb: fn~(uv_handle)) {
alt the_timer { alt the_timer {
uv_timer(id, lp) { uv_timer(id, lp) {
let msg = msg_timer_start(id, timeout, repeat, timer_cb); let mut msg = msg_timer_start(id, timeout, repeat, timer_cb);
let loop_chan = get_loop_chan_from_uv_loop(lp); let loop_chan = get_loop_chan_from_uv_loop(lp);
comm::send(loop_chan, msg); comm::send(loop_chan, msg);
} }
@ -387,7 +387,7 @@ fn timer_stop(the_timer: uv_handle, after_cb: fn~(uv_handle)) {
alt the_timer { alt the_timer {
uv_timer(id, lp) { uv_timer(id, lp) {
let loop_chan = get_loop_chan_from_uv_loop(lp); let loop_chan = get_loop_chan_from_uv_loop(lp);
let msg = msg_timer_stop(id, after_cb); let mut msg = msg_timer_stop(id, after_cb);
comm::send(loop_chan, msg); comm::send(loop_chan, msg);
} }
_ { _ {
@ -466,7 +466,7 @@ crust fn process_operation(
data: *uv_loop_data) unsafe { data: *uv_loop_data) unsafe {
let op_port = (*data).operation_port; let op_port = (*data).operation_port;
let loop_chan = get_loop_chan_from_data(data); let loop_chan = get_loop_chan_from_data(data);
let op_pending = comm::peek(op_port); let mut op_pending = comm::peek(op_port);
while(op_pending) { while(op_pending) {
alt comm::recv(op_port) { alt comm::recv(op_port) {
op_async_init(id) { op_async_init(id) {