Convert more core types to camel case
This commit is contained in:
parent
e640a66eb4
commit
11258310e2
@ -8,7 +8,7 @@ import rustc::metadata::filesearch::{get_cargo_root, get_cargo_root_nearest,
|
||||
import syntax::diagnostic;
|
||||
|
||||
import result::{ok, err};
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import std::{map, json, tempfile, term, sort, getopts};
|
||||
import map::hashmap;
|
||||
import to_str::to_str;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import run::spawn_process;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import libc::{c_int, pid_t};
|
||||
|
||||
import pipes::chan;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
import common::mode_run_pass;
|
||||
import common::mode_run_fail;
|
||||
@ -339,7 +339,7 @@ fn compose_and_run_compiler(
|
||||
config.compile_lib_path, input)
|
||||
}
|
||||
|
||||
fn ensure_dir(path: path) {
|
||||
fn ensure_dir(path: Path) {
|
||||
if os::path_is_dir(path) { return; }
|
||||
if !os::make_dir(path, 0x1c0i32) {
|
||||
fail fmt!{"can't make dir %s", path};
|
||||
@ -455,7 +455,7 @@ fn dump_output_file(config: config, testfile: ~str,
|
||||
out: ~str, extension: ~str) {
|
||||
let outfile = make_out_name(config, testfile, extension);
|
||||
let writer = result::get(
|
||||
io::file_writer(outfile, ~[io::create, io::truncate]));
|
||||
io::file_writer(outfile, ~[io::Create, io::Truncate]));
|
||||
writer.write_str(out);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ d.write("// AUTO-GENERATED FILE: DO NOT EDIT\n")
|
||||
d.write("use std;\n")
|
||||
d.write("use 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(" let out = io::stdout();\n");
|
||||
i = 0
|
||||
|
@ -1,4 +1,4 @@
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
import syntax::{ast, ast_util, fold, visit, codemap};
|
||||
import syntax::parse;
|
||||
@ -10,7 +10,7 @@ type context = { mode: test_mode }; // + rng
|
||||
|
||||
fn write_file(filename: ~str, content: ~str) {
|
||||
result::get(
|
||||
io::file_writer(filename, ~[io::create, io::truncate]))
|
||||
io::file_writer(filename, ~[io::Create, io::Truncate]))
|
||||
.write_str(content);
|
||||
}
|
||||
|
||||
@ -216,9 +216,9 @@ fn under(n: uint, it: fn(uint)) {
|
||||
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();
|
||||
f(io::mem_buffer_writer(buf));
|
||||
io::mem_buffer_str(buf)
|
||||
|
@ -54,6 +54,7 @@ export send_map;
|
||||
export hash;
|
||||
export cmp;
|
||||
export num;
|
||||
export path;
|
||||
|
||||
// NDM seems to be necessary for resolve to work
|
||||
export option_iter;
|
||||
@ -214,11 +215,16 @@ mod pipes;
|
||||
|
||||
// Runtime and language-primitive support
|
||||
|
||||
#[warn(non_camel_case_types)]
|
||||
mod io;
|
||||
mod libc;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod os;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod path;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod rand;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod run;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod sys;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import option::{some, none};
|
||||
import option = option::option;
|
||||
import path = path::path;
|
||||
import Path = path::Path;
|
||||
import tuple::{TupleOps, ExtendedTupleOps};
|
||||
import str::{str_slice, unique_str};
|
||||
import vec::{const_vector, copyable_vector, immutable_vector};
|
||||
@ -14,7 +14,7 @@ import num::Num;
|
||||
import ptr::ptr;
|
||||
import to_str::ToStr;
|
||||
|
||||
export path, option, some, none, unreachable;
|
||||
export Path, option, some, none, unreachable;
|
||||
export extensions;
|
||||
// The following exports are the extension impls for numeric types
|
||||
export Num, times, timesi;
|
||||
|
@ -13,8 +13,8 @@
|
||||
* CPRNG like rand::rng.
|
||||
*/
|
||||
|
||||
import io::writer;
|
||||
import io::writer_util;
|
||||
import io::Writer;
|
||||
import io::WriterUtil;
|
||||
|
||||
export Streaming, 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
|
||||
fn write(msg: &[const u8]) {
|
||||
@ -209,7 +209,7 @@ impl &SipState : io::writer {
|
||||
self.ntail = left;
|
||||
}
|
||||
|
||||
fn seek(_x: int, _s: io::seek_style) {
|
||||
fn seek(_x: int, _s: io::SeekStyle) {
|
||||
fail;
|
||||
}
|
||||
fn tell() -> uint {
|
||||
@ -218,8 +218,8 @@ impl &SipState : io::writer {
|
||||
fn flush() -> int {
|
||||
0
|
||||
}
|
||||
fn get_type() -> io::writer_type {
|
||||
io::file
|
||||
fn get_type() -> io::WriterType {
|
||||
io::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::extra::*;
|
||||
|
||||
#[allow(non_camel_case_types)] // not sure what to do about this
|
||||
type fd_t = c_int;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
@ -24,11 +25,11 @@ extern mod rustrt {
|
||||
|
||||
// FIXME (#2004): This is all buffered. We might need an unbuffered variant
|
||||
// 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.
|
||||
trait reader {
|
||||
trait Reader {
|
||||
// FIXME (#2004): Seekable really should be orthogonal.
|
||||
|
||||
// FIXME (#2982): This should probably return an error.
|
||||
@ -36,13 +37,13 @@ trait reader {
|
||||
fn read_byte() -> int;
|
||||
fn unread_byte(int);
|
||||
fn eof() -> bool;
|
||||
fn seek(int, seek_style);
|
||||
fn seek(int, SeekStyle);
|
||||
fn tell() -> uint;
|
||||
}
|
||||
|
||||
// Generic utility functions defined on readers
|
||||
|
||||
impl reader {
|
||||
impl Reader {
|
||||
fn read_bytes(len: uint) -> ~[u8] {
|
||||
let mut buf = ~[mut];
|
||||
vec::reserve(buf, len);
|
||||
@ -195,15 +196,15 @@ impl reader {
|
||||
|
||||
// Reader implementations
|
||||
|
||||
fn convert_whence(whence: seek_style) -> i32 {
|
||||
fn convert_whence(whence: SeekStyle) -> i32 {
|
||||
return match whence {
|
||||
seek_set => 0i32,
|
||||
seek_cur => 1i32,
|
||||
seek_end => 2i32
|
||||
SeekSet => 0i32,
|
||||
SeekCur => 1i32,
|
||||
SeekEnd => 2i32
|
||||
};
|
||||
}
|
||||
|
||||
impl *libc::FILE: reader {
|
||||
impl *libc::FILE: Reader {
|
||||
fn read(buf: &[mut u8], len: uint) -> uint {
|
||||
do vec::as_buf(buf) |buf_p, buf_len| {
|
||||
assert buf_len <= len;
|
||||
@ -217,7 +218,7 @@ impl *libc::FILE: reader {
|
||||
fn read_byte() -> int { return libc::fgetc(self) as int; }
|
||||
fn unread_byte(byte: int) { libc::ungetc(byte as c_int, self); }
|
||||
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))
|
||||
== 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
|
||||
// duration of its lifetime.
|
||||
// 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_byte() -> int { self.base.read_byte() }
|
||||
fn unread_byte(byte: int) { self.base.unread_byte(byte); }
|
||||
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() }
|
||||
}
|
||||
|
||||
class FILE_res {
|
||||
class FILERes {
|
||||
let f: *libc::FILE;
|
||||
new(f: *libc::FILE) { self.f = 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 {
|
||||
{base: f, cleanup: FILE_res(f)} as reader
|
||||
{base: f, cleanup: FILERes(f)} as Reader
|
||||
} 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
|
||||
// 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| {
|
||||
os::as_c_charp(~"r", |modebuf|
|
||||
libc::fopen(pathbuf, modebuf)
|
||||
@ -271,9 +272,9 @@ fn file_reader(path: ~str) -> result<reader, ~str> {
|
||||
|
||||
// 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 {
|
||||
let count = uint::min(len, self.len - self.pos);
|
||||
|
||||
@ -293,65 +294,65 @@ impl byte_buf: reader {
|
||||
// FIXME (#2738): implement this
|
||||
fn unread_byte(_byte: int) { error!{"Unimplemented: unread_byte"}; fail; }
|
||||
fn eof() -> bool { self.pos == self.len }
|
||||
fn seek(offset: int, whence: seek_style) {
|
||||
fn seek(offset: int, whence: SeekStyle) {
|
||||
let pos = self.pos;
|
||||
self.pos = seek_in_buf(offset, pos, self.len, whence);
|
||||
}
|
||||
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))
|
||||
}
|
||||
|
||||
fn bytes_reader_between(bytes: ~[u8], start: uint, end: uint) -> reader {
|
||||
{buf: bytes, mut pos: start, len: end} as reader
|
||||
fn bytes_reader_between(bytes: ~[u8], start: uint, end: uint) -> 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))
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
fn str_reader(s: ~str) -> reader {
|
||||
fn str_reader(s: ~str) -> Reader {
|
||||
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| {
|
||||
with_bytes_reader_between(bytes, 0u, str::len(s), f)
|
||||
}
|
||||
}
|
||||
|
||||
// Writing
|
||||
enum fileflag { append, create, truncate, no_flag, }
|
||||
enum FileFlag { Append, Create, Truncate, NoFlag, }
|
||||
|
||||
// What type of writer are we?
|
||||
enum writer_type { screen, file }
|
||||
enum WriterType { Screen, File }
|
||||
|
||||
// FIXME (#2004): Seekable really should be orthogonal.
|
||||
// FIXME (#2004): eventually u64
|
||||
trait writer {
|
||||
trait Writer {
|
||||
fn write(v: &[const u8]);
|
||||
fn seek(int, seek_style);
|
||||
fn seek(int, SeekStyle);
|
||||
fn tell() -> uint;
|
||||
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 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 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]) {
|
||||
do vec::as_const_buf(v) |vbuf, len| {
|
||||
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))
|
||||
== 0 as c_int;
|
||||
}
|
||||
fn tell() -> uint { libc::ftell(self) as uint }
|
||||
fn flush() -> int { libc::fflush(self) as int }
|
||||
fn get_type() -> writer_type {
|
||||
fn get_type() -> WriterType {
|
||||
let fd = libc::fileno(self);
|
||||
if libc::isatty(fd) == 0 { file }
|
||||
else { screen }
|
||||
if libc::isatty(fd) == 0 { File }
|
||||
else { Screen }
|
||||
}
|
||||
}
|
||||
|
||||
fn FILE_writer(f: *libc::FILE, cleanup: bool) -> writer {
|
||||
fn FILE_writer(f: *libc::FILE, cleanup: bool) -> Writer {
|
||||
if cleanup {
|
||||
{base: f, cleanup: FILE_res(f)} as writer
|
||||
{base: f, cleanup: FILERes(f)} as Writer
|
||||
} else {
|
||||
f as writer
|
||||
f as Writer
|
||||
}
|
||||
}
|
||||
|
||||
impl fd_t: writer {
|
||||
impl fd_t: Writer {
|
||||
fn write(v: &[const u8]) {
|
||||
let mut count = 0u;
|
||||
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"};
|
||||
fail;
|
||||
}
|
||||
@ -409,28 +410,28 @@ impl fd_t: writer {
|
||||
fail;
|
||||
}
|
||||
fn flush() -> int { 0 }
|
||||
fn get_type() -> writer_type {
|
||||
if libc::isatty(self) == 0 { file } else { screen }
|
||||
fn get_type() -> WriterType {
|
||||
if libc::isatty(self) == 0 { File } else { Screen }
|
||||
}
|
||||
}
|
||||
|
||||
class fd_res {
|
||||
class FdRes {
|
||||
let fd: fd_t;
|
||||
new(fd: fd_t) { self.fd = 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 {
|
||||
{base: fd, cleanup: fd_res(fd)} as writer
|
||||
{base: fd, cleanup: FdRes(fd)} as Writer
|
||||
} else {
|
||||
fd as writer
|
||||
fd as Writer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn mk_file_writer(path: ~str, flags: ~[fileflag])
|
||||
-> result<writer, ~str> {
|
||||
fn mk_file_writer(path: ~str, flags: ~[FileFlag])
|
||||
-> result<Writer, ~str> {
|
||||
|
||||
#[cfg(windows)]
|
||||
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();
|
||||
for vec::each(flags) |f| {
|
||||
match f {
|
||||
append => fflags |= O_APPEND as c_int,
|
||||
create => fflags |= O_CREAT as c_int,
|
||||
truncate => fflags |= O_TRUNC as c_int,
|
||||
no_flag => ()
|
||||
Append => fflags |= O_APPEND as c_int,
|
||||
Create => fflags |= O_CREAT as c_int,
|
||||
Truncate => fflags |= O_TRUNC as c_int,
|
||||
NoFlag => ()
|
||||
}
|
||||
}
|
||||
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
|
||||
// default methods on writer)
|
||||
trait writer_util {
|
||||
trait WriterUtil {
|
||||
fn write_char(ch: char);
|
||||
fn write_str(s: &str);
|
||||
fn write_line(s: &str);
|
||||
@ -560,7 +561,7 @@ trait writer_util {
|
||||
fn write_u8(n: u8);
|
||||
}
|
||||
|
||||
impl<T:writer> T : writer_util {
|
||||
impl<T: Writer> T : WriterUtil {
|
||||
fn write_char(ch: char) {
|
||||
if ch as uint < 128u {
|
||||
self.write(&[ch as u8]);
|
||||
@ -631,13 +632,13 @@ impl<T:writer> T : writer_util {
|
||||
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))
|
||||
}
|
||||
|
||||
|
||||
// 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| {
|
||||
do os::as_c_charp(~"w") |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) why are these different from the way stdin() is
|
||||
// implemented?
|
||||
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 stdout() -> Writer { fd_writer(libc::STDOUT_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 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]) {
|
||||
// Fast path.
|
||||
let vlen = vec::len(v);
|
||||
@ -679,33 +680,33 @@ impl mem_buffer: writer {
|
||||
self.buf.push_slice(v, vpos, vlen);
|
||||
self.pos += vlen;
|
||||
}
|
||||
fn seek(offset: int, whence: seek_style) {
|
||||
fn seek(offset: int, whence: SeekStyle) {
|
||||
let pos = self.pos;
|
||||
let len = self.buf.len();
|
||||
self.pos = seek_in_buf(offset, pos, len, whence);
|
||||
}
|
||||
fn tell() -> uint { self.pos }
|
||||
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}
|
||||
}
|
||||
fn mem_buffer_writer(b: mem_buffer) -> writer { b as writer }
|
||||
fn mem_buffer_buf(b: mem_buffer) -> ~[u8] { b.buf.get() }
|
||||
fn mem_buffer_str(b: mem_buffer) -> ~str {
|
||||
fn mem_buffer_writer(b: MemBuffer) -> Writer { b as Writer }
|
||||
fn mem_buffer_buf(b: MemBuffer) -> ~[u8] { b.buf.get() }
|
||||
fn mem_buffer_str(b: MemBuffer) -> ~str {
|
||||
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 wr = mem_buffer_writer(buf);
|
||||
f(wr);
|
||||
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 wr = mem_buffer_writer(buf);
|
||||
f(wr);
|
||||
@ -713,14 +714,14 @@ fn with_buf_writer(f: fn(writer)) -> ~[u8] {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
let mut bpos = pos as int;
|
||||
let blen = len as int;
|
||||
match whence {
|
||||
seek_set => bpos = offset,
|
||||
seek_cur => bpos += offset,
|
||||
seek_end => bpos = blen + offset
|
||||
SeekSet => bpos = offset,
|
||||
SeekCur => bpos += offset,
|
||||
SeekEnd => bpos = blen + offset
|
||||
}
|
||||
if bpos < 0 { bpos = 0; } else if bpos > blen { bpos = blen; }
|
||||
return bpos as uint;
|
||||
@ -748,24 +749,24 @@ fn read_whole_file(file: ~str) -> result<~[u8], ~str> {
|
||||
|
||||
mod fsync {
|
||||
|
||||
enum level {
|
||||
enum Level {
|
||||
// whatever fsync does on that platform
|
||||
fsync,
|
||||
FSync,
|
||||
|
||||
// fdatasync on linux, similiar or more on other platforms
|
||||
fdatasync,
|
||||
FDataSync,
|
||||
|
||||
// full fsync
|
||||
//
|
||||
// You must additionally sync the parent directory as well!
|
||||
fullfsync,
|
||||
FullFSync,
|
||||
}
|
||||
|
||||
|
||||
// Artifacts that need to fsync on destruction
|
||||
class res<t> {
|
||||
let arg: arg<t>;
|
||||
new(-arg: arg<t>) { self.arg <- arg; }
|
||||
class Res<t> {
|
||||
let arg: Arg<t>;
|
||||
new(-arg: Arg<t>) { self.arg <- arg; }
|
||||
drop {
|
||||
match self.arg.opt_level {
|
||||
option::none => (),
|
||||
@ -777,44 +778,47 @@ mod fsync {
|
||||
}
|
||||
}
|
||||
|
||||
type arg<t> = {
|
||||
type Arg<t> = {
|
||||
val: t,
|
||||
opt_level: option<level>,
|
||||
fsync_fn: fn@(t, level) -> int
|
||||
opt_level: option<Level>,
|
||||
fsync_fn: fn@(t, Level) -> int
|
||||
};
|
||||
|
||||
// fsync file after executing blk
|
||||
// FIXME (#2004) find better way to create resources within lifetime of
|
||||
// outer res
|
||||
fn FILE_res_sync(&&file: FILE_res, opt_level: option<level>,
|
||||
blk: fn(&&res<*libc::FILE>)) {
|
||||
blk(res({
|
||||
fn FILE_res_sync(&&file: FILERes, opt_level: option<Level>,
|
||||
blk: fn(&&Res<*libc::FILE>)) {
|
||||
blk(Res({
|
||||
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;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// fsync fd after executing blk
|
||||
fn fd_res_sync(&&fd: fd_res, opt_level: option<level>,
|
||||
blk: fn(&&res<fd_t>)) {
|
||||
blk(res({
|
||||
fn fd_res_sync(&&fd: FdRes, opt_level: option<Level>,
|
||||
blk: fn(&&Res<fd_t>)) {
|
||||
blk(Res({
|
||||
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;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// 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
|
||||
fn obj_sync(&&o: t, opt_level: option<level>, blk: fn(&&res<t>)) {
|
||||
blk(res({
|
||||
fn obj_sync(&&o: FSyncable, opt_level: option<Level>,
|
||||
blk: fn(&&Res<FSyncable>)) {
|
||||
blk(Res({
|
||||
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.";
|
||||
log(debug, frood);
|
||||
{
|
||||
let out: io::writer =
|
||||
let out: io::Writer =
|
||||
result::get(
|
||||
io::file_writer(tmpfile, ~[io::create, io::truncate]));
|
||||
io::file_writer(tmpfile, ~[io::Create, io::Truncate]));
|
||||
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();
|
||||
log(debug, frood2);
|
||||
assert frood == frood2;
|
||||
@ -843,7 +847,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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);
|
||||
assert(vec::len(res) == 0u);
|
||||
}
|
||||
@ -858,7 +862,7 @@ mod tests {
|
||||
29983, 38152, 30340, 27748,
|
||||
21273, 20999, 32905, 27748];
|
||||
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);
|
||||
if (len <= vec::len(ivals)) {
|
||||
assert(vec::len(res) == len);
|
||||
@ -877,14 +881,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_readchar() {
|
||||
let inp : io::reader = io::str_reader(~"生");
|
||||
let inp : io::Reader = io::str_reader(~"生");
|
||||
let res : char = inp.read_char();
|
||||
assert(res as int == 29983);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_readchar_empty() {
|
||||
let inp : io::reader = io::str_reader(~"");
|
||||
let inp : io::Reader = io::str_reader(~"");
|
||||
let res : char = inp.read_char();
|
||||
assert(res as int == -1);
|
||||
}
|
||||
@ -924,12 +928,12 @@ mod tests {
|
||||
let mbuf = mem_buffer();
|
||||
mbuf.write(~[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]);
|
||||
assert mem_buffer_buf(mbuf) == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8];
|
||||
mbuf.seek(-2, seek_end);
|
||||
mbuf.seek(-2, SeekEnd);
|
||||
mbuf.write(~[8u8]);
|
||||
mbuf.seek(1, seek_set);
|
||||
mbuf.seek(1, SeekSet);
|
||||
mbuf.write(~[9u8]);
|
||||
assert mem_buffer_buf(mbuf) == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8];
|
||||
}
|
||||
|
@ -37,6 +37,8 @@
|
||||
* dissolved.
|
||||
*/
|
||||
|
||||
#[allow(non_camel_case_types)];
|
||||
|
||||
// Initial glob-exports mean that all the contents of all the modules
|
||||
// wind up exported, if you're interested in writing platform-specific code.
|
||||
|
||||
|
@ -134,34 +134,34 @@ mod global_env {
|
||||
fn rust_global_env_chan_ptr() -> *libc::uintptr_t;
|
||||
}
|
||||
|
||||
enum msg {
|
||||
msg_getenv(~str, comm::chan<option<~str>>),
|
||||
msg_setenv(~str, ~str, comm::chan<()>),
|
||||
msg_env(comm::chan<~[(~str,~str)]>)
|
||||
enum Msg {
|
||||
MsgGetEnv(~str, comm::chan<option<~str>>),
|
||||
MsgSetEnv(~str, ~str, comm::chan<()>),
|
||||
MsgEnv(comm::chan<~[(~str,~str)]>)
|
||||
}
|
||||
|
||||
fn getenv(n: ~str) -> option<~str> {
|
||||
let env_ch = get_global_env_chan();
|
||||
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)
|
||||
}
|
||||
|
||||
fn setenv(n: ~str, v: ~str) {
|
||||
let env_ch = get_global_env_chan();
|
||||
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)
|
||||
}
|
||||
|
||||
fn env() -> ~[(~str,~str)] {
|
||||
let env_ch = get_global_env_chan();
|
||||
let po = comm::port();
|
||||
comm::send(env_ch, msg_env(comm::chan(po)));
|
||||
comm::send(env_ch, MsgEnv(comm::chan(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();
|
||||
unsafe {
|
||||
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 {
|
||||
do priv::weaken_task |weak_po| {
|
||||
loop {
|
||||
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))
|
||||
}
|
||||
either::left(msg_setenv(n, v, resp_ch)) => {
|
||||
either::left(MsgSetEnv(n, v, resp_ch)) => {
|
||||
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())
|
||||
}
|
||||
either::right(_) => break
|
||||
@ -272,28 +272,28 @@ fn fdopen(fd: c_int) -> *FILE {
|
||||
// fsync related
|
||||
|
||||
#[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::*;
|
||||
return commit(fd);
|
||||
}
|
||||
|
||||
#[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::*;
|
||||
match level {
|
||||
io::fsync::fsync
|
||||
| io::fsync::fullfsync => return fsync(fd),
|
||||
io::fsync::fdatasync => return fdatasync(fd)
|
||||
io::fsync::FSync
|
||||
| io::fsync::FullFSync => return fsync(fd),
|
||||
io::fsync::FDataSync => return fdatasync(fd)
|
||||
}
|
||||
}
|
||||
|
||||
#[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::funcs::posix88::fcntl::*;
|
||||
import libc::funcs::posix01::unistd::*;
|
||||
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
|
||||
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")]
|
||||
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::*;
|
||||
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")]
|
||||
fn load_self() -> option<path> {
|
||||
fn load_self() -> option<Path> {
|
||||
unsafe {
|
||||
import libc::funcs::bsd44::*;
|
||||
import libc::consts::os::extra::*;
|
||||
@ -388,7 +388,7 @@ fn self_exe_path() -> option<path> {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn load_self() -> option<path> {
|
||||
fn load_self() -> option<Path> {
|
||||
import libc::funcs::posix01::unistd::readlink;
|
||||
do fill_charp_buf() |buf, sz| {
|
||||
do as_c_charp(~"/proc/self/exe") |proc_self_buf| {
|
||||
@ -398,7 +398,7 @@ fn self_exe_path() -> option<path> {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn load_self() -> option<path> {
|
||||
fn load_self() -> option<Path> {
|
||||
// FIXME: remove imports when export globs work properly. #1238
|
||||
import libc::funcs::extra::*;
|
||||
do fill_charp_buf() |buf, sz| {
|
||||
@ -408,7 +408,7 @@ fn self_exe_path() -> option<path> {
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn load_self() -> option<path> {
|
||||
fn load_self() -> option<Path> {
|
||||
// FIXME: remove imports when export globs work properly. #1238
|
||||
import libc::types::os::arch::extra::*;
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
@ -437,7 +437,7 @@ fn self_exe_path() -> option<path> {
|
||||
*
|
||||
* Otherwise, homedir returns option::none.
|
||||
*/
|
||||
fn homedir() -> option<path> {
|
||||
fn homedir() -> option<Path> {
|
||||
return match getenv(~"HOME") {
|
||||
some(p) => if !str::is_empty(p) {
|
||||
some(p)
|
||||
@ -448,12 +448,12 @@ fn homedir() -> option<path> {
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
fn secondary() -> option<path> {
|
||||
fn secondary() -> option<Path> {
|
||||
none
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn secondary() -> option<path> {
|
||||
fn secondary() -> option<Path> {
|
||||
do option::chain(getenv(~"USERPROFILE")) |p| {
|
||||
if !str::is_empty(p) {
|
||||
some(p)
|
||||
@ -465,11 +465,11 @@ fn homedir() -> option<path> {
|
||||
}
|
||||
|
||||
/// 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);
|
||||
|
||||
fn walk_dir_(p: path, f: fn(path) -> bool) -> bool {
|
||||
fn walk_dir_(p: Path, f: fn(Path) -> bool) -> bool {
|
||||
let mut keepgoing = true;
|
||||
do list_dir(p).each |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
|
||||
fn path_is_dir(p: path) -> bool {
|
||||
fn path_is_dir(p: Path) -> bool {
|
||||
do str::as_c_str(p) |buf| {
|
||||
rustrt::rust_path_is_dir(buf) != 0 as c_int
|
||||
}
|
||||
}
|
||||
|
||||
/// Indicates whether a path exists
|
||||
fn path_exists(p: path) -> bool {
|
||||
fn path_exists(p: Path) -> bool {
|
||||
do str::as_c_str(p) |buf| {
|
||||
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
|
||||
// querying; what it does depends on the process working directory, not just
|
||||
// the input paths.
|
||||
fn make_absolute(p: path) -> path {
|
||||
fn make_absolute(p: Path) -> Path {
|
||||
if path::path_is_absolute(p) {
|
||||
p
|
||||
} else {
|
||||
@ -529,11 +529,11 @@ fn make_absolute(p: path) -> 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);
|
||||
|
||||
#[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
|
||||
import libc::types::os::arch::extra::*;
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
@ -546,7 +546,7 @@ fn make_dir(p: path, mode: c_int) -> bool {
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn mkdir(p: path, mode: c_int) -> bool {
|
||||
fn mkdir(p: Path, mode: c_int) -> bool {
|
||||
do as_c_charp(p) |c| {
|
||||
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
|
||||
fn list_dir(p: path) -> ~[~str] {
|
||||
fn list_dir(p: Path) -> ~[~str] {
|
||||
|
||||
#[cfg(unix)]
|
||||
fn star(p: ~str) -> ~str { p }
|
||||
@ -580,7 +580,7 @@ fn list_dir(p: path) -> ~[~str] {
|
||||
*
|
||||
* 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 pl = str::len(p);
|
||||
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
|
||||
fn remove_dir(p: path) -> bool {
|
||||
fn remove_dir(p: Path) -> bool {
|
||||
return rmdir(p);
|
||||
|
||||
#[cfg(windows)]
|
||||
fn rmdir(p: path) -> bool {
|
||||
fn rmdir(p: Path) -> bool {
|
||||
// FIXME: remove imports when export globs work properly. #1238
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
import libc::types::os::arch::extra::*;
|
||||
@ -606,18 +606,18 @@ fn remove_dir(p: path) -> bool {
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn rmdir(p: path) -> bool {
|
||||
fn rmdir(p: Path) -> bool {
|
||||
return do as_c_charp(p) |buf| {
|
||||
libc::rmdir(buf) == (0 as c_int)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn change_dir(p: path) -> bool {
|
||||
fn change_dir(p: Path) -> bool {
|
||||
return chdir(p);
|
||||
|
||||
#[cfg(windows)]
|
||||
fn chdir(p: path) -> bool {
|
||||
fn chdir(p: Path) -> bool {
|
||||
// FIXME: remove imports when export globs work properly. #1238
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
import libc::types::os::arch::extra::*;
|
||||
@ -628,7 +628,7 @@ fn change_dir(p: path) -> bool {
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn chdir(p: path) -> bool {
|
||||
fn chdir(p: Path) -> bool {
|
||||
return do as_c_charp(p) |buf| {
|
||||
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
|
||||
fn copy_file(from: path, to: path) -> bool {
|
||||
fn copy_file(from: Path, to: Path) -> bool {
|
||||
return do_copy_file(from, to);
|
||||
|
||||
#[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
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
import libc::types::os::arch::extra::*;
|
||||
@ -653,7 +653,7 @@ fn copy_file(from: path, to: path) -> bool {
|
||||
}
|
||||
|
||||
#[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| {
|
||||
do as_c_charp(~"rb") |modebuf| {
|
||||
libc::fopen(fromp, modebuf)
|
||||
@ -699,11 +699,11 @@ fn copy_file(from: path, to: path) -> bool {
|
||||
}
|
||||
|
||||
/// Deletes an existing file
|
||||
fn remove_file(p: path) -> bool {
|
||||
fn remove_file(p: Path) -> bool {
|
||||
return unlink(p);
|
||||
|
||||
#[cfg(windows)]
|
||||
fn unlink(p: path) -> bool {
|
||||
fn unlink(p: Path) -> bool {
|
||||
// FIXME (similar to Issue #2006): remove imports when export globs
|
||||
// work properly.
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
@ -715,7 +715,7 @@ fn remove_file(p: path) -> bool {
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn unlink(p: path) -> bool {
|
||||
fn unlink(p: Path) -> bool {
|
||||
return do as_c_charp(p) |buf| {
|
||||
libc::unlink(buf) == (0 as c_int)
|
||||
};
|
||||
@ -792,7 +792,7 @@ mod tests {
|
||||
|
||||
fn make_rand_name() -> ~str {
|
||||
import rand;
|
||||
let rng: rand::rng = rand::rng();
|
||||
let rng: rand::Rng = rand::rng();
|
||||
let n = ~"TEST" + rng.gen_str(10u);
|
||||
assert option::is_none(getenv(n));
|
||||
n
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Path data type and helper functions
|
||||
|
||||
export path;
|
||||
export Path;
|
||||
export consts;
|
||||
export path_is_absolute;
|
||||
export path_sep;
|
||||
@ -14,7 +14,7 @@ export normalize;
|
||||
|
||||
// FIXME: This type should probably be constrained (#2624)
|
||||
/// A path or fragment of a filesystem path
|
||||
type path = ~str;
|
||||
type Path = ~str;
|
||||
|
||||
#[cfg(unix)]
|
||||
mod consts {
|
||||
@ -45,7 +45,7 @@ mod consts {
|
||||
* on Windows, begins with a drive letter.
|
||||
*/
|
||||
#[cfg(unix)]
|
||||
fn path_is_absolute(p: path) -> bool {
|
||||
fn path_is_absolute(p: Path) -> bool {
|
||||
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
|
||||
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|
|
||||
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.
|
||||
*/
|
||||
fn dirname(pp: path) -> path {
|
||||
fn dirname(pp: Path) -> Path {
|
||||
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
|
||||
* 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;
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ fn basename(pp: path) -> path {
|
||||
* and any leading path separator on `post`, and returns the concatenation of
|
||||
* 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 post_ = post;
|
||||
let sep = consts::path_sep as u8;
|
||||
@ -127,7 +127,7 @@ fn connect(pre: path, post: path) -> path {
|
||||
*
|
||||
* Inserts path separators as needed.
|
||||
*/
|
||||
fn connect_many(paths: ~[path]) -> path {
|
||||
fn connect_many(paths: ~[Path]) -> Path {
|
||||
return if vec::len(paths) == 1u {
|
||||
paths[0]
|
||||
} else {
|
||||
@ -144,7 +144,7 @@ fn connect_many(paths: ~[path]) -> path {
|
||||
* the first element of the returned vector will be the drive letter
|
||||
* followed by a colon.
|
||||
*/
|
||||
fn split(p: path) -> ~[path] {
|
||||
fn split(p: Path) -> ~[Path] {
|
||||
str::split_nonempty(p, |c| {
|
||||
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
|
||||
* 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) { (~"", ~"") }
|
||||
else {
|
||||
let parts = str::split_char(p, '.');
|
||||
@ -212,7 +212,7 @@ fn splitext(p: path) -> (~str, ~str) {
|
||||
* * 'a/b/../../../' becomes '..'
|
||||
* * '/a/b/c/../d/./../../e/' becomes '/a/e/'
|
||||
*/
|
||||
fn normalize(p: path) -> path {
|
||||
fn normalize(p: Path) -> Path {
|
||||
let s = split(p);
|
||||
let s = strip_dots(s);
|
||||
let s = rollup_doubledots(s);
|
||||
@ -233,7 +233,7 @@ fn normalize(p: path) -> path {
|
||||
|
||||
return s;
|
||||
|
||||
fn strip_dots(s: ~[path]) -> ~[path] {
|
||||
fn strip_dots(s: ~[Path]) -> ~[Path] {
|
||||
vec::filter_map(s, |elem|
|
||||
if elem == ~"." {
|
||||
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) {
|
||||
return ~[];
|
||||
}
|
||||
@ -271,7 +271,7 @@ fn normalize(p: path) -> path {
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn reabsolute(orig: path, n: path) -> path {
|
||||
fn reabsolute(orig: Path, n: Path) -> Path {
|
||||
if path_is_absolute(orig) {
|
||||
path_sep() + n
|
||||
} else {
|
||||
@ -280,7 +280,7 @@ fn normalize(p: path) -> path {
|
||||
}
|
||||
|
||||
#[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 {
|
||||
str::from_char(consts::path_sep) + newp
|
||||
} 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];
|
||||
if last == consts::path_sep as u8
|
||||
|| last == consts::path_sep as u8 {
|
||||
|
@ -1,8 +1,9 @@
|
||||
//! Random number generation
|
||||
|
||||
export rng, seed, seeded_rng, weighted, extensions;
|
||||
export Rng, rng, seed, seeded_rng, Weighted, extensions;
|
||||
export xorshift, seeded_xorshift;
|
||||
|
||||
#[allow(non_camel_case_types)] // runtime type
|
||||
enum rctx {}
|
||||
|
||||
#[abi = "cdecl"]
|
||||
@ -15,16 +16,16 @@ extern mod rustrt {
|
||||
}
|
||||
|
||||
/// A random number generator
|
||||
trait rng {
|
||||
trait Rng {
|
||||
/// Return the next random integer
|
||||
fn next() -> u32;
|
||||
}
|
||||
|
||||
/// 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
|
||||
impl rng {
|
||||
impl Rng {
|
||||
|
||||
/// Return a random int
|
||||
fn gen_int() -> int {
|
||||
@ -181,7 +182,7 @@ impl rng {
|
||||
* Choose an item respecting the relative weights, failing if the sum of
|
||||
* 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()
|
||||
}
|
||||
|
||||
@ -189,7 +190,7 @@ impl rng {
|
||||
* Choose some(item) respecting the relative weights, returning none if
|
||||
* 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;
|
||||
for v.each |item| {
|
||||
total += item.weight;
|
||||
@ -212,7 +213,7 @@ impl rng {
|
||||
* Return a vec containing copies of the items, in order, where
|
||||
* 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 = ~[];
|
||||
for v.each |item| {
|
||||
for uint::range(0u, item.weight) |_i| {
|
||||
@ -242,13 +243,13 @@ impl rng {
|
||||
|
||||
}
|
||||
|
||||
class rand_res {
|
||||
class RandRes {
|
||||
let c: *rctx;
|
||||
new(c: *rctx) { self.c = c; }
|
||||
drop { rustrt::rand_free(self.c); }
|
||||
}
|
||||
|
||||
impl @rand_res: rng {
|
||||
impl @RandRes: Rng {
|
||||
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
|
||||
fn rng() -> rng {
|
||||
@rand_res(rustrt::rand_new()) as rng
|
||||
fn rng() -> 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
|
||||
* length.
|
||||
*/
|
||||
fn seeded_rng(seed: ~[u8]) -> rng {
|
||||
@rand_res(rustrt::rand_new_seeded(seed)) as rng
|
||||
fn seeded_rng(seed: ~[u8]) -> Rng {
|
||||
@RandRes(rustrt::rand_new_seeded(seed)) as Rng
|
||||
}
|
||||
|
||||
type xorshift_state = {
|
||||
type XorShiftState = {
|
||||
mut x: u32,
|
||||
mut y: u32,
|
||||
mut z: u32,
|
||||
mut w: u32
|
||||
};
|
||||
|
||||
impl xorshift_state: rng {
|
||||
impl XorShiftState: Rng {
|
||||
fn next() -> u32 {
|
||||
let x = self.x;
|
||||
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
|
||||
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -6,7 +6,7 @@
|
||||
import option::{some, none};
|
||||
import libc::{pid_t, c_void, c_int};
|
||||
|
||||
export program;
|
||||
export Program;
|
||||
export run_program;
|
||||
export start_program;
|
||||
export program_output;
|
||||
@ -22,18 +22,18 @@ extern mod rustrt {
|
||||
}
|
||||
|
||||
/// A value representing a child process
|
||||
trait program {
|
||||
trait Program {
|
||||
/// Returns the process id of the program
|
||||
fn get_id() -> pid_t;
|
||||
|
||||
/// 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
|
||||
fn output() -> io::reader;
|
||||
fn output() -> io::Reader;
|
||||
|
||||
/// 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
|
||||
fn close_input();
|
||||
@ -187,7 +187,7 @@ fn run_program(prog: &str, args: &[~str]) -> int {
|
||||
*
|
||||
* 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_output = 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_err.out);
|
||||
|
||||
type prog_repr = {pid: pid_t,
|
||||
mut in_fd: c_int,
|
||||
out_file: *libc::FILE,
|
||||
err_file: *libc::FILE,
|
||||
mut finished: bool};
|
||||
type ProgRepr = {pid: pid_t,
|
||||
mut in_fd: c_int,
|
||||
out_file: *libc::FILE,
|
||||
err_file: *libc::FILE,
|
||||
mut finished: bool};
|
||||
|
||||
fn close_repr_input(r: &prog_repr) {
|
||||
fn close_repr_input(r: &ProgRepr) {
|
||||
let invalid_fd = -1i32;
|
||||
if r.in_fd != invalid_fd {
|
||||
libc::close(r.in_fd);
|
||||
r.in_fd = invalid_fd;
|
||||
}
|
||||
}
|
||||
fn finish_repr(r: &prog_repr) -> int {
|
||||
fn finish_repr(r: &ProgRepr) -> int {
|
||||
if r.finished { return 0; }
|
||||
r.finished = true;
|
||||
close_repr_input(r);
|
||||
return waitpid(r.pid);
|
||||
}
|
||||
fn destroy_repr(r: &prog_repr) {
|
||||
fn destroy_repr(r: &ProgRepr) {
|
||||
finish_repr(r);
|
||||
libc::fclose(r.out_file);
|
||||
libc::fclose(r.err_file);
|
||||
}
|
||||
class prog_res {
|
||||
let r: prog_repr;
|
||||
new(+r: prog_repr) { self.r = r; }
|
||||
class ProgRes {
|
||||
let r: ProgRepr;
|
||||
new(+r: ProgRepr) { self.r = r; }
|
||||
drop { destroy_repr(&self.r); }
|
||||
}
|
||||
|
||||
impl prog_res: program {
|
||||
impl ProgRes: Program {
|
||||
fn get_id() -> pid_t { return self.r.pid; }
|
||||
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 err() -> io::reader { io::FILE_reader(self.r.err_file, 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 err() -> io::Reader { io::FILE_reader(self.r.err_file, false) }
|
||||
fn close_input() { close_repr_input(&self.r); }
|
||||
fn finish() -> int { finish_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),
|
||||
err_file: os::fdopen(pipe_err.in),
|
||||
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 = ~"";
|
||||
while !rd.eof() {
|
||||
let bytes = rd.read_bytes(4096u);
|
||||
@ -326,7 +326,7 @@ fn program_output(prog: &str, args: &[~str]) ->
|
||||
}
|
||||
|
||||
fn writeclose(fd: c_int, s: &str) {
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
error!{"writeclose %d, %s", fd as int, s};
|
||||
let writer = io::fd_writer(fd, false);
|
||||
@ -392,7 +392,7 @@ fn waitpid(pid: pid_t) -> int {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
// Regression test for memory leaks
|
||||
#[ignore(cfg(windows))] // FIXME (#2626)
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import libc::size_t;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
export
|
||||
// Creating a string
|
||||
|
@ -1,4 +1,4 @@
|
||||
import io::reader;
|
||||
import io::Reader;
|
||||
|
||||
trait to_base64 {
|
||||
fn to_base64() -> ~str;
|
||||
|
@ -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 }
|
||||
|
||||
// ebml writing
|
||||
type writer_ = {writer: io::writer, mut size_positions: ~[uint]};
|
||||
type writer_ = {writer: io::Writer, mut size_positions: ~[uint]};
|
||||
|
||||
enum 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 {
|
||||
1u => w.write(&[0x80u8 | (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 < 0x4000_u { write_sized_vuint(w, n, 2u); 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};
|
||||
}
|
||||
|
||||
fn writer(w: io::writer) -> writer {
|
||||
fn writer(w: io::Writer) -> writer {
|
||||
let size_positions: ~[uint] = ~[];
|
||||
return writer_({writer: w, mut size_positions: size_positions});
|
||||
}
|
||||
@ -220,10 +220,10 @@ impl writer {
|
||||
fn end_tag() {
|
||||
let last_size_pos = vec::pop::<uint>(self.size_positions);
|
||||
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);
|
||||
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};
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
import result::{result, ok, err};
|
||||
import io;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import map;
|
||||
import map::hashmap;
|
||||
import map::map;
|
||||
@ -43,7 +43,7 @@ type error = {
|
||||
};
|
||||
|
||||
/// 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 {
|
||||
num(n) => wr.write_str(float::to_str(n, 6u)),
|
||||
string(s) => wr.write_str(escape_str(*s)),
|
||||
@ -109,7 +109,7 @@ fn to_str(j: json) -> ~str {
|
||||
}
|
||||
|
||||
type parser_ = {
|
||||
rdr: io::reader,
|
||||
rdr: io::Reader,
|
||||
mut ch: char,
|
||||
mut line: uint,
|
||||
mut col: uint,
|
||||
@ -458,7 +458,7 @@ impl parser {
|
||||
}
|
||||
|
||||
/// 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_({
|
||||
rdr: rdr,
|
||||
mut ch: rdr.read_char(),
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#[warn(deprecated_mode)];
|
||||
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import to_str::ToStr;
|
||||
export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash;
|
||||
export box_str_hash;
|
||||
@ -328,7 +328,7 @@ mod chained {
|
||||
}
|
||||
|
||||
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 {
|
||||
wr.write_str(~"{}");
|
||||
return;
|
||||
|
@ -8,7 +8,7 @@ import future_spawn = future::spawn;
|
||||
// should be able to, but can't atm, replace w/ result::{result, extensions};
|
||||
import result::*;
|
||||
import libc::size_t;
|
||||
import io::{reader, writer};
|
||||
import io::{Reader, Writer};
|
||||
|
||||
// tcp interfaces
|
||||
export tcp_socket;
|
||||
@ -752,7 +752,7 @@ impl 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 {
|
||||
// Loop until our buffer has enough data in it for us to read from.
|
||||
while self.data.buf.len() < len {
|
||||
@ -795,7 +795,7 @@ impl @tcp_socket_buf: io::reader {
|
||||
fn eof() -> bool {
|
||||
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});
|
||||
// noop
|
||||
}
|
||||
@ -805,7 +805,7 @@ impl @tcp_socket_buf: io::reader {
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
let socket_data_ptr =
|
||||
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});
|
||||
}
|
||||
}
|
||||
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});
|
||||
// noop
|
||||
}
|
||||
@ -827,8 +827,8 @@ impl @tcp_socket_buf: io::writer {
|
||||
fn flush() -> int {
|
||||
0
|
||||
}
|
||||
fn get_type() -> io::writer_type {
|
||||
io::file
|
||||
fn get_type() -> io::WriterType {
|
||||
io::File
|
||||
}
|
||||
}
|
||||
|
||||
@ -1441,11 +1441,11 @@ mod test {
|
||||
assert false;
|
||||
}
|
||||
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!
|
||||
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))
|
||||
};
|
||||
|
||||
@ -1458,7 +1458,7 @@ mod test {
|
||||
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)});
|
||||
do str::byte_slice(val) |b_slice| {
|
||||
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);
|
||||
log(debug, fmt!{"in buf_read.. new_bytes len: %?",
|
||||
vec::len(new_bytes)});
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
import map;
|
||||
import map::{hashmap, str_hash};
|
||||
import io::reader;
|
||||
import io::Reader;
|
||||
import dvec::dvec;
|
||||
|
||||
export url, userinfo, query;
|
||||
|
@ -1,8 +1,8 @@
|
||||
import io::writer;
|
||||
import io::writer_util;
|
||||
import io::Writer;
|
||||
import io::WriterUtil;
|
||||
import serialization::serializer;
|
||||
|
||||
impl writer: serializer {
|
||||
impl Writer: serializer {
|
||||
fn emit_nil() {
|
||||
self.write_str(~"()")
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ const color_bright_magenta: u8 = 13u8;
|
||||
const color_bright_cyan: u8 = 14u8;
|
||||
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
|
||||
fn reset(writer: io::writer) {
|
||||
fn reset(writer: io::Writer) {
|
||||
esc(writer);
|
||||
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);
|
||||
esc(writer);
|
||||
let mut color = color;
|
||||
@ -55,12 +55,12 @@ fn set_color(writer: io::writer, first_char: u8, color: u8) {
|
||||
}
|
||||
|
||||
/// 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);
|
||||
}
|
||||
|
||||
/// 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);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
import either::either;
|
||||
import result::{ok, err};
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import libc::size_t;
|
||||
import task::task_builder;
|
||||
|
||||
@ -91,8 +91,8 @@ fn parse_opts(args: ~[~str]) -> opt_res {
|
||||
enum test_result { tr_ok, tr_failed, tr_ignored, }
|
||||
|
||||
type console_test_state =
|
||||
@{out: io::writer,
|
||||
log_out: option<io::writer>,
|
||||
@{out: io::Writer,
|
||||
log_out: option<io::Writer>,
|
||||
use_color: bool,
|
||||
mut total: uint,
|
||||
mut passed: uint,
|
||||
@ -141,7 +141,7 @@ fn run_tests_console(opts: test_opts,
|
||||
|
||||
let log_out = match opts.logfile {
|
||||
some(path) => match io::file_writer(path,
|
||||
~[io::create, io::truncate]) {
|
||||
~[io::Create, io::Truncate]) {
|
||||
result::ok(w) => some(w),
|
||||
result::err(s) => {
|
||||
fail(fmt!{"can't open output file: %s", s})
|
||||
@ -179,7 +179,7 @@ fn run_tests_console(opts: test_opts,
|
||||
|
||||
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",
|
||||
match result {
|
||||
tr_ok => ~"ok",
|
||||
@ -188,19 +188,19 @@ fn run_tests_console(opts: test_opts,
|
||||
}, 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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() {
|
||||
term::fg(out, color);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import libc::{c_char, c_int, c_long, size_t, time_t};
|
||||
import io::reader;
|
||||
import io::Reader;
|
||||
import result::{result, ok, err};
|
||||
|
||||
export
|
||||
|
@ -1,5 +1,5 @@
|
||||
import std::term;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import codemap::span;
|
||||
|
||||
export emitter, emit;
|
||||
@ -166,7 +166,7 @@ fn diagnosticcolor(lvl: level) -> u8 {
|
||||
|
||||
fn print_diagnostic(topic: ~str, lvl: level, msg: ~str) {
|
||||
let use_color = term::color_supported() &&
|
||||
io::stderr().get_type() == io::screen;
|
||||
io::stderr().get_type() == io::Screen;
|
||||
if str::is_not_empty(topic) {
|
||||
io::stderr().write_str(fmt!{"%s ", topic});
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import base::*;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, tt: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
|
@ -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
|
||||
if !path::path_is_absolute(arg) {
|
||||
let cu = codemap::span_to_filename(sp, cx.codemap());
|
||||
|
@ -273,7 +273,7 @@ type lit = {lit: ~str, pos: uint};
|
||||
|
||||
fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
|
||||
path: ~str,
|
||||
srdr: io::reader) ->
|
||||
srdr: io::Reader) ->
|
||||
{cmnts: ~[cmnt], lits: ~[lit]} {
|
||||
let src = @str::from_bytes(srdr.read_whole_stream());
|
||||
let itr = @interner::mk::<@~str>(
|
||||
|
@ -1,4 +1,4 @@
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import dvec::dvec;
|
||||
|
||||
/*
|
||||
@ -95,7 +95,7 @@ type print_stack_elt = {offset: int, pbreak: print_stack_break};
|
||||
|
||||
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
|
||||
// fall behind.
|
||||
let n: uint = 3u * linewidth;
|
||||
@ -201,7 +201,7 @@ fn mk_printer(out: io::writer, linewidth: uint) -> printer {
|
||||
* called 'print'.
|
||||
*/
|
||||
type printer_ = {
|
||||
out: io::writer,
|
||||
out: io::Writer,
|
||||
buf_len: uint,
|
||||
mut margin: int, // width of lines we're constrained to
|
||||
mut space: int, // number of spaces left on line
|
||||
|
@ -48,7 +48,7 @@ fn end(s: ps) {
|
||||
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),
|
||||
cm: none::<codemap>,
|
||||
intr: @interner::mk::<@~str>(|x| str::hash(*x),
|
||||
@ -61,7 +61,7 @@ fn rust_printer(writer: io::writer) -> ps {
|
||||
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),
|
||||
cm: none::<codemap>,
|
||||
intr: intr,
|
||||
@ -83,8 +83,8 @@ const default_columns: uint = 78u;
|
||||
// copy forward.
|
||||
fn print_crate(cm: codemap, intr: @interner::interner<@~str>,
|
||||
span_diagnostic: diagnostic::span_handler,
|
||||
crate: @ast::crate, filename: ~str, in: io::reader,
|
||||
out: io::writer, ann: pp_ann, is_expanded: bool) {
|
||||
crate: @ast::crate, filename: ~str, in: io::Reader,
|
||||
out: io::Writer, ann: pp_ann, is_expanded: bool) {
|
||||
let r = comments::gather_comments_and_literals(span_diagnostic,
|
||||
filename, in);
|
||||
let s =
|
||||
|
@ -15,7 +15,7 @@ import lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False,
|
||||
FileType};
|
||||
import metadata::filesearch;
|
||||
import syntax::ast_map::{path, path_mod, path_name};
|
||||
import io::{writer, writer_util};
|
||||
import io::{Writer, WriterUtil};
|
||||
|
||||
enum output_type {
|
||||
output_type_none,
|
||||
|
@ -36,7 +36,7 @@ fn get_rpath_flags(sess: session::session, out_filename: ~str) -> ~[~str] {
|
||||
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()],
|
||||
filesearch::relative_target_lib_path(
|
||||
sess.opts.target_triple));
|
||||
@ -48,8 +48,8 @@ fn rpaths_to_flags(rpaths: ~[~str]) -> ~[~str] {
|
||||
vec::map(rpaths, |rpath| fmt!{"-Wl,-rpath,%s",rpath} )
|
||||
}
|
||||
|
||||
fn get_rpaths(os: session::os, cwd: path::path, sysroot: path::path,
|
||||
output: path::path, libs: ~[path::path],
|
||||
fn get_rpaths(os: session::os, cwd: path::Path, sysroot: path::Path,
|
||||
output: path::Path, libs: ~[path::Path],
|
||||
target_triple: ~str) -> ~[~str] {
|
||||
debug!{"cwd: %s", cwd};
|
||||
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,
|
||||
cwd: path::path,
|
||||
output: path::path,
|
||||
libs: ~[path::path]) -> ~[~str] {
|
||||
cwd: path::Path,
|
||||
output: path::Path,
|
||||
libs: ~[path::Path]) -> ~[~str] {
|
||||
vec::map(libs, |a| {
|
||||
get_rpath_relative_to_output(os, cwd, output, a)
|
||||
})
|
||||
}
|
||||
|
||||
fn get_rpath_relative_to_output(os: session::os,
|
||||
cwd: path::path,
|
||||
output: path::path,
|
||||
&&lib: path::path) -> ~str {
|
||||
cwd: path::Path,
|
||||
output: path::Path,
|
||||
&&lib: path::Path) -> ~str {
|
||||
assert not_win32(os);
|
||||
|
||||
// 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
|
||||
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(abs2);
|
||||
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) )
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
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) {
|
||||
lib
|
||||
} 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"};
|
||||
|
||||
if install_prefix == ~"" {
|
||||
|
@ -10,7 +10,7 @@ import util::ppaux;
|
||||
import back::link;
|
||||
import result::{ok, err};
|
||||
import std::getopts;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import getopts::{optopt, optmulti, optflag, optflagopt, opt_present};
|
||||
import back::{x86, x86_64};
|
||||
import std::map::hashmap;
|
||||
@ -701,7 +701,7 @@ fn early_error(emitter: diagnostic::emitter, msg: ~str) -> ! {
|
||||
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(
|
||||
session::sess_os_to_meta_os(sess.targ_cfg.os), path, out);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
import std::{ebml, map};
|
||||
import std::map::{hashmap, str_hash};
|
||||
import dvec::dvec;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import syntax::{ast, ast_util};
|
||||
import syntax::attr;
|
||||
import middle::ty;
|
||||
@ -846,13 +846,13 @@ fn get_attributes(md: ebml::doc) -> ~[ast::attribute] {
|
||||
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| {
|
||||
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});
|
||||
|
||||
for get_attributes(md).each |attr| {
|
||||
@ -887,7 +887,7 @@ fn get_crate_deps(data: @~[u8]) -> ~[crate_dep] {
|
||||
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");
|
||||
|
||||
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");
|
||||
let items = ebml::get_doc(md, tag_items);
|
||||
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 md = ebml::doc(bytes);
|
||||
list_crate_attributes(md, hash, out);
|
||||
|
@ -4,7 +4,7 @@ import util::ppaux::ty_to_str;
|
||||
|
||||
import std::{ebml, map};
|
||||
import std::map::hashmap;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import ebml::writer;
|
||||
import syntax::ast::*;
|
||||
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>]],
|
||||
write_fn: fn(io::writer, T)) {
|
||||
write_fn: fn(io::Writer, T)) {
|
||||
let writer = ebml_w.writer;
|
||||
ebml_w.start_tag(tag_index);
|
||||
let mut bucket_locs: ~[uint] = ~[];
|
||||
@ -1032,9 +1032,9 @@ fn encode_index<T>(ebml_w: ebml::writer, buckets: ~[@~[entry<T>]],
|
||||
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;
|
||||
writer.write_be_u32(n as u32);
|
||||
}
|
||||
|
@ -14,31 +14,31 @@ export get_cargo_root;
|
||||
export get_cargo_root_nearest;
|
||||
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) }
|
||||
else { option::none }
|
||||
}
|
||||
|
||||
trait filesearch {
|
||||
fn sysroot() -> path;
|
||||
fn lib_search_paths() -> ~[path];
|
||||
fn get_target_lib_path() -> path;
|
||||
fn get_target_lib_file_path(file: path) -> path;
|
||||
fn sysroot() -> Path;
|
||||
fn lib_search_paths() -> ~[Path];
|
||||
fn get_target_lib_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,
|
||||
addl_lib_search_paths: ~[path]) -> filesearch {
|
||||
type filesearch_impl = {sysroot: path,
|
||||
addl_lib_search_paths: ~[path],
|
||||
addl_lib_search_paths: ~[Path]) -> filesearch {
|
||||
type filesearch_impl = {sysroot: Path,
|
||||
addl_lib_search_paths: ~[Path],
|
||||
target_triple: ~str};
|
||||
impl filesearch_impl: filesearch {
|
||||
fn sysroot() -> path { self.sysroot }
|
||||
fn lib_search_paths() -> ~[path] {
|
||||
fn sysroot() -> Path { self.sysroot }
|
||||
fn lib_search_paths() -> ~[Path] {
|
||||
let mut paths = self.addl_lib_search_paths;
|
||||
|
||||
vec::push(paths,
|
||||
@ -53,10 +53,10 @@ fn mk_filesearch(maybe_sysroot: option<path>,
|
||||
}
|
||||
paths
|
||||
}
|
||||
fn get_target_lib_path() -> path {
|
||||
fn get_target_lib_path() -> Path {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@ -88,38 +88,38 @@ fn search<T: copy>(filesearch: filesearch, pick: pick<T>) -> option<T> {
|
||||
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()]
|
||||
}
|
||||
|
||||
fn make_target_lib_path(sysroot: path,
|
||||
target_triple: ~str) -> path {
|
||||
fn make_target_lib_path(sysroot: Path,
|
||||
target_triple: ~str) -> Path {
|
||||
let path = vec::append(~[sysroot],
|
||||
relative_target_lib_path(target_triple));
|
||||
let path = path::connect_many(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
fn get_default_sysroot() -> path {
|
||||
fn get_default_sysroot() -> Path {
|
||||
match os::self_exe_path() {
|
||||
option::some(p) => path::normalize(path::connect(p, ~"..")),
|
||||
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 {
|
||||
option::some(sr) => sr,
|
||||
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"];
|
||||
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") {
|
||||
some(_p) => result::ok(_p),
|
||||
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| {
|
||||
let cwd = os::getcwd();
|
||||
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| {
|
||||
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| {
|
||||
result::ok(path::connect(p, libdir()))
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import syntax::print::pprust;
|
||||
import syntax::codemap::span;
|
||||
import lib::llvm::{False, llvm, mk_object_file, mk_section_iter};
|
||||
import filesearch::filesearch;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
export os;
|
||||
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
|
||||
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) {
|
||||
option::some(bytes) => decoder::list_crate_metadata(bytes, out),
|
||||
option::none => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Type encoding
|
||||
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import std::map::hashmap;
|
||||
import syntax::ast::*;
|
||||
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 {
|
||||
ac_no_abbrevs => {
|
||||
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 {
|
||||
m_imm => (),
|
||||
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);
|
||||
}
|
||||
|
||||
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 {
|
||||
none => w.write_char('n'),
|
||||
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_ty) |t| { enc_ty(w, cx, t) }
|
||||
w.write_char('[');
|
||||
@ -122,7 +122,7 @@ fn enc_substs(w: io::writer, cx: @ctxt, substs: ty::substs) {
|
||||
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 {
|
||||
ty::re_bound(br) => {
|
||||
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 {
|
||||
ty::br_self => w.write_char('s'),
|
||||
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('/');
|
||||
match v {
|
||||
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 {
|
||||
ty::ty_nil => w.write_char('n'),
|
||||
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");
|
||||
match proto {
|
||||
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) {
|
||||
by_mutbl_ref => 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 {
|
||||
pure_fn => w.write_char('p'),
|
||||
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_purity(w, ft.purity);
|
||||
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| {
|
||||
match bound {
|
||||
ty::bound_send => w.write_char('S'),
|
||||
|
@ -6,7 +6,7 @@ import syntax::attr;
|
||||
import syntax::codemap::span;
|
||||
import std::map::{map,hashmap,int_hash,hash_from_strs};
|
||||
import std::smallintmap::{map,smallintmap};
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import util::ppaux::{ty_to_str};
|
||||
import middle::pat_util::{pat_bindings};
|
||||
import syntax::ast_util::{path_to_ident};
|
||||
|
@ -108,7 +108,7 @@ import visit::vt;
|
||||
import syntax::codemap::span;
|
||||
import syntax::ast::*;
|
||||
import driver::session::session;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import capture::{cap_move, cap_drop, cap_copy, cap_ref};
|
||||
|
||||
export check_crate;
|
||||
@ -647,7 +647,7 @@ class liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn write_vars(wr: io::writer,
|
||||
fn write_vars(wr: io::Writer,
|
||||
ln: live_node,
|
||||
test: fn(uint) -> live_node) {
|
||||
let node_base_idx = self.idx(ln, variable(0u));
|
||||
|
@ -88,7 +88,7 @@ fn pandoc_writer(
|
||||
];
|
||||
|
||||
do generic_writer |markdown| {
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
debug!{"pandoc cmd: %s", pandoc_cmd};
|
||||
debug!{"pandoc args: %s", str::connect(pandoc_args, ~" ")};
|
||||
@ -254,9 +254,9 @@ mod test {
|
||||
}
|
||||
|
||||
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) => {
|
||||
writer.write_str(s);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import std::time::precise_time_s;
|
||||
import std::map;
|
||||
import std::map::{map, hashmap};
|
||||
|
||||
import io::reader;
|
||||
import io::Reader;
|
||||
|
||||
fn main(argv: ~[~str]) {
|
||||
#macro[
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use std;
|
||||
import dvec::dvec;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
fn collect_raw(num: uint) -> ~[uint] {
|
||||
let mut result = ~[];
|
||||
|
@ -13,7 +13,7 @@ import std::map::hashmap;
|
||||
import std::deque;
|
||||
import std::deque::t;
|
||||
import std::par;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import comm::*;
|
||||
import int::abs;
|
||||
|
||||
@ -24,7 +24,7 @@ type bfs_result = ~[node_id];
|
||||
fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] {
|
||||
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) {
|
||||
|
||||
let A = 0.57;
|
||||
|
@ -11,8 +11,8 @@
|
||||
// xfail-pretty
|
||||
|
||||
use std;
|
||||
import io::writer;
|
||||
import io::writer_util;
|
||||
import io::Writer;
|
||||
import io::WriterUtil;
|
||||
|
||||
import pipes::{port, chan, shared_chan};
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
// xfail-pretty
|
||||
|
||||
use std;
|
||||
import io::writer;
|
||||
import io::writer_util;
|
||||
import io::Writer;
|
||||
import io::WriterUtil;
|
||||
|
||||
import pipes::{port, port_set, chan};
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
// I *think* it's the same, more or less.
|
||||
|
||||
use std;
|
||||
import io::writer;
|
||||
import io::writer_util;
|
||||
import io::Writer;
|
||||
import io::WriterUtil;
|
||||
|
||||
enum request {
|
||||
get_count,
|
||||
|
@ -10,7 +10,7 @@ import vec;
|
||||
import uint;
|
||||
import int;
|
||||
import str;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
let rng = @{mut last: rand::rng().next()};
|
||||
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); }
|
||||
}
|
||||
|
||||
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);
|
||||
let mut op: ~str = ~"";
|
||||
let sl: uint = str::len(s);
|
||||
@ -85,7 +85,7 @@ fn main(args: ~[~str]) {
|
||||
};
|
||||
|
||||
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 {
|
||||
io::stdout()
|
||||
};
|
||||
|
@ -13,7 +13,7 @@
|
||||
// writes pbm image to output path
|
||||
|
||||
use std;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import std::map::hashmap;
|
||||
|
||||
struct cmplx {
|
||||
@ -90,12 +90,12 @@ fn chanmb(i: uint, size: uint, ch: comm::chan<line>) -> ()
|
||||
|
||||
type devnull = {dn: int};
|
||||
|
||||
impl devnull: io::writer {
|
||||
impl devnull: io::Writer {
|
||||
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 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)
|
||||
@ -103,9 +103,9 @@ fn writer(path: ~str, writech: comm::chan<comm::chan<line>>, size: uint)
|
||||
let p: comm::port<line> = comm::port();
|
||||
let ch = comm::chan(p);
|
||||
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()
|
||||
@ -113,7 +113,7 @@ fn writer(path: ~str, writech: comm::chan<comm::chan<line>>, size: uint)
|
||||
_ => {
|
||||
result::get(
|
||||
io::file_writer(path,
|
||||
~[io::create, io::truncate]))
|
||||
~[io::Create, io::Truncate]))
|
||||
}
|
||||
};
|
||||
cout.write_line(~"P4");
|
||||
|
@ -13,7 +13,7 @@
|
||||
use std;
|
||||
|
||||
import std::{time, getopts};
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import int::range;
|
||||
import pipes::port;
|
||||
import pipes::chan;
|
||||
|
@ -3,7 +3,7 @@
|
||||
use std;
|
||||
import std::smallintmap;
|
||||
import std::smallintmap::smallintmap;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
fn append_sequential(min: uint, max: uint, map: smallintmap<uint>) {
|
||||
for uint::range(min, max) |i| {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std;
|
||||
|
||||
import std::bitv;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
// Computes a single solution to a given 9x9 sudoku
|
||||
//
|
||||
@ -28,7 +28,7 @@ type grid = ~[~[mut u8]];
|
||||
enum grid_t { grid_ctor(grid), }
|
||||
|
||||
// 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" */
|
||||
|
||||
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| {
|
||||
f.write_str(fmt!{"%u", (*g)[row][0] as uint});
|
||||
for u8::range(1u8, 9u8) |col| {
|
||||
|
@ -20,7 +20,7 @@ import std::map;
|
||||
import std::map::hashmap;
|
||||
import vec;
|
||||
import io;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
|
||||
import std::time;
|
||||
import u64;
|
||||
@ -73,7 +73,7 @@ fn join(t: joinable_task) {
|
||||
t.recv()
|
||||
}
|
||||
|
||||
impl io::reader: word_reader {
|
||||
impl io::Reader: word_reader {
|
||||
fn read_word() -> option<~str> { read_word(self) }
|
||||
}
|
||||
|
||||
@ -331,7 +331,7 @@ fn main(argv: ~[~str]) {
|
||||
+ u64::str(elapsed) + ~"ms");
|
||||
}
|
||||
|
||||
fn read_word(r: io::reader) -> option<~str> {
|
||||
fn read_word(r: io::Reader) -> option<~str> {
|
||||
let mut w = ~"";
|
||||
|
||||
while !r.eof() {
|
||||
@ -350,7 +350,7 @@ fn is_word_char(c: char) -> bool {
|
||||
|
||||
class random_word_reader: word_reader {
|
||||
let mut remaining: uint;
|
||||
let rng: rand::rng;
|
||||
let rng: rand::Rng;
|
||||
new(count: uint) {
|
||||
self.remaining = count;
|
||||
self.rng = rand::rng();
|
||||
|
@ -1,7 +1,7 @@
|
||||
// error-pattern:explicit failure
|
||||
// Don't double free the string
|
||||
use std;
|
||||
import io::reader;
|
||||
import io::Reader;
|
||||
|
||||
fn main() {
|
||||
do io::with_str_reader(~"") |rdr| {
|
||||
|
@ -85,7 +85,7 @@ fn main() {
|
||||
|
||||
fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: ~str) {
|
||||
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);
|
||||
pp::eof(pp.s);
|
||||
let str = mem_buffer_str(buf);
|
||||
|
@ -4,14 +4,14 @@ use std;
|
||||
// the common code.
|
||||
|
||||
import std::ebml;
|
||||
import io::writer;
|
||||
import io::Writer;
|
||||
import std::serialization::{serialize_uint, deserialize_uint};
|
||||
|
||||
fn test_ser_and_deser<A>(a1: A,
|
||||
expected: ~str,
|
||||
ebml_ser_fn: fn(ebml::writer, 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:
|
||||
io_ser_fn(io::stdout(), a1);
|
||||
@ -21,7 +21,7 @@ fn test_ser_and_deser<A>(a1: A,
|
||||
|
||||
// check the EBML serializer:
|
||||
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);
|
||||
let d = ebml::doc(@io::mem_buffer_buf(buf));
|
||||
let a2 = ebml_deser_fn(ebml::ebml_deserializer(d));
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std;
|
||||
import io;
|
||||
import io::writer_util;
|
||||
import io::WriterUtil;
|
||||
import std::map::hashmap;
|
||||
|
||||
enum object
|
||||
|
@ -45,8 +45,8 @@ fn square_from_char(c: char) -> square {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_board_grid<rdr: owned io::reader>(+in: rdr) -> ~[~[square]] {
|
||||
let in = in as io::reader;
|
||||
fn read_board_grid<rdr: owned io::Reader>(+in: rdr) -> ~[~[square]] {
|
||||
let in = in as io::Reader;
|
||||
let mut grid = ~[];
|
||||
for in.each_line |line| {
|
||||
let mut row = ~[];
|
||||
|
Loading…
Reference in New Issue
Block a user