Rename std modules to be camelcased

(Have fun mergining your stuff with this.)
This commit is contained in:
Marijn Haverbeke 2011-05-06 22:13:13 +02:00
parent 44c1621525
commit a3ec0b1f64
100 changed files with 2150 additions and 2151 deletions

View file

@ -21,19 +21,19 @@ fn create(uint nbits, bool init) -> t {
elt = 0u;
}
auto storage = _vec.init_elt_mut[uint](elt, nbits / uint_bits() + 1u);
auto storage = Vec.init_elt_mut[uint](elt, nbits / uint_bits() + 1u);
ret rec(storage = storage, nbits = nbits);
}
fn process(&fn(uint, uint) -> uint op, &t v0, &t v1) -> bool {
auto len = _vec.len(v1.storage);
auto len = Vec.len(v1.storage);
assert (_vec.len(v0.storage) == len);
assert (Vec.len(v0.storage) == len);
assert (v0.nbits == v1.nbits);
auto changed = false;
for each (uint i in _uint.range(0u, len)) {
for each (uint i in UInt.range(0u, len)) {
auto w0 = v0.storage.(i);
auto w1 = v1.storage.(i);
@ -75,9 +75,9 @@ fn copy(&t v0, t v1) -> bool {
}
fn clone(t v) -> t {
auto storage = _vec.init_elt_mut[uint](0u, v.nbits / uint_bits() + 1u);
auto len = _vec.len(v.storage);
for each (uint i in _uint.range(0u, len)) {
auto storage = Vec.init_elt_mut[uint](0u, v.nbits / uint_bits() + 1u);
auto len = Vec.len(v.storage);
for each (uint i in UInt.range(0u, len)) {
storage.(i) = v.storage.(i);
}
ret rec(storage = storage, nbits = v.nbits);
@ -97,7 +97,7 @@ fn get(&t v, uint i) -> bool {
fn equal(&t v0, &t v1) -> bool {
// FIXME: when we can break or return from inside an iterator loop,
// we can eliminate this painful while-loop
auto len = _vec.len(v1.storage);
auto len = Vec.len(v1.storage);
auto i = 0u;
while (i < len) {
if (v0.storage.(i) != v1.storage.(i)) {
@ -109,13 +109,13 @@ fn equal(&t v0, &t v1) -> bool {
}
fn clear(&t v) {
for each (uint i in _uint.range(0u, _vec.len(v.storage))) {
for each (uint i in UInt.range(0u, Vec.len(v.storage))) {
v.storage.(i) = 0u;
}
}
fn invert(&t v) {
for each (uint i in _uint.range(0u, _vec.len(v.storage))) {
for each (uint i in UInt.range(0u, Vec.len(v.storage))) {
v.storage.(i) = ~v.storage.(i);
}
}
@ -176,13 +176,13 @@ fn init_to_vec(t v, uint i) -> uint {
fn to_vec(&t v) -> vec[uint] {
auto sub = bind init_to_vec(v, _);
ret _vec.init_fn[uint](sub, v.nbits);
ret Vec.init_fn[uint](sub, v.nbits);
}
fn to_str(&t v) -> str {
auto res = "";
for (uint i in bitv.to_vec(v)) {
for (uint i in BitV.to_vec(v)) {
if (i == 1u) {
res += "1";
}
@ -196,7 +196,7 @@ fn to_str(&t v) -> str {
// FIXME: can we just use structural equality on to_vec?
fn eq_vec(&t v0, &vec[uint] v1) -> bool {
assert (v0.nbits == _vec.len[uint](v1));
assert (v0.nbits == Vec.len[uint](v1));
auto len = v0.nbits;
auto i = 0u;
while (i < len) {

View file

@ -20,7 +20,7 @@ native "rust" mod rustrt {
}
fn debug_vec[T](vec[T] v) {
_vec.print_debug_info[T](v);
Vec.print_debug_info[T](v);
}
fn debug_tydesc[T]() {

View file

@ -19,7 +19,7 @@ type t[T] = obj {
fn create[T]() -> t[T] {
type cell[T] = option.t[T];
type cell[T] = Option.t[T];
let uint initial_capacity = 32u; // 2^5
@ -28,25 +28,25 @@ fn create[T]() -> t[T] {
* elsewhere.
*/
fn grow[T](uint nelts, uint lo, vec[cell[T]] elts) -> vec[cell[T]] {
assert (nelts == _vec.len[cell[T]](elts));
assert (nelts == Vec.len[cell[T]](elts));
fn fill[T](uint i, uint nelts, uint lo,
vec[cell[T]] old) -> cell[T] {
if (i < nelts) {
ret old.((lo + i) % nelts);
} else {
ret option.none[T];
ret Option.none[T];
}
}
let uint nalloc = _uint.next_power_of_two(nelts + 1u);
let _vec.init_op[cell[T]] copy_op = bind fill[T](_, nelts, lo, elts);
ret _vec.init_fn[cell[T]](copy_op, nalloc);
let uint nalloc = UInt.next_power_of_two(nelts + 1u);
let Vec.init_op[cell[T]] copy_op = bind fill[T](_, nelts, lo, elts);
ret Vec.init_fn[cell[T]](copy_op, nalloc);
}
fn get[T](vec[cell[T]] elts, uint i) -> T {
alt (elts.(i)) {
case (option.some[T](?t)) { ret t; }
case (Option.some[T](?t)) { ret t; }
case (_) { fail; }
}
fail; // FIXME: remove me when exhaustiveness checking works
@ -63,18 +63,18 @@ fn create[T]() -> t[T] {
let uint oldlo = lo;
if (lo == 0u) {
lo = _vec.len[cell[T]](elts) - 1u;
lo = Vec.len[cell[T]](elts) - 1u;
} else {
lo -= 1u;
}
if (lo == hi) {
elts = grow[T](nelts, oldlo, elts);
lo = _vec.len[cell[T]](elts) - 1u;
lo = Vec.len[cell[T]](elts) - 1u;
hi = nelts;
}
elts.(lo) = option.some[T](t);
elts.(lo) = Option.some[T](t);
nelts += 1u;
}
@ -85,8 +85,8 @@ fn create[T]() -> t[T] {
hi = nelts;
}
elts.(hi) = option.some[T](t);
hi = (hi + 1u) % _vec.len[cell[T]](elts);
elts.(hi) = Option.some[T](t);
hi = (hi + 1u) % Vec.len[cell[T]](elts);
nelts += 1u;
}
@ -96,21 +96,21 @@ fn create[T]() -> t[T] {
*/
fn pop_front() -> T {
let T t = get[T](elts, lo);
elts.(lo) = option.none[T];
lo = (lo + 1u) % _vec.len[cell[T]](elts);
elts.(lo) = Option.none[T];
lo = (lo + 1u) % Vec.len[cell[T]](elts);
nelts -= 1u;
ret t;
}
fn pop_back() -> T {
if (hi == 0u) {
hi = _vec.len[cell[T]](elts) - 1u;
hi = Vec.len[cell[T]](elts) - 1u;
} else {
hi -= 1u;
}
let T t = get[T](elts, hi);
elts.(hi) = option.none[T];
elts.(hi) = Option.none[T];
nelts -= 1u;
ret t;
}
@ -124,12 +124,12 @@ fn create[T]() -> t[T] {
}
fn get(int i) -> T {
let uint idx = (lo + (i as uint)) % _vec.len[cell[T]](elts);
let uint idx = (lo + (i as uint)) % Vec.len[cell[T]](elts);
ret get[T](elts, idx);
}
}
let vec[cell[T]] v = _vec.init_elt[cell[T]](option.none[T],
let vec[cell[T]] v = Vec.init_elt[cell[T]](Option.none[T],
initial_capacity);
ret deque[T](0u, 0u, 0u, v);

View file

@ -2,8 +2,8 @@
// cursor model. See the specification here:
// http://www.matroska.org/technical/specs/rfc/index.html
import option.none;
import option.some;
import Option.none;
import Option.some;
type ebml_tag = rec(uint id, uint size);
type ebml_state = rec(ebml_tag ebml_tag, uint tag_pos, uint data_pos);
@ -38,7 +38,7 @@ fn vint_at(vec[u8] data, uint start) -> tup(uint, uint) {
}
fn new_doc(vec[u8] data) -> doc {
ret rec(data=data, start=0u, end=_vec.len[u8](data));
ret rec(data=data, start=0u, end=Vec.len[u8](data));
}
fn doc_at(vec[u8] data, uint start) -> doc {
@ -48,7 +48,7 @@ fn doc_at(vec[u8] data, uint start) -> doc {
ret rec(data=data, start=elt_size._1, end=end);
}
fn maybe_get_doc(doc d, uint tg) -> option.t[doc] {
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);
@ -65,7 +65,7 @@ fn get_doc(doc d, uint tg) -> doc {
alt (maybe_get_doc(d, tg)) {
case (some[doc](?d)) {ret d;}
case (none[doc]) {
log_err "failed to find block with tag " + _uint.to_str(tg, 10u);
log_err "failed to find block with tag " + UInt.to_str(tg, 10u);
fail;
}
}
@ -94,7 +94,7 @@ iter tagged_docs(doc d, uint tg) -> doc {
}
fn doc_data(doc d) -> vec[u8] {
ret _vec.slice[u8](d.data, d.start, d.end);
ret Vec.slice[u8](d.data, d.start, d.end);
}
fn be_uint_from_bytes(vec[u8] data, uint start, uint size) -> uint {
@ -116,9 +116,9 @@ fn doc_as_uint(doc d) -> uint {
// EBML writing
type writer = rec(io.buf_writer writer, mutable vec[uint] size_positions);
type writer = rec(IO.buf_writer writer, mutable vec[uint] size_positions);
fn write_sized_vint(&io.buf_writer w, uint n, uint size) {
fn write_sized_vint(&IO.buf_writer w, uint n, uint size) {
let vec[u8] buf;
alt (size) {
case (1u) {
@ -148,7 +148,7 @@ fn write_sized_vint(&io.buf_writer w, uint n, uint size) {
w.write(buf);
}
fn write_vint(&io.buf_writer w, uint n) {
fn write_vint(&IO.buf_writer w, uint n) {
if (n < 0x7fu) { write_sized_vint(w, n, 1u); ret; }
if (n < 0x4000u) { write_sized_vint(w, n, 2u); ret; }
if (n < 0x200000u) { write_sized_vint(w, n, 3u); ret; }
@ -157,7 +157,7 @@ fn write_vint(&io.buf_writer w, uint n) {
fail;
}
fn create_writer(&io.buf_writer w) -> writer {
fn create_writer(&IO.buf_writer w) -> writer {
let vec[uint] size_positions = vec();
ret rec(writer=w, mutable size_positions=size_positions);
}
@ -175,11 +175,11 @@ fn start_tag(&writer w, uint tag_id) {
}
fn end_tag(&writer w) {
auto last_size_pos = _vec.pop[uint](w.size_positions);
auto last_size_pos = Vec.pop[uint](w.size_positions);
auto cur_pos = w.writer.tell();
w.writer.seek(last_size_pos as int, io.seek_set);
w.writer.seek(last_size_pos as int, IO.seek_set);
write_sized_vint(w.writer, cur_pos - last_size_pos - 4u, 4u);
w.writer.seek(cur_pos as int, io.seek_set);
w.writer.seek(cur_pos as int, IO.seek_set);
}
// TODO: optionally perform "relaxations" on end_tag to more efficiently

View file

@ -13,8 +13,8 @@
* combinations at the moment.
*/
import option.none;
import option.some;
import Option.none;
import Option.some;
/*
* We have a CT (compile-time) module that parses format strings into a
@ -66,7 +66,7 @@ mod CT {
}
// A formatted conversion from an expression to a string
type conv = rec(option.t[int] param,
type conv = rec(Option.t[int] param,
vec[flag] flags,
count width,
count precision,
@ -80,11 +80,11 @@ mod CT {
fn parse_fmt_string(str s) -> vec[piece] {
let vec[piece] pieces = vec();
auto lim = _str.byte_len(s);
auto lim = Str.byte_len(s);
auto buf = "";
fn flush_buf(str buf, &vec[piece] pieces) -> str {
if (_str.byte_len(buf) > 0u) {
if (Str.byte_len(buf) > 0u) {
auto piece = piece_string(buf);
pieces += vec(piece);
}
@ -93,15 +93,15 @@ mod CT {
auto i = 0u;
while (i < lim) {
auto curr = _str.substr(s, i, 1u);
if (_str.eq(curr, "%")) {
auto curr = Str.substr(s, i, 1u);
if (Str.eq(curr, "%")) {
i += 1u;
if (i >= lim) {
log_err "unterminated conversion at end of string";
fail;
}
auto curr2 = _str.substr(s, i, 1u);
if (_str.eq(curr2, "%")) {
auto curr2 = Str.substr(s, i, 1u);
if (Str.eq(curr2, "%")) {
i += 1u;
} else {
buf = flush_buf(buf, pieces);
@ -118,14 +118,14 @@ mod CT {
ret pieces;
}
fn peek_num(str s, uint i, uint lim) -> option.t[tup(uint, uint)] {
fn peek_num(str s, uint i, uint lim) -> Option.t[tup(uint, uint)] {
if (i >= lim) {
ret none[tup(uint, uint)];
}
auto c = s.(i);
if (!('0' as u8 <= c && c <= '9' as u8)) {
ret option.none[tup(uint, uint)];
ret Option.none[tup(uint, uint)];
}
auto n = (c - ('0' as u8)) as uint;
@ -156,7 +156,7 @@ mod CT {
ty._1);
}
fn parse_parameter(str s, uint i, uint lim) -> tup(option.t[int], uint) {
fn parse_parameter(str s, uint i, uint lim) -> tup(Option.t[int], uint) {
if (i >= lim) {
ret tup(none[int], i);
}
@ -270,27 +270,27 @@ mod CT {
}
auto t;
auto tstr = _str.substr(s, i, 1u);
if (_str.eq(tstr, "b")) {
auto tstr = Str.substr(s, i, 1u);
if (Str.eq(tstr, "b")) {
t = ty_bool;
} else if (_str.eq(tstr, "s")) {
} else if (Str.eq(tstr, "s")) {
t = ty_str;
} else if (_str.eq(tstr, "c")) {
} else if (Str.eq(tstr, "c")) {
t = ty_char;
} else if (_str.eq(tstr, "d")
|| _str.eq(tstr, "i")) {
} else if (Str.eq(tstr, "d")
|| Str.eq(tstr, "i")) {
// TODO: Do we really want two signed types here?
// How important is it to be printf compatible?
t = ty_int(signed);
} else if (_str.eq(tstr, "u")) {
} else if (Str.eq(tstr, "u")) {
t = ty_int(unsigned);
} else if (_str.eq(tstr, "x")) {
} else if (Str.eq(tstr, "x")) {
t = ty_hex(case_lower);
} else if (_str.eq(tstr, "X")) {
} else if (Str.eq(tstr, "X")) {
t = ty_hex(case_upper);
} else if (_str.eq(tstr, "t")) {
} else if (Str.eq(tstr, "t")) {
t = ty_bits;
} else if (_str.eq(tstr, "o")) {
} else if (Str.eq(tstr, "o")) {
t = ty_octal;
} else {
log_err "unknown type in conversion";
@ -364,7 +364,7 @@ mod RT {
res = uint_to_str_prec(u, 16u, prec);
}
case (ty_hex_upper) {
res = _str.to_upper(uint_to_str_prec(u, 16u, prec));
res = Str.to_upper(uint_to_str_prec(u, 16u, prec));
}
case (ty_bits) {
res = uint_to_str_prec(u, 2u, prec);
@ -389,7 +389,7 @@ mod RT {
}
fn conv_char(&conv cv, char c) -> str {
ret pad(cv, _str.from_char(c), pad_nozero);
ret pad(cv, Str.from_char(c), pad_nozero);
}
fn conv_str(&conv cv, str s) -> str {
@ -399,9 +399,9 @@ mod RT {
}
case (count_is(?max)) {
// For strings, precision is the maximum characters displayed
if (max as uint < _str.char_len(s)) {
if (max as uint < Str.char_len(s)) {
// FIXME: substr works on bytes, not chars!
unpadded = _str.substr(s, 0u, max as uint);
unpadded = Str.substr(s, 0u, max as uint);
}
}
}
@ -420,15 +420,15 @@ mod RT {
// Convert a uint to string with a minimum number of digits. If precision
// is 0 and num is 0 then the result is the empty string. Could move this
// to _uint, but it doesn't seem all that useful.
// to UInt. but it doesn't seem all that useful.
fn uint_to_str_prec(uint num, uint radix, uint prec) -> str {
auto s;
if (prec == 0u && num == 0u) {
s = "";
} else {
s = _uint.to_str(num, radix);
auto len = _str.char_len(s);
s = UInt.to_str(num, radix);
auto len = Str.char_len(s);
if (len < prec) {
auto diff = prec - len;
auto pad = str_init_elt('0', diff);
@ -450,12 +450,12 @@ mod RT {
}
}
// FIXME: This might be useful in _str, but needs to be utf8 safe first
// FIXME: This might be useful in Str. but needs to be utf8 safe first
fn str_init_elt(char c, uint n_elts) -> str {
auto svec = _vec.init_elt[u8](c as u8, n_elts);
auto svec = Vec.init_elt[u8](c as u8, n_elts);
// FIXME: Using unsafe_from_bytes because rustboot
// can't figure out the is_utf8 predicate on from_bytes?
ret _str.unsafe_from_bytes(svec);
ret Str.unsafe_from_bytes(svec);
}
tag pad_mode {
@ -476,7 +476,7 @@ mod RT {
}
}
auto strlen = _str.char_len(s);
auto strlen = Str.char_len(s);
if (uwidth <= strlen) {
ret s;
}
@ -532,16 +532,16 @@ mod RT {
// instead.
if (signed
&& zero_padding
&& _str.byte_len(s) > 0u) {
&& Str.byte_len(s) > 0u) {
auto head = s.(0);
if (head == '+' as u8
|| head == '-' as u8
|| head == ' ' as u8) {
auto headstr = _str.unsafe_from_bytes(vec(head));
auto bytelen = _str.byte_len(s);
auto numpart = _str.substr(s, 1u, bytelen - 1u);
auto headstr = Str.unsafe_from_bytes(vec(head));
auto bytelen = Str.byte_len(s);
auto numpart = Str.substr(s, 1u, bytelen - 1u);
ret headstr + padstr + numpart;
}
}

View file

@ -3,25 +3,25 @@ native "rust" mod rustrt {
}
fn path_sep() -> str {
ret _str.from_char(os_fs.path_sep);
ret Str.from_char(OS_FS.path_sep);
}
type path = str;
fn dirname(path p) -> path {
let int i = _str.rindex(p, os_fs.path_sep as u8);
let int i = Str.rindex(p, OS_FS.path_sep as u8);
if (i == -1) {
i = _str.rindex(p, os_fs.alt_path_sep as u8);
i = Str.rindex(p, OS_FS.alt_path_sep as u8);
if (i == -1) {
ret p;
}
}
ret _str.substr(p, 0u, i as uint);
ret Str.substr(p, 0u, i as uint);
}
fn connect(path pre, path post) -> path {
auto len = _str.byte_len(pre);
if (pre.(len - 1u) == (os_fs.path_sep as u8)) { // Trailing '/'?
auto len = Str.byte_len(pre);
if (pre.(len - 1u) == (OS_FS.path_sep as u8)) { // Trailing '/'?
ret pre + post;
}
ret pre + path_sep() + post;
@ -32,14 +32,14 @@ fn file_is_dir(path p) -> bool {
}
fn list_dir(path p) -> vec[str] {
auto pl = _str.byte_len(p);
if (pl == 0u || p.(pl - 1u) as char != os_fs.path_sep) {
auto pl = Str.byte_len(p);
if (pl == 0u || p.(pl - 1u) as char != OS_FS.path_sep) {
p += path_sep();
}
let vec[str] full_paths = vec();
for (str filename in os_fs.list_dir(p)) {
if (!_str.eq(filename, ".")) {if (!_str.eq(filename, "..")) {
_vec.push[str](full_paths, p + filename);
for (str filename in OS_FS.list_dir(p)) {
if (!Str.eq(filename, ".")) {if (!Str.eq(filename, "..")) {
Vec.push[str](full_paths, p + filename);
}}
}
ret full_paths;

View file

@ -1,4 +1,4 @@
fn getenv(str n) -> str {
ret _str.str_from_cstr(os.libc.getenv(_str.buf(n)));
ret Str.str_from_cstr(OS.libc.getenv(Str.buf(n)));
}

View file

@ -7,8 +7,8 @@
* argument values out of the match object.
*/
import option.some;
import option.none;
import Option.some;
import Option.none;
tag name { long(str); short(char); }
tag hasarg { yes; no; maybe; }
@ -17,7 +17,7 @@ tag occur { req; optional; multi; }
type opt = rec(name name, hasarg hasarg, occur occur);
fn mkname(str nm) -> name {
if (_str.char_len(nm) == 1u) { ret short(_str.char_at(nm, 0u)); }
if (Str.char_len(nm) == 1u) { ret short(Str.char_at(nm, 0u)); }
else { ret long(nm); }
}
fn reqopt(str name) -> opt {
@ -41,11 +41,11 @@ tag optval {
type match = rec(vec[opt] opts, vec[mutable vec[optval]] vals, vec[str] free);
fn is_arg(str arg) -> bool {
ret _str.byte_len(arg) > 1u && arg.(0) == '-' as u8;
ret Str.byte_len(arg) > 1u && arg.(0) == '-' as u8;
}
fn name_str(name nm) -> str {
alt (nm) {
case (short(?ch)) {ret _str.from_char(ch);}
case (short(?ch)) {ret Str.from_char(ch);}
case (long(?s)) {ret s;}
}
}
@ -55,16 +55,16 @@ fn name_eq(name a, name b) -> bool {
alt (a) {
case (long(?a)) {
alt (b) {
case (long(?b)) { ret _str.eq(a, b); }
case (long(?b)) { ret Str.eq(a, b); }
case (_) { ret false; }
}
}
case (_) { if (a == b) { ret true; } else {ret false; } }
}
}
fn find_opt(vec[opt] opts, name nm) -> option.t[uint] {
fn find_opt(vec[opt] opts, name nm) -> Option.t[uint] {
auto i = 0u;
auto l = _vec.len[opt](opts);
auto l = Vec.len[opt](opts);
while (i < l) {
if (name_eq(opts.(i).name, nm)) { ret some[uint](i); }
i += 1u;
@ -102,41 +102,41 @@ tag result {
}
fn getopts(vec[str] args, vec[opt] opts) -> result {
auto n_opts = _vec.len[opt](opts);
fn empty_(uint x) -> vec[optval]{ret _vec.empty[optval]();}
auto n_opts = Vec.len[opt](opts);
fn empty_(uint x) -> vec[optval]{ret Vec.empty[optval]();}
auto f = empty_;
auto vals = _vec.init_fn_mut[vec[optval]](f, n_opts);
auto vals = Vec.init_fn_mut[vec[optval]](f, n_opts);
let vec[str] free = vec();
auto l = _vec.len[str](args);
auto l = Vec.len[str](args);
auto i = 0u;
while (i < l) {
auto cur = args.(i);
auto curlen = _str.byte_len(cur);
auto curlen = Str.byte_len(cur);
if (!is_arg(cur)) {
_vec.push[str](free, cur);
} else if (_str.eq(cur, "--")) {
free += _vec.slice[str](args, i + 1u, l);
Vec.push[str](free, cur);
} else if (Str.eq(cur, "--")) {
free += Vec.slice[str](args, i + 1u, l);
break;
} else {
auto names;
auto i_arg = option.none[str];
auto i_arg = Option.none[str];
if (cur.(1) == '-' as u8) {
auto tail = _str.slice(cur, 2u, curlen);
auto eq = _str.index(tail, '=' as u8);
auto tail = Str.slice(cur, 2u, curlen);
auto eq = Str.index(tail, '=' as u8);
if (eq == -1) {
names = vec(long(tail));
} else {
names = vec(long(_str.slice(tail, 0u, eq as uint)));
i_arg = option.some[str]
(_str.slice(tail, (eq as uint) + 1u, curlen - 2u));
names = vec(long(Str.slice(tail, 0u, eq as uint)));
i_arg = Option.some[str]
(Str.slice(tail, (eq as uint) + 1u, curlen - 2u));
}
} else {
auto j = 1u;
names = vec();
while (j < curlen) {
auto range = _str.char_range_at(cur, j);
_vec.push[name](names, short(range._0));
auto range = Str.char_range_at(cur, j);
Vec.push[name](names, short(range._0));
j = range._1;
}
}
@ -152,29 +152,29 @@ fn getopts(vec[str] args, vec[opt] opts) -> result {
}
alt (opts.(optid).hasarg) {
case (no) {
_vec.push[optval](vals.(optid), given);
Vec.push[optval](vals.(optid), given);
}
case (maybe) {
if (!option.is_none[str](i_arg)) {
_vec.push[optval](vals.(optid),
val(option.get[str](i_arg)));
} else if (name_pos < _vec.len[name](names) ||
if (!Option.is_none[str](i_arg)) {
Vec.push[optval](vals.(optid),
val(Option.get[str](i_arg)));
} else if (name_pos < Vec.len[name](names) ||
i + 1u == l || is_arg(args.(i + 1u))) {
_vec.push[optval](vals.(optid), given);
Vec.push[optval](vals.(optid), given);
} else {
i += 1u;
_vec.push[optval](vals.(optid), val(args.(i)));
Vec.push[optval](vals.(optid), val(args.(i)));
}
}
case (yes) {
if (!option.is_none[str](i_arg)) {
_vec.push[optval](vals.(optid),
val(option.get[str](i_arg)));
if (!Option.is_none[str](i_arg)) {
Vec.push[optval](vals.(optid),
val(Option.get[str](i_arg)));
} else if (i + 1u == l) {
ret failure(argument_missing(name_str(nm)));
} else {
i += 1u;
_vec.push[optval](vals.(optid), val(args.(i)));
Vec.push[optval](vals.(optid), val(args.(i)));
}
}
}
@ -185,7 +185,7 @@ fn getopts(vec[str] args, vec[opt] opts) -> result {
i = 0u;
while (i < n_opts) {
auto n = _vec.len[optval](vals.(i));
auto n = Vec.len[optval](vals.(i));
auto occ = opts.(i).occur;
if (occ == req) {if (n == 0u) {
ret failure(option_missing(name_str(opts.(i).name)));
@ -212,7 +212,7 @@ fn opt_val(match m, str nm) -> optval {
ret opt_vals(m, nm).(0);
}
fn opt_present(match m, str nm) -> bool {
ret _vec.len[optval](opt_vals(m, nm)) > 0u;
ret Vec.len[optval](opt_vals(m, nm)) > 0u;
}
fn opt_str(match m, str nm) -> str {
alt (opt_val(m, nm)) {
@ -224,15 +224,15 @@ fn opt_strs(match m, str nm) -> vec[str] {
let vec[str] acc = vec();
for (optval v in opt_vals(m, nm)) {
alt (v) {
case (val(?s)) { _vec.push[str](acc, s); }
case (val(?s)) { Vec.push[str](acc, s); }
case (_) {}
}
}
ret acc;
}
fn opt_maybe_str(match m, str nm) -> option.t[str] {
fn opt_maybe_str(match m, str nm) -> Option.t[str] {
auto vals = opt_vals(m, nm);
if (_vec.len[optval](vals) == 0u) { ret none[str]; }
if (Vec.len[optval](vals) == 0u) { ret none[str]; }
alt (vals.(0)) {
case (val(?s)) { ret some[str](s); }
case (_) { ret none[str]; }

View file

@ -1,8 +1,8 @@
import os.libc;
import OS.libc;
native "rust" mod rustrt {
fn rust_get_stdin() -> os.libc.FILE;
fn rust_get_stdout() -> os.libc.FILE;
fn rust_get_stdin() -> OS.libc.FILE;
fn rust_get_stdout() -> OS.libc.FILE;
}
// Reading
@ -55,30 +55,30 @@ fn convert_whence(seek_style whence) -> int {
}
}
state obj FILE_buf_reader(os.libc.FILE f, bool must_close) {
state obj FILE_buf_reader(OS.libc.FILE f, bool must_close) {
fn read(uint len) -> vec[u8] {
auto buf = _vec.alloc[u8](len);
auto read = os.libc.fread(_vec.buf[u8](buf), 1u, len, f);
_vec.len_set[u8](buf, read);
auto buf = Vec.alloc[u8](len);
auto read = OS.libc.fread(Vec.buf[u8](buf), 1u, len, f);
Vec.len_set[u8](buf, read);
ret buf;
}
fn read_byte() -> int {
ret os.libc.fgetc(f);
ret OS.libc.fgetc(f);
}
fn unread_byte(int byte) {
os.libc.ungetc(byte, f);
OS.libc.ungetc(byte, f);
}
fn eof() -> bool {
ret os.libc.feof(f) != 0;
ret OS.libc.feof(f) != 0;
}
fn seek(int offset, seek_style whence) {
assert (os.libc.fseek(f, offset, convert_whence(whence)) == 0);
assert (OS.libc.fseek(f, offset, convert_whence(whence)) == 0);
}
fn tell() -> uint {
ret os.libc.ftell(f) as uint;
ret OS.libc.ftell(f) as uint;
}
drop {
if (must_close) { os.libc.fclose(f); }
if (must_close) { OS.libc.fclose(f); }
}
}
@ -100,7 +100,7 @@ state obj new_reader(buf_reader rdr) {
auto c0 = rdr.read_byte();
if (c0 == -1) {ret -1 as char;} // FIXME will this stay valid?
auto b0 = c0 as u8;
auto w = _str.utf8_char_width(b0);
auto w = Str.utf8_char_width(b0);
assert (w > 0u);
if (w == 1u) {ret b0 as char;}
auto val = 0u;
@ -112,7 +112,7 @@ state obj new_reader(buf_reader rdr) {
val <<= 6u;
val += (next & 0x3f) as uint;
}
// See _str.char_at
// See Str.char_at
val += ((b0 << ((w + 1u) as u8)) as uint) << ((w - 1u) * 6u - w - 1u);
ret val as char;
}
@ -126,9 +126,9 @@ state obj new_reader(buf_reader rdr) {
while (go_on) {
auto ch = rdr.read_byte();
if (ch == -1 || ch == 10) {go_on = false;}
else {_vec.push[u8](buf, ch as u8);}
else {Vec.push[u8](buf, ch as u8);}
}
ret _str.unsafe_from_bytes(buf);
ret Str.unsafe_from_bytes(buf);
}
fn read_c_str() -> str {
let vec[u8] buf = vec();
@ -136,9 +136,9 @@ state obj new_reader(buf_reader rdr) {
while (go_on) {
auto ch = rdr.read_byte();
if (ch < 1) {go_on = false;}
else {_vec.push[u8](buf, ch as u8);}
else {Vec.push[u8](buf, ch as u8);}
}
ret _str.unsafe_from_bytes(buf);
ret Str.unsafe_from_bytes(buf);
}
// FIXME deal with eof?
fn read_le_uint(uint size) -> uint {
@ -191,7 +191,7 @@ fn stdin() -> reader {
}
fn file_reader(str path) -> reader {
auto f = os.libc.fopen(_str.buf(path), _str.buf("r"));
auto f = OS.libc.fopen(Str.buf(path), Str.buf("r"));
if (f as uint == 0u) {
log_err "error opening " + path;
fail;
@ -212,17 +212,17 @@ type byte_buf = @rec(vec[u8] buf, mutable uint pos);
state obj byte_buf_reader(byte_buf bbuf) {
fn read(uint len) -> vec[u8] {
auto rest = _vec.len[u8](bbuf.buf) - bbuf.pos;
auto rest = Vec.len[u8](bbuf.buf) - bbuf.pos;
auto to_read = len;
if (rest < to_read) {
to_read = rest;
}
auto range = _vec.slice[u8](bbuf.buf, bbuf.pos, bbuf.pos + to_read);
auto range = Vec.slice[u8](bbuf.buf, bbuf.pos, bbuf.pos + to_read);
bbuf.pos += to_read;
ret range;
}
fn read_byte() -> int {
if (bbuf.pos == _vec.len[u8](bbuf.buf)) {ret -1;}
if (bbuf.pos == Vec.len[u8](bbuf.buf)) {ret -1;}
auto b = bbuf.buf.(bbuf.pos);
bbuf.pos += 1u;
ret b as int;
@ -234,12 +234,12 @@ state obj byte_buf_reader(byte_buf bbuf) {
}
fn eof() -> bool {
ret bbuf.pos == _vec.len[u8](bbuf.buf);
ret bbuf.pos == Vec.len[u8](bbuf.buf);
}
fn seek(int offset, seek_style whence) {
auto pos = bbuf.pos;
auto len = _vec.len[u8](bbuf.buf);
auto len = Vec.len[u8](bbuf.buf);
bbuf.pos = seek_in_buf(offset, pos, len, whence);
}
@ -268,40 +268,40 @@ type buf_writer = state obj {
fn tell() -> uint; // FIXME: eventually u64
};
state obj FILE_writer(os.libc.FILE f, bool must_close) {
state obj FILE_writer(OS.libc.FILE f, bool must_close) {
fn write(vec[u8] v) {
auto len = _vec.len[u8](v);
auto vbuf = _vec.buf[u8](v);
auto nout = os.libc.fwrite(vbuf, len, 1u, f);
auto len = Vec.len[u8](v);
auto vbuf = Vec.buf[u8](v);
auto nout = OS.libc.fwrite(vbuf, len, 1u, f);
if (nout < 1u) {
log_err "error dumping buffer";
}
}
fn seek(int offset, seek_style whence) {
assert (os.libc.fseek(f, offset, convert_whence(whence)) == 0);
assert (OS.libc.fseek(f, offset, convert_whence(whence)) == 0);
}
fn tell() -> uint {
ret os.libc.ftell(f) as uint;
ret OS.libc.ftell(f) as uint;
}
drop {
if (must_close) {os.libc.fclose(f);}
if (must_close) {OS.libc.fclose(f);}
}
}
state obj fd_buf_writer(int fd, bool must_close) {
fn write(vec[u8] v) {
auto len = _vec.len[u8](v);
auto len = Vec.len[u8](v);
auto count = 0u;
auto vbuf;
while (count < len) {
vbuf = _vec.buf_off[u8](v, count);
auto nout = os.libc.write(fd, vbuf, len);
vbuf = Vec.buf_off[u8](v, count);
auto nout = OS.libc.write(fd, vbuf, len);
if (nout < 0) {
log_err "error dumping buffer";
log_err sys.rustrt.last_os_error();
log_err Sys.rustrt.last_os_error();
fail;
}
count += nout as uint;
@ -319,32 +319,32 @@ state obj fd_buf_writer(int fd, bool must_close) {
}
drop {
if (must_close) {os.libc.close(fd);}
if (must_close) {OS.libc.close(fd);}
}
}
fn file_buf_writer(str path, vec[fileflag] flags) -> buf_writer {
let int fflags =
os.libc_constants.O_WRONLY() |
os.libc_constants.O_BINARY();
OS.libc_constants.O_WRONLY() |
OS.libc_constants.O_BINARY();
for (fileflag f in flags) {
alt (f) {
case (append) { fflags |= os.libc_constants.O_APPEND(); }
case (create) { fflags |= os.libc_constants.O_CREAT(); }
case (truncate) { fflags |= os.libc_constants.O_TRUNC(); }
case (append) { fflags |= OS.libc_constants.O_APPEND(); }
case (create) { fflags |= OS.libc_constants.O_CREAT(); }
case (truncate) { fflags |= OS.libc_constants.O_TRUNC(); }
case (none) {}
}
}
auto fd = os.libc.open(_str.buf(path),
auto fd = OS.libc.open(Str.buf(path),
fflags,
os.libc_constants.S_IRUSR() |
os.libc_constants.S_IWUSR());
OS.libc_constants.S_IRUSR() |
OS.libc_constants.S_IWUSR());
if (fd < 0) {
log_err "error opening file for writing";
log_err sys.rustrt.last_os_error();
log_err Sys.rustrt.last_os_error();
fail;
}
ret fd_buf_writer(fd, true);
@ -390,17 +390,17 @@ state obj new_writer(buf_writer out) {
ret out;
}
fn write_str(str s) {
out.write(_str.bytes(s));
out.write(Str.bytes(s));
}
fn write_char(char ch) {
// FIXME needlessly consy
out.write(_str.bytes(_str.from_char(ch)));
out.write(Str.bytes(Str.from_char(ch)));
}
fn write_int(int n) {
out.write(_str.bytes(_int.to_str(n, 10u)));
out.write(Str.bytes(Int.to_str(n, 10u)));
}
fn write_uint(uint n) {
out.write(_str.bytes(_uint.to_str(n, 10u)));
out.write(Str.bytes(UInt.to_str(n, 10u)));
}
fn write_bytes(vec[u8] bytes) {
out.write(bytes);
@ -427,7 +427,7 @@ fn file_writer(str path, vec[fileflag] flags) -> writer {
// FIXME: fileflags
fn buffered_file_buf_writer(str path) -> buf_writer {
auto f = os.libc.fopen(_str.buf(path), _str.buf("w"));
auto f = OS.libc.fopen(Str.buf(path), Str.buf("w"));
if (f as uint == 0u) {
log_err "error opening " + path;
fail;
@ -451,21 +451,21 @@ type mutable_byte_buf = @rec(mutable vec[mutable u8] buf, mutable uint pos);
state obj byte_buf_writer(mutable_byte_buf buf) {
fn write(vec[u8] v) {
// Fast path.
if (buf.pos == _vec.len(buf.buf)) {
if (buf.pos == Vec.len(buf.buf)) {
// FIXME: Fix our type system. There's no reason you shouldn't be
// able to add a mutable vector to an immutable one.
auto mv = _vec.rustrt.unsafe_vec_to_mut[u8](v);
auto mv = Vec.rustrt.unsafe_vec_to_mut[u8](v);
buf.buf += mv;
buf.pos += _vec.len[u8](v);
buf.pos += Vec.len[u8](v);
ret;
}
// FIXME: Optimize. These should be unique pointers.
auto vlen = _vec.len[u8](v);
auto vlen = Vec.len[u8](v);
auto vpos = 0u;
while (vpos < vlen) {
auto b = v.(vpos);
if (buf.pos == _vec.len(buf.buf)) {
if (buf.pos == Vec.len(buf.buf)) {
buf.buf += vec(mutable b);
} else {
buf.buf.(buf.pos) = b;
@ -477,7 +477,7 @@ state obj byte_buf_writer(mutable_byte_buf buf) {
fn seek(int offset, seek_style whence) {
auto pos = buf.pos;
auto len = _vec.len(buf.buf);
auto len = Vec.len(buf.buf);
buf.pos = seek_in_buf(offset, pos, len, whence);
}
@ -487,12 +487,12 @@ state obj byte_buf_writer(mutable_byte_buf buf) {
fn string_writer() -> str_writer {
// FIXME: yikes, this is bad. Needs fixing of mutable syntax.
let vec[mutable u8] b = vec(mutable 0u8);
_vec.pop(b);
Vec.pop(b);
let mutable_byte_buf buf = @rec(mutable buf = b, mutable pos = 0u);
state obj str_writer_wrap(writer wr, mutable_byte_buf buf) {
fn get_writer() -> writer {ret wr;}
fn get_str() -> str {ret _str.unsafe_from_mutable_bytes(buf.buf);}
fn get_str() -> str {ret Str.unsafe_from_mutable_bytes(buf.buf);}
}
ret str_writer_wrap(new_writer(byte_buf_writer(buf)), buf);
}

View file

@ -29,9 +29,9 @@ fn to_str(int n, uint radix) -> str
{
assert (0u < radix && radix <= 16u);
if (n < 0) {
ret "-" + _uint.to_str((-n) as uint, radix);
ret "-" + UInt.to_str((-n) as uint, radix);
} else {
ret _uint.to_str(n as uint, radix);
ret UInt.to_str(n as uint, radix);
}
}

View file

@ -1,5 +1,5 @@
import option.some;
import option.none;
import Option.some;
import Option.none;
// FIXME: It would probably be more appealing to define this as
// type list[T] = rec(T hd, option[@list[T]] tl), but at the moment
@ -27,7 +27,7 @@ fn foldl[T,U](&list[T] ls, &U u, fn(&T t, &U u) -> U f) -> U {
}
fn find[T,U](&list[T] ls,
(fn(&T) -> option.t[U]) f) -> option.t[U] {
(fn(&T) -> Option.t[U]) f) -> Option.t[U] {
alt(ls) {
case (cons[T](?hd, ?tl)) {
alt (f(hd)) {

View file

@ -11,8 +11,8 @@ state type hashmap[K, V] = state obj {
fn insert(&K key, &V val) -> bool;
fn contains_key(&K key) -> bool;
fn get(&K key) -> V;
fn find(&K key) -> option.t[V];
fn remove(&K key) -> option.t[V];
fn find(&K key) -> Option.t[V];
fn remove(&K key) -> Option.t[V];
fn rehash();
iter items() -> @tup(K,V);
};
@ -20,7 +20,7 @@ state type hashmap[K, V] = state obj {
fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
let uint initial_capacity = 32u; // 2^5
let util.rational load_factor = rec(num=3, den=4);
let Util.rational load_factor = rec(num=3, den=4);
tag bucket[K, V] {
nil;
@ -29,7 +29,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
}
fn make_buckets[K, V](uint nbkts) -> vec[mutable bucket[K, V]] {
ret _vec.init_elt_mut[bucket[K, V]](nil[K, V], nbkts);
ret Vec.init_elt_mut[bucket[K, V]](nil[K, V], nbkts);
}
// Derive two hash functions from the one given by taking the upper
@ -96,7 +96,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
vec[mutable bucket[K, V]] bkts,
uint nbkts,
&K key)
-> option.t[V]
-> Option.t[V]
{
let uint i = 0u;
let uint h = hasher(key);
@ -105,17 +105,17 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
alt (bkts.(j)) {
case (some[K, V](?k, ?v)) {
if (eqer(key, k)) {
ret option.some[V](v);
ret Option.some[V](v);
}
}
case (nil[K, V]) {
ret option.none[V];
ret Option.none[V];
}
case (deleted[K, V]) { }
}
i += 1u;
}
ret option.none[V];
ret Option.none[V];
}
@ -140,15 +140,15 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
mutable vec[mutable bucket[K, V]] bkts,
mutable uint nbkts,
mutable uint nelts,
util.rational lf)
Util.rational lf)
{
fn size() -> uint { ret nelts; }
fn insert(&K key, &V val) -> bool {
let util.rational load = rec(num=(nelts + 1u) as int,
let Util.rational load = rec(num=(nelts + 1u) as int,
den=nbkts as int);
if (!util.rational_leq(load, lf)) {
let uint nnewbkts = _uint.next_power_of_two(nbkts + 1u);
if (!Util.rational_leq(load, lf)) {
let uint nnewbkts = UInt.next_power_of_two(nbkts + 1u);
let vec[mutable bucket[K, V]] newbkts =
make_buckets[K, V](nnewbkts);
rehash[K, V](hasher, eqer, bkts, nbkts,
@ -167,7 +167,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
fn contains_key(&K key) -> bool {
alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
case (option.some[V](_)) { ret true; }
case (Option.some[V](_)) { ret true; }
case (_) { ret false; }
}
fail; // FIXME: remove me when exhaustiveness checking works
@ -175,19 +175,19 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
fn get(&K key) -> V {
alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
case (option.some[V](?val)) { ret val; }
case (Option.some[V](?val)) { ret val; }
case (_) { fail; }
}
fail; // FIXME: remove me when exhaustiveness checking works
}
fn find(&K key) -> option.t[V] {
fn find(&K key) -> Option.t[V] {
// FIXME: should be 'be' but parametric tail-calls don't
// work at the moment.
ret find_common[K, V](hasher, eqer, bkts, nbkts, key);
}
fn remove(&K key) -> option.t[V] {
fn remove(&K key) -> Option.t[V] {
let uint i = 0u;
let uint h = hasher(key);
while (i < nbkts) {
@ -197,17 +197,17 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
if (eqer(key, k)) {
bkts.(j) = deleted[K, V];
nelts -= 1u;
ret option.some[V](v);
ret Option.some[V](v);
}
}
case (deleted[K, V]) { }
case (nil[K, V]) {
ret option.none[V];
ret Option.none[V];
}
}
i += 1u;
}
ret option.none[V];
ret Option.none[V];
}
fn rehash() {

View file

@ -1,4 +1,4 @@
// lib/option.rs
// lib/Option.rs
tag t[T] {
none;
@ -39,7 +39,7 @@ fn is_none[T](&t[T] opt) -> bool {
}
fn from_maybe[T](&T def, &t[T] opt) -> T {
auto f = bind util.id[T](_);
auto f = bind Util.id[T](_);
ret maybe[T, T](def, f, opt);
}

View file

@ -1,74 +1,74 @@
import _str.sbuf;
import _vec.vbuf;
import Str.sbuf;
import Vec.vbuf;
native "rust" mod rustrt {
fn rust_run_program(vbuf argv, int in_fd, int out_fd, int err_fd) -> int;
}
fn argvec(str prog, vec[str] args) -> vec[sbuf] {
auto argptrs = vec(_str.buf(prog));
auto argptrs = vec(Str.buf(prog));
for (str arg in args) {
_vec.push[sbuf](argptrs, _str.buf(arg));
Vec.push[sbuf](argptrs, Str.buf(arg));
}
_vec.push[sbuf](argptrs, 0 as sbuf);
Vec.push[sbuf](argptrs, 0 as sbuf);
ret argptrs;
}
fn run_program(str prog, vec[str] args) -> int {
auto pid = rustrt.rust_run_program(_vec.buf[sbuf](argvec(prog, args)),
auto pid = rustrt.rust_run_program(Vec.buf[sbuf](argvec(prog, args)),
0, 0, 0);
ret os.waitpid(pid);
ret OS.waitpid(pid);
}
type program =
state obj {
fn get_id() -> int;
fn input() -> io.writer;
fn output() -> io.reader;
fn input() -> IO.writer;
fn output() -> IO.reader;
fn close_input();
fn finish() -> int;
};
fn start_program(str prog, vec[str] args) -> @program {
auto pipe_input = os.pipe();
auto pipe_output = os.pipe();
auto pipe_input = OS.pipe();
auto pipe_output = OS.pipe();
auto pid = rustrt.rust_run_program
(_vec.buf[sbuf](argvec(prog, args)),
(Vec.buf[sbuf](argvec(prog, args)),
pipe_input._0, pipe_output._1, 0);
if (pid == -1) {fail;}
os.libc.close(pipe_input._0);
os.libc.close(pipe_output._1);
OS.libc.close(pipe_input._0);
OS.libc.close(pipe_output._1);
state obj new_program(int pid,
int in_fd,
os.libc.FILE out_file,
OS.libc.FILE out_file,
mutable bool finished) {
fn get_id() -> int {ret pid;}
fn input() -> io.writer {
ret io.new_writer(io.fd_buf_writer(in_fd, false));
fn input() -> IO.writer {
ret IO.new_writer(IO.fd_buf_writer(in_fd, false));
}
fn output() -> io.reader {
ret io.new_reader(io.FILE_buf_reader(out_file, false));
fn output() -> IO.reader {
ret IO.new_reader(IO.FILE_buf_reader(out_file, false));
}
fn close_input() {
os.libc.close(in_fd);
OS.libc.close(in_fd);
}
fn finish() -> int {
if (finished) {ret 0;}
finished = true;
os.libc.close(in_fd);
ret os.waitpid(pid);
OS.libc.close(in_fd);
ret OS.waitpid(pid);
}
drop {
if (!finished) {
os.libc.close(in_fd);
os.waitpid(pid);
OS.libc.close(in_fd);
OS.waitpid(pid);
}
os.libc.fclose(out_file);
OS.libc.fclose(out_file);
}
}
ret @new_program(pid, pipe_input._1,
os.fd_FILE(pipe_output._0),
OS.fd_FILE(pipe_output._0),
false);
}
@ -80,7 +80,7 @@ fn program_output(str prog, vec[str] args)
auto buf = "";
while (!out.eof()) {
auto bytes = out.read_bytes(4096u);
buf += _str.unsafe_from_bytes(bytes);
buf += Str.unsafe_from_bytes(bytes);
}
ret rec(status=pr.finish(), out=buf);
}

View file

@ -67,7 +67,7 @@ fn mk_sha1() -> sha1 {
fn process_msg_block(&sha1state st) {
// FIXME: Make precondition
assert (_vec.len(st.h) == digest_buf_len);
assert (Vec.len(st.h) == digest_buf_len);
// Constants
auto k = vec(0x5A827999u32,
@ -76,7 +76,7 @@ fn mk_sha1() -> sha1 {
0xCA62C1D6u32);
let int t; // Loop counter
let vec[mutable u32] w = _vec.init_elt_mut[u32](0u32, 80u);
let vec[mutable u32] w = Vec.init_elt_mut[u32](0u32, 80u);
// Initialize the first 16 words of the vector w
t = 0;
@ -192,7 +192,7 @@ fn mk_sha1() -> sha1 {
*/
fn pad_msg(&sha1state st) {
// FIXME: Should be a precondition
assert (_vec.len(st.msg_block) == msg_block_len);
assert (Vec.len(st.msg_block) == msg_block_len);
/*
* Check to see if the current message block is too small to hold
@ -236,7 +236,7 @@ fn mk_sha1() -> sha1 {
fn reset() {
// FIXME: Should be typestate precondition
assert (_vec.len(st.h) == digest_buf_len);
assert (Vec.len(st.h) == digest_buf_len);
st.len_low = 0u32;
st.len_high = 0u32;
@ -256,7 +256,7 @@ fn mk_sha1() -> sha1 {
}
fn input_str(&str msg) {
add_input(st, _str.bytes(msg));
add_input(st, Str.bytes(msg));
}
fn result() -> vec[u8] {
@ -267,16 +267,16 @@ fn mk_sha1() -> sha1 {
auto r = mk_result(st);
auto s = "";
for (u8 b in r) {
s += _uint.to_str(b as uint, 16u);
s += UInt.to_str(b as uint, 16u);
}
ret s;
}
}
auto st = rec(h = _vec.init_elt_mut[u32](0u32, digest_buf_len),
auto st = rec(h = Vec.init_elt_mut[u32](0u32, digest_buf_len),
mutable len_low = 0u32,
mutable len_high = 0u32,
msg_block = _vec.init_elt_mut[u8](0u8, msg_block_len),
msg_block = Vec.init_elt_mut[u8](0u8, msg_block_len),
mutable msg_block_idx = 0u,
mutable computed = false);
auto sh = sha1(st);

View file

@ -1,5 +1,5 @@
import _vec.len;
import _vec.slice;
import Vec.len;
import Vec.slice;
type lteq[T] = fn(&T a, &T b) -> bool;

View file

@ -1,6 +1,6 @@
import rustrt.sbuf;
import _vec.rustrt.vbuf;
import Vec.rustrt.vbuf;
native "rust" mod rustrt {
type sbuf;
@ -83,7 +83,7 @@ const uint tag_six_b = 0xfc_u;
fn is_utf8(vec[u8] v) -> bool {
auto i = 0u;
auto total = _vec.len[u8](v);
auto total = Vec.len[u8](v);
while (i < total) {
auto chsize = utf8_char_width(v.(i));
if (chsize == 0u) {ret false;}
@ -261,7 +261,7 @@ 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);
Vec.push[char](buf, cur._0);
i = cur._1;
}
ret buf;
@ -296,7 +296,7 @@ fn unshift_char(&mutable str s, char ch) {
fn refcount(str s) -> uint {
auto r = rustrt.refcount[u8](s);
if (r == dbg.const_refcount) {
if (r == Dbg.const_refcount) {
ret r;
} else {
// -1 because calling this function incremented the refcount.
@ -319,7 +319,7 @@ fn index(str s, u8 c) -> int {
}
fn rindex(str s, u8 c) -> int {
let int n = _str.byte_len(s) as int;
let int n = Str.byte_len(s) as int;
while (n >= 0) {
if (s.(n) == c) {
ret n;
@ -443,7 +443,7 @@ fn split(str s, u8 sep) -> vec[str] {
ends_with_sep = false;
}
}
if (_str.byte_len(accum) != 0u ||
if (Str.byte_len(accum) != 0u ||
ends_with_sep) {
v += vec(accum);
}

View file

@ -21,20 +21,20 @@ const u8 color_bright_magenta = 13u8;
const u8 color_bright_cyan = 14u8;
const u8 color_bright_white = 15u8;
fn esc(io.buf_writer writer) {
fn esc(IO.buf_writer writer) {
writer.write(vec(0x1bu8, '[' as u8));
}
fn reset(io.buf_writer writer) {
fn reset(IO.buf_writer writer) {
esc(writer);
writer.write(vec('0' as u8, 'm' as u8));
}
fn color_supported() -> bool {
ret _str.eq(GenericOS.getenv("TERM"), "xterm-color");
ret Str.eq(GenericOS.getenv("TERM"), "xterm-color");
}
fn set_color(io.buf_writer writer, u8 first_char, u8 color) {
fn set_color(IO.buf_writer writer, u8 first_char, u8 color) {
assert (color < 16u8);
esc(writer);
@ -45,11 +45,11 @@ fn set_color(io.buf_writer writer, u8 first_char, u8 color) {
writer.write(vec(first_char, ('0' as u8) + color, 'm' as u8));
}
fn fg(io.buf_writer writer, u8 color) {
fn fg(IO.buf_writer writer, u8 color) {
ret set_color(writer, '3' as u8, color);
}
fn bg(io.buf_writer writer, u8 color) {
fn bg(IO.buf_writer writer, u8 color) {
ret set_color(writer, '4' as u8, color);
}

View file

@ -1,19 +1,19 @@
import option.none;
import option.some;
import Option.none;
import Option.some;
// A very naive implementation of union-find with unsigned integer nodes.
type node = option.t[uint];
type node = Option.t[uint];
type ufind = rec(mutable vec[mutable node] nodes);
fn make() -> ufind {
let vec[mutable node] v = vec(mutable none[uint]);
_vec.pop(v); // FIXME: botch
Vec.pop(v); // FIXME: botch
ret rec(mutable nodes=v);
}
fn make_set(&ufind ufnd) -> uint {
auto idx = _vec.len(ufnd.nodes);
auto idx = Vec.len(ufnd.nodes);
ufnd.nodes += vec(mutable none[uint]);
ret idx;
}

View file

@ -23,7 +23,7 @@ iter range(uint lo, uint hi) -> uint {
fn next_power_of_two(uint n) -> uint {
// FIXME change |* uint(4)| below to |* uint(8) / uint(2)| and watch the
// world explode.
let uint halfbits = sys.rustrt.size_of[uint]() * 4u;
let uint halfbits = Sys.rustrt.size_of[uint]() * 4u;
let uint tmp = n - 1u;
let uint shift = 1u;
while (shift <= halfbits) {
@ -34,12 +34,12 @@ fn next_power_of_two(uint n) -> uint {
}
fn parse_buf(vec[u8] buf, uint radix) -> uint {
if (_vec.len[u8](buf) == 0u) {
if (Vec.len[u8](buf) == 0u) {
log_err "parse_buf(): buf is empty";
fail;
}
auto i = _vec.len[u8](buf) - 1u;
auto i = Vec.len[u8](buf) - 1u;
auto power = 1u;
auto n = 0u;
while (true) {
@ -83,15 +83,15 @@ fn to_str(uint num, uint radix) -> str
let str s = "";
while (n != 0u) {
s += _str.unsafe_from_byte(digit(n % radix) as u8);
s += Str.unsafe_from_byte(digit(n % radix) as u8);
n /= radix;
}
let str s1 = "";
let uint len = _str.byte_len(s);
let uint len = Str.byte_len(s);
while (len != 0u) {
len -= 1u;
s1 += _str.unsafe_from_byte(s.(len));
s1 += Str.unsafe_from_byte(s.(len));
}
ret s1;

View file

@ -4,7 +4,7 @@ fn id[T](&T x) -> T {
/* FIXME (issue #141): See test/run-pass/constrained-type.rs. Uncomment
* the constraint once fixed. */
type rational = rec(int num, int den); // : _int.positive(*.den);
type rational = rec(int num, int den); // : Int.positive(*.den);
fn rational_leq(&rational x, &rational y) -> bool {
// NB: Uses the fact that rationals have positive denominators WLOG.

View file

@ -1,6 +1,6 @@
import option.none;
import option.some;
import util.orb;
import Option.none;
import Option.some;
import Util.orb;
type vbuf = rustrt.vbuf;
@ -47,7 +47,7 @@ fn alloc_mut[T](uint n_elts) -> vec[mutable T] {
fn refcount[T](array[T] v) -> uint {
auto r = rustrt.refcount[T](v);
if (r == dbg.const_refcount) {
if (r == Dbg.const_refcount) {
ret r;
} else {
// -1 because calling this function incremented the refcount.
@ -140,7 +140,7 @@ fn print_debug_info[T](array[T] v) {
}
// Returns the last element of v.
fn last[T](array[T] v) -> option.t[T] {
fn last[T](array[T] v) -> Option.t[T] {
auto l = len[T](v);
if (l == 0u) {
ret none[T];
@ -199,14 +199,14 @@ fn grow[T](&array[T] v, uint n, &T initval) {
}
fn grow_set[T](&vec[mutable T] v, uint index, &T initval, &T val) {
auto length = _vec.len(v);
auto length = Vec.len(v);
if (index >= length) {
grow(v, index - length + 1u, initval);
}
v.(index) = val;
}
fn map[T, U](&option.operator[T,U] f, &array[T] v) -> vec[U] {
fn map[T, U](&Option.operator[T,U] f, &array[T] v) -> vec[U] {
let vec[U] u = alloc[U](len[T](v));
for (T ve in v) {
u += vec(f(ve));
@ -230,7 +230,7 @@ fn map2[T,U,V](&operator2[T,U,V] f, &array[T] v0, &array[U] v1) -> vec[V] {
ret u;
}
fn find[T](fn (&T) -> bool f, &array[T] v) -> option.t[T] {
fn find[T](fn (&T) -> bool f, &array[T] v) -> Option.t[T] {
for (T elt in v) {
if (f(elt)) {
ret some[T](elt);
@ -270,24 +270,24 @@ fn unzip[T, U](&vec[tup(T, U)] v) -> tup(vec[T], vec[U]) {
fn or(&vec[bool] v) -> bool {
auto f = orb;
ret _vec.foldl[bool, bool](f, false, v);
ret Vec.foldl[bool, bool](f, false, v);
}
fn clone[T](&vec[T] v) -> vec[T] {
ret slice[T](v, 0u, len[T](v));
}
fn plus_option[T](&vec[T] v, &option.t[T] o) -> () {
fn plus_option[T](&vec[T] v, &Option.t[T] o) -> () {
alt (o) {
case (none[T]) {}
case (some[T](?x)) { v += vec(x); }
}
}
fn cat_options[T](&vec[option.t[T]] v) -> vec[T] {
fn cat_options[T](&vec[Option.t[T]] v) -> vec[T] {
let vec[T] res = vec();
for (option.t[T] o in v) {
for (Option.t[T] o in v) {
alt (o) {
case (none[T]) { }
case (some[T](?t)) {

View file

@ -1,5 +1,5 @@
import _str.sbuf;
import _vec.vbuf;
import Str.sbuf;
import Vec.vbuf;
// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult
// by https://github.com/graydon/rust/issues#issue/268
@ -66,17 +66,17 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0);
assert (os.libc.pipe(_vec.buf(fds)) == 0);
assert (OS.libc.pipe(Vec.buf(fds)) == 0);
ret tup(fds.(0), fds.(1));
}
fn fd_FILE(int fd) -> libc.FILE {
ret libc.fdopen(fd, _str.buf("r"));
ret libc.fdopen(fd, Str.buf("r"));
}
fn waitpid(int pid) -> int {
let vec[mutable int] status = vec(mutable 0);
assert (os.libc.waitpid(pid, _vec.buf(status), 0) != -1);
assert (OS.libc.waitpid(pid, Vec.buf(status), 0) != -1);
ret status.(0);
}

View file

@ -1,5 +1,5 @@
import _str.sbuf;
import _vec.vbuf;
import Str.sbuf;
import Vec.vbuf;
native mod libc = "libc.dylib" {
@ -63,17 +63,17 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0);
assert (os.libc.pipe(_vec.buf[mutable int](fds)) == 0);
assert (OS.libc.pipe(Vec.buf[mutable int](fds)) == 0);
ret tup(fds.(0), fds.(1));
}
fn fd_FILE(int fd) -> libc.FILE {
ret libc.fdopen(fd, _str.buf("r"));
ret libc.fdopen(fd, Str.buf("r"));
}
fn waitpid(int pid) -> int {
let vec[mutable int] status = vec(mutable 0);
assert (os.libc.waitpid(pid, _vec.buf[mutable int](status), 0) != -1);
assert (OS.libc.waitpid(pid, Vec.buf[mutable int](status), 0) != -1);
ret status.(0);
}

View file

@ -1,21 +1,21 @@
native "rust" mod rustrt {
fn rust_dirent_filename(os.libc.dirent ent) -> str;
fn rust_dirent_filename(OS.libc.dirent ent) -> str;
}
fn list_dir(str path) -> vec[str] {
// TODO ensure this is always closed
auto dir = os.libc.opendir(_str.buf(path));
auto dir = OS.libc.opendir(Str.buf(path));
assert (dir as uint != 0u);
let vec[str] result = vec();
while (true) {
auto ent = os.libc.readdir(dir);
auto ent = OS.libc.readdir(dir);
if (ent as int == 0) {
os.libc.closedir(dir);
OS.libc.closedir(dir);
ret result;
}
_vec.push[str](result, rustrt.rust_dirent_filename(ent));
Vec.push[str](result, rustrt.rust_dirent_filename(ent));
}
os.libc.closedir(dir);
OS.libc.closedir(dir);
ret result;
}

View file

@ -6,39 +6,38 @@ meta (name = "std",
// Built-in types support modules.
mod _int;
mod _uint;
mod _u8;
mod _vec;
mod _str;
mod Int;
mod UInt;
mod U8;
mod Vec;
mod Str;
// General IO and system-services modules.
mod io;
mod sys;
mod _task;
mod IO;
mod Sys;
mod Task;
// Utility modules.
mod option;
mod util;
mod Option;
mod Util;
// Authorize various rule-bendings.
auth io = unsafe;
auth fs = unsafe;
auth os = unsafe;
auth os_fs = unsafe;
auth run = unsafe;
auth _str = unsafe;
auth _vec = unsafe;
auth _task = unsafe;
auth IO = unsafe;
auth FS = unsafe;
auth OS_FS = unsafe;
auth Run = unsafe;
auth Str = unsafe;
auth Vec = unsafe;
auth Task = unsafe;
auth dbg = unsafe;
auth Dbg = unsafe;
auth _uint.next_power_of_two = unsafe;
auth map.mk_hashmap = unsafe;
auth rand.mk_rng = unsafe;
auth UInt.next_power_of_two = unsafe;
auth Map.mk_hashmap = unsafe;
auth Rand.mk_rng = unsafe;
// Target-OS module.
@ -47,30 +46,30 @@ mod GenericOS;
alt (target_os) {
case ("win32") {
mod os = "win32_os.rs";
mod os_fs = "win32_fs.rs";
mod OS = "win32_OS.rs";
mod OS_FS = "win32_FS.rs";
} case ("macos") {
mod os = "macos_os.rs";
mod os_fs = "posix_fs.rs";
mod OS = "macos_OS.rs";
mod OS_FS = "posix_FS.rs";
} else {
mod os = "linux_os.rs";
mod os_fs = "posix_fs.rs";
mod OS = "linux_OS.rs";
mod OS_FS = "posix_FS.rs";
}
}
mod run = "run_program.rs";
mod fs;
mod Run = "Run_Program.rs";
mod FS;
// FIXME: parametric
mod map;
mod deque;
mod list;
mod rand;
mod dbg;
mod bitv;
mod sort;
mod sha1;
mod ebml;
mod Map;
mod Deque;
mod List;
mod Rand;
mod Dbg;
mod BitV;
mod Sort;
mod SHA1;
mod EBML;
mod UFind;
mod ExtFmt;
mod Box;

View file

@ -1,5 +1,5 @@
import _str.sbuf;
import _vec.vbuf;
import Str.sbuf;
import Vec.vbuf;
native mod libc = "msvcrt.dll" {
fn open(sbuf s, int flags, uint mode) -> int = "_open";
@ -53,13 +53,13 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0);
assert (os.libc._pipe(_vec.buf[mutable int](fds), 1024u,
assert (OS.libc._pipe(Vec.buf[mutable int](fds), 1024u,
libc_constants.O_BINARY()) == 0);
ret tup(fds.(0), fds.(1));
}
fn fd_FILE(int fd) -> libc.FILE {
ret libc._fdopen(fd, _str.buf("r"));
ret libc._fdopen(fd, Str.buf("r"));
}
native "rust" mod rustrt {