Remove all uses of tuples from the compiler and stdlib
This commit is contained in:
parent
e123366bff
commit
aea537779e
45 changed files with 759 additions and 723 deletions
|
|
@ -17,21 +17,25 @@ type ebml_state = rec(ebml_tag ebml_tag, uint tag_pos, uint data_pos);
|
|||
// ebml reading
|
||||
type doc = rec(vec[u8] data, uint start, uint end);
|
||||
|
||||
fn vint_at(vec[u8] data, uint start) -> tup(uint, uint) {
|
||||
fn vint_at(vec[u8] data, uint start) -> rec(uint val, uint next) {
|
||||
auto a = data.(start);
|
||||
if (a & 0x80u8 != 0u8) { ret tup(a & 0x7fu8 as uint, start + 1u); }
|
||||
if (a & 0x80u8 != 0u8) {
|
||||
ret rec(val=a & 0x7fu8 as uint, next=start + 1u);
|
||||
}
|
||||
if (a & 0x40u8 != 0u8) {
|
||||
ret tup((a & 0x3fu8 as uint) << 8u | (data.(start + 1u) as uint),
|
||||
start + 2u);
|
||||
ret rec(val=(a & 0x3fu8 as uint) << 8u | (data.(start + 1u) as uint),
|
||||
next=start + 2u);
|
||||
} else if (a & 0x20u8 != 0u8) {
|
||||
ret tup((a & 0x1fu8 as uint) << 16u |
|
||||
ret rec(val=(a & 0x1fu8 as uint) << 16u |
|
||||
(data.(start + 1u) as uint) << 8u |
|
||||
(data.(start + 2u) as uint), start + 3u);
|
||||
(data.(start + 2u) as uint),
|
||||
next=start + 3u);
|
||||
} else if (a & 0x10u8 != 0u8) {
|
||||
ret tup((a & 0x0fu8 as uint) << 24u |
|
||||
ret rec(val=(a & 0x0fu8 as uint) << 24u |
|
||||
(data.(start + 1u) as uint) << 16u |
|
||||
(data.(start + 2u) as uint) << 8u |
|
||||
(data.(start + 3u) as uint), start + 4u);
|
||||
(data.(start + 3u) as uint),
|
||||
next=start + 4u);
|
||||
} else { log_err "vint too big"; fail; }
|
||||
}
|
||||
|
||||
|
|
@ -41,19 +45,19 @@ fn new_doc(vec[u8] data) -> doc {
|
|||
|
||||
fn doc_at(vec[u8] data, uint start) -> doc {
|
||||
auto elt_tag = vint_at(data, start);
|
||||
auto elt_size = vint_at(data, elt_tag._1);
|
||||
auto end = elt_size._1 + elt_size._0;
|
||||
ret rec(data=data, start=elt_size._1, end=end);
|
||||
auto elt_size = vint_at(data, elt_tag.next);
|
||||
auto end = elt_size.next + elt_size.val;
|
||||
ret rec(data=data, start=elt_size.next, end=end);
|
||||
}
|
||||
|
||||
fn maybe_get_doc(doc d, uint tg) -> option::t[doc] {
|
||||
auto pos = d.start;
|
||||
while (pos < d.end) {
|
||||
auto elt_tag = vint_at(d.data, pos);
|
||||
auto elt_size = vint_at(d.data, elt_tag._1);
|
||||
pos = elt_size._1 + elt_size._0;
|
||||
if (elt_tag._0 == tg) {
|
||||
ret some[doc](rec(data=d.data, start=elt_size._1, end=pos));
|
||||
auto elt_size = vint_at(d.data, elt_tag.next);
|
||||
pos = elt_size.next + elt_size.val;
|
||||
if (elt_tag.val == tg) {
|
||||
ret some[doc](rec(data=d.data, start=elt_size.next, end=pos));
|
||||
}
|
||||
}
|
||||
ret none[doc];
|
||||
|
|
@ -69,13 +73,14 @@ fn get_doc(doc d, uint tg) -> doc {
|
|||
}
|
||||
}
|
||||
|
||||
iter docs(doc d) -> tup(uint, doc) {
|
||||
iter docs(doc d) -> rec(uint tag, doc doc) {
|
||||
auto pos = d.start;
|
||||
while (pos < d.end) {
|
||||
auto elt_tag = vint_at(d.data, pos);
|
||||
auto elt_size = vint_at(d.data, elt_tag._1);
|
||||
pos = elt_size._1 + elt_size._0;
|
||||
put tup(elt_tag._0, rec(data=d.data, start=elt_size._1, end=pos));
|
||||
auto elt_size = vint_at(d.data, elt_tag.next);
|
||||
pos = elt_size.next + elt_size.val;
|
||||
put rec(tag=elt_tag.val,
|
||||
doc=rec(data=d.data, start=elt_size.next, end=pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,10 +88,10 @@ iter tagged_docs(doc d, uint tg) -> doc {
|
|||
auto pos = d.start;
|
||||
while (pos < d.end) {
|
||||
auto elt_tag = vint_at(d.data, pos);
|
||||
auto elt_size = vint_at(d.data, elt_tag._1);
|
||||
pos = elt_size._1 + elt_size._0;
|
||||
if (elt_tag._0 == tg) {
|
||||
put rec(data=d.data, start=elt_size._1, end=pos);
|
||||
auto elt_size = vint_at(d.data, elt_tag.next);
|
||||
pos = elt_size.next + elt_size.val;
|
||||
if (elt_tag.val == tg) {
|
||||
put rec(data=d.data, start=elt_size.next, end=pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,21 +17,25 @@ type ebml_state = rec(ebml_tag ebml_tag, uint tag_pos, uint data_pos);
|
|||
// ebml reading
|
||||
type doc = rec(@u8[] data, uint start, uint end);
|
||||
|
||||
fn vint_at(&u8[] data, uint start) -> tup(uint, uint) {
|
||||
fn vint_at(&u8[] data, uint start) -> rec(uint val, uint next) {
|
||||
auto a = data.(start);
|
||||
if (a & 0x80u8 != 0u8) { ret tup(a & 0x7fu8 as uint, start + 1u); }
|
||||
if (a & 0x80u8 != 0u8) {
|
||||
ret rec(val=a & 0x7fu8 as uint, next=start + 1u);
|
||||
}
|
||||
if (a & 0x40u8 != 0u8) {
|
||||
ret tup((a & 0x3fu8 as uint) << 8u | (data.(start + 1u) as uint),
|
||||
start + 2u);
|
||||
ret rec(val=(a & 0x3fu8 as uint) << 8u | (data.(start + 1u) as uint),
|
||||
next=start + 2u);
|
||||
} else if (a & 0x20u8 != 0u8) {
|
||||
ret tup((a & 0x1fu8 as uint) << 16u |
|
||||
ret rec(val=(a & 0x1fu8 as uint) << 16u |
|
||||
(data.(start + 1u) as uint) << 8u |
|
||||
(data.(start + 2u) as uint), start + 3u);
|
||||
(data.(start + 2u) as uint),
|
||||
next=start + 3u);
|
||||
} else if (a & 0x10u8 != 0u8) {
|
||||
ret tup((a & 0x0fu8 as uint) << 24u |
|
||||
ret rec(val=(a & 0x0fu8 as uint) << 24u |
|
||||
(data.(start + 1u) as uint) << 16u |
|
||||
(data.(start + 2u) as uint) << 8u |
|
||||
(data.(start + 3u) as uint), start + 4u);
|
||||
(data.(start + 3u) as uint),
|
||||
next=start + 4u);
|
||||
} else { log_err "vint too big"; fail; }
|
||||
}
|
||||
|
||||
|
|
@ -41,19 +45,19 @@ fn new_doc(&@u8[] data) -> doc {
|
|||
|
||||
fn doc_at(&@u8[] data, uint start) -> doc {
|
||||
auto elt_tag = vint_at(*data, start);
|
||||
auto elt_size = vint_at(*data, elt_tag._1);
|
||||
auto end = elt_size._1 + elt_size._0;
|
||||
ret rec(data=data, start=elt_size._1, end=end);
|
||||
auto elt_size = vint_at(*data, elt_tag.next);
|
||||
auto end = elt_size.next + elt_size.val;
|
||||
ret rec(data=data, start=elt_size.next, end=end);
|
||||
}
|
||||
|
||||
fn maybe_get_doc(doc d, uint tg) -> option::t[doc] {
|
||||
auto pos = d.start;
|
||||
while (pos < d.end) {
|
||||
auto elt_tag = vint_at(*d.data, pos);
|
||||
auto elt_size = vint_at(*d.data, elt_tag._1);
|
||||
pos = elt_size._1 + elt_size._0;
|
||||
if (elt_tag._0 == tg) {
|
||||
ret some[doc](rec(data=d.data, start=elt_size._1, end=pos));
|
||||
auto elt_size = vint_at(*d.data, elt_tag.next);
|
||||
pos = elt_size.next + elt_size.val;
|
||||
if (elt_tag.val == tg) {
|
||||
ret some[doc](rec(data=d.data, start=elt_size.next, end=pos));
|
||||
}
|
||||
}
|
||||
ret none[doc];
|
||||
|
|
@ -69,13 +73,14 @@ fn get_doc(doc d, uint tg) -> doc {
|
|||
}
|
||||
}
|
||||
|
||||
iter docs(doc d) -> tup(uint, doc) {
|
||||
iter docs(doc d) -> rec(uint tag, doc doc) {
|
||||
auto pos = d.start;
|
||||
while (pos < d.end) {
|
||||
auto elt_tag = vint_at(*d.data, pos);
|
||||
auto elt_size = vint_at(*d.data, elt_tag._1);
|
||||
pos = elt_size._1 + elt_size._0;
|
||||
put tup(elt_tag._0, rec(data=d.data, start=elt_size._1, end=pos));
|
||||
auto elt_size = vint_at(*d.data, elt_tag.next);
|
||||
pos = elt_size.next + elt_size.val;
|
||||
put rec(tag=elt_tag.val,
|
||||
doc=rec(data=d.data, start=elt_size.next, end=pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,10 +88,10 @@ iter tagged_docs(doc d, uint tg) -> doc {
|
|||
auto pos = d.start;
|
||||
while (pos < d.end) {
|
||||
auto elt_tag = vint_at(*d.data, pos);
|
||||
auto elt_size = vint_at(*d.data, elt_tag._1);
|
||||
pos = elt_size._1 + elt_size._0;
|
||||
if (elt_tag._0 == tg) {
|
||||
put rec(data=d.data, start=elt_size._1, end=pos);
|
||||
auto elt_size = vint_at(*d.data, elt_tag.next);
|
||||
pos = elt_size.next + elt_size.val;
|
||||
if (elt_tag.val == tg) {
|
||||
put rec(data=d.data, start=elt_size.next, end=pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ fn rights[T, U](&(t[T, U])[] eithers) -> U[] {
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn partition[T, U](&(t[T, U])[] eithers) -> tup(T[], U[]) {
|
||||
fn partition[T, U](&(t[T, U])[] eithers)
|
||||
-> rec(T[] lefts, U[] rights) {
|
||||
let T[] lefts = ~[];
|
||||
let U[] rights = ~[];
|
||||
for (t[T, U] elt in eithers) {
|
||||
|
|
@ -47,7 +48,7 @@ fn partition[T, U](&(t[T, U])[] eithers) -> tup(T[], U[]) {
|
|||
case (right(?r)) { rights += ~[r] }
|
||||
}
|
||||
}
|
||||
ret tup(lefts, rights);
|
||||
ret rec(lefts=lefts, rights=rights);
|
||||
}
|
||||
//
|
||||
// Local Variables:
|
||||
|
|
|
|||
|
|
@ -96,66 +96,71 @@ mod ct {
|
|||
} else {
|
||||
buf = flush_buf(buf, pieces);
|
||||
auto rs = parse_conversion(s, i, lim, error);
|
||||
pieces += [rs._0];
|
||||
i = rs._1;
|
||||
pieces += [rs.piece];
|
||||
i = rs.next;
|
||||
}
|
||||
} else { buf += curr; i += 1u; }
|
||||
}
|
||||
buf = flush_buf(buf, pieces);
|
||||
ret pieces;
|
||||
}
|
||||
fn peek_num(str s, uint i, uint lim) -> option::t[tup(uint, uint)] {
|
||||
if (i >= lim) { ret none[tup(uint, uint)]; }
|
||||
fn peek_num(str s, uint i, uint lim)
|
||||
-> option::t[rec(uint num, uint next)] {
|
||||
if (i >= lim) { ret none; }
|
||||
auto c = s.(i);
|
||||
if (!('0' as u8 <= c && c <= '9' as u8)) {
|
||||
ret option::none[tup(uint, uint)];
|
||||
ret option::none;
|
||||
}
|
||||
auto n = c - ('0' as u8) as uint;
|
||||
ret alt (peek_num(s, i + 1u, lim)) {
|
||||
case (none) { some[tup(uint, uint)](tup(n, i + 1u)) }
|
||||
case (none) { some(rec(num=n, next=i + 1u)) }
|
||||
case (some(?next)) {
|
||||
auto m = next._0;
|
||||
auto j = next._1;
|
||||
some[tup(uint, uint)](tup(n * 10u + m, j))
|
||||
auto m = next.num;
|
||||
auto j = next.next;
|
||||
some(rec(num=n * 10u + m, next=j))
|
||||
}
|
||||
};
|
||||
}
|
||||
fn parse_conversion(str s, uint i, uint lim, error_fn error) ->
|
||||
tup(piece, uint) {
|
||||
fn parse_conversion(str s, uint i, uint lim, error_fn error)
|
||||
-> rec(piece piece, uint next) {
|
||||
auto parm = parse_parameter(s, i, lim);
|
||||
auto flags = parse_flags(s, parm._1, lim);
|
||||
auto width = parse_count(s, flags._1, lim);
|
||||
auto prec = parse_precision(s, width._1, lim);
|
||||
auto ty = parse_type(s, prec._1, lim, error);
|
||||
ret tup(piece_conv(rec(param=parm._0,
|
||||
flags=flags._0,
|
||||
width=width._0,
|
||||
precision=prec._0,
|
||||
ty=ty._0)), ty._1);
|
||||
auto flags = parse_flags(s, parm.next, lim);
|
||||
auto width = parse_count(s, flags.next, lim);
|
||||
auto prec = parse_precision(s, width.next, lim);
|
||||
auto ty = parse_type(s, prec.next, lim, error);
|
||||
ret rec(piece=piece_conv(rec(param=parm.param,
|
||||
flags=flags.flags,
|
||||
width=width.count,
|
||||
precision=prec.count,
|
||||
ty=ty.ty)),
|
||||
next=ty.next);
|
||||
}
|
||||
fn parse_parameter(str s, uint i, uint lim) -> tup(option::t[int], uint) {
|
||||
if (i >= lim) { ret tup(none[int], i); }
|
||||
fn parse_parameter(str s, uint i, uint lim)
|
||||
-> rec(option::t[int] param, uint next) {
|
||||
if (i >= lim) { ret rec(param=none, next=i); }
|
||||
auto num = peek_num(s, i, lim);
|
||||
ret alt (num) {
|
||||
case (none) { tup(none[int], i) }
|
||||
case (none) { rec(param=none, next=i) }
|
||||
case (some(?t)) {
|
||||
auto n = t._0;
|
||||
auto j = t._1;
|
||||
auto n = t.num;
|
||||
auto j = t.next;
|
||||
if (j < lim && s.(j) == '$' as u8) {
|
||||
tup(some[int](n as int), j + 1u)
|
||||
} else { tup(none[int], i) }
|
||||
rec(param=some(n as int), next=j + 1u)
|
||||
} else { rec(param=none, next=i) }
|
||||
}
|
||||
};
|
||||
}
|
||||
fn parse_flags(str s, uint i, uint lim) -> tup(vec[flag], uint) {
|
||||
fn parse_flags(str s, uint i, uint lim)
|
||||
-> rec(vec[flag] flags, uint next) {
|
||||
let vec[flag] noflags = [];
|
||||
if (i >= lim) { ret tup(noflags, i); }
|
||||
fn more_(flag f, str s, uint i, uint lim) -> tup(vec[flag], uint) {
|
||||
if (i >= lim) { ret rec(flags=noflags, next=i); }
|
||||
fn more_(flag f, str s, uint i, uint lim)
|
||||
-> rec(vec[flag] flags, uint next) {
|
||||
auto next = parse_flags(s, i + 1u, lim);
|
||||
auto rest = next._0;
|
||||
auto j = next._1;
|
||||
auto rest = next.flags;
|
||||
auto j = next.next;
|
||||
let vec[flag] curr = [f];
|
||||
ret tup(curr + rest, j);
|
||||
ret rec(flags=curr + rest, next=j);
|
||||
}
|
||||
auto more = bind more_(_, s, i, lim);
|
||||
auto f = s.(i);
|
||||
|
|
@ -169,41 +174,46 @@ mod ct {
|
|||
more(flag_sign_always)
|
||||
} else if (f == '#' as u8) {
|
||||
more(flag_alternate)
|
||||
} else { tup(noflags, i) };
|
||||
} else { rec(flags=noflags, next=i) };
|
||||
}
|
||||
fn parse_count(str s, uint i, uint lim) -> tup(count, uint) {
|
||||
fn parse_count(str s, uint i, uint lim)
|
||||
-> rec(count count, uint next) {
|
||||
ret if (i >= lim) {
|
||||
tup(count_implied, i)
|
||||
rec(count=count_implied, next=i)
|
||||
} else if (s.(i) == '*' as u8) {
|
||||
auto param = parse_parameter(s, i + 1u, lim);
|
||||
auto j = param._1;
|
||||
alt (param._0) {
|
||||
case (none) { tup(count_is_next_param, j) }
|
||||
case (some(?n)) { tup(count_is_param(n), j) }
|
||||
auto j = param.next;
|
||||
alt (param.param) {
|
||||
case (none) { rec(count=count_is_next_param, next=j) }
|
||||
case (some(?n)) { rec(count=count_is_param(n), next=j) }
|
||||
}
|
||||
} else {
|
||||
auto num = peek_num(s, i, lim);
|
||||
alt (num) {
|
||||
case (none) { tup(count_implied, i) }
|
||||
case (some(?num)) { tup(count_is(num._0 as int), num._1) }
|
||||
case (none) { rec(count=count_implied, next=i) }
|
||||
case (some(?num)) { rec(count=count_is(num.num as int),
|
||||
next=num.next) }
|
||||
}
|
||||
};
|
||||
}
|
||||
fn parse_precision(str s, uint i, uint lim) -> tup(count, uint) {
|
||||
fn parse_precision(str s, uint i, uint lim)
|
||||
-> rec(count count, uint next) {
|
||||
ret if (i >= lim) {
|
||||
tup(count_implied, i)
|
||||
rec(count=count_implied, next=i)
|
||||
} else if (s.(i) == '.' as u8) {
|
||||
auto count = parse_count(s, i + 1u, lim);
|
||||
|
||||
// If there were no digits specified, i.e. the precision
|
||||
// was ".", then the precision is 0
|
||||
alt (count._0) {
|
||||
case (count_implied) { tup(count_is(0), count._1) }
|
||||
alt (count.count) {
|
||||
case (count_implied) { rec(count=count_is(0),
|
||||
next=count.next) }
|
||||
case (_) { count }
|
||||
}
|
||||
} else { tup(count_implied, i) };
|
||||
} else { rec(count=count_implied, next=i) };
|
||||
}
|
||||
fn parse_type(str s, uint i, uint lim, error_fn error) -> tup(ty, uint) {
|
||||
fn parse_type(str s, uint i, uint lim, error_fn error)
|
||||
-> rec(ty ty, uint next) {
|
||||
if (i >= lim) { error("missing type in conversion"); }
|
||||
auto tstr = str::substr(s, i, 1u);
|
||||
auto t =
|
||||
|
|
@ -229,7 +239,7 @@ mod ct {
|
|||
} else if (str::eq(tstr, "o")) {
|
||||
ty_octal
|
||||
} else { error("unknown type in conversion: " + tstr) };
|
||||
ret tup(t, i + 1u);
|
||||
ret rec(ty=t, next=i + 1u);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -165,8 +165,8 @@ fn getopts_ivec(&str[] args, &opt[] opts) -> result {
|
|||
names = ~[];
|
||||
while (j < curlen) {
|
||||
auto range = str::char_range_at(cur, j);
|
||||
names += ~[short(range._0)];
|
||||
j = range._1;
|
||||
names += ~[short(range.ch)];
|
||||
j = range.next;
|
||||
}
|
||||
}
|
||||
auto name_pos = 0u;
|
||||
|
|
|
|||
|
|
@ -257,29 +257,29 @@ fn find[T](fn(&T) -> bool f, &T[] v) -> option::t[T] {
|
|||
ret none[T];
|
||||
}
|
||||
|
||||
fn unzip[T, U](&tup(T, U)[] v) -> tup(T[], U[]) {
|
||||
auto sz = len[tup(T, U)](v);
|
||||
fn unzip[T, U](&rec(T _0, U _1)[] v) -> rec(T[] _0, U[] _1) {
|
||||
auto sz = len(v);
|
||||
if (sz == 0u) {
|
||||
ret tup(~[], ~[]);
|
||||
ret rec(_0=~[], _1=~[]);
|
||||
} else {
|
||||
auto rest = slice[tup(T, U)](v, 1u, sz);
|
||||
auto tl = unzip[T, U](rest);
|
||||
auto rest = slice(v, 1u, sz);
|
||||
auto tl = unzip(rest);
|
||||
auto a = ~[v.(0)._0];
|
||||
auto b = ~[v.(0)._1];
|
||||
ret tup(a + tl._0, b + tl._1);
|
||||
ret rec(_0=a + tl._0, _1=b + tl._1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// FIXME make the lengths being equal a constraint
|
||||
fn zip[T, U](&T[] v, &U[] u) -> tup(T, U)[] {
|
||||
auto sz = len[T](v);
|
||||
assert (sz == len[U](u));
|
||||
fn zip[T, U](&T[] v, &U[] u) -> rec(T _0, U _1)[] {
|
||||
auto sz = len(v);
|
||||
assert (sz == len(u));
|
||||
if (sz == 0u) {
|
||||
ret ~[];
|
||||
} else {
|
||||
auto rest = zip[T, U](slice[T](v, 1u, sz), slice[U](u, 1u, sz));
|
||||
ret ~[tup(v.(0), u.(0))] + rest;
|
||||
auto rest = zip(slice(v, 1u, sz), slice(u, 1u, sz));
|
||||
ret ~[rec(_0=v.(0), _1=u.(0))] + rest;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,10 +66,10 @@ fn target_os() -> str { ret "linux"; }
|
|||
|
||||
fn dylib_filename(str base) -> str { ret "lib" + base + ".so"; }
|
||||
|
||||
fn pipe() -> tup(int, int) {
|
||||
auto fds = tup(mutable 0, 0);
|
||||
assert (os::libc::pipe(ptr::addr_of(fds._0)) == 0);
|
||||
ret tup(fds._0, fds._1);
|
||||
fn pipe() -> rec(int in, int out) {
|
||||
auto fds = rec(mutable in=0, mutable out=0);
|
||||
assert (os::libc::pipe(ptr::addr_of(fds.in)) == 0);
|
||||
ret rec(in=fds.in, out=fds.out);
|
||||
}
|
||||
|
||||
fn fd_FILE(int fd) -> libc::FILE { ret libc::fdopen(fd, str::buf("r")); }
|
||||
|
|
|
|||
|
|
@ -63,10 +63,10 @@ fn target_os() -> str { ret "macos"; }
|
|||
|
||||
fn dylib_filename(str base) -> str { ret "lib" + base + ".dylib"; }
|
||||
|
||||
fn pipe() -> tup(int, int) {
|
||||
auto fds = tup(mutable 0, 0);
|
||||
assert (os::libc::pipe(ptr::addr_of(fds._0)) == 0);
|
||||
ret tup(fds._0, fds._1);
|
||||
fn pipe() -> rec(int in, int out) {
|
||||
auto fds = rec(mutable in=0, mutable out=0);
|
||||
assert (os::libc::pipe(ptr::addr_of(fds.in)) == 0);
|
||||
ret rec(in=fds.in, out=fds.out);
|
||||
}
|
||||
|
||||
fn fd_FILE(int fd) -> libc::FILE { ret libc::fdopen(fd, str::buf("r")); }
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ type hashmap[K, V] =
|
|||
fn find(&K) -> option::t[V] ;
|
||||
fn remove(&K) -> option::t[V] ;
|
||||
fn rehash() ;
|
||||
iter items() -> @tup(K, V) ;
|
||||
iter items() -> @rec(K key, V val);
|
||||
iter keys() -> K ;
|
||||
};
|
||||
type hashset[K] = hashmap[K, ()];
|
||||
|
|
@ -185,10 +185,10 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
|
|||
rehash[K, V](hasher, eqer, bkts, nbkts, newbkts, nbkts);
|
||||
bkts = newbkts;
|
||||
}
|
||||
iter items() -> @tup(K, V) {
|
||||
iter items() -> @rec(K key, V val) {
|
||||
for (bucket[K, V] b in bkts) {
|
||||
alt (b) {
|
||||
case (some(?k, ?v)) { put @tup(k, v); }
|
||||
case (some(?k, ?v)) { put @rec(key=k, val=v); }
|
||||
case (_) { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,11 +44,11 @@ type program =
|
|||
fn start_program(str prog, vec[str] args) -> @program {
|
||||
auto pipe_input = os::pipe();
|
||||
auto pipe_output = os::pipe();
|
||||
auto pid = spawn_process(prog, args, pipe_input._0, pipe_output._1, 0);
|
||||
auto pid = spawn_process(prog, args, pipe_input.in, pipe_output.out, 0);
|
||||
|
||||
if (pid == -1) { fail; }
|
||||
os::libc::close(pipe_input._0);
|
||||
os::libc::close(pipe_output._1);
|
||||
os::libc::close(pipe_input.in);
|
||||
os::libc::close(pipe_output.out);
|
||||
obj new_program(int pid,
|
||||
mutable int in_fd,
|
||||
os::libc::FILE out_file,
|
||||
|
|
@ -80,7 +80,7 @@ fn start_program(str prog, vec[str] args) -> @program {
|
|||
os::libc::fclose(out_file);
|
||||
}
|
||||
}
|
||||
ret @new_program(pid, pipe_input._1, os::fd_FILE(pipe_output._0), false);
|
||||
ret @new_program(pid, pipe_input.out, os::fd_FILE(pipe_output.in), false);
|
||||
}
|
||||
|
||||
fn program_output(str prog, vec[str] args) -> rec(int status, str out) {
|
||||
|
|
|
|||
|
|
@ -262,11 +262,11 @@ fn utf8_char_width(u8 b) -> uint {
|
|||
ret 6u;
|
||||
}
|
||||
|
||||
fn char_range_at(str s, uint i) -> tup(char, uint) {
|
||||
fn char_range_at(str s, uint i) -> rec(char ch, uint next) {
|
||||
auto b0 = s.(i);
|
||||
auto w = utf8_char_width(b0);
|
||||
assert (w != 0u);
|
||||
if (w == 1u) { ret tup(b0 as char, i + 1u); }
|
||||
if (w == 1u) { ret rec(ch=b0 as char, next=i + 1u); }
|
||||
auto val = 0u;
|
||||
auto end = i + w;
|
||||
i += 1u;
|
||||
|
|
@ -282,10 +282,10 @@ fn char_range_at(str s, uint i) -> tup(char, uint) {
|
|||
// a second (as uint) to get it to the right position.
|
||||
|
||||
val += (b0 << (w + 1u as u8) as uint) << (w - 1u) * 6u - w - 1u;
|
||||
ret tup(val as char, i);
|
||||
ret rec(ch=val as char, next=i);
|
||||
}
|
||||
|
||||
fn char_at(str s, uint i) -> char { ret char_range_at(s, i)._0; }
|
||||
fn char_at(str s, uint i) -> char { ret char_range_at(s, i).ch; }
|
||||
|
||||
fn char_len(str s) -> uint {
|
||||
auto i = 0u;
|
||||
|
|
@ -307,8 +307,8 @@ fn to_chars(str s) -> vec[char] {
|
|||
auto len = byte_len(s);
|
||||
while (i < len) {
|
||||
auto cur = char_range_at(s, i);
|
||||
vec::push[char](buf, cur._0);
|
||||
i = cur._1;
|
||||
vec::push[char](buf, cur.ch);
|
||||
i = cur.next;
|
||||
}
|
||||
ret buf;
|
||||
}
|
||||
|
|
@ -326,8 +326,8 @@ fn pop_char(&mutable str s) -> char {
|
|||
|
||||
fn shift_char(&mutable str s) -> char {
|
||||
auto r = char_range_at(s, 0u);
|
||||
s = substr(s, r._1, byte_len(s) - r._1);
|
||||
ret r._0;
|
||||
s = substr(s, r.next, byte_len(s) - r.next);
|
||||
ret r.ch;
|
||||
}
|
||||
|
||||
fn unshift_char(&mutable str s, char ch) {
|
||||
|
|
|
|||
|
|
@ -15,10 +15,6 @@ fn rational_leq(&rational x, &rational y) -> bool {
|
|||
ret x.num * y.den <= y.num * x.den;
|
||||
}
|
||||
|
||||
fn fst[T, U](&tup(T, U) x) -> T { ret x._0; }
|
||||
|
||||
fn snd[T, U](&tup(T, U) x) -> U { ret x._1; }
|
||||
|
||||
fn orb(&bool a, &bool b) -> bool { ret a || b; }
|
||||
// Local Variables:
|
||||
// mode: rust;
|
||||
|
|
|
|||
|
|
@ -266,29 +266,29 @@ fn foldl[T, U](fn(&U, &T) -> U p, &U z, &vec[T] v) -> U {
|
|||
}
|
||||
}
|
||||
|
||||
fn unzip[T, U](&vec[tup(T, U)] v) -> tup(vec[T], vec[U]) {
|
||||
auto sz = len[tup(T, U)](v);
|
||||
fn unzip[T, U](&vec[rec(T _0, U _1)] v) -> rec(vec[T] _0, vec[U] _1) {
|
||||
auto sz = len(v);
|
||||
if (sz == 0u) {
|
||||
ret tup(alloc[T](0u), alloc[U](0u));
|
||||
ret rec(_0=alloc[T](0u), _1=alloc[U](0u));
|
||||
} else {
|
||||
auto rest = slice[tup(T, U)](v, 1u, sz);
|
||||
auto rest = slice(v, 1u, sz);
|
||||
auto tl = unzip[T, U](rest);
|
||||
auto a = [v.(0)._0];
|
||||
auto b = [v.(0)._1];
|
||||
ret tup(a + tl._0, b + tl._1);
|
||||
ret rec(_0=a + tl._0, _1=b + tl._1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// FIXME make the lengths being equal a constraint
|
||||
fn zip[T, U](&vec[T] v, &vec[U] u) -> vec[tup(T, U)] {
|
||||
auto sz = len[T](v);
|
||||
assert (sz == len[U](u));
|
||||
fn zip[T, U](&vec[T] v, &vec[U] u) -> vec[rec(T _0, U _1)] {
|
||||
auto sz = len(v);
|
||||
assert (sz == len(u));
|
||||
if (sz == 0u) {
|
||||
ret alloc[tup(T, U)](0u);
|
||||
ret alloc(0u);
|
||||
} else {
|
||||
auto rest = zip[T, U](slice[T](v, 1u, sz), slice[U](u, 1u, sz));
|
||||
vec::push(rest, tup(v.(0), u.(0)));
|
||||
auto rest = zip(slice(v, 1u, sz), slice(u, 1u, sz));
|
||||
vec::push(rest, rec(_0=v.(0), _1=u.(0)));
|
||||
ret rest;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,11 +59,11 @@ fn target_os() -> str { ret "win32"; }
|
|||
|
||||
fn dylib_filename(str base) -> str { ret base + ".dll"; }
|
||||
|
||||
fn pipe() -> tup(int, int) {
|
||||
auto fds = tup(mutable 0, 0);
|
||||
assert (os::libc::_pipe(ptr::addr_of(fds._0), 1024u,
|
||||
fn pipe() -> rec(int in, int out) {
|
||||
auto fds = rec(mutable int=0, mutable out=0);
|
||||
assert (os::libc::_pipe(ptr::addr_of(fds.in), 1024u,
|
||||
libc_constants::O_BINARY()) == 0);
|
||||
ret tup(fds._0, fds._1);
|
||||
ret rec(in=fds.in, out=fds.out);
|
||||
}
|
||||
|
||||
fn fd_FILE(int fd) -> libc::FILE { ret libc::_fdopen(fd, str::buf("r")); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue