Have the pretty-printer take a writer stream as argument

It now uses a string writer to also fill in for
middle.ty.ast_ty_to_str
This commit is contained in:
Marijn Haverbeke 2011-03-09 11:41:50 +01:00 committed by unknown
parent dddd7d8f44
commit aed40fbcd8
6 changed files with 61 additions and 119 deletions

View file

@ -91,26 +91,21 @@ tag fileflag {
truncate;
}
// FIXME move into fd_buf_writer
fn writefd(int fd, vec[u8] v) {
auto len = _vec.len[u8](v);
auto count = 0u;
auto vbuf;
while (count < len) {
vbuf = _vec.buf_off[u8](v, count);
auto nout = os.libc.write(fd, vbuf, len);
if (nout < 0) {
log "error dumping buffer";
log sys.rustrt.last_os_error();
fail;
}
count += nout as uint;
}
}
state obj fd_buf_writer(int fd, bool must_close) {
fn write(vec[u8] v) {
writefd(fd, v);
auto len = _vec.len[u8](v);
auto count = 0u;
auto vbuf;
while (count < len) {
vbuf = _vec.buf_off[u8](v, count);
auto nout = os.libc.write(fd, vbuf, len);
if (nout < 0) {
log "error dumping buffer";
log sys.rustrt.last_os_error();
fail;
}
count += nout as uint;
}
}
drop {
@ -152,9 +147,15 @@ type writer =
};
state obj new_writer(buf_writer out) {
impure fn write_str(str s) { out.write(_str.bytes(s)); }
impure fn write_int(int n) { out.write(_str.bytes(_int.to_str(n, 10u))); }
impure fn write_uint(uint n) { out.write(_str.bytes(_uint.to_str(n, 10u))); }
impure fn write_str(str s) {
out.write(_str.bytes(s));
}
impure fn write_int(int n) {
out.write(_str.bytes(_int.to_str(n, 10u)));
}
impure fn write_uint(uint n) {
out.write(_str.bytes(_uint.to_str(n, 10u)));
}
}
fn file_writer(str path, vec[fileflag] flags) -> writer {