1
Fork 0

Convert more core types to camel case

This commit is contained in:
Brian Anderson 2012-08-14 13:38:35 -07:00
parent e640a66eb4
commit 11258310e2
59 changed files with 419 additions and 406 deletions

View file

@ -8,7 +8,7 @@ import rustc::metadata::filesearch::{get_cargo_root, get_cargo_root_nearest,
import syntax::diagnostic; import syntax::diagnostic;
import result::{ok, err}; import result::{ok, err};
import io::writer_util; import io::WriterUtil;
import std::{map, json, tempfile, term, sort, getopts}; import std::{map, json, tempfile, term, sort, getopts};
import map::hashmap; import map::hashmap;
import to_str::to_str; import to_str::to_str;

View file

@ -1,5 +1,5 @@
import run::spawn_process; import run::spawn_process;
import io::writer_util; import io::WriterUtil;
import libc::{c_int, pid_t}; import libc::{c_int, pid_t};
import pipes::chan; import pipes::chan;

View file

@ -1,4 +1,4 @@
import io::writer_util; import io::WriterUtil;
import common::mode_run_pass; import common::mode_run_pass;
import common::mode_run_fail; import common::mode_run_fail;
@ -339,7 +339,7 @@ fn compose_and_run_compiler(
config.compile_lib_path, input) config.compile_lib_path, input)
} }
fn ensure_dir(path: path) { fn ensure_dir(path: Path) {
if os::path_is_dir(path) { return; } if os::path_is_dir(path) { return; }
if !os::make_dir(path, 0x1c0i32) { if !os::make_dir(path, 0x1c0i32) {
fail fmt!{"can't make dir %s", path}; fail fmt!{"can't make dir %s", path};
@ -455,7 +455,7 @@ fn dump_output_file(config: config, testfile: ~str,
out: ~str, extension: ~str) { out: ~str, extension: ~str) {
let outfile = make_out_name(config, testfile, extension); let outfile = make_out_name(config, testfile, extension);
let writer = result::get( let writer = result::get(
io::file_writer(outfile, ~[io::create, io::truncate])); io::file_writer(outfile, ~[io::Create, io::Truncate]));
writer.write_str(out); writer.write_str(out);
} }

View file

@ -54,7 +54,7 @@ d.write("// AUTO-GENERATED FILE: DO NOT EDIT\n")
d.write("use std;\n") d.write("use std;\n")
d.write("use run_pass_stage2;\n") d.write("use run_pass_stage2;\n")
d.write("import run_pass_stage2::*;\n") d.write("import run_pass_stage2::*;\n")
d.write("import io::writer_util;\n"); d.write("import io::WriterUtil;\n");
d.write("fn main() {\n"); d.write("fn main() {\n");
d.write(" let out = io::stdout();\n"); d.write(" let out = io::stdout();\n");
i = 0 i = 0

View file

@ -1,4 +1,4 @@
import io::writer_util; import io::WriterUtil;
import syntax::{ast, ast_util, fold, visit, codemap}; import syntax::{ast, ast_util, fold, visit, codemap};
import syntax::parse; import syntax::parse;
@ -10,7 +10,7 @@ type context = { mode: test_mode }; // + rng
fn write_file(filename: ~str, content: ~str) { fn write_file(filename: ~str, content: ~str) {
result::get( result::get(
io::file_writer(filename, ~[io::create, io::truncate])) io::file_writer(filename, ~[io::Create, io::Truncate]))
.write_str(content); .write_str(content);
} }
@ -216,9 +216,9 @@ fn under(n: uint, it: fn(uint)) {
while i < n { it(i); i += 1u; } while i < n { it(i); i += 1u; }
} }
fn devnull() -> io::writer { io::mem_buffer_writer(io::mem_buffer()) } fn devnull() -> io::Writer { io::mem_buffer_writer(io::mem_buffer()) }
fn as_str(f: fn@(io::writer)) -> ~str { fn as_str(f: fn@(io::Writer)) -> ~str {
let buf = io::mem_buffer(); let buf = io::mem_buffer();
f(io::mem_buffer_writer(buf)); f(io::mem_buffer_writer(buf));
io::mem_buffer_str(buf) io::mem_buffer_str(buf)

View file

@ -54,6 +54,7 @@ export send_map;
export hash; export hash;
export cmp; export cmp;
export num; export num;
export path;
// NDM seems to be necessary for resolve to work // NDM seems to be necessary for resolve to work
export option_iter; export option_iter;
@ -214,11 +215,16 @@ mod pipes;
// Runtime and language-primitive support // Runtime and language-primitive support
#[warn(non_camel_case_types)]
mod io; mod io;
mod libc; mod libc;
#[warn(non_camel_case_types)]
mod os; mod os;
#[warn(non_camel_case_types)]
mod path; mod path;
#[warn(non_camel_case_types)]
mod rand; mod rand;
#[warn(non_camel_case_types)]
mod run; mod run;
#[warn(non_camel_case_types)] #[warn(non_camel_case_types)]
mod sys; mod sys;

View file

@ -4,7 +4,7 @@
import option::{some, none}; import option::{some, none};
import option = option::option; import option = option::option;
import path = path::path; import Path = path::Path;
import tuple::{TupleOps, ExtendedTupleOps}; import tuple::{TupleOps, ExtendedTupleOps};
import str::{str_slice, unique_str}; import str::{str_slice, unique_str};
import vec::{const_vector, copyable_vector, immutable_vector}; import vec::{const_vector, copyable_vector, immutable_vector};
@ -14,7 +14,7 @@ import num::Num;
import ptr::ptr; import ptr::ptr;
import to_str::ToStr; import to_str::ToStr;
export path, option, some, none, unreachable; export Path, option, some, none, unreachable;
export extensions; export extensions;
// The following exports are the extension impls for numeric types // The following exports are the extension impls for numeric types
export Num, times, timesi; export Num, times, timesi;

View file

@ -13,8 +13,8 @@
* CPRNG like rand::rng. * CPRNG like rand::rng.
*/ */
import io::writer; import io::Writer;
import io::writer_util; import io::WriterUtil;
export Streaming, State; export Streaming, State;
export default_state; export default_state;
@ -126,7 +126,7 @@ fn SipState(key0: u64, key1: u64) -> SipState {
} }
impl &SipState : io::writer { impl &SipState : io::Writer {
// Methods for io::writer // Methods for io::writer
fn write(msg: &[const u8]) { fn write(msg: &[const u8]) {
@ -209,7 +209,7 @@ impl &SipState : io::writer {
self.ntail = left; self.ntail = left;
} }
fn seek(_x: int, _s: io::seek_style) { fn seek(_x: int, _s: io::SeekStyle) {
fail; fail;
} }
fn tell() -> uint { fn tell() -> uint {
@ -218,8 +218,8 @@ impl &SipState : io::writer {
fn flush() -> int { fn flush() -> int {
0 0
} }
fn get_type() -> io::writer_type { fn get_type() -> io::WriterType {
io::file io::File
} }
} }

View file

@ -11,6 +11,7 @@ import libc::{c_int, c_long, c_uint, c_void, size_t, ssize_t};
import libc::consts::os::posix88::*; import libc::consts::os::posix88::*;
import libc::consts::os::extra::*; import libc::consts::os::extra::*;
#[allow(non_camel_case_types)] // not sure what to do about this
type fd_t = c_int; type fd_t = c_int;
#[abi = "cdecl"] #[abi = "cdecl"]
@ -24,11 +25,11 @@ extern mod rustrt {
// FIXME (#2004): This is all buffered. We might need an unbuffered variant // FIXME (#2004): This is all buffered. We might need an unbuffered variant
// as well // as well
enum seek_style { seek_set, seek_end, seek_cur, } enum SeekStyle { SeekSet, SeekEnd, SeekCur, }
// The raw underlying reader trait. All readers must implement this. // The raw underlying reader trait. All readers must implement this.
trait reader { trait Reader {
// FIXME (#2004): Seekable really should be orthogonal. // FIXME (#2004): Seekable really should be orthogonal.
// FIXME (#2982): This should probably return an error. // FIXME (#2982): This should probably return an error.
@ -36,13 +37,13 @@ trait reader {
fn read_byte() -> int; fn read_byte() -> int;
fn unread_byte(int); fn unread_byte(int);
fn eof() -> bool; fn eof() -> bool;
fn seek(int, seek_style); fn seek(int, SeekStyle);
fn tell() -> uint; fn tell() -> uint;
} }
// Generic utility functions defined on readers // Generic utility functions defined on readers
impl reader { impl Reader {
fn read_bytes(len: uint) -> ~[u8] { fn read_bytes(len: uint) -> ~[u8] {
let mut buf = ~[mut]; let mut buf = ~[mut];
vec::reserve(buf, len); vec::reserve(buf, len);
@ -195,15 +196,15 @@ impl reader {
// Reader implementations // Reader implementations
fn convert_whence(whence: seek_style) -> i32 { fn convert_whence(whence: SeekStyle) -> i32 {
return match whence { return match whence {
seek_set => 0i32, SeekSet => 0i32,
seek_cur => 1i32, SeekCur => 1i32,
seek_end => 2i32 SeekEnd => 2i32
}; };
} }
impl *libc::FILE: reader { impl *libc::FILE: Reader {
fn read(buf: &[mut u8], len: uint) -> uint { fn read(buf: &[mut u8], len: uint) -> uint {
do vec::as_buf(buf) |buf_p, buf_len| { do vec::as_buf(buf) |buf_p, buf_len| {
assert buf_len <= len; assert buf_len <= len;
@ -217,7 +218,7 @@ impl *libc::FILE: reader {
fn read_byte() -> int { return libc::fgetc(self) as int; } fn read_byte() -> int { return libc::fgetc(self) as int; }
fn unread_byte(byte: int) { libc::ungetc(byte as c_int, self); } fn unread_byte(byte: int) { libc::ungetc(byte as c_int, self); }
fn eof() -> bool { return libc::feof(self) != 0 as c_int; } fn eof() -> bool { return libc::feof(self) != 0 as c_int; }
fn seek(offset: int, whence: seek_style) { fn seek(offset: int, whence: SeekStyle) {
assert libc::fseek(self, offset as c_long, convert_whence(whence)) assert libc::fseek(self, offset as c_long, convert_whence(whence))
== 0 as c_int; == 0 as c_int;
} }
@ -227,26 +228,26 @@ impl *libc::FILE: reader {
// A forwarding impl of reader that also holds on to a resource for the // A forwarding impl of reader that also holds on to a resource for the
// duration of its lifetime. // duration of its lifetime.
// FIXME there really should be a better way to do this // #2004 // FIXME there really should be a better way to do this // #2004
impl<T: reader, C> {base: T, cleanup: C}: reader { impl<T: Reader, C> {base: T, cleanup: C}: Reader {
fn read(buf: &[mut u8], len: uint) -> uint { self.base.read(buf, len) } fn read(buf: &[mut u8], len: uint) -> uint { self.base.read(buf, len) }
fn read_byte() -> int { self.base.read_byte() } fn read_byte() -> int { self.base.read_byte() }
fn unread_byte(byte: int) { self.base.unread_byte(byte); } fn unread_byte(byte: int) { self.base.unread_byte(byte); }
fn eof() -> bool { self.base.eof() } fn eof() -> bool { self.base.eof() }
fn seek(off: int, whence: seek_style) { self.base.seek(off, whence) } fn seek(off: int, whence: SeekStyle) { self.base.seek(off, whence) }
fn tell() -> uint { self.base.tell() } fn tell() -> uint { self.base.tell() }
} }
class FILE_res { class FILERes {
let f: *libc::FILE; let f: *libc::FILE;
new(f: *libc::FILE) { self.f = f; } new(f: *libc::FILE) { self.f = f; }
drop { libc::fclose(self.f); } drop { libc::fclose(self.f); }
} }
fn FILE_reader(f: *libc::FILE, cleanup: bool) -> reader { fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader {
if cleanup { if cleanup {
{base: f, cleanup: FILE_res(f)} as reader {base: f, cleanup: FILERes(f)} as Reader
} else { } else {
f as reader f as Reader
} }
} }
@ -254,9 +255,9 @@ fn FILE_reader(f: *libc::FILE, cleanup: bool) -> reader {
// top-level functions that take a reader, or a set of default methods on // top-level functions that take a reader, or a set of default methods on
// reader (which can then be called reader) // reader (which can then be called reader)
fn stdin() -> reader { rustrt::rust_get_stdin() as reader } fn stdin() -> Reader { rustrt::rust_get_stdin() as Reader }
fn file_reader(path: ~str) -> result<reader, ~str> { fn file_reader(path: ~str) -> result<Reader, ~str> {
let f = os::as_c_charp(path, |pathbuf| { let f = os::as_c_charp(path, |pathbuf| {
os::as_c_charp(~"r", |modebuf| os::as_c_charp(~"r", |modebuf|
libc::fopen(pathbuf, modebuf) libc::fopen(pathbuf, modebuf)
@ -271,9 +272,9 @@ fn file_reader(path: ~str) -> result<reader, ~str> {
// Byte buffer readers // Byte buffer readers
type byte_buf = {buf: ~[const u8], mut pos: uint, len: uint}; type ByteBuf = {buf: ~[const u8], mut pos: uint, len: uint};
impl byte_buf: reader { impl ByteBuf: Reader {
fn read(buf: &[mut u8], len: uint) -> uint { fn read(buf: &[mut u8], len: uint) -> uint {
let count = uint::min(len, self.len - self.pos); let count = uint::min(len, self.len - self.pos);
@ -293,65 +294,65 @@ impl byte_buf: reader {
// FIXME (#2738): implement this // FIXME (#2738): implement this
fn unread_byte(_byte: int) { error!{"Unimplemented: unread_byte"}; fail; } fn unread_byte(_byte: int) { error!{"Unimplemented: unread_byte"}; fail; }
fn eof() -> bool { self.pos == self.len } fn eof() -> bool { self.pos == self.len }
fn seek(offset: int, whence: seek_style) { fn seek(offset: int, whence: SeekStyle) {
let pos = self.pos; let pos = self.pos;
self.pos = seek_in_buf(offset, pos, self.len, whence); self.pos = seek_in_buf(offset, pos, self.len, whence);
} }
fn tell() -> uint { self.pos } fn tell() -> uint { self.pos }
} }
fn bytes_reader(bytes: ~[u8]) -> reader { fn bytes_reader(bytes: ~[u8]) -> Reader {
bytes_reader_between(bytes, 0u, vec::len(bytes)) bytes_reader_between(bytes, 0u, vec::len(bytes))
} }
fn bytes_reader_between(bytes: ~[u8], start: uint, end: uint) -> reader { fn bytes_reader_between(bytes: ~[u8], start: uint, end: uint) -> Reader {
{buf: bytes, mut pos: start, len: end} as reader {buf: bytes, mut pos: start, len: end} as Reader
} }
fn with_bytes_reader<t>(bytes: ~[u8], f: fn(reader) -> t) -> t { fn with_bytes_reader<t>(bytes: ~[u8], f: fn(Reader) -> t) -> t {
f(bytes_reader(bytes)) f(bytes_reader(bytes))
} }
fn with_bytes_reader_between<t>(bytes: ~[u8], start: uint, end: uint, fn with_bytes_reader_between<t>(bytes: ~[u8], start: uint, end: uint,
f: fn(reader) -> t) -> t { f: fn(Reader) -> t) -> t {
f(bytes_reader_between(bytes, start, end)) f(bytes_reader_between(bytes, start, end))
} }
fn str_reader(s: ~str) -> reader { fn str_reader(s: ~str) -> Reader {
bytes_reader(str::bytes(s)) bytes_reader(str::bytes(s))
} }
fn with_str_reader<T>(s: ~str, f: fn(reader) -> T) -> T { fn with_str_reader<T>(s: ~str, f: fn(Reader) -> T) -> T {
do str::as_bytes(s) |bytes| { do str::as_bytes(s) |bytes| {
with_bytes_reader_between(bytes, 0u, str::len(s), f) with_bytes_reader_between(bytes, 0u, str::len(s), f)
} }
} }
// Writing // Writing
enum fileflag { append, create, truncate, no_flag, } enum FileFlag { Append, Create, Truncate, NoFlag, }
// What type of writer are we? // What type of writer are we?
enum writer_type { screen, file } enum WriterType { Screen, File }
// FIXME (#2004): Seekable really should be orthogonal. // FIXME (#2004): Seekable really should be orthogonal.
// FIXME (#2004): eventually u64 // FIXME (#2004): eventually u64
trait writer { trait Writer {
fn write(v: &[const u8]); fn write(v: &[const u8]);
fn seek(int, seek_style); fn seek(int, SeekStyle);
fn tell() -> uint; fn tell() -> uint;
fn flush() -> int; fn flush() -> int;
fn get_type() -> writer_type; fn get_type() -> WriterType;
} }
impl<T: writer, C> {base: T, cleanup: C}: writer { impl<T: Writer, C> {base: T, cleanup: C}: Writer {
fn write(bs: &[const u8]) { self.base.write(bs); } fn write(bs: &[const u8]) { self.base.write(bs); }
fn seek(off: int, style: seek_style) { self.base.seek(off, style); } fn seek(off: int, style: SeekStyle) { self.base.seek(off, style); }
fn tell() -> uint { self.base.tell() } fn tell() -> uint { self.base.tell() }
fn flush() -> int { self.base.flush() } fn flush() -> int { self.base.flush() }
fn get_type() -> writer_type { file } fn get_type() -> WriterType { File }
} }
impl *libc::FILE: writer { impl *libc::FILE: Writer {
fn write(v: &[const u8]) { fn write(v: &[const u8]) {
do vec::as_const_buf(v) |vbuf, len| { do vec::as_const_buf(v) |vbuf, len| {
let nout = libc::fwrite(vbuf as *c_void, len as size_t, let nout = libc::fwrite(vbuf as *c_void, len as size_t,
@ -363,28 +364,28 @@ impl *libc::FILE: writer {
} }
} }
} }
fn seek(offset: int, whence: seek_style) { fn seek(offset: int, whence: SeekStyle) {
assert libc::fseek(self, offset as c_long, convert_whence(whence)) assert libc::fseek(self, offset as c_long, convert_whence(whence))
== 0 as c_int; == 0 as c_int;
} }
fn tell() -> uint { libc::ftell(self) as uint } fn tell() -> uint { libc::ftell(self) as uint }
fn flush() -> int { libc::fflush(self) as int } fn flush() -> int { libc::fflush(self) as int }
fn get_type() -> writer_type { fn get_type() -> WriterType {
let fd = libc::fileno(self); let fd = libc::fileno(self);
if libc::isatty(fd) == 0 { file } if libc::isatty(fd) == 0 { File }
else { screen } else { Screen }
} }
} }
fn FILE_writer(f: *libc::FILE, cleanup: bool) -> writer { fn FILE_writer(f: *libc::FILE, cleanup: bool) -> Writer {
if cleanup { if cleanup {
{base: f, cleanup: FILE_res(f)} as writer {base: f, cleanup: FILERes(f)} as Writer
} else { } else {
f as writer f as Writer
} }
} }
impl fd_t: writer { impl fd_t: Writer {
fn write(v: &[const u8]) { fn write(v: &[const u8]) {
let mut count = 0u; let mut count = 0u;
do vec::as_const_buf(v) |vbuf, len| { do vec::as_const_buf(v) |vbuf, len| {
@ -400,7 +401,7 @@ impl fd_t: writer {
} }
} }
} }
fn seek(_offset: int, _whence: seek_style) { fn seek(_offset: int, _whence: SeekStyle) {
error!{"need 64-bit foreign calls for seek, sorry"}; error!{"need 64-bit foreign calls for seek, sorry"};
fail; fail;
} }
@ -409,28 +410,28 @@ impl fd_t: writer {
fail; fail;
} }
fn flush() -> int { 0 } fn flush() -> int { 0 }
fn get_type() -> writer_type { fn get_type() -> WriterType {
if libc::isatty(self) == 0 { file } else { screen } if libc::isatty(self) == 0 { File } else { Screen }
} }
} }
class fd_res { class FdRes {
let fd: fd_t; let fd: fd_t;
new(fd: fd_t) { self.fd = fd; } new(fd: fd_t) { self.fd = fd; }
drop { libc::close(self.fd); } drop { libc::close(self.fd); }
} }
fn fd_writer(fd: fd_t, cleanup: bool) -> writer { fn fd_writer(fd: fd_t, cleanup: bool) -> Writer {
if cleanup { if cleanup {
{base: fd, cleanup: fd_res(fd)} as writer {base: fd, cleanup: FdRes(fd)} as Writer
} else { } else {
fd as writer fd as Writer
} }
} }
fn mk_file_writer(path: ~str, flags: ~[fileflag]) fn mk_file_writer(path: ~str, flags: ~[FileFlag])
-> result<writer, ~str> { -> result<Writer, ~str> {
#[cfg(windows)] #[cfg(windows)]
fn wb() -> c_int { (O_WRONLY | O_BINARY) as c_int } fn wb() -> c_int { (O_WRONLY | O_BINARY) as c_int }
@ -441,10 +442,10 @@ fn mk_file_writer(path: ~str, flags: ~[fileflag])
let mut fflags: c_int = wb(); let mut fflags: c_int = wb();
for vec::each(flags) |f| { for vec::each(flags) |f| {
match f { match f {
append => fflags |= O_APPEND as c_int, Append => fflags |= O_APPEND as c_int,
create => fflags |= O_CREAT as c_int, Create => fflags |= O_CREAT as c_int,
truncate => fflags |= O_TRUNC as c_int, Truncate => fflags |= O_TRUNC as c_int,
no_flag => () NoFlag => ()
} }
} }
let fd = do os::as_c_charp(path) |pathbuf| { let fd = do os::as_c_charp(path) |pathbuf| {
@ -535,7 +536,7 @@ fn u64_from_be_bytes(data: ~[u8], start: uint, size: uint) -> u64 {
// FIXME: #3048 combine trait+impl (or just move these to // FIXME: #3048 combine trait+impl (or just move these to
// default methods on writer) // default methods on writer)
trait writer_util { trait WriterUtil {
fn write_char(ch: char); fn write_char(ch: char);
fn write_str(s: &str); fn write_str(s: &str);
fn write_line(s: &str); fn write_line(s: &str);
@ -560,7 +561,7 @@ trait writer_util {
fn write_u8(n: u8); fn write_u8(n: u8);
} }
impl<T:writer> T : writer_util { impl<T: Writer> T : WriterUtil {
fn write_char(ch: char) { fn write_char(ch: char) {
if ch as uint < 128u { if ch as uint < 128u {
self.write(&[ch as u8]); self.write(&[ch as u8]);
@ -631,13 +632,13 @@ impl<T:writer> T : writer_util {
fn write_u8(n: u8) { self.write(&[n]) } fn write_u8(n: u8) { self.write(&[n]) }
} }
fn file_writer(path: ~str, flags: ~[fileflag]) -> result<writer, ~str> { fn file_writer(path: ~str, flags: ~[FileFlag]) -> result<Writer, ~str> {
result::chain(mk_file_writer(path, flags), |w| result::ok(w)) result::chain(mk_file_writer(path, flags), |w| result::ok(w))
} }
// FIXME: fileflags // #2004 // FIXME: fileflags // #2004
fn buffered_file_writer(path: ~str) -> result<writer, ~str> { fn buffered_file_writer(path: ~str) -> result<Writer, ~str> {
let f = do os::as_c_charp(path) |pathbuf| { let f = do os::as_c_charp(path) |pathbuf| {
do os::as_c_charp(~"w") |modebuf| { do os::as_c_charp(~"w") |modebuf| {
libc::fopen(pathbuf, modebuf) libc::fopen(pathbuf, modebuf)
@ -650,15 +651,15 @@ fn buffered_file_writer(path: ~str) -> result<writer, ~str> {
// FIXME (#2004) it would be great if this could be a const // FIXME (#2004) it would be great if this could be a const
// FIXME (#2004) why are these different from the way stdin() is // FIXME (#2004) why are these different from the way stdin() is
// implemented? // implemented?
fn stdout() -> writer { fd_writer(libc::STDOUT_FILENO as c_int, false) } fn stdout() -> Writer { fd_writer(libc::STDOUT_FILENO as c_int, false) }
fn stderr() -> writer { fd_writer(libc::STDERR_FILENO as c_int, false) } fn stderr() -> Writer { fd_writer(libc::STDERR_FILENO as c_int, false) }
fn print(s: &str) { stdout().write_str(s); } fn print(s: &str) { stdout().write_str(s); }
fn println(s: &str) { stdout().write_line(s); } fn println(s: &str) { stdout().write_line(s); }
type mem_buffer = @{buf: dvec<u8>, mut pos: uint}; type MemBuffer = @{buf: dvec<u8>, mut pos: uint};
impl mem_buffer: writer { impl MemBuffer: Writer {
fn write(v: &[const u8]) { fn write(v: &[const u8]) {
// Fast path. // Fast path.
let vlen = vec::len(v); let vlen = vec::len(v);
@ -679,33 +680,33 @@ impl mem_buffer: writer {
self.buf.push_slice(v, vpos, vlen); self.buf.push_slice(v, vpos, vlen);
self.pos += vlen; self.pos += vlen;
} }
fn seek(offset: int, whence: seek_style) { fn seek(offset: int, whence: SeekStyle) {
let pos = self.pos; let pos = self.pos;
let len = self.buf.len(); let len = self.buf.len();
self.pos = seek_in_buf(offset, pos, len, whence); self.pos = seek_in_buf(offset, pos, len, whence);
} }
fn tell() -> uint { self.pos } fn tell() -> uint { self.pos }
fn flush() -> int { 0 } fn flush() -> int { 0 }
fn get_type() -> writer_type { file } fn get_type() -> WriterType { File }
} }
fn mem_buffer() -> mem_buffer { fn mem_buffer() -> MemBuffer {
@{buf: dvec(), mut pos: 0u} @{buf: dvec(), mut pos: 0u}
} }
fn mem_buffer_writer(b: mem_buffer) -> writer { b as writer } fn mem_buffer_writer(b: MemBuffer) -> Writer { b as Writer }
fn mem_buffer_buf(b: mem_buffer) -> ~[u8] { b.buf.get() } fn mem_buffer_buf(b: MemBuffer) -> ~[u8] { b.buf.get() }
fn mem_buffer_str(b: mem_buffer) -> ~str { fn mem_buffer_str(b: MemBuffer) -> ~str {
str::from_bytes(b.buf.get()) str::from_bytes(b.buf.get())
} }
fn with_str_writer(f: fn(writer)) -> ~str { fn with_str_writer(f: fn(Writer)) -> ~str {
let buf = mem_buffer(); let buf = mem_buffer();
let wr = mem_buffer_writer(buf); let wr = mem_buffer_writer(buf);
f(wr); f(wr);
io::mem_buffer_str(buf) io::mem_buffer_str(buf)
} }
fn with_buf_writer(f: fn(writer)) -> ~[u8] { fn with_buf_writer(f: fn(Writer)) -> ~[u8] {
let buf = mem_buffer(); let buf = mem_buffer();
let wr = mem_buffer_writer(buf); let wr = mem_buffer_writer(buf);
f(wr); f(wr);
@ -713,14 +714,14 @@ fn with_buf_writer(f: fn(writer)) -> ~[u8] {
} }
// Utility functions // Utility functions
fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) -> fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
uint { uint {
let mut bpos = pos as int; let mut bpos = pos as int;
let blen = len as int; let blen = len as int;
match whence { match whence {
seek_set => bpos = offset, SeekSet => bpos = offset,
seek_cur => bpos += offset, SeekCur => bpos += offset,
seek_end => bpos = blen + offset SeekEnd => bpos = blen + offset
} }
if bpos < 0 { bpos = 0; } else if bpos > blen { bpos = blen; } if bpos < 0 { bpos = 0; } else if bpos > blen { bpos = blen; }
return bpos as uint; return bpos as uint;
@ -748,24 +749,24 @@ fn read_whole_file(file: ~str) -> result<~[u8], ~str> {
mod fsync { mod fsync {
enum level { enum Level {
// whatever fsync does on that platform // whatever fsync does on that platform
fsync, FSync,
// fdatasync on linux, similiar or more on other platforms // fdatasync on linux, similiar or more on other platforms
fdatasync, FDataSync,
// full fsync // full fsync
// //
// You must additionally sync the parent directory as well! // You must additionally sync the parent directory as well!
fullfsync, FullFSync,
} }
// Artifacts that need to fsync on destruction // Artifacts that need to fsync on destruction
class res<t> { class Res<t> {
let arg: arg<t>; let arg: Arg<t>;
new(-arg: arg<t>) { self.arg <- arg; } new(-arg: Arg<t>) { self.arg <- arg; }
drop { drop {
match self.arg.opt_level { match self.arg.opt_level {
option::none => (), option::none => (),
@ -777,44 +778,47 @@ mod fsync {
} }
} }
type arg<t> = { type Arg<t> = {
val: t, val: t,
opt_level: option<level>, opt_level: option<Level>,
fsync_fn: fn@(t, level) -> int fsync_fn: fn@(t, Level) -> int
}; };
// fsync file after executing blk // fsync file after executing blk
// FIXME (#2004) find better way to create resources within lifetime of // FIXME (#2004) find better way to create resources within lifetime of
// outer res // outer res
fn FILE_res_sync(&&file: FILE_res, opt_level: option<level>, fn FILE_res_sync(&&file: FILERes, opt_level: option<Level>,
blk: fn(&&res<*libc::FILE>)) { blk: fn(&&Res<*libc::FILE>)) {
blk(res({ blk(Res({
val: file.f, opt_level: opt_level, val: file.f, opt_level: opt_level,
fsync_fn: fn@(&&file: *libc::FILE, l: level) -> int { fsync_fn: fn@(&&file: *libc::FILE, l: Level) -> int {
return os::fsync_fd(libc::fileno(file), l) as int; return os::fsync_fd(libc::fileno(file), l) as int;
} }
})); }));
} }
// fsync fd after executing blk // fsync fd after executing blk
fn fd_res_sync(&&fd: fd_res, opt_level: option<level>, fn fd_res_sync(&&fd: FdRes, opt_level: option<Level>,
blk: fn(&&res<fd_t>)) { blk: fn(&&Res<fd_t>)) {
blk(res({ blk(Res({
val: fd.fd, opt_level: opt_level, val: fd.fd, opt_level: opt_level,
fsync_fn: fn@(&&fd: fd_t, l: level) -> int { fsync_fn: fn@(&&fd: fd_t, l: Level) -> int {
return os::fsync_fd(fd, l) as int; return os::fsync_fd(fd, l) as int;
} }
})); }));
} }
// Type of objects that may want to fsync // Type of objects that may want to fsync
trait t { fn fsync(l: level) -> int; } trait FSyncable { fn fsync(l: Level) -> int; }
// Call o.fsync after executing blk // Call o.fsync after executing blk
fn obj_sync(&&o: t, opt_level: option<level>, blk: fn(&&res<t>)) { fn obj_sync(&&o: FSyncable, opt_level: option<Level>,
blk(res({ blk: fn(&&Res<FSyncable>)) {
blk(Res({
val: o, opt_level: opt_level, val: o, opt_level: opt_level,
fsync_fn: fn@(&&o: t, l: level) -> int { return o.fsync(l); } fsync_fn: fn@(&&o: FSyncable, l: Level) -> int {
return o.fsync(l);
}
})); }));
} }
} }
@ -830,12 +834,12 @@ mod tests {
~"A hoopy frood who really knows where his towel is."; ~"A hoopy frood who really knows where his towel is.";
log(debug, frood); log(debug, frood);
{ {
let out: io::writer = let out: io::Writer =
result::get( result::get(
io::file_writer(tmpfile, ~[io::create, io::truncate])); io::file_writer(tmpfile, ~[io::Create, io::Truncate]));
out.write_str(frood); out.write_str(frood);
} }
let inp: io::reader = result::get(io::file_reader(tmpfile)); let inp: io::Reader = result::get(io::file_reader(tmpfile));
let frood2: ~str = inp.read_c_str(); let frood2: ~str = inp.read_c_str();
log(debug, frood2); log(debug, frood2);
assert frood == frood2; assert frood == frood2;
@ -843,7 +847,7 @@ mod tests {
#[test] #[test]
fn test_readchars_empty() { fn test_readchars_empty() {
let inp : io::reader = io::str_reader(~""); let inp : io::Reader = io::str_reader(~"");
let res : ~[char] = inp.read_chars(128u); let res : ~[char] = inp.read_chars(128u);
assert(vec::len(res) == 0u); assert(vec::len(res) == 0u);
} }
@ -858,7 +862,7 @@ mod tests {
29983, 38152, 30340, 27748, 29983, 38152, 30340, 27748,
21273, 20999, 32905, 27748]; 21273, 20999, 32905, 27748];
fn check_read_ln(len : uint, s: ~str, ivals: ~[int]) { fn check_read_ln(len : uint, s: ~str, ivals: ~[int]) {
let inp : io::reader = io::str_reader(s); let inp : io::Reader = io::str_reader(s);
let res : ~[char] = inp.read_chars(len); let res : ~[char] = inp.read_chars(len);
if (len <= vec::len(ivals)) { if (len <= vec::len(ivals)) {
assert(vec::len(res) == len); assert(vec::len(res) == len);
@ -877,14 +881,14 @@ mod tests {
#[test] #[test]
fn test_readchar() { fn test_readchar() {
let inp : io::reader = io::str_reader(~""); let inp : io::Reader = io::str_reader(~"");
let res : char = inp.read_char(); let res : char = inp.read_char();
assert(res as int == 29983); assert(res as int == 29983);
} }
#[test] #[test]
fn test_readchar_empty() { fn test_readchar_empty() {
let inp : io::reader = io::str_reader(~""); let inp : io::Reader = io::str_reader(~"");
let res : char = inp.read_char(); let res : char = inp.read_char();
assert(res as int == -1); assert(res as int == -1);
} }
@ -924,12 +928,12 @@ mod tests {
let mbuf = mem_buffer(); let mbuf = mem_buffer();
mbuf.write(~[0u8, 1u8, 2u8, 3u8]); mbuf.write(~[0u8, 1u8, 2u8, 3u8]);
assert mem_buffer_buf(mbuf) == ~[0u8, 1u8, 2u8, 3u8]; assert mem_buffer_buf(mbuf) == ~[0u8, 1u8, 2u8, 3u8];
mbuf.seek(-2, seek_cur); mbuf.seek(-2, SeekCur);
mbuf.write(~[4u8, 5u8, 6u8, 7u8]); mbuf.write(~[4u8, 5u8, 6u8, 7u8]);
assert mem_buffer_buf(mbuf) == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]; assert mem_buffer_buf(mbuf) == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8];
mbuf.seek(-2, seek_end); mbuf.seek(-2, SeekEnd);
mbuf.write(~[8u8]); mbuf.write(~[8u8]);
mbuf.seek(1, seek_set); mbuf.seek(1, SeekSet);
mbuf.write(~[9u8]); mbuf.write(~[9u8]);
assert mem_buffer_buf(mbuf) == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]; assert mem_buffer_buf(mbuf) == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8];
} }

View file

@ -37,6 +37,8 @@
* dissolved. * dissolved.
*/ */
#[allow(non_camel_case_types)];
// Initial glob-exports mean that all the contents of all the modules // Initial glob-exports mean that all the contents of all the modules
// wind up exported, if you're interested in writing platform-specific code. // wind up exported, if you're interested in writing platform-specific code.

View file

@ -134,34 +134,34 @@ mod global_env {
fn rust_global_env_chan_ptr() -> *libc::uintptr_t; fn rust_global_env_chan_ptr() -> *libc::uintptr_t;
} }
enum msg { enum Msg {
msg_getenv(~str, comm::chan<option<~str>>), MsgGetEnv(~str, comm::chan<option<~str>>),
msg_setenv(~str, ~str, comm::chan<()>), MsgSetEnv(~str, ~str, comm::chan<()>),
msg_env(comm::chan<~[(~str,~str)]>) MsgEnv(comm::chan<~[(~str,~str)]>)
} }
fn getenv(n: ~str) -> option<~str> { fn getenv(n: ~str) -> option<~str> {
let env_ch = get_global_env_chan(); let env_ch = get_global_env_chan();
let po = comm::port(); let po = comm::port();
comm::send(env_ch, msg_getenv(n, comm::chan(po))); comm::send(env_ch, MsgGetEnv(n, comm::chan(po)));
comm::recv(po) comm::recv(po)
} }
fn setenv(n: ~str, v: ~str) { fn setenv(n: ~str, v: ~str) {
let env_ch = get_global_env_chan(); let env_ch = get_global_env_chan();
let po = comm::port(); let po = comm::port();
comm::send(env_ch, msg_setenv(n, v, comm::chan(po))); comm::send(env_ch, MsgSetEnv(n, v, comm::chan(po)));
comm::recv(po) comm::recv(po)
} }
fn env() -> ~[(~str,~str)] { fn env() -> ~[(~str,~str)] {
let env_ch = get_global_env_chan(); let env_ch = get_global_env_chan();
let po = comm::port(); let po = comm::port();
comm::send(env_ch, msg_env(comm::chan(po))); comm::send(env_ch, MsgEnv(comm::chan(po)));
comm::recv(po) comm::recv(po)
} }
fn get_global_env_chan() -> comm::chan<msg> { fn get_global_env_chan() -> comm::chan<Msg> {
let global_ptr = rustrt::rust_global_env_chan_ptr(); let global_ptr = rustrt::rust_global_env_chan_ptr();
unsafe { unsafe {
priv::chan_from_global_ptr(global_ptr, || { priv::chan_from_global_ptr(global_ptr, || {
@ -172,18 +172,18 @@ mod global_env {
} }
} }
fn global_env_task(msg_po: comm::port<msg>) { fn global_env_task(msg_po: comm::port<Msg>) {
unsafe { unsafe {
do priv::weaken_task |weak_po| { do priv::weaken_task |weak_po| {
loop { loop {
match comm::select2(msg_po, weak_po) { match comm::select2(msg_po, weak_po) {
either::left(msg_getenv(n, resp_ch)) => { either::left(MsgGetEnv(n, resp_ch)) => {
comm::send(resp_ch, impl::getenv(n)) comm::send(resp_ch, impl::getenv(n))
} }
either::left(msg_setenv(n, v, resp_ch)) => { either::left(MsgSetEnv(n, v, resp_ch)) => {
comm::send(resp_ch, impl::setenv(n, v)) comm::send(resp_ch, impl::setenv(n, v))
} }
either::left(msg_env(resp_ch)) => { either::left(MsgEnv(resp_ch)) => {
comm::send(resp_ch, impl::env()) comm::send(resp_ch, impl::env())
} }
either::right(_) => break either::right(_) => break
@ -272,28 +272,28 @@ fn fdopen(fd: c_int) -> *FILE {
// fsync related // fsync related
#[cfg(windows)] #[cfg(windows)]
fn fsync_fd(fd: c_int, _level: io::fsync::level) -> c_int { fn fsync_fd(fd: c_int, _level: io::fsync::Level) -> c_int {
import libc::funcs::extra::msvcrt::*; import libc::funcs::extra::msvcrt::*;
return commit(fd); return commit(fd);
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int { fn fsync_fd(fd: c_int, level: io::fsync::Level) -> c_int {
import libc::funcs::posix01::unistd::*; import libc::funcs::posix01::unistd::*;
match level { match level {
io::fsync::fsync io::fsync::FSync
| io::fsync::fullfsync => return fsync(fd), | io::fsync::FullFSync => return fsync(fd),
io::fsync::fdatasync => return fdatasync(fd) io::fsync::FDataSync => return fdatasync(fd)
} }
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int { fn fsync_fd(fd: c_int, level: io::fsync::Level) -> c_int {
import libc::consts::os::extra::*; import libc::consts::os::extra::*;
import libc::funcs::posix88::fcntl::*; import libc::funcs::posix88::fcntl::*;
import libc::funcs::posix01::unistd::*; import libc::funcs::posix01::unistd::*;
match level { match level {
io::fsync::fsync => return fsync(fd), io::fsync::FSync => return fsync(fd),
_ => { _ => {
// According to man fnctl, the ok retval is only specified to be !=-1 // According to man fnctl, the ok retval is only specified to be !=-1
if (fcntl(F_FULLFSYNC as c_int, fd) == -1 as c_int) if (fcntl(F_FULLFSYNC as c_int, fd) == -1 as c_int)
@ -305,7 +305,7 @@ fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int {
} }
#[cfg(target_os = "freebsd")] #[cfg(target_os = "freebsd")]
fn fsync_fd(fd: c_int, _l: io::fsync::level) -> c_int { fn fsync_fd(fd: c_int, _l: io::fsync::Level) -> c_int {
import libc::funcs::posix01::unistd::*; import libc::funcs::posix01::unistd::*;
return fsync(fd); return fsync(fd);
} }
@ -369,10 +369,10 @@ fn dll_filename(base: ~str) -> ~str {
} }
fn self_exe_path() -> option<path> { fn self_exe_path() -> option<Path> {
#[cfg(target_os = "freebsd")] #[cfg(target_os = "freebsd")]
fn load_self() -> option<path> { fn load_self() -> option<Path> {
unsafe { unsafe {
import libc::funcs::bsd44::*; import libc::funcs::bsd44::*;
import libc::consts::os::extra::*; import libc::consts::os::extra::*;
@ -388,7 +388,7 @@ fn self_exe_path() -> option<path> {
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn load_self() -> option<path> { fn load_self() -> option<Path> {
import libc::funcs::posix01::unistd::readlink; import libc::funcs::posix01::unistd::readlink;
do fill_charp_buf() |buf, sz| { do fill_charp_buf() |buf, sz| {
do as_c_charp(~"/proc/self/exe") |proc_self_buf| { do as_c_charp(~"/proc/self/exe") |proc_self_buf| {
@ -398,7 +398,7 @@ fn self_exe_path() -> option<path> {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn load_self() -> option<path> { fn load_self() -> option<Path> {
// FIXME: remove imports when export globs work properly. #1238 // FIXME: remove imports when export globs work properly. #1238
import libc::funcs::extra::*; import libc::funcs::extra::*;
do fill_charp_buf() |buf, sz| { do fill_charp_buf() |buf, sz| {
@ -408,7 +408,7 @@ fn self_exe_path() -> option<path> {
} }
#[cfg(windows)] #[cfg(windows)]
fn load_self() -> option<path> { fn load_self() -> option<Path> {
// FIXME: remove imports when export globs work properly. #1238 // FIXME: remove imports when export globs work properly. #1238
import libc::types::os::arch::extra::*; import libc::types::os::arch::extra::*;
import libc::funcs::extra::kernel32::*; import libc::funcs::extra::kernel32::*;
@ -437,7 +437,7 @@ fn self_exe_path() -> option<path> {
* *
* Otherwise, homedir returns option::none. * Otherwise, homedir returns option::none.
*/ */
fn homedir() -> option<path> { fn homedir() -> option<Path> {
return match getenv(~"HOME") { return match getenv(~"HOME") {
some(p) => if !str::is_empty(p) { some(p) => if !str::is_empty(p) {
some(p) some(p)
@ -448,12 +448,12 @@ fn homedir() -> option<path> {
}; };
#[cfg(unix)] #[cfg(unix)]
fn secondary() -> option<path> { fn secondary() -> option<Path> {
none none
} }
#[cfg(windows)] #[cfg(windows)]
fn secondary() -> option<path> { fn secondary() -> option<Path> {
do option::chain(getenv(~"USERPROFILE")) |p| { do option::chain(getenv(~"USERPROFILE")) |p| {
if !str::is_empty(p) { if !str::is_empty(p) {
some(p) some(p)
@ -465,11 +465,11 @@ fn homedir() -> option<path> {
} }
/// Recursively walk a directory structure /// Recursively walk a directory structure
fn walk_dir(p: path, f: fn(path) -> bool) { fn walk_dir(p: Path, f: fn(Path) -> bool) {
walk_dir_(p, f); walk_dir_(p, f);
fn walk_dir_(p: path, f: fn(path) -> bool) -> bool { fn walk_dir_(p: Path, f: fn(Path) -> bool) -> bool {
let mut keepgoing = true; let mut keepgoing = true;
do list_dir(p).each |q| { do list_dir(p).each |q| {
let path = path::connect(p, q); let path = path::connect(p, q);
@ -494,14 +494,14 @@ fn walk_dir(p: path, f: fn(path) -> bool) {
} }
/// Indicates whether a path represents a directory /// Indicates whether a path represents a directory
fn path_is_dir(p: path) -> bool { fn path_is_dir(p: Path) -> bool {
do str::as_c_str(p) |buf| { do str::as_c_str(p) |buf| {
rustrt::rust_path_is_dir(buf) != 0 as c_int rustrt::rust_path_is_dir(buf) != 0 as c_int
} }
} }
/// Indicates whether a path exists /// Indicates whether a path exists
fn path_exists(p: path) -> bool { fn path_exists(p: Path) -> bool {
do str::as_c_str(p) |buf| { do str::as_c_str(p) |buf| {
rustrt::rust_path_exists(buf) != 0 as c_int rustrt::rust_path_exists(buf) != 0 as c_int
} }
@ -519,7 +519,7 @@ fn path_exists(p: path) -> bool {
// NB: this is here rather than in path because it is a form of environment // NB: this is here rather than in path because it is a form of environment
// querying; what it does depends on the process working directory, not just // querying; what it does depends on the process working directory, not just
// the input paths. // the input paths.
fn make_absolute(p: path) -> path { fn make_absolute(p: Path) -> Path {
if path::path_is_absolute(p) { if path::path_is_absolute(p) {
p p
} else { } else {
@ -529,11 +529,11 @@ fn make_absolute(p: path) -> path {
/// Creates a directory at the specified path /// Creates a directory at the specified path
fn make_dir(p: path, mode: c_int) -> bool { fn make_dir(p: Path, mode: c_int) -> bool {
return mkdir(p, mode); return mkdir(p, mode);
#[cfg(windows)] #[cfg(windows)]
fn mkdir(p: path, _mode: c_int) -> bool { fn mkdir(p: Path, _mode: c_int) -> bool {
// FIXME: remove imports when export globs work properly. #1238 // FIXME: remove imports when export globs work properly. #1238
import libc::types::os::arch::extra::*; import libc::types::os::arch::extra::*;
import libc::funcs::extra::kernel32::*; import libc::funcs::extra::kernel32::*;
@ -546,7 +546,7 @@ fn make_dir(p: path, mode: c_int) -> bool {
} }
#[cfg(unix)] #[cfg(unix)]
fn mkdir(p: path, mode: c_int) -> bool { fn mkdir(p: Path, mode: c_int) -> bool {
do as_c_charp(p) |c| { do as_c_charp(p) |c| {
libc::mkdir(c, mode as mode_t) == (0 as c_int) libc::mkdir(c, mode as mode_t) == (0 as c_int)
} }
@ -554,7 +554,7 @@ fn make_dir(p: path, mode: c_int) -> bool {
} }
/// Lists the contents of a directory /// Lists the contents of a directory
fn list_dir(p: path) -> ~[~str] { fn list_dir(p: Path) -> ~[~str] {
#[cfg(unix)] #[cfg(unix)]
fn star(p: ~str) -> ~str { p } fn star(p: ~str) -> ~str { p }
@ -580,7 +580,7 @@ fn list_dir(p: path) -> ~[~str] {
* *
* This version prepends each entry with the directory. * This version prepends each entry with the directory.
*/ */
fn list_dir_path(p: path) -> ~[~str] { fn list_dir_path(p: Path) -> ~[~str] {
let mut p = p; let mut p = p;
let pl = str::len(p); let pl = str::len(p);
if pl == 0u || (p[pl - 1u] as char != path::consts::path_sep if pl == 0u || (p[pl - 1u] as char != path::consts::path_sep
@ -591,11 +591,11 @@ fn list_dir_path(p: path) -> ~[~str] {
} }
/// Removes a directory at the specified path /// Removes a directory at the specified path
fn remove_dir(p: path) -> bool { fn remove_dir(p: Path) -> bool {
return rmdir(p); return rmdir(p);
#[cfg(windows)] #[cfg(windows)]
fn rmdir(p: path) -> bool { fn rmdir(p: Path) -> bool {
// FIXME: remove imports when export globs work properly. #1238 // FIXME: remove imports when export globs work properly. #1238
import libc::funcs::extra::kernel32::*; import libc::funcs::extra::kernel32::*;
import libc::types::os::arch::extra::*; import libc::types::os::arch::extra::*;
@ -606,18 +606,18 @@ fn remove_dir(p: path) -> bool {
} }
#[cfg(unix)] #[cfg(unix)]
fn rmdir(p: path) -> bool { fn rmdir(p: Path) -> bool {
return do as_c_charp(p) |buf| { return do as_c_charp(p) |buf| {
libc::rmdir(buf) == (0 as c_int) libc::rmdir(buf) == (0 as c_int)
}; };
} }
} }
fn change_dir(p: path) -> bool { fn change_dir(p: Path) -> bool {
return chdir(p); return chdir(p);
#[cfg(windows)] #[cfg(windows)]
fn chdir(p: path) -> bool { fn chdir(p: Path) -> bool {
// FIXME: remove imports when export globs work properly. #1238 // FIXME: remove imports when export globs work properly. #1238
import libc::funcs::extra::kernel32::*; import libc::funcs::extra::kernel32::*;
import libc::types::os::arch::extra::*; import libc::types::os::arch::extra::*;
@ -628,7 +628,7 @@ fn change_dir(p: path) -> bool {
} }
#[cfg(unix)] #[cfg(unix)]
fn chdir(p: path) -> bool { fn chdir(p: Path) -> bool {
return do as_c_charp(p) |buf| { return do as_c_charp(p) |buf| {
libc::chdir(buf) == (0 as c_int) libc::chdir(buf) == (0 as c_int)
}; };
@ -636,11 +636,11 @@ fn change_dir(p: path) -> bool {
} }
/// Copies a file from one location to another /// Copies a file from one location to another
fn copy_file(from: path, to: path) -> bool { fn copy_file(from: Path, to: Path) -> bool {
return do_copy_file(from, to); return do_copy_file(from, to);
#[cfg(windows)] #[cfg(windows)]
fn do_copy_file(from: path, to: path) -> bool { fn do_copy_file(from: Path, to: Path) -> bool {
// FIXME: remove imports when export globs work properly. #1238 // FIXME: remove imports when export globs work properly. #1238
import libc::funcs::extra::kernel32::*; import libc::funcs::extra::kernel32::*;
import libc::types::os::arch::extra::*; import libc::types::os::arch::extra::*;
@ -653,7 +653,7 @@ fn copy_file(from: path, to: path) -> bool {
} }
#[cfg(unix)] #[cfg(unix)]
fn do_copy_file(from: path, to: path) -> bool { fn do_copy_file(from: Path, to: Path) -> bool {
let istream = do as_c_charp(from) |fromp| { let istream = do as_c_charp(from) |fromp| {
do as_c_charp(~"rb") |modebuf| { do as_c_charp(~"rb") |modebuf| {
libc::fopen(fromp, modebuf) libc::fopen(fromp, modebuf)
@ -699,11 +699,11 @@ fn copy_file(from: path, to: path) -> bool {
} }
/// Deletes an existing file /// Deletes an existing file
fn remove_file(p: path) -> bool { fn remove_file(p: Path) -> bool {
return unlink(p); return unlink(p);
#[cfg(windows)] #[cfg(windows)]
fn unlink(p: path) -> bool { fn unlink(p: Path) -> bool {
// FIXME (similar to Issue #2006): remove imports when export globs // FIXME (similar to Issue #2006): remove imports when export globs
// work properly. // work properly.
import libc::funcs::extra::kernel32::*; import libc::funcs::extra::kernel32::*;
@ -715,7 +715,7 @@ fn remove_file(p: path) -> bool {
} }
#[cfg(unix)] #[cfg(unix)]
fn unlink(p: path) -> bool { fn unlink(p: Path) -> bool {
return do as_c_charp(p) |buf| { return do as_c_charp(p) |buf| {
libc::unlink(buf) == (0 as c_int) libc::unlink(buf) == (0 as c_int)
}; };
@ -792,7 +792,7 @@ mod tests {
fn make_rand_name() -> ~str { fn make_rand_name() -> ~str {
import rand; import rand;
let rng: rand::rng = rand::rng(); let rng: rand::Rng = rand::rng();
let n = ~"TEST" + rng.gen_str(10u); let n = ~"TEST" + rng.gen_str(10u);
assert option::is_none(getenv(n)); assert option::is_none(getenv(n));
n n

View file

@ -1,6 +1,6 @@
//! Path data type and helper functions //! Path data type and helper functions
export path; export Path;
export consts; export consts;
export path_is_absolute; export path_is_absolute;
export path_sep; export path_sep;
@ -14,7 +14,7 @@ export normalize;
// FIXME: This type should probably be constrained (#2624) // FIXME: This type should probably be constrained (#2624)
/// A path or fragment of a filesystem path /// A path or fragment of a filesystem path
type path = ~str; type Path = ~str;
#[cfg(unix)] #[cfg(unix)]
mod consts { mod consts {
@ -45,7 +45,7 @@ mod consts {
* on Windows, begins with a drive letter. * on Windows, begins with a drive letter.
*/ */
#[cfg(unix)] #[cfg(unix)]
fn path_is_absolute(p: path) -> bool { fn path_is_absolute(p: Path) -> bool {
str::char_at(p, 0u) == '/' str::char_at(p, 0u) == '/'
} }
@ -60,7 +60,7 @@ fn path_is_absolute(p: ~str) -> bool {
/// Get the default path separator for the host platform /// Get the default path separator for the host platform
fn path_sep() -> ~str { return str::from_char(consts::path_sep); } fn path_sep() -> ~str { return str::from_char(consts::path_sep); }
fn split_dirname_basename (pp: path) -> {dirname: ~str, basename: ~str} { fn split_dirname_basename (pp: Path) -> {dirname: ~str, basename: ~str} {
match str::rfind(pp, |ch| match str::rfind(pp, |ch|
ch == consts::path_sep || ch == consts::alt_path_sep ch == consts::path_sep || ch == consts::alt_path_sep
) { ) {
@ -81,7 +81,7 @@ fn split_dirname_basename (pp: path) -> {dirname: ~str, basename: ~str} {
* *
* If the path is not prefixed with a directory, then "." is returned. * If the path is not prefixed with a directory, then "." is returned.
*/ */
fn dirname(pp: path) -> path { fn dirname(pp: Path) -> Path {
return split_dirname_basename(pp).dirname; return split_dirname_basename(pp).dirname;
} }
@ -94,7 +94,7 @@ fn dirname(pp: path) -> path {
* the provided path. If an empty path is provided or the path ends * the provided path. If an empty path is provided or the path ends
* with a path separator then an empty path is returned. * with a path separator then an empty path is returned.
*/ */
fn basename(pp: path) -> path { fn basename(pp: Path) -> Path {
return split_dirname_basename(pp).basename; return split_dirname_basename(pp).basename;
} }
@ -105,7 +105,7 @@ fn basename(pp: path) -> path {
* and any leading path separator on `post`, and returns the concatenation of * and any leading path separator on `post`, and returns the concatenation of
* the two with a single path separator between them. * the two with a single path separator between them.
*/ */
fn connect(pre: path, post: path) -> path { fn connect(pre: Path, post: Path) -> Path {
let mut pre_ = pre; let mut pre_ = pre;
let mut post_ = post; let mut post_ = post;
let sep = consts::path_sep as u8; let sep = consts::path_sep as u8;
@ -127,7 +127,7 @@ fn connect(pre: path, post: path) -> path {
* *
* Inserts path separators as needed. * Inserts path separators as needed.
*/ */
fn connect_many(paths: ~[path]) -> path { fn connect_many(paths: ~[Path]) -> Path {
return if vec::len(paths) == 1u { return if vec::len(paths) == 1u {
paths[0] paths[0]
} else { } else {
@ -144,7 +144,7 @@ fn connect_many(paths: ~[path]) -> path {
* the first element of the returned vector will be the drive letter * the first element of the returned vector will be the drive letter
* followed by a colon. * followed by a colon.
*/ */
fn split(p: path) -> ~[path] { fn split(p: Path) -> ~[Path] {
str::split_nonempty(p, |c| { str::split_nonempty(p, |c| {
c == consts::path_sep || c == consts::alt_path_sep c == consts::path_sep || c == consts::alt_path_sep
}) })
@ -159,7 +159,7 @@ fn split(p: path) -> ~[path] {
* ignored. If the path includes directory components then they are included * ignored. If the path includes directory components then they are included
* in the filename part of the result pair. * in the filename part of the result pair.
*/ */
fn splitext(p: path) -> (~str, ~str) { fn splitext(p: Path) -> (~str, ~str) {
if str::is_empty(p) { (~"", ~"") } if str::is_empty(p) { (~"", ~"") }
else { else {
let parts = str::split_char(p, '.'); let parts = str::split_char(p, '.');
@ -212,7 +212,7 @@ fn splitext(p: path) -> (~str, ~str) {
* * 'a/b/../../../' becomes '..' * * 'a/b/../../../' becomes '..'
* * '/a/b/c/../d/./../../e/' becomes '/a/e/' * * '/a/b/c/../d/./../../e/' becomes '/a/e/'
*/ */
fn normalize(p: path) -> path { fn normalize(p: Path) -> Path {
let s = split(p); let s = split(p);
let s = strip_dots(s); let s = strip_dots(s);
let s = rollup_doubledots(s); let s = rollup_doubledots(s);
@ -233,7 +233,7 @@ fn normalize(p: path) -> path {
return s; return s;
fn strip_dots(s: ~[path]) -> ~[path] { fn strip_dots(s: ~[Path]) -> ~[Path] {
vec::filter_map(s, |elem| vec::filter_map(s, |elem|
if elem == ~"." { if elem == ~"." {
option::none option::none
@ -242,7 +242,7 @@ fn normalize(p: path) -> path {
}) })
} }
fn rollup_doubledots(s: ~[path]) -> ~[path] { fn rollup_doubledots(s: ~[Path]) -> ~[Path] {
if vec::is_empty(s) { if vec::is_empty(s) {
return ~[]; return ~[];
} }
@ -271,7 +271,7 @@ fn normalize(p: path) -> path {
} }
#[cfg(unix)] #[cfg(unix)]
fn reabsolute(orig: path, n: path) -> path { fn reabsolute(orig: Path, n: Path) -> Path {
if path_is_absolute(orig) { if path_is_absolute(orig) {
path_sep() + n path_sep() + n
} else { } else {
@ -280,7 +280,7 @@ fn normalize(p: path) -> path {
} }
#[cfg(windows)] #[cfg(windows)]
fn reabsolute(orig: path, newp: path) -> path { fn reabsolute(orig: Path, newp: Path) -> Path {
if path_is_absolute(orig) && orig[0] == consts::path_sep as u8 { if path_is_absolute(orig) && orig[0] == consts::path_sep as u8 {
str::from_char(consts::path_sep) + newp str::from_char(consts::path_sep) + newp
} else { } else {
@ -288,7 +288,7 @@ fn normalize(p: path) -> path {
} }
} }
fn reterminate(orig: path, newp: path) -> path { fn reterminate(orig: Path, newp: Path) -> Path {
let last = orig[str::len(orig) - 1u]; let last = orig[str::len(orig) - 1u];
if last == consts::path_sep as u8 if last == consts::path_sep as u8
|| last == consts::path_sep as u8 { || last == consts::path_sep as u8 {

View file

@ -1,8 +1,9 @@
//! Random number generation //! Random number generation
export rng, seed, seeded_rng, weighted, extensions; export Rng, rng, seed, seeded_rng, Weighted, extensions;
export xorshift, seeded_xorshift; export xorshift, seeded_xorshift;
#[allow(non_camel_case_types)] // runtime type
enum rctx {} enum rctx {}
#[abi = "cdecl"] #[abi = "cdecl"]
@ -15,16 +16,16 @@ extern mod rustrt {
} }
/// A random number generator /// A random number generator
trait rng { trait Rng {
/// Return the next random integer /// Return the next random integer
fn next() -> u32; fn next() -> u32;
} }
/// A value with a particular weight compared to other values /// A value with a particular weight compared to other values
type weighted<T> = { weight: uint, item: T }; type Weighted<T> = { weight: uint, item: T };
/// Extension methods for random number generators /// Extension methods for random number generators
impl rng { impl Rng {
/// Return a random int /// Return a random int
fn gen_int() -> int { fn gen_int() -> int {
@ -181,7 +182,7 @@ impl rng {
* Choose an item respecting the relative weights, failing if the sum of * Choose an item respecting the relative weights, failing if the sum of
* the weights is 0 * the weights is 0
*/ */
fn choose_weighted<T: copy>(v : ~[weighted<T>]) -> T { fn choose_weighted<T: copy>(v : ~[Weighted<T>]) -> T {
self.choose_weighted_option(v).get() self.choose_weighted_option(v).get()
} }
@ -189,7 +190,7 @@ impl rng {
* Choose some(item) respecting the relative weights, returning none if * Choose some(item) respecting the relative weights, returning none if
* the sum of the weights is 0 * the sum of the weights is 0
*/ */
fn choose_weighted_option<T:copy>(v: ~[weighted<T>]) -> option<T> { fn choose_weighted_option<T:copy>(v: ~[Weighted<T>]) -> option<T> {
let mut total = 0u; let mut total = 0u;
for v.each |item| { for v.each |item| {
total += item.weight; total += item.weight;
@ -212,7 +213,7 @@ impl rng {
* Return a vec containing copies of the items, in order, where * Return a vec containing copies of the items, in order, where
* the weight of the item determines how many copies there are * the weight of the item determines how many copies there are
*/ */
fn weighted_vec<T:copy>(v: ~[weighted<T>]) -> ~[T] { fn weighted_vec<T:copy>(v: ~[Weighted<T>]) -> ~[T] {
let mut r = ~[]; let mut r = ~[];
for v.each |item| { for v.each |item| {
for uint::range(0u, item.weight) |_i| { for uint::range(0u, item.weight) |_i| {
@ -242,13 +243,13 @@ impl rng {
} }
class rand_res { class RandRes {
let c: *rctx; let c: *rctx;
new(c: *rctx) { self.c = c; } new(c: *rctx) { self.c = c; }
drop { rustrt::rand_free(self.c); } drop { rustrt::rand_free(self.c); }
} }
impl @rand_res: rng { impl @RandRes: Rng {
fn next() -> u32 { return rustrt::rand_next((*self).c); } fn next() -> u32 { return rustrt::rand_next((*self).c); }
} }
@ -258,8 +259,8 @@ fn seed() -> ~[u8] {
} }
/// Create a random number generator with a system specified seed /// Create a random number generator with a system specified seed
fn rng() -> rng { fn rng() -> Rng {
@rand_res(rustrt::rand_new()) as rng @RandRes(rustrt::rand_new()) as Rng
} }
/** /**
@ -268,18 +269,18 @@ fn rng() -> rng {
* all other generators constructed with the same seed. The seed may be any * all other generators constructed with the same seed. The seed may be any
* length. * length.
*/ */
fn seeded_rng(seed: ~[u8]) -> rng { fn seeded_rng(seed: ~[u8]) -> Rng {
@rand_res(rustrt::rand_new_seeded(seed)) as rng @RandRes(rustrt::rand_new_seeded(seed)) as Rng
} }
type xorshift_state = { type XorShiftState = {
mut x: u32, mut x: u32,
mut y: u32, mut y: u32,
mut z: u32, mut z: u32,
mut w: u32 mut w: u32
}; };
impl xorshift_state: rng { impl XorShiftState: Rng {
fn next() -> u32 { fn next() -> u32 {
let x = self.x; let x = self.x;
let mut t = x ^ (x << 11); let mut t = x ^ (x << 11);
@ -292,13 +293,13 @@ impl xorshift_state: rng {
} }
} }
fn xorshift() -> rng { fn xorshift() -> Rng {
// constants taken from http://en.wikipedia.org/wiki/Xorshift // constants taken from http://en.wikipedia.org/wiki/Xorshift
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32) seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
} }
fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> rng { fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng {
{mut x: x, mut y: y, mut z: z, mut w: w} as rng {mut x: x, mut y: y, mut z: z, mut w: w} as Rng
} }
#[cfg(test)] #[cfg(test)]

View file

@ -6,7 +6,7 @@
import option::{some, none}; import option::{some, none};
import libc::{pid_t, c_void, c_int}; import libc::{pid_t, c_void, c_int};
export program; export Program;
export run_program; export run_program;
export start_program; export start_program;
export program_output; export program_output;
@ -22,18 +22,18 @@ extern mod rustrt {
} }
/// A value representing a child process /// A value representing a child process
trait program { trait Program {
/// Returns the process id of the program /// Returns the process id of the program
fn get_id() -> pid_t; fn get_id() -> pid_t;
/// Returns an io::writer that can be used to write to stdin /// Returns an io::writer that can be used to write to stdin
fn input() -> io::writer; fn input() -> io::Writer;
/// Returns an io::reader that can be used to read from stdout /// Returns an io::reader that can be used to read from stdout
fn output() -> io::reader; fn output() -> io::Reader;
/// Returns an io::reader that can be used to read from stderr /// Returns an io::reader that can be used to read from stderr
fn err() -> io::reader; fn err() -> io::Reader;
/// Closes the handle to the child processes standard input /// Closes the handle to the child processes standard input
fn close_input(); fn close_input();
@ -187,7 +187,7 @@ fn run_program(prog: &str, args: &[~str]) -> int {
* *
* A class with a <program> field * A class with a <program> field
*/ */
fn start_program(prog: &str, args: &[~str]) -> program { fn start_program(prog: &str, args: &[~str]) -> Program {
let pipe_input = os::pipe(); let pipe_input = os::pipe();
let pipe_output = os::pipe(); let pipe_output = os::pipe();
let pipe_err = os::pipe(); let pipe_err = os::pipe();
@ -201,41 +201,41 @@ fn start_program(prog: &str, args: &[~str]) -> program {
libc::close(pipe_output.out); libc::close(pipe_output.out);
libc::close(pipe_err.out); libc::close(pipe_err.out);
type prog_repr = {pid: pid_t, type ProgRepr = {pid: pid_t,
mut in_fd: c_int, mut in_fd: c_int,
out_file: *libc::FILE, out_file: *libc::FILE,
err_file: *libc::FILE, err_file: *libc::FILE,
mut finished: bool}; mut finished: bool};
fn close_repr_input(r: &prog_repr) { fn close_repr_input(r: &ProgRepr) {
let invalid_fd = -1i32; let invalid_fd = -1i32;
if r.in_fd != invalid_fd { if r.in_fd != invalid_fd {
libc::close(r.in_fd); libc::close(r.in_fd);
r.in_fd = invalid_fd; r.in_fd = invalid_fd;
} }
} }
fn finish_repr(r: &prog_repr) -> int { fn finish_repr(r: &ProgRepr) -> int {
if r.finished { return 0; } if r.finished { return 0; }
r.finished = true; r.finished = true;
close_repr_input(r); close_repr_input(r);
return waitpid(r.pid); return waitpid(r.pid);
} }
fn destroy_repr(r: &prog_repr) { fn destroy_repr(r: &ProgRepr) {
finish_repr(r); finish_repr(r);
libc::fclose(r.out_file); libc::fclose(r.out_file);
libc::fclose(r.err_file); libc::fclose(r.err_file);
} }
class prog_res { class ProgRes {
let r: prog_repr; let r: ProgRepr;
new(+r: prog_repr) { self.r = r; } new(+r: ProgRepr) { self.r = r; }
drop { destroy_repr(&self.r); } drop { destroy_repr(&self.r); }
} }
impl prog_res: program { impl ProgRes: Program {
fn get_id() -> pid_t { return self.r.pid; } fn get_id() -> pid_t { return self.r.pid; }
fn input() -> io::writer { io::fd_writer(self.r.in_fd, false) } fn input() -> io::Writer { io::fd_writer(self.r.in_fd, false) }
fn output() -> io::reader { io::FILE_reader(self.r.out_file, false) } fn output() -> io::Reader { io::FILE_reader(self.r.out_file, false) }
fn err() -> io::reader { io::FILE_reader(self.r.err_file, false) } fn err() -> io::Reader { io::FILE_reader(self.r.err_file, false) }
fn close_input() { close_repr_input(&self.r); } fn close_input() { close_repr_input(&self.r); }
fn finish() -> int { finish_repr(&self.r) } fn finish() -> int { finish_repr(&self.r) }
fn destroy() { destroy_repr(&self.r); } fn destroy() { destroy_repr(&self.r); }
@ -245,10 +245,10 @@ fn start_program(prog: &str, args: &[~str]) -> program {
out_file: os::fdopen(pipe_output.in), out_file: os::fdopen(pipe_output.in),
err_file: os::fdopen(pipe_err.in), err_file: os::fdopen(pipe_err.in),
mut finished: false}; mut finished: false};
return prog_res(move repr) as program; return ProgRes(move repr) as Program;
} }
fn read_all(rd: io::reader) -> ~str { fn read_all(rd: io::Reader) -> ~str {
let mut buf = ~""; let mut buf = ~"";
while !rd.eof() { while !rd.eof() {
let bytes = rd.read_bytes(4096u); let bytes = rd.read_bytes(4096u);
@ -326,7 +326,7 @@ fn program_output(prog: &str, args: &[~str]) ->
} }
fn writeclose(fd: c_int, s: &str) { fn writeclose(fd: c_int, s: &str) {
import io::writer_util; import io::WriterUtil;
error!{"writeclose %d, %s", fd as int, s}; error!{"writeclose %d, %s", fd as int, s};
let writer = io::fd_writer(fd, false); let writer = io::fd_writer(fd, false);
@ -392,7 +392,7 @@ fn waitpid(pid: pid_t) -> int {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
import io::writer_util; import io::WriterUtil;
// Regression test for memory leaks // Regression test for memory leaks
#[ignore(cfg(windows))] // FIXME (#2626) #[ignore(cfg(windows))] // FIXME (#2626)

View file

@ -8,7 +8,7 @@
*/ */
import libc::size_t; import libc::size_t;
import io::writer_util; import io::WriterUtil;
export export
// Creating a string // Creating a string

View file

@ -1,4 +1,4 @@
import io::reader; import io::Reader;
trait to_base64 { trait to_base64 {
fn to_base64() -> ~str; fn to_base64() -> ~str;

View file

@ -172,13 +172,13 @@ fn doc_as_i32(d: doc) -> i32 { doc_as_u32(d) as i32 }
fn doc_as_i64(d: doc) -> i64 { doc_as_u64(d) as i64 } fn doc_as_i64(d: doc) -> i64 { doc_as_u64(d) as i64 }
// ebml writing // ebml writing
type writer_ = {writer: io::writer, mut size_positions: ~[uint]}; type writer_ = {writer: io::Writer, mut size_positions: ~[uint]};
enum writer { enum writer {
writer_(writer_) writer_(writer_)
} }
fn write_sized_vuint(w: io::writer, n: uint, size: uint) { fn write_sized_vuint(w: io::Writer, n: uint, size: uint) {
match size { match size {
1u => w.write(&[0x80u8 | (n as u8)]), 1u => w.write(&[0x80u8 | (n as u8)]),
2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]), 2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
@ -190,7 +190,7 @@ fn write_sized_vuint(w: io::writer, n: uint, size: uint) {
}; };
} }
fn write_vuint(w: io::writer, n: uint) { fn write_vuint(w: io::Writer, n: uint) {
if n < 0x7f_u { write_sized_vuint(w, n, 1u); return; } if n < 0x7f_u { write_sized_vuint(w, n, 1u); return; }
if n < 0x4000_u { write_sized_vuint(w, n, 2u); return; } if n < 0x4000_u { write_sized_vuint(w, n, 2u); return; }
if n < 0x200000_u { write_sized_vuint(w, n, 3u); return; } if n < 0x200000_u { write_sized_vuint(w, n, 3u); return; }
@ -198,7 +198,7 @@ fn write_vuint(w: io::writer, n: uint) {
fail fmt!{"vint to write too big: %?", n}; fail fmt!{"vint to write too big: %?", n};
} }
fn writer(w: io::writer) -> writer { fn writer(w: io::Writer) -> writer {
let size_positions: ~[uint] = ~[]; let size_positions: ~[uint] = ~[];
return writer_({writer: w, mut size_positions: size_positions}); return writer_({writer: w, mut size_positions: size_positions});
} }
@ -220,10 +220,10 @@ impl writer {
fn end_tag() { fn end_tag() {
let last_size_pos = vec::pop::<uint>(self.size_positions); let last_size_pos = vec::pop::<uint>(self.size_positions);
let cur_pos = self.writer.tell(); let cur_pos = self.writer.tell();
self.writer.seek(last_size_pos as int, io::seek_set); self.writer.seek(last_size_pos as int, io::SeekSet);
let size = (cur_pos - last_size_pos - 4u); let size = (cur_pos - last_size_pos - 4u);
write_sized_vuint(self.writer, size, 4u); write_sized_vuint(self.writer, size, 4u);
self.writer.seek(cur_pos as int, io::seek_set); self.writer.seek(cur_pos as int, io::SeekSet);
debug!{"End tag (size = %u)", size}; debug!{"End tag (size = %u)", size};
} }

View file

@ -5,7 +5,7 @@
import result::{result, ok, err}; import result::{result, ok, err};
import io; import io;
import io::writer_util; import io::WriterUtil;
import map; import map;
import map::hashmap; import map::hashmap;
import map::map; import map::map;
@ -43,7 +43,7 @@ type error = {
}; };
/// Serializes a json value into a io::writer /// Serializes a json value into a io::writer
fn to_writer(wr: io::writer, j: json) { fn to_writer(wr: io::Writer, j: json) {
match j { match j {
num(n) => wr.write_str(float::to_str(n, 6u)), num(n) => wr.write_str(float::to_str(n, 6u)),
string(s) => wr.write_str(escape_str(*s)), string(s) => wr.write_str(escape_str(*s)),
@ -109,7 +109,7 @@ fn to_str(j: json) -> ~str {
} }
type parser_ = { type parser_ = {
rdr: io::reader, rdr: io::Reader,
mut ch: char, mut ch: char,
mut line: uint, mut line: uint,
mut col: uint, mut col: uint,
@ -458,7 +458,7 @@ impl parser {
} }
/// Deserializes a json value from an io::reader /// Deserializes a json value from an io::reader
fn from_reader(rdr: io::reader) -> result<json, error> { fn from_reader(rdr: io::Reader) -> result<json, error> {
let parser = parser_({ let parser = parser_({
rdr: rdr, rdr: rdr,
mut ch: rdr.read_char(), mut ch: rdr.read_char(),

View file

@ -2,7 +2,7 @@
#[warn(deprecated_mode)]; #[warn(deprecated_mode)];
import io::writer_util; import io::WriterUtil;
import to_str::ToStr; import to_str::ToStr;
export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash; export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash;
export box_str_hash; export box_str_hash;
@ -328,7 +328,7 @@ mod chained {
} }
impl<K: copy ToStr, V: ToStr copy> t<K, V>: ToStr { impl<K: copy ToStr, V: ToStr copy> t<K, V>: ToStr {
fn to_writer(wr: io::writer) { fn to_writer(wr: io::Writer) {
if self.count == 0u { if self.count == 0u {
wr.write_str(~"{}"); wr.write_str(~"{}");
return; return;

View file

@ -8,7 +8,7 @@ import future_spawn = future::spawn;
// should be able to, but can't atm, replace w/ result::{result, extensions}; // should be able to, but can't atm, replace w/ result::{result, extensions};
import result::*; import result::*;
import libc::size_t; import libc::size_t;
import io::{reader, writer}; import io::{Reader, Writer};
// tcp interfaces // tcp interfaces
export tcp_socket; export tcp_socket;
@ -752,7 +752,7 @@ impl tcp_socket {
} }
/// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket` /// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket`
impl @tcp_socket_buf: io::reader { impl @tcp_socket_buf: io::Reader {
fn read(buf: &[mut u8], len: uint) -> uint { fn read(buf: &[mut u8], len: uint) -> uint {
// Loop until our buffer has enough data in it for us to read from. // Loop until our buffer has enough data in it for us to read from.
while self.data.buf.len() < len { while self.data.buf.len() < len {
@ -795,7 +795,7 @@ impl @tcp_socket_buf: io::reader {
fn eof() -> bool { fn eof() -> bool {
false // noop false // noop
} }
fn seek(dist: int, seek: io::seek_style) { fn seek(dist: int, seek: io::SeekStyle) {
log(debug, fmt!{"tcp_socket_buf seek stub %? %?", dist, seek}); log(debug, fmt!{"tcp_socket_buf seek stub %? %?", dist, seek});
// noop // noop
} }
@ -805,7 +805,7 @@ impl @tcp_socket_buf: io::reader {
} }
/// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket` /// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket`
impl @tcp_socket_buf: io::writer { impl @tcp_socket_buf: io::Writer {
fn write(data: &[const u8]) unsafe { fn write(data: &[const u8]) unsafe {
let socket_data_ptr = let socket_data_ptr =
ptr::addr_of(*((*(self.data)).sock).socket_data); ptr::addr_of(*((*(self.data)).sock).socket_data);
@ -817,7 +817,7 @@ impl @tcp_socket_buf: io::writer {
err_data.err_name, err_data.err_msg}); err_data.err_name, err_data.err_msg});
} }
} }
fn seek(dist: int, seek: io::seek_style) { fn seek(dist: int, seek: io::SeekStyle) {
log(debug, fmt!{"tcp_socket_buf seek stub %? %?", dist, seek}); log(debug, fmt!{"tcp_socket_buf seek stub %? %?", dist, seek});
// noop // noop
} }
@ -827,8 +827,8 @@ impl @tcp_socket_buf: io::writer {
fn flush() -> int { fn flush() -> int {
0 0
} }
fn get_type() -> io::writer_type { fn get_type() -> io::WriterType {
io::file io::File
} }
} }
@ -1441,11 +1441,11 @@ mod test {
assert false; assert false;
} }
let sock_buf = @socket_buf(result::unwrap(conn_result)); let sock_buf = @socket_buf(result::unwrap(conn_result));
buf_write(sock_buf as io::writer, expected_req); buf_write(sock_buf as io::Writer, expected_req);
// so contrived! // so contrived!
let actual_resp = do str::as_bytes(expected_resp) |resp_buf| { let actual_resp = do str::as_bytes(expected_resp) |resp_buf| {
buf_read(sock_buf as io::reader, buf_read(sock_buf as io::Reader,
vec::len(resp_buf)) vec::len(resp_buf))
}; };
@ -1458,7 +1458,7 @@ mod test {
assert str::contains(actual_resp, expected_resp); assert str::contains(actual_resp, expected_resp);
} }
fn buf_write(+w: io::writer, val: ~str) { fn buf_write(+w: io::Writer, val: ~str) {
log(debug, fmt!{"BUF_WRITE: val len %?", str::len(val)}); log(debug, fmt!{"BUF_WRITE: val len %?", str::len(val)});
do str::byte_slice(val) |b_slice| { do str::byte_slice(val) |b_slice| {
log(debug, fmt!{"BUF_WRITE: b_slice len %?", log(debug, fmt!{"BUF_WRITE: b_slice len %?",
@ -1467,7 +1467,7 @@ mod test {
} }
} }
fn buf_read(+r: io::reader, len: uint) -> ~str { fn buf_read(+r: io::Reader, len: uint) -> ~str {
let new_bytes = r.read_bytes(len); let new_bytes = r.read_bytes(len);
log(debug, fmt!{"in buf_read.. new_bytes len: %?", log(debug, fmt!{"in buf_read.. new_bytes len: %?",
vec::len(new_bytes)}); vec::len(new_bytes)});

View file

@ -2,7 +2,7 @@
import map; import map;
import map::{hashmap, str_hash}; import map::{hashmap, str_hash};
import io::reader; import io::Reader;
import dvec::dvec; import dvec::dvec;
export url, userinfo, query; export url, userinfo, query;

View file

@ -1,8 +1,8 @@
import io::writer; import io::Writer;
import io::writer_util; import io::WriterUtil;
import serialization::serializer; import serialization::serializer;
impl writer: serializer { impl Writer: serializer {
fn emit_nil() { fn emit_nil() {
self.write_str(~"()") self.write_str(~"()")
} }

View file

@ -23,10 +23,10 @@ const color_bright_magenta: u8 = 13u8;
const color_bright_cyan: u8 = 14u8; const color_bright_cyan: u8 = 14u8;
const color_bright_white: u8 = 15u8; const color_bright_white: u8 = 15u8;
fn esc(writer: io::writer) { writer.write(~[0x1bu8, '[' as u8]); } fn esc(writer: io::Writer) { writer.write(~[0x1bu8, '[' as u8]); }
/// Reset the foreground and background colors to default /// Reset the foreground and background colors to default
fn reset(writer: io::writer) { fn reset(writer: io::Writer) {
esc(writer); esc(writer);
writer.write(~['0' as u8, 'm' as u8]); writer.write(~['0' as u8, 'm' as u8]);
} }
@ -46,7 +46,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 mut color = color; let mut color = color;
@ -55,12 +55,12 @@ fn set_color(writer: io::writer, first_char: u8, color: u8) {
} }
/// Set the foreground color /// Set the foreground color
fn fg(writer: io::writer, color: u8) { fn fg(writer: io::Writer, color: u8) {
return set_color(writer, '3' as u8, color); return set_color(writer, '3' as u8, color);
} }
/// Set the background color /// Set the background color
fn bg(writer: io::writer, color: u8) { fn bg(writer: io::Writer, color: u8) {
return set_color(writer, '4' as u8, color); return set_color(writer, '4' as u8, color);
} }

View file

@ -7,7 +7,7 @@
import either::either; import either::either;
import result::{ok, err}; import result::{ok, err};
import io::writer_util; import io::WriterUtil;
import libc::size_t; import libc::size_t;
import task::task_builder; import task::task_builder;
@ -91,8 +91,8 @@ fn parse_opts(args: ~[~str]) -> opt_res {
enum test_result { tr_ok, tr_failed, tr_ignored, } enum test_result { tr_ok, tr_failed, tr_ignored, }
type console_test_state = type console_test_state =
@{out: io::writer, @{out: io::Writer,
log_out: option<io::writer>, log_out: option<io::Writer>,
use_color: bool, use_color: bool,
mut total: uint, mut total: uint,
mut passed: uint, mut passed: uint,
@ -141,7 +141,7 @@ fn run_tests_console(opts: test_opts,
let log_out = match opts.logfile { let log_out = match opts.logfile {
some(path) => match io::file_writer(path, some(path) => match io::file_writer(path,
~[io::create, io::truncate]) { ~[io::Create, io::Truncate]) {
result::ok(w) => some(w), result::ok(w) => some(w),
result::err(s) => { result::err(s) => {
fail(fmt!{"can't open output file: %s", s}) fail(fmt!{"can't open output file: %s", s})
@ -179,7 +179,7 @@ fn run_tests_console(opts: test_opts,
return success; return success;
fn write_log(out: io::writer, result: test_result, test: test_desc) { fn write_log(out: io::Writer, result: test_result, test: test_desc) {
out.write_line(fmt!{"%s %s", out.write_line(fmt!{"%s %s",
match result { match result {
tr_ok => ~"ok", tr_ok => ~"ok",
@ -188,19 +188,19 @@ fn run_tests_console(opts: test_opts,
}, test.name}); }, test.name});
} }
fn write_ok(out: io::writer, use_color: bool) { fn write_ok(out: io::Writer, use_color: bool) {
write_pretty(out, ~"ok", term::color_green, use_color); write_pretty(out, ~"ok", term::color_green, use_color);
} }
fn write_failed(out: io::writer, use_color: bool) { fn write_failed(out: io::Writer, use_color: bool) {
write_pretty(out, ~"FAILED", term::color_red, use_color); write_pretty(out, ~"FAILED", term::color_red, use_color);
} }
fn write_ignored(out: io::writer, use_color: bool) { fn write_ignored(out: io::Writer, use_color: bool) {
write_pretty(out, ~"ignored", term::color_yellow, use_color); write_pretty(out, ~"ignored", term::color_yellow, use_color);
} }
fn write_pretty(out: io::writer, word: ~str, color: u8, use_color: bool) { fn write_pretty(out: io::Writer, word: ~str, color: u8, use_color: bool) {
if use_color && term::color_supported() { if use_color && term::color_supported() {
term::fg(out, color); term::fg(out, color);
} }

View file

@ -1,5 +1,5 @@
import libc::{c_char, c_int, c_long, size_t, time_t}; import libc::{c_char, c_int, c_long, size_t, time_t};
import io::reader; import io::Reader;
import result::{result, ok, err}; import result::{result, ok, err};
export export

View file

@ -1,5 +1,5 @@
import std::term; import std::term;
import io::writer_util; import io::WriterUtil;
import codemap::span; import codemap::span;
export emitter, emit; export emitter, emit;
@ -166,7 +166,7 @@ fn diagnosticcolor(lvl: level) -> u8 {
fn print_diagnostic(topic: ~str, lvl: level, msg: ~str) { fn print_diagnostic(topic: ~str, lvl: level, msg: ~str) {
let use_color = term::color_supported() && let use_color = term::color_supported() &&
io::stderr().get_type() == io::screen; io::stderr().get_type() == io::Screen;
if str::is_not_empty(topic) { if str::is_not_empty(topic) {
io::stderr().write_str(fmt!{"%s ", topic}); io::stderr().write_str(fmt!{"%s ", topic});
} }

View file

@ -1,5 +1,5 @@
import base::*; import base::*;
import io::writer_util; import io::WriterUtil;
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, tt: ~[ast::token_tree]) fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, tt: ~[ast::token_tree])
-> base::mac_result { -> base::mac_result {

View file

@ -99,7 +99,7 @@ fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
} }
} }
fn res_rel_file(cx: ext_ctxt, sp: codemap::span, +arg: path) -> path { fn res_rel_file(cx: ext_ctxt, sp: codemap::span, +arg: Path) -> Path {
// NB: relative paths are resolved relative to the compilation unit // NB: relative paths are resolved relative to the compilation unit
if !path::path_is_absolute(arg) { if !path::path_is_absolute(arg) {
let cu = codemap::span_to_filename(sp, cx.codemap()); let cu = codemap::span_to_filename(sp, cx.codemap());

View file

@ -273,7 +273,7 @@ type lit = {lit: ~str, pos: uint};
fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler, fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
path: ~str, path: ~str,
srdr: io::reader) -> srdr: io::Reader) ->
{cmnts: ~[cmnt], lits: ~[lit]} { {cmnts: ~[cmnt], lits: ~[lit]} {
let src = @str::from_bytes(srdr.read_whole_stream()); let src = @str::from_bytes(srdr.read_whole_stream());
let itr = @interner::mk::<@~str>( let itr = @interner::mk::<@~str>(

View file

@ -1,4 +1,4 @@
import io::writer_util; import io::WriterUtil;
import dvec::dvec; import dvec::dvec;
/* /*
@ -95,7 +95,7 @@ type print_stack_elt = {offset: int, pbreak: print_stack_break};
const size_infinity: int = 0xffff; const size_infinity: int = 0xffff;
fn mk_printer(out: io::writer, linewidth: uint) -> printer { fn mk_printer(out: io::Writer, linewidth: uint) -> printer {
// Yes 3, it makes the ring buffers big enough to never // Yes 3, it makes the ring buffers big enough to never
// fall behind. // fall behind.
let n: uint = 3u * linewidth; let n: uint = 3u * linewidth;
@ -201,7 +201,7 @@ fn mk_printer(out: io::writer, linewidth: uint) -> printer {
* called 'print'. * called 'print'.
*/ */
type printer_ = { type printer_ = {
out: io::writer, out: io::Writer,
buf_len: uint, buf_len: uint,
mut margin: int, // width of lines we're constrained to mut margin: int, // width of lines we're constrained to
mut space: int, // number of spaces left on line mut space: int, // number of spaces left on line

View file

@ -48,7 +48,7 @@ fn end(s: ps) {
pp::end(s.s); pp::end(s.s);
} }
fn rust_printer(writer: io::writer) -> ps { fn rust_printer(writer: io::Writer) -> ps {
return @{s: pp::mk_printer(writer, default_columns), return @{s: pp::mk_printer(writer, default_columns),
cm: none::<codemap>, cm: none::<codemap>,
intr: @interner::mk::<@~str>(|x| str::hash(*x), intr: @interner::mk::<@~str>(|x| str::hash(*x),
@ -61,7 +61,7 @@ fn rust_printer(writer: io::writer) -> ps {
ann: no_ann()}; ann: no_ann()};
} }
fn unexpanded_rust_printer(writer: io::writer, intr: ident_interner) -> ps { fn unexpanded_rust_printer(writer: io::Writer, intr: ident_interner) -> ps {
return @{s: pp::mk_printer(writer, default_columns), return @{s: pp::mk_printer(writer, default_columns),
cm: none::<codemap>, cm: none::<codemap>,
intr: intr, intr: intr,
@ -83,8 +83,8 @@ const default_columns: uint = 78u;
// copy forward. // copy forward.
fn print_crate(cm: codemap, intr: @interner::interner<@~str>, fn print_crate(cm: codemap, intr: @interner::interner<@~str>,
span_diagnostic: diagnostic::span_handler, span_diagnostic: diagnostic::span_handler,
crate: @ast::crate, filename: ~str, in: io::reader, crate: @ast::crate, filename: ~str, in: io::Reader,
out: io::writer, ann: pp_ann, is_expanded: bool) { out: io::Writer, ann: pp_ann, is_expanded: bool) {
let r = comments::gather_comments_and_literals(span_diagnostic, let r = comments::gather_comments_and_literals(span_diagnostic,
filename, in); filename, in);
let s = let s =

View file

@ -15,7 +15,7 @@ import lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False,
FileType}; FileType};
import metadata::filesearch; import metadata::filesearch;
import syntax::ast_map::{path, path_mod, path_name}; import syntax::ast_map::{path, path_mod, path_name};
import io::{writer, writer_util}; import io::{Writer, WriterUtil};
enum output_type { enum output_type {
output_type_none, output_type_none,

View file

@ -36,7 +36,7 @@ fn get_rpath_flags(sess: session::session, out_filename: ~str) -> ~[~str] {
rpaths_to_flags(rpaths) rpaths_to_flags(rpaths)
} }
fn get_sysroot_absolute_rt_lib(sess: session::session) -> path::path { fn get_sysroot_absolute_rt_lib(sess: session::session) -> path::Path {
let mut path = vec::append(~[sess.filesearch.sysroot()], let mut path = vec::append(~[sess.filesearch.sysroot()],
filesearch::relative_target_lib_path( filesearch::relative_target_lib_path(
sess.opts.target_triple)); sess.opts.target_triple));
@ -48,8 +48,8 @@ fn rpaths_to_flags(rpaths: ~[~str]) -> ~[~str] {
vec::map(rpaths, |rpath| fmt!{"-Wl,-rpath,%s",rpath} ) vec::map(rpaths, |rpath| fmt!{"-Wl,-rpath,%s",rpath} )
} }
fn get_rpaths(os: session::os, cwd: path::path, sysroot: path::path, fn get_rpaths(os: session::os, cwd: path::Path, sysroot: path::Path,
output: path::path, libs: ~[path::path], output: path::Path, libs: ~[path::Path],
target_triple: ~str) -> ~[~str] { target_triple: ~str) -> ~[~str] {
debug!{"cwd: %s", cwd}; debug!{"cwd: %s", cwd};
debug!{"sysroot: %s", sysroot}; debug!{"sysroot: %s", sysroot};
@ -93,18 +93,18 @@ fn get_rpaths(os: session::os, cwd: path::path, sysroot: path::path,
} }
fn get_rpaths_relative_to_output(os: session::os, fn get_rpaths_relative_to_output(os: session::os,
cwd: path::path, cwd: path::Path,
output: path::path, output: path::Path,
libs: ~[path::path]) -> ~[~str] { libs: ~[path::Path]) -> ~[~str] {
vec::map(libs, |a| { vec::map(libs, |a| {
get_rpath_relative_to_output(os, cwd, output, a) get_rpath_relative_to_output(os, cwd, output, a)
}) })
} }
fn get_rpath_relative_to_output(os: session::os, fn get_rpath_relative_to_output(os: session::os,
cwd: path::path, cwd: path::Path,
output: path::path, output: path::Path,
&&lib: path::path) -> ~str { &&lib: path::Path) -> ~str {
assert not_win32(os); assert not_win32(os);
// Mac doesn't appear to support $ORIGIN // Mac doesn't appear to support $ORIGIN
@ -121,7 +121,7 @@ fn get_rpath_relative_to_output(os: session::os,
} }
// Find the relative path from one file to another // Find the relative path from one file to another
fn get_relative_to(abs1: path::path, abs2: path::path) -> path::path { fn get_relative_to(abs1: path::Path, abs2: path::Path) -> path::Path {
assert path::path_is_absolute(abs1); assert path::path_is_absolute(abs1);
assert path::path_is_absolute(abs2); assert path::path_is_absolute(abs2);
debug!{"finding relative path from %s to %s", debug!{"finding relative path from %s to %s",
@ -154,15 +154,15 @@ fn get_relative_to(abs1: path::path, abs2: path::path) -> path::path {
} }
} }
fn get_absolute_rpaths(cwd: path::path, libs: ~[path::path]) -> ~[~str] { fn get_absolute_rpaths(cwd: path::Path, libs: ~[path::Path]) -> ~[~str] {
vec::map(libs, |a| get_absolute_rpath(cwd, a) ) vec::map(libs, |a| get_absolute_rpath(cwd, a) )
} }
fn get_absolute_rpath(cwd: path::path, &&lib: path::path) -> ~str { fn get_absolute_rpath(cwd: path::Path, &&lib: path::Path) -> ~str {
path::dirname(get_absolute(cwd, lib)) path::dirname(get_absolute(cwd, lib))
} }
fn get_absolute(cwd: path::path, lib: path::path) -> path::path { fn get_absolute(cwd: path::Path, lib: path::Path) -> path::Path {
if path::path_is_absolute(lib) { if path::path_is_absolute(lib) {
lib lib
} else { } else {
@ -170,7 +170,7 @@ fn get_absolute(cwd: path::path, lib: path::path) -> path::path {
} }
} }
fn get_install_prefix_rpath(cwd: path::path, target_triple: ~str) -> ~str { fn get_install_prefix_rpath(cwd: path::Path, target_triple: ~str) -> ~str {
let install_prefix = env!{"CFG_PREFIX"}; let install_prefix = env!{"CFG_PREFIX"};
if install_prefix == ~"" { if install_prefix == ~"" {

View file

@ -10,7 +10,7 @@ import util::ppaux;
import back::link; import back::link;
import result::{ok, err}; import result::{ok, err};
import std::getopts; import std::getopts;
import io::writer_util; import io::WriterUtil;
import getopts::{optopt, optmulti, optflag, optflagopt, opt_present}; import getopts::{optopt, optmulti, optflag, optflagopt, opt_present};
import back::{x86, x86_64}; import back::{x86, x86_64};
import std::map::hashmap; import std::map::hashmap;
@ -701,7 +701,7 @@ fn early_error(emitter: diagnostic::emitter, msg: ~str) -> ! {
fail; fail;
} }
fn list_metadata(sess: session, path: ~str, out: io::writer) { fn list_metadata(sess: session, path: ~str, out: io::Writer) {
metadata::loader::list_file_metadata( metadata::loader::list_file_metadata(
session::sess_os_to_meta_os(sess.targ_cfg.os), path, out); session::sess_os_to_meta_os(sess.targ_cfg.os), path, out);
} }

View file

@ -3,7 +3,7 @@
import std::{ebml, map}; import std::{ebml, map};
import std::map::{hashmap, str_hash}; import std::map::{hashmap, str_hash};
import dvec::dvec; import dvec::dvec;
import io::writer_util; import io::WriterUtil;
import syntax::{ast, ast_util}; import syntax::{ast, ast_util};
import syntax::attr; import syntax::attr;
import middle::ty; import middle::ty;
@ -846,13 +846,13 @@ fn get_attributes(md: ebml::doc) -> ~[ast::attribute] {
return attrs; return attrs;
} }
fn list_meta_items(meta_items: ebml::doc, out: io::writer) { fn list_meta_items(meta_items: ebml::doc, out: io::Writer) {
for get_meta_items(meta_items).each |mi| { for get_meta_items(meta_items).each |mi| {
out.write_str(fmt!{"%s\n", pprust::meta_item_to_str(*mi)}); out.write_str(fmt!{"%s\n", pprust::meta_item_to_str(*mi)});
} }
} }
fn list_crate_attributes(md: ebml::doc, hash: @~str, out: io::writer) { fn list_crate_attributes(md: ebml::doc, hash: @~str, out: io::Writer) {
out.write_str(fmt!{"=Crate Attributes (%s)=\n", *hash}); out.write_str(fmt!{"=Crate Attributes (%s)=\n", *hash});
for get_attributes(md).each |attr| { for get_attributes(md).each |attr| {
@ -887,7 +887,7 @@ fn get_crate_deps(data: @~[u8]) -> ~[crate_dep] {
return deps; return deps;
} }
fn list_crate_deps(data: @~[u8], out: io::writer) { fn list_crate_deps(data: @~[u8], out: io::Writer) {
out.write_str(~"=External Dependencies=\n"); out.write_str(~"=External Dependencies=\n");
for get_crate_deps(data).each |dep| { for get_crate_deps(data).each |dep| {
@ -913,7 +913,7 @@ fn get_crate_vers(data: @~[u8]) -> @~str {
}; };
} }
fn list_crate_items(bytes: @~[u8], md: ebml::doc, out: io::writer) { fn list_crate_items(bytes: @~[u8], md: ebml::doc, out: io::Writer) {
out.write_str(~"=Items=\n"); out.write_str(~"=Items=\n");
let items = ebml::get_doc(md, tag_items); let items = ebml::get_doc(md, tag_items);
do iter_crate_items(bytes) |tag, path, did| { do iter_crate_items(bytes) |tag, path, did| {
@ -969,7 +969,7 @@ fn get_crate_module_paths(bytes: @~[u8]) -> ~[(ast::def_id, ~str)] {
} }
} }
fn list_crate_metadata(bytes: @~[u8], out: io::writer) { fn list_crate_metadata(bytes: @~[u8], out: io::Writer) {
let hash = get_crate_hash(bytes); let hash = get_crate_hash(bytes);
let md = ebml::doc(bytes); let md = ebml::doc(bytes);
list_crate_attributes(md, hash, out); list_crate_attributes(md, hash, out);

View file

@ -4,7 +4,7 @@ import util::ppaux::ty_to_str;
import std::{ebml, map}; import std::{ebml, map};
import std::map::hashmap; import std::map::hashmap;
import io::writer_util; import io::WriterUtil;
import ebml::writer; import ebml::writer;
import syntax::ast::*; import syntax::ast::*;
import syntax::print::pprust; import syntax::print::pprust;
@ -1005,7 +1005,7 @@ fn create_index<T: copy>(index: ~[entry<T>], hash_fn: fn@(T) -> uint) ->
} }
fn encode_index<T>(ebml_w: ebml::writer, buckets: ~[@~[entry<T>]], fn encode_index<T>(ebml_w: ebml::writer, buckets: ~[@~[entry<T>]],
write_fn: fn(io::writer, T)) { write_fn: fn(io::Writer, T)) {
let writer = ebml_w.writer; let writer = ebml_w.writer;
ebml_w.start_tag(tag_index); ebml_w.start_tag(tag_index);
let mut bucket_locs: ~[uint] = ~[]; let mut bucket_locs: ~[uint] = ~[];
@ -1032,9 +1032,9 @@ fn encode_index<T>(ebml_w: ebml::writer, buckets: ~[@~[entry<T>]],
ebml_w.end_tag(); ebml_w.end_tag();
} }
fn write_str(writer: io::writer, &&s: ~str) { writer.write_str(s); } fn write_str(writer: io::Writer, &&s: ~str) { writer.write_str(s); }
fn write_int(writer: io::writer, &&n: int) { fn write_int(writer: io::Writer, &&n: int) {
assert n < 0x7fff_ffff; assert n < 0x7fff_ffff;
writer.write_be_u32(n as u32); writer.write_be_u32(n as u32);
} }

View file

@ -14,31 +14,31 @@ export get_cargo_root;
export get_cargo_root_nearest; export get_cargo_root_nearest;
export libdir; export libdir;
import path::path; import path::Path;
type pick<T> = fn(path: path) -> option<T>; type pick<T> = fn(path: Path) -> option<T>;
fn pick_file(file: path, path: path) -> option<path> { fn pick_file(file: Path, path: Path) -> option<Path> {
if path::basename(path) == file { option::some(path) } if path::basename(path) == file { option::some(path) }
else { option::none } else { option::none }
} }
trait filesearch { trait filesearch {
fn sysroot() -> path; fn sysroot() -> Path;
fn lib_search_paths() -> ~[path]; fn lib_search_paths() -> ~[Path];
fn get_target_lib_path() -> path; fn get_target_lib_path() -> Path;
fn get_target_lib_file_path(file: path) -> path; fn get_target_lib_file_path(file: Path) -> Path;
} }
fn mk_filesearch(maybe_sysroot: option<path>, fn mk_filesearch(maybe_sysroot: option<Path>,
target_triple: ~str, target_triple: ~str,
addl_lib_search_paths: ~[path]) -> filesearch { addl_lib_search_paths: ~[Path]) -> filesearch {
type filesearch_impl = {sysroot: path, type filesearch_impl = {sysroot: Path,
addl_lib_search_paths: ~[path], addl_lib_search_paths: ~[Path],
target_triple: ~str}; target_triple: ~str};
impl filesearch_impl: filesearch { impl filesearch_impl: filesearch {
fn sysroot() -> path { self.sysroot } fn sysroot() -> Path { self.sysroot }
fn lib_search_paths() -> ~[path] { fn lib_search_paths() -> ~[Path] {
let mut paths = self.addl_lib_search_paths; let mut paths = self.addl_lib_search_paths;
vec::push(paths, vec::push(paths,
@ -53,10 +53,10 @@ fn mk_filesearch(maybe_sysroot: option<path>,
} }
paths paths
} }
fn get_target_lib_path() -> path { fn get_target_lib_path() -> Path {
make_target_lib_path(self.sysroot, self.target_triple) make_target_lib_path(self.sysroot, self.target_triple)
} }
fn get_target_lib_file_path(file: path) -> path { fn get_target_lib_file_path(file: Path) -> Path {
path::connect(self.get_target_lib_path(), file) path::connect(self.get_target_lib_path(), file)
} }
} }
@ -88,38 +88,38 @@ fn search<T: copy>(filesearch: filesearch, pick: pick<T>) -> option<T> {
return rslt; return rslt;
} }
fn relative_target_lib_path(target_triple: ~str) -> ~[path] { fn relative_target_lib_path(target_triple: ~str) -> ~[Path] {
~[libdir(), ~"rustc", target_triple, libdir()] ~[libdir(), ~"rustc", target_triple, libdir()]
} }
fn make_target_lib_path(sysroot: path, fn make_target_lib_path(sysroot: Path,
target_triple: ~str) -> path { target_triple: ~str) -> Path {
let path = vec::append(~[sysroot], let path = vec::append(~[sysroot],
relative_target_lib_path(target_triple)); relative_target_lib_path(target_triple));
let path = path::connect_many(path); let path = path::connect_many(path);
return path; return path;
} }
fn get_default_sysroot() -> path { fn get_default_sysroot() -> Path {
match os::self_exe_path() { match os::self_exe_path() {
option::some(p) => path::normalize(path::connect(p, ~"..")), option::some(p) => path::normalize(path::connect(p, ~"..")),
option::none => fail ~"can't determine value for sysroot" option::none => fail ~"can't determine value for sysroot"
} }
} }
fn get_sysroot(maybe_sysroot: option<path>) -> path { fn get_sysroot(maybe_sysroot: option<Path>) -> Path {
match maybe_sysroot { match maybe_sysroot {
option::some(sr) => sr, option::some(sr) => sr,
option::none => get_default_sysroot() option::none => get_default_sysroot()
} }
} }
fn get_cargo_sysroot() -> result<path, ~str> { fn get_cargo_sysroot() -> result<Path, ~str> {
let path = ~[get_default_sysroot(), libdir(), ~"cargo"]; let path = ~[get_default_sysroot(), libdir(), ~"cargo"];
result::ok(path::connect_many(path)) result::ok(path::connect_many(path))
} }
fn get_cargo_root() -> result<path, ~str> { fn get_cargo_root() -> result<Path, ~str> {
match os::getenv(~"CARGO_ROOT") { match os::getenv(~"CARGO_ROOT") {
some(_p) => result::ok(_p), some(_p) => result::ok(_p),
none => match os::homedir() { none => match os::homedir() {
@ -129,7 +129,7 @@ fn get_cargo_root() -> result<path, ~str> {
} }
} }
fn get_cargo_root_nearest() -> result<path, ~str> { fn get_cargo_root_nearest() -> result<Path, ~str> {
do result::chain(get_cargo_root()) |p| { do result::chain(get_cargo_root()) |p| {
let cwd = os::getcwd(); let cwd = os::getcwd();
let mut dirname = path::dirname(cwd); let mut dirname = path::dirname(cwd);
@ -153,13 +153,13 @@ fn get_cargo_root_nearest() -> result<path, ~str> {
} }
} }
fn get_cargo_lib_path() -> result<path, ~str> { fn get_cargo_lib_path() -> result<Path, ~str> {
do result::chain(get_cargo_root()) |p| { do result::chain(get_cargo_root()) |p| {
result::ok(path::connect(p, libdir())) result::ok(path::connect(p, libdir()))
} }
} }
fn get_cargo_lib_path_nearest() -> result<path, ~str> { fn get_cargo_lib_path_nearest() -> result<Path, ~str> {
do result::chain(get_cargo_root_nearest()) |p| { do result::chain(get_cargo_root_nearest()) |p| {
result::ok(path::connect(p, libdir())) result::ok(path::connect(p, libdir()))
} }

View file

@ -6,7 +6,7 @@ import syntax::print::pprust;
import syntax::codemap::span; import syntax::codemap::span;
import lib::llvm::{False, llvm, mk_object_file, mk_section_iter}; import lib::llvm::{False, llvm, mk_object_file, mk_section_iter};
import filesearch::filesearch; import filesearch::filesearch;
import io::writer_util; import io::WriterUtil;
export os; export os;
export os_macos, os_win32, os_linux, os_freebsd; export os_macos, os_win32, os_linux, os_freebsd;
@ -206,7 +206,7 @@ fn meta_section_name(os: os) -> ~str {
} }
// A diagnostic function for dumping crate metadata to an output stream // A diagnostic function for dumping crate metadata to an output stream
fn list_file_metadata(os: os, path: ~str, out: io::writer) { fn list_file_metadata(os: os, path: ~str, out: io::Writer) {
match get_metadata_section(os, path) { match get_metadata_section(os, path) {
option::some(bytes) => decoder::list_crate_metadata(bytes, out), option::some(bytes) => decoder::list_crate_metadata(bytes, out),
option::none => { option::none => {

View file

@ -1,6 +1,6 @@
// Type encoding // Type encoding
import io::writer_util; import io::WriterUtil;
import std::map::hashmap; import std::map::hashmap;
import syntax::ast::*; import syntax::ast::*;
import syntax::diagnostic::span_handler; import syntax::diagnostic::span_handler;
@ -40,7 +40,7 @@ fn cx_uses_abbrevs(cx: @ctxt) -> bool {
} }
} }
fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) { fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) {
match cx.abbrevs { match cx.abbrevs {
ac_no_abbrevs => { ac_no_abbrevs => {
let result_str = match cx.tcx.short_names_cache.find(t) { let result_str = match cx.tcx.short_names_cache.find(t) {
@ -95,7 +95,7 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
} }
} }
} }
fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) { fn enc_mt(w: io::Writer, cx: @ctxt, mt: ty::mt) {
match mt.mutbl { match mt.mutbl {
m_imm => (), m_imm => (),
m_mutbl => w.write_char('m'), m_mutbl => w.write_char('m'),
@ -104,7 +104,7 @@ fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) {
enc_ty(w, cx, mt.ty); enc_ty(w, cx, mt.ty);
} }
fn enc_opt<T>(w: io::writer, t: option<T>, enc_f: fn(T)) { fn enc_opt<T>(w: io::Writer, t: option<T>, enc_f: fn(T)) {
match t { match t {
none => w.write_char('n'), none => w.write_char('n'),
some(v) => { some(v) => {
@ -114,7 +114,7 @@ fn enc_opt<T>(w: io::writer, t: option<T>, enc_f: fn(T)) {
} }
} }
fn enc_substs(w: io::writer, cx: @ctxt, substs: ty::substs) { fn enc_substs(w: io::Writer, cx: @ctxt, substs: ty::substs) {
do enc_opt(w, substs.self_r) |r| { enc_region(w, cx, r) } do enc_opt(w, substs.self_r) |r| { enc_region(w, cx, r) }
do enc_opt(w, substs.self_ty) |t| { enc_ty(w, cx, t) } do enc_opt(w, substs.self_ty) |t| { enc_ty(w, cx, t) }
w.write_char('['); w.write_char('[');
@ -122,7 +122,7 @@ fn enc_substs(w: io::writer, cx: @ctxt, substs: ty::substs) {
w.write_char(']'); w.write_char(']');
} }
fn enc_region(w: io::writer, cx: @ctxt, r: ty::region) { fn enc_region(w: io::Writer, cx: @ctxt, r: ty::region) {
match r { match r {
ty::re_bound(br) => { ty::re_bound(br) => {
w.write_char('b'); w.write_char('b');
@ -151,7 +151,7 @@ fn enc_region(w: io::writer, cx: @ctxt, r: ty::region) {
} }
} }
fn enc_bound_region(w: io::writer, br: ty::bound_region) { fn enc_bound_region(w: io::Writer, br: ty::bound_region) {
match br { match br {
ty::br_self => w.write_char('s'), ty::br_self => w.write_char('s'),
ty::br_anon => w.write_char('a'), ty::br_anon => w.write_char('a'),
@ -169,7 +169,7 @@ fn enc_bound_region(w: io::writer, br: ty::bound_region) {
} }
} }
fn enc_vstore(w: io::writer, cx: @ctxt, v: ty::vstore) { fn enc_vstore(w: io::Writer, cx: @ctxt, v: ty::vstore) {
w.write_char('/'); w.write_char('/');
match v { match v {
ty::vstore_fixed(u) => { ty::vstore_fixed(u) => {
@ -189,7 +189,7 @@ fn enc_vstore(w: io::writer, cx: @ctxt, v: ty::vstore) {
} }
} }
fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) { fn enc_sty(w: io::Writer, cx: @ctxt, st: ty::sty) {
match st { match st {
ty::ty_nil => w.write_char('n'), ty::ty_nil => w.write_char('n'),
ty::ty_bot => w.write_char('z'), ty::ty_bot => w.write_char('z'),
@ -307,7 +307,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
} }
} }
fn enc_proto(w: io::writer, cx: @ctxt, proto: ty::fn_proto) { fn enc_proto(w: io::Writer, cx: @ctxt, proto: ty::fn_proto) {
w.write_str(&"f"); w.write_str(&"f");
match proto { match proto {
ty::proto_bare => w.write_str(&"n"), ty::proto_bare => w.write_str(&"n"),
@ -318,7 +318,7 @@ fn enc_proto(w: io::writer, cx: @ctxt, proto: ty::fn_proto) {
} }
} }
fn enc_mode(w: io::writer, cx: @ctxt, m: mode) { fn enc_mode(w: io::Writer, cx: @ctxt, m: mode) {
match ty::resolved_mode(cx.tcx, m) { match ty::resolved_mode(cx.tcx, m) {
by_mutbl_ref => w.write_char('&'), by_mutbl_ref => w.write_char('&'),
by_move => w.write_char('-'), by_move => w.write_char('-'),
@ -328,7 +328,7 @@ fn enc_mode(w: io::writer, cx: @ctxt, m: mode) {
} }
} }
fn enc_purity(w: io::writer, p: purity) { fn enc_purity(w: io::Writer, p: purity) {
match p { match p {
pure_fn => w.write_char('p'), pure_fn => w.write_char('p'),
impure_fn => w.write_char('i'), impure_fn => w.write_char('i'),
@ -337,7 +337,7 @@ fn enc_purity(w: io::writer, p: purity) {
} }
} }
fn enc_ty_fn(w: io::writer, cx: @ctxt, ft: ty::fn_ty) { fn enc_ty_fn(w: io::Writer, cx: @ctxt, ft: ty::fn_ty) {
enc_proto(w, cx, ft.proto); enc_proto(w, cx, ft.proto);
enc_purity(w, ft.purity); enc_purity(w, ft.purity);
enc_bounds(w, cx, ft.bounds); enc_bounds(w, cx, ft.bounds);
@ -353,7 +353,7 @@ fn enc_ty_fn(w: io::writer, cx: @ctxt, ft: ty::fn_ty) {
} }
} }
fn enc_bounds(w: io::writer, cx: @ctxt, bs: @~[ty::param_bound]) { fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) {
for vec::each(*bs) |bound| { for vec::each(*bs) |bound| {
match bound { match bound {
ty::bound_send => w.write_char('S'), ty::bound_send => w.write_char('S'),

View file

@ -6,7 +6,7 @@ import syntax::attr;
import syntax::codemap::span; import syntax::codemap::span;
import std::map::{map,hashmap,int_hash,hash_from_strs}; import std::map::{map,hashmap,int_hash,hash_from_strs};
import std::smallintmap::{map,smallintmap}; import std::smallintmap::{map,smallintmap};
import io::writer_util; import io::WriterUtil;
import util::ppaux::{ty_to_str}; import util::ppaux::{ty_to_str};
import middle::pat_util::{pat_bindings}; import middle::pat_util::{pat_bindings};
import syntax::ast_util::{path_to_ident}; import syntax::ast_util::{path_to_ident};

View file

@ -108,7 +108,7 @@ import visit::vt;
import syntax::codemap::span; import syntax::codemap::span;
import syntax::ast::*; import syntax::ast::*;
import driver::session::session; import driver::session::session;
import io::writer_util; import io::WriterUtil;
import capture::{cap_move, cap_drop, cap_copy, cap_ref}; import capture::{cap_move, cap_drop, cap_copy, cap_ref};
export check_crate; export check_crate;
@ -647,7 +647,7 @@ class liveness {
} }
} }
fn write_vars(wr: io::writer, fn write_vars(wr: io::Writer,
ln: live_node, ln: live_node,
test: fn(uint) -> live_node) { test: fn(uint) -> live_node) {
let node_base_idx = self.idx(ln, variable(0u)); let node_base_idx = self.idx(ln, variable(0u));

View file

@ -88,7 +88,7 @@ fn pandoc_writer(
]; ];
do generic_writer |markdown| { do generic_writer |markdown| {
import io::writer_util; import io::WriterUtil;
debug!{"pandoc cmd: %s", pandoc_cmd}; debug!{"pandoc cmd: %s", pandoc_cmd};
debug!{"pandoc args: %s", str::connect(pandoc_args, ~" ")}; debug!{"pandoc args: %s", str::connect(pandoc_args, ~" ")};
@ -254,9 +254,9 @@ mod test {
} }
fn write_file(path: ~str, s: ~str) { fn write_file(path: ~str, s: ~str) {
import io::writer_util; import io::WriterUtil;
match io::file_writer(path, ~[io::create, io::truncate]) { match io::file_writer(path, ~[io::Create, io::Truncate]) {
result::ok(writer) => { result::ok(writer) => {
writer.write_str(s); writer.write_str(s);
} }

View file

@ -6,7 +6,7 @@ import std::time::precise_time_s;
import std::map; import std::map;
import std::map::{map, hashmap}; import std::map::{map, hashmap};
import io::reader; import io::Reader;
fn main(argv: ~[~str]) { fn main(argv: ~[~str]) {
#macro[ #macro[

View file

@ -2,7 +2,7 @@
use std; use std;
import dvec::dvec; import dvec::dvec;
import io::writer_util; import io::WriterUtil;
fn collect_raw(num: uint) -> ~[uint] { fn collect_raw(num: uint) -> ~[uint] {
let mut result = ~[]; let mut result = ~[];

View file

@ -13,7 +13,7 @@ import std::map::hashmap;
import std::deque; import std::deque;
import std::deque::t; import std::deque::t;
import std::par; import std::par;
import io::writer_util; import io::WriterUtil;
import comm::*; import comm::*;
import int::abs; import int::abs;
@ -24,7 +24,7 @@ type bfs_result = ~[node_id];
fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] { fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] {
let r = rand::xorshift(); let r = rand::xorshift();
fn choose_edge(i: node_id, j: node_id, scale: uint, r: rand::rng) fn choose_edge(i: node_id, j: node_id, scale: uint, r: rand::Rng)
-> (node_id, node_id) { -> (node_id, node_id) {
let A = 0.57; let A = 0.57;

View file

@ -11,8 +11,8 @@
// xfail-pretty // xfail-pretty
use std; use std;
import io::writer; import io::Writer;
import io::writer_util; import io::WriterUtil;
import pipes::{port, chan, shared_chan}; import pipes::{port, chan, shared_chan};

View file

@ -7,8 +7,8 @@
// xfail-pretty // xfail-pretty
use std; use std;
import io::writer; import io::Writer;
import io::writer_util; import io::WriterUtil;
import pipes::{port, port_set, chan}; import pipes::{port, port_set, chan};

View file

@ -5,8 +5,8 @@
// I *think* it's the same, more or less. // I *think* it's the same, more or less.
use std; use std;
import io::writer; import io::Writer;
import io::writer_util; import io::WriterUtil;
enum request { enum request {
get_count, get_count,

View file

@ -10,7 +10,7 @@ import vec;
import uint; import uint;
import int; import int;
import str; import str;
import io::writer_util; import io::WriterUtil;
fn LINE_LENGTH() -> uint { return 60u; } fn LINE_LENGTH() -> uint { return 60u; }
@ -43,7 +43,7 @@ fn select_random(r: u32, genelist: ~[aminoacids]) -> char {
return bisect(genelist, 0u, vec::len::<aminoacids>(genelist) - 1u, r); return bisect(genelist, 0u, vec::len::<aminoacids>(genelist) - 1u, r);
} }
fn make_random_fasta(wr: io::writer, id: ~str, desc: ~str, genelist: ~[aminoacids], n: int) { fn make_random_fasta(wr: io::Writer, id: ~str, desc: ~str, genelist: ~[aminoacids], n: int) {
wr.write_line(~">" + id + ~" " + desc); wr.write_line(~">" + id + ~" " + desc);
let rng = @{mut last: rand::rng().next()}; let rng = @{mut last: rand::rng().next()};
let mut op: ~str = ~""; let mut op: ~str = ~"";
@ -58,7 +58,7 @@ fn make_random_fasta(wr: io::writer, id: ~str, desc: ~str, genelist: ~[aminoacid
if str::len(op) > 0u { wr.write_line(op); } if str::len(op) > 0u { wr.write_line(op); }
} }
fn make_repeat_fasta(wr: io::writer, id: ~str, desc: ~str, s: ~str, n: int) unsafe { fn make_repeat_fasta(wr: io::Writer, id: ~str, desc: ~str, s: ~str, n: int) unsafe {
wr.write_line(~">" + id + ~" " + desc); wr.write_line(~">" + id + ~" " + desc);
let mut op: ~str = ~""; let mut op: ~str = ~"";
let sl: uint = str::len(s); let sl: uint = str::len(s);
@ -85,7 +85,7 @@ fn main(args: ~[~str]) {
}; };
let writer = if os::getenv(~"RUST_BENCH").is_some() { let writer = if os::getenv(~"RUST_BENCH").is_some() {
result::get(io::file_writer(~"./shootout-fasta.data", ~[io::truncate, io::create])) result::get(io::file_writer(~"./shootout-fasta.data", ~[io::Truncate, io::Create]))
} else { } else {
io::stdout() io::stdout()
}; };

View file

@ -13,7 +13,7 @@
// writes pbm image to output path // writes pbm image to output path
use std; use std;
import io::writer_util; import io::WriterUtil;
import std::map::hashmap; import std::map::hashmap;
struct cmplx { struct cmplx {
@ -90,12 +90,12 @@ fn chanmb(i: uint, size: uint, ch: comm::chan<line>) -> ()
type devnull = {dn: int}; type devnull = {dn: int};
impl devnull: io::writer { impl devnull: io::Writer {
fn write(_b: &[const u8]) {} fn write(_b: &[const u8]) {}
fn seek(_i: int, _s: io::seek_style) {} fn seek(_i: int, _s: io::SeekStyle) {}
fn tell() -> uint {0_u} fn tell() -> uint {0_u}
fn flush() -> int {0} fn flush() -> int {0}
fn get_type() -> io::writer_type { io::file } fn get_type() -> io::WriterType { io::File }
} }
fn writer(path: ~str, writech: comm::chan<comm::chan<line>>, size: uint) fn writer(path: ~str, writech: comm::chan<comm::chan<line>>, size: uint)
@ -103,9 +103,9 @@ fn writer(path: ~str, writech: comm::chan<comm::chan<line>>, size: uint)
let p: comm::port<line> = comm::port(); let p: comm::port<line> = comm::port();
let ch = comm::chan(p); let ch = comm::chan(p);
comm::send(writech, ch); comm::send(writech, ch);
let cout: io::writer = match path { let cout: io::Writer = match path {
~"" => { ~"" => {
{dn: 0} as io::writer {dn: 0} as io::Writer
} }
~"-" => { ~"-" => {
io::stdout() io::stdout()
@ -113,7 +113,7 @@ fn writer(path: ~str, writech: comm::chan<comm::chan<line>>, size: uint)
_ => { _ => {
result::get( result::get(
io::file_writer(path, io::file_writer(path,
~[io::create, io::truncate])) ~[io::Create, io::Truncate]))
} }
}; };
cout.write_line(~"P4"); cout.write_line(~"P4");

View file

@ -13,7 +13,7 @@
use std; use std;
import std::{time, getopts}; import std::{time, getopts};
import io::writer_util; import io::WriterUtil;
import int::range; import int::range;
import pipes::port; import pipes::port;
import pipes::chan; import pipes::chan;

View file

@ -3,7 +3,7 @@
use std; use std;
import std::smallintmap; import std::smallintmap;
import std::smallintmap::smallintmap; import std::smallintmap::smallintmap;
import io::writer_util; import io::WriterUtil;
fn append_sequential(min: uint, max: uint, map: smallintmap<uint>) { fn append_sequential(min: uint, max: uint, map: smallintmap<uint>) {
for uint::range(min, max) |i| { for uint::range(min, max) |i| {

View file

@ -1,7 +1,7 @@
use std; use std;
import std::bitv; import std::bitv;
import io::writer_util; import io::WriterUtil;
// Computes a single solution to a given 9x9 sudoku // Computes a single solution to a given 9x9 sudoku
// //
@ -28,7 +28,7 @@ type grid = ~[~[mut u8]];
enum grid_t { grid_ctor(grid), } enum grid_t { grid_ctor(grid), }
// read a sudoku problem from file f // read a sudoku problem from file f
fn read_grid(f: io::reader) -> grid_t { fn read_grid(f: io::Reader) -> grid_t {
assert f.read_line() == ~"9,9"; /* assert first line is exactly "9,9" */ assert f.read_line() == ~"9,9"; /* assert first line is exactly "9,9" */
let g = vec::from_fn(10u, {|_i| let g = vec::from_fn(10u, {|_i|
@ -116,7 +116,7 @@ fn solve_grid(g: grid_t) {
} }
} }
fn write_grid(f: io::writer, g: grid_t) { fn write_grid(f: io::Writer, g: grid_t) {
for u8::range(0u8, 9u8) |row| { for u8::range(0u8, 9u8) |row| {
f.write_str(fmt!{"%u", (*g)[row][0] as uint}); f.write_str(fmt!{"%u", (*g)[row][0] as uint});
for u8::range(1u8, 9u8) |col| { for u8::range(1u8, 9u8) |col| {

View file

@ -20,7 +20,7 @@ import std::map;
import std::map::hashmap; import std::map::hashmap;
import vec; import vec;
import io; import io;
import io::writer_util; import io::WriterUtil;
import std::time; import std::time;
import u64; import u64;
@ -73,7 +73,7 @@ fn join(t: joinable_task) {
t.recv() t.recv()
} }
impl io::reader: word_reader { impl io::Reader: word_reader {
fn read_word() -> option<~str> { read_word(self) } fn read_word() -> option<~str> { read_word(self) }
} }
@ -331,7 +331,7 @@ fn main(argv: ~[~str]) {
+ u64::str(elapsed) + ~"ms"); + u64::str(elapsed) + ~"ms");
} }
fn read_word(r: io::reader) -> option<~str> { fn read_word(r: io::Reader) -> option<~str> {
let mut w = ~""; let mut w = ~"";
while !r.eof() { while !r.eof() {
@ -350,7 +350,7 @@ fn is_word_char(c: char) -> bool {
class random_word_reader: word_reader { class random_word_reader: word_reader {
let mut remaining: uint; let mut remaining: uint;
let rng: rand::rng; let rng: rand::Rng;
new(count: uint) { new(count: uint) {
self.remaining = count; self.remaining = count;
self.rng = rand::rng(); self.rng = rand::rng();

View file

@ -1,7 +1,7 @@
// error-pattern:explicit failure // error-pattern:explicit failure
// Don't double free the string // Don't double free the string
use std; use std;
import io::reader; import io::Reader;
fn main() { fn main() {
do io::with_str_reader(~"") |rdr| { do io::with_str_reader(~"") |rdr| {

View file

@ -85,7 +85,7 @@ fn main() {
fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: ~str) { fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: ~str) {
let buf = mem_buffer(); let buf = mem_buffer();
let pp = pprust::rust_printer(buf as io::writer); let pp = pprust::rust_printer(buf as io::Writer);
f(pp, expr); f(pp, expr);
pp::eof(pp.s); pp::eof(pp.s);
let str = mem_buffer_str(buf); let str = mem_buffer_str(buf);

View file

@ -4,14 +4,14 @@ use std;
// the common code. // the common code.
import std::ebml; import std::ebml;
import io::writer; import io::Writer;
import std::serialization::{serialize_uint, deserialize_uint}; import std::serialization::{serialize_uint, deserialize_uint};
fn test_ser_and_deser<A>(a1: A, fn test_ser_and_deser<A>(a1: A,
expected: ~str, expected: ~str,
ebml_ser_fn: fn(ebml::writer, A), ebml_ser_fn: fn(ebml::writer, A),
ebml_deser_fn: fn(ebml::ebml_deserializer) -> A, ebml_deser_fn: fn(ebml::ebml_deserializer) -> A,
io_ser_fn: fn(io::writer, A)) { io_ser_fn: fn(io::Writer, A)) {
// check the pretty printer: // check the pretty printer:
io_ser_fn(io::stdout(), a1); io_ser_fn(io::stdout(), a1);
@ -21,7 +21,7 @@ fn test_ser_and_deser<A>(a1: A,
// check the EBML serializer: // check the EBML serializer:
let buf = io::mem_buffer(); let buf = io::mem_buffer();
let w = ebml::writer(buf as io::writer); let w = ebml::writer(buf as io::Writer);
ebml_ser_fn(w, a1); ebml_ser_fn(w, a1);
let d = ebml::doc(@io::mem_buffer_buf(buf)); let d = ebml::doc(@io::mem_buffer_buf(buf));
let a2 = ebml_deser_fn(ebml::ebml_deserializer(d)); let a2 = ebml_deser_fn(ebml::ebml_deserializer(d));

View file

@ -1,6 +1,6 @@
use std; use std;
import io; import io;
import io::writer_util; import io::WriterUtil;
import std::map::hashmap; import std::map::hashmap;
enum object enum object

View file

@ -45,8 +45,8 @@ fn square_from_char(c: char) -> square {
} }
} }
fn read_board_grid<rdr: owned io::reader>(+in: rdr) -> ~[~[square]] { fn read_board_grid<rdr: owned io::Reader>(+in: rdr) -> ~[~[square]] {
let in = in as io::reader; let in = in as io::Reader;
let mut grid = ~[]; let mut grid = ~[];
for in.each_line |line| { for in.each_line |line| {
let mut row = ~[]; let mut row = ~[];