From f9fbd86f52cf597b85359ade1ca60b8d6ebf7286 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 6 Oct 2011 12:26:12 +0200 Subject: Parse and typecheck by-value and by-ref arg specs Add sprinkle && throughout the compiler to make it typecheck again. Issue #1008 --- src/lib/io.rs | 13 +++++-------- src/lib/list.rs | 2 +- src/lib/map.rs | 8 ++++---- src/lib/option.rs | 5 +++++ src/lib/vec.rs | 11 +++++++++++ 5 files changed, 26 insertions(+), 13 deletions(-) (limited to 'src/lib') diff --git a/src/lib/io.rs b/src/lib/io.rs index 73460e50588..d8f7f36b24f 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -175,14 +175,11 @@ fn stdin() -> reader { } fn file_reader(path: str) -> reader { - let f = - str::as_buf(path, - {|pathbuf| - str::as_buf("r", - {|modebuf| - os::libc::fopen(pathbuf, modebuf) - }) - }); + let f = str::as_buf(path, {|pathbuf| + str::as_buf("r", {|modebuf| + os::libc::fopen(pathbuf, modebuf) + }) + }); if f as uint == 0u { log_err "error opening " + path; fail; } ret new_reader(FILE_buf_reader(f, option::some(@FILE_res(f)))); } diff --git a/src/lib/list.rs b/src/lib/list.rs index 7037cff365a..58f976110d9 100644 --- a/src/lib/list.rs +++ b/src/lib/list.rs @@ -49,7 +49,7 @@ fn has<@T>(ls_: list, elt: T) -> bool { } fn length<@T>(ls: list) -> uint { - fn count(_t: T, u: uint) -> uint { ret u + 1u; } + fn count(_t: T, &&u: uint) -> uint { ret u + 1u; } ret foldl(ls, 0u, count); } diff --git a/src/lib/map.rs b/src/lib/map.rs index 81be20a6620..c63183b1893 100644 --- a/src/lib/map.rs +++ b/src/lib/map.rs @@ -199,14 +199,14 @@ fn new_str_hash<@V>() -> hashmap { } fn new_int_hash<@V>() -> hashmap { - fn hash_int(x: int) -> uint { ret x as uint; } - fn eq_int(a: int, b: int) -> bool { ret a == b; } + fn hash_int(&&x: int) -> uint { ret x as uint; } + fn eq_int(&&a: int, &&b: int) -> bool { ret a == b; } ret mk_hashmap(hash_int, eq_int); } fn new_uint_hash<@V>() -> hashmap { - fn hash_uint(x: uint) -> uint { ret x; } - fn eq_uint(a: uint, b: uint) -> bool { ret a == b; } + fn hash_uint(&&x: uint) -> uint { ret x; } + fn eq_uint(&&a: uint, &&b: uint) -> bool { ret a == b; } ret mk_hashmap(hash_uint, eq_uint); } diff --git a/src/lib/option.rs b/src/lib/option.rs index 53c19ba8c0a..56b56b5f69f 100644 --- a/src/lib/option.rs +++ b/src/lib/option.rs @@ -9,6 +9,11 @@ fn get<@T>(opt: t) -> &T { fn map<@T, @U>(f: block(T) -> U, opt: t) -> t { alt opt { some(x) { some(f(x)) } none. { none } } } +// FIXME This is needed to make working with by-value functions a bit less +// painful. We should come up with a better solution. +fn map_imm<@T, @U>(f: block(+T) -> U, opt: t) -> t { + alt opt { some(x) { some(f(x)) } none. { none } } +} fn is_none<@T>(opt: t) -> bool { alt opt { none. { true } some(_) { false } } diff --git a/src/lib/vec.rs b/src/lib/vec.rs index 59f29d40d7c..bc4334a06bc 100644 --- a/src/lib/vec.rs +++ b/src/lib/vec.rs @@ -191,6 +191,17 @@ fn map<@T, @U>(f: block(T) -> U, v: [mutable? T]) -> [U] { } ret result; } +// FIXME This is needed to make working with by-value functions a bit less +// painful. We should come up with a better solution. +fn map_imm<@T, @U>(f: block(+T) -> U, v: [mutable? T]) -> [U] { + let result = []; + reserve(result, len(v)); + for elem: T in v { + let elem2 = elem; // satisfies alias checker + result += [f(elem2)]; + } + ret result; +} fn map2<@T, @U, @V>(f: block(T, U) -> V, v0: [T], v1: [U]) -> [V] { let v0_len = len::(v0); -- cgit 1.4.1-3-g733a5