1
Fork 0

Name types after their modules instead of 't'

This commit is contained in:
Brian Anderson 2012-03-13 14:39:28 -07:00
parent a38ccf1254
commit b968c8e6cd
29 changed files with 190 additions and 189 deletions

View file

@ -1540,11 +1540,11 @@ You can then declare a function to take a `circular_buf<u8>` or return
an `option<str>`, or even an `option<T>` if the function itself is an `option<str>`, or even an `option<T>` if the function itself is
generic. generic.
The `option` type given above exists in the core library as The `option` type given above exists in the core library and is the
`option::t`, and is the way Rust programs express the thing that in C way Rust programs express the thing that in C would be a nullable
would be a nullable pointer. The nice part is that you have to pointer. The nice part is that you have to explicitly unpack an
explicitly unpack an `option` type, so accidental null pointer `option` type, so accidental null pointer dereferences become
dereferences become impossible. impossible.
## Type-inference and generics ## Type-inference and generics
@ -1562,7 +1562,7 @@ you really want to have such a statement, you'll have to write it like
this: this:
~~~~ ~~~~
let n2: option::t<int> = option::none; let n2: option<int> = option::none;
// or // or
let n = option::none::<int>; let n = option::none::<int>;
~~~~ ~~~~

View file

@ -167,7 +167,7 @@ fn recv_<T: send>(p: *rust_port) -> T {
#[doc = "Receive on one of two ports"] #[doc = "Receive on one of two ports"]
fn select2<A: send, B: send>( fn select2<A: send, B: send>(
p_a: port<A>, p_b: port<B> p_a: port<A>, p_b: port<B>
) -> either::t<A, B> unsafe { ) -> either<A, B> unsafe {
fn select(dptr: **rust_port, ports: **rust_port, fn select(dptr: **rust_port, ports: **rust_port,
n_ports: libc::size_t, yield: *libc::uintptr_t) { n_ports: libc::size_t, yield: *libc::uintptr_t) {

View file

@ -3,7 +3,9 @@
// Export various ubiquitous types, constructors, methods. // Export various ubiquitous types, constructors, methods.
import option::{some, none}; import option::{some, none};
import option = option::t; import option = option::option;
import either = either::either;
import result = result::result;
import path = path::path; import path = path::path;
import vec::vec_len; import vec::vec_len;
export path, option, some, none, vec_len, unreachable; export path, option, some, none, vec_len, unreachable;

View file

@ -1,13 +1,13 @@
#[doc = "A type that represents one of two alternatives"]; #[doc = "A type that represents one of two alternatives"];
#[doc = "The either type"] #[doc = "The either type"]
enum t<T, U> { enum either<T, U> {
left(T), left(T),
right(U) right(U)
} }
fn either<T, U, V>(f_left: fn(T) -> V, fn either<T, U, V>(f_left: fn(T) -> V,
f_right: fn(U) -> V, value: t<T, U>) -> V { f_right: fn(U) -> V, value: either<T, U>) -> V {
#[doc = " #[doc = "
Applies a function based on the given either value Applies a function based on the given either value
@ -19,27 +19,27 @@ fn either<T, U, V>(f_left: fn(T) -> V,
alt value { left(l) { f_left(l) } right(r) { f_right(r) } } alt value { left(l) { f_left(l) } right(r) { f_right(r) } }
} }
fn lefts<T: copy, U>(eithers: [t<T, U>]) -> [T] { fn lefts<T: copy, U>(eithers: [either<T, U>]) -> [T] {
#[doc = "Extracts from a vector of either all the left values"]; #[doc = "Extracts from a vector of either all the left values"];
let mut result: [T] = []; let mut result: [T] = [];
for elt: t<T, U> in eithers { for elt: either<T, U> in eithers {
alt elt { left(l) { result += [l]; } _ {/* fallthrough */ } } alt elt { left(l) { result += [l]; } _ {/* fallthrough */ } }
} }
ret result; ret result;
} }
fn rights<T, U: copy>(eithers: [t<T, U>]) -> [U] { fn rights<T, U: copy>(eithers: [either<T, U>]) -> [U] {
#[doc = "Extracts from a vector of either all the right values"]; #[doc = "Extracts from a vector of either all the right values"];
let mut result: [U] = []; let mut result: [U] = [];
for elt: t<T, U> in eithers { for elt: either<T, U> in eithers {
alt elt { right(r) { result += [r]; } _ {/* fallthrough */ } } alt elt { right(r) { result += [r]; } _ {/* fallthrough */ } }
} }
ret result; ret result;
} }
fn partition<T: copy, U: copy>(eithers: [t<T, U>]) fn partition<T: copy, U: copy>(eithers: [either<T, U>])
-> {lefts: [T], rights: [U]} { -> {lefts: [T], rights: [U]} {
#[doc = " #[doc = "
Extracts from a vector of either all the left values and right values Extracts from a vector of either all the left values and right values
@ -50,13 +50,13 @@ fn partition<T: copy, U: copy>(eithers: [t<T, U>])
let mut lefts: [T] = []; let mut lefts: [T] = [];
let mut rights: [U] = []; let mut rights: [U] = [];
for elt: t<T, U> in eithers { for elt: either<T, U> in eithers {
alt elt { left(l) { lefts += [l]; } right(r) { rights += [r]; } } alt elt { left(l) { lefts += [l]; } right(r) { rights += [r]; } }
} }
ret {lefts: lefts, rights: rights}; ret {lefts: lefts, rights: rights};
} }
pure fn flip<T: copy, U: copy>(eith: t<T, U>) -> t<U, T> { pure fn flip<T: copy, U: copy>(eith: either<T, U>) -> either<U, T> {
#[doc = "Flips between left and right of a given either"]; #[doc = "Flips between left and right of a given either"];
alt eith { alt eith {
@ -65,7 +65,8 @@ pure fn flip<T: copy, U: copy>(eith: t<T, U>) -> t<U, T> {
} }
} }
pure fn to_result<T: copy, U: copy>(eith: t<T, U>) -> result::t<U, T> { pure fn to_result<T: copy, U: copy>(
eith: either<T, U>) -> result<U, T> {
#[doc = " #[doc = "
Converts either::t to a result::t Converts either::t to a result::t
@ -79,13 +80,13 @@ pure fn to_result<T: copy, U: copy>(eith: t<T, U>) -> result::t<U, T> {
} }
} }
pure fn is_left<T, U>(eith: t<T, U>) -> bool { pure fn is_left<T, U>(eith: either<T, U>) -> bool {
#[doc = "Checks whether the given value is a left"]; #[doc = "Checks whether the given value is a left"];
alt eith { left(_) { true } _ { false } } alt eith { left(_) { true } _ { false } }
} }
pure fn is_right<T, U>(eith: t<T, U>) -> bool { pure fn is_right<T, U>(eith: either<T, U>) -> bool {
#[doc = "Checks whether the given value is a right"]; #[doc = "Checks whether the given value is a right"];
alt eith { right(_) { true } _ { false } } alt eith { right(_) { true } _ { false } }
@ -116,14 +117,14 @@ fn test_lefts() {
#[test] #[test]
fn test_lefts_none() { fn test_lefts_none() {
let input: [t<int, int>] = [right(10), right(10)]; let input: [either<int, int>] = [right(10), right(10)];
let result = lefts(input); let result = lefts(input);
assert (vec::len(result) == 0u); assert (vec::len(result) == 0u);
} }
#[test] #[test]
fn test_lefts_empty() { fn test_lefts_empty() {
let input: [t<int, int>] = []; let input: [either<int, int>] = [];
let result = lefts(input); let result = lefts(input);
assert (vec::len(result) == 0u); assert (vec::len(result) == 0u);
} }
@ -137,14 +138,14 @@ fn test_rights() {
#[test] #[test]
fn test_rights_none() { fn test_rights_none() {
let input: [t<int, int>] = [left(10), left(10)]; let input: [either<int, int>] = [left(10), left(10)];
let result = rights(input); let result = rights(input);
assert (vec::len(result) == 0u); assert (vec::len(result) == 0u);
} }
#[test] #[test]
fn test_rights_empty() { fn test_rights_empty() {
let input: [t<int, int>] = []; let input: [either<int, int>] = [];
let result = rights(input); let result = rights(input);
assert (vec::len(result) == 0u); assert (vec::len(result) == 0u);
} }
@ -162,7 +163,7 @@ fn test_partition() {
#[test] #[test]
fn test_partition_no_lefts() { fn test_partition_no_lefts() {
let input: [t<int, int>] = [right(10), right(11)]; let input: [either<int, int>] = [right(10), right(11)];
let result = partition(input); let result = partition(input);
assert (vec::len(result.lefts) == 0u); assert (vec::len(result.lefts) == 0u);
assert (vec::len(result.rights) == 2u); assert (vec::len(result.rights) == 2u);
@ -170,7 +171,7 @@ fn test_partition_no_lefts() {
#[test] #[test]
fn test_partition_no_rights() { fn test_partition_no_rights() {
let input: [t<int, int>] = [left(10), left(11)]; let input: [either<int, int>] = [left(10), left(11)];
let result = partition(input); let result = partition(input);
assert (vec::len(result.lefts) == 2u); assert (vec::len(result.lefts) == 2u);
assert (vec::len(result.rights) == 0u); assert (vec::len(result.rights) == 0u);
@ -178,7 +179,7 @@ fn test_partition_no_rights() {
#[test] #[test]
fn test_partition_empty() { fn test_partition_empty() {
let input: [t<int, int>] = []; let input: [either<int, int>] = [];
let result = partition(input); let result = partition(input);
assert (vec::len(result.lefts) == 0u); assert (vec::len(result.lefts) == 0u);
assert (vec::len(result.rights) == 0u); assert (vec::len(result.rights) == 0u);

View file

@ -20,8 +20,6 @@ export lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix;
export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc; export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
export signbit; export signbit;
type t = f32;
// These are not defined inside consts:: for consistency with // These are not defined inside consts:: for consistency with
// the integer types // the integer types

View file

@ -21,8 +21,6 @@ export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
export signbit; export signbit;
export epsilon; export epsilon;
type t = f64;
// These are not defined inside consts:: for consistency with // These are not defined inside consts:: for consistency with
// the integer types // the integer types

View file

@ -26,8 +26,6 @@ export j0, j1, jn, y0, y1, yn;
import m_float = f64; import m_float = f64;
import f64::*; import f64::*;
type t = float;
/** /**
* Section: String Conversions * Section: String Conversions
*/ */

View file

@ -20,8 +20,6 @@ export get;
export with; export with;
export spawn; export spawn;
import either = either::t;
#[doc = "The future type"] #[doc = "The future type"]
enum future<A> = { enum future<A> = {
mutable v: either<@A, fn@() -> A> mutable v: either<@A, fn@() -> A>

View file

@ -218,7 +218,7 @@ fn FILE_reader(f: *libc::FILE, cleanup: bool) -> 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::t<reader, str> { fn file_reader(path: str) -> result<reader, str> {
let f = os::as_c_charp(path, {|pathbuf| let f = os::as_c_charp(path, {|pathbuf|
os::as_c_charp("r", {|modebuf| os::as_c_charp("r", {|modebuf|
libc::fopen(pathbuf, modebuf) libc::fopen(pathbuf, modebuf)
@ -374,7 +374,7 @@ fn fd_writer(fd: fd_t, cleanup: bool) -> writer {
fn mk_file_writer(path: str, flags: [fileflag]) fn mk_file_writer(path: str, flags: [fileflag])
-> result::t<writer, str> { -> result<writer, str> {
#[cfg(target_os = "win32")] #[cfg(target_os = "win32")]
fn wb() -> c_int { (O_WRONLY | O_BINARY) as c_int } fn wb() -> c_int { (O_WRONLY | O_BINARY) as c_int }
@ -487,13 +487,13 @@ impl writer_util for writer {
fn write_u8(n: u8) { self.write([n]) } fn write_u8(n: u8) { self.write([n]) }
} }
fn file_writer(path: str, flags: [fileflag]) -> result::t<writer, str> { fn file_writer(path: str, flags: [fileflag]) -> result<writer, str> {
result::chain(mk_file_writer(path, flags), { |w| result::ok(w)}) result::chain(mk_file_writer(path, flags), { |w| result::ok(w)})
} }
// FIXME: fileflags // FIXME: fileflags
fn buffered_file_writer(path: str) -> result::t<writer, str> { fn buffered_file_writer(path: str) -> result<writer, str> {
let f = os::as_c_charp(path) {|pathbuf| let f = os::as_c_charp(path) {|pathbuf|
os::as_c_charp("w") {|modebuf| os::as_c_charp("w") {|modebuf|
libc::fopen(pathbuf, modebuf) libc::fopen(pathbuf, modebuf)
@ -581,7 +581,7 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) ->
ret bpos as uint; ret bpos as uint;
} }
fn read_whole_file_str(file: str) -> result::t<str, str> { fn read_whole_file_str(file: str) -> result<str, str> {
result::chain(read_whole_file(file), { |bytes| result::chain(read_whole_file(file), { |bytes|
result::ok(str::from_bytes(bytes)) result::ok(str::from_bytes(bytes))
}) })
@ -589,7 +589,7 @@ fn read_whole_file_str(file: str) -> result::t<str, str> {
// FIXME implement this in a low-level way. Going through the abstractions is // FIXME implement this in a low-level way. Going through the abstractions is
// pointless. // pointless.
fn read_whole_file(file: str) -> result::t<[u8], str> { fn read_whole_file(file: str) -> result<[u8], str> {
result::chain(file_reader(file), { |rdr| result::chain(file_reader(file), { |rdr|
result::ok(rdr.read_whole_stream()) result::ok(rdr.read_whole_stream())
}) })

View file

@ -8,12 +8,12 @@ languages you might use a nullable type, in Rust you would use an option type.
"]; "];
#[doc = "The option type"] #[doc = "The option type"]
enum t<T> { enum option<T> {
none, none,
some(T), some(T),
} }
pure fn get<T: copy>(opt: t<T>) -> T { pure fn get<T: copy>(opt: option<T>) -> T {
#[doc = " #[doc = "
Gets the value out of an option Gets the value out of an option
@ -25,13 +25,13 @@ pure fn get<T: copy>(opt: t<T>) -> T {
alt opt { some(x) { ret x; } none { fail "option none"; } } alt opt { some(x) { ret x; } none { fail "option none"; } }
} }
fn map<T, U: copy>(opt: t<T>, f: fn(T) -> U) -> t<U> { fn map<T, U: copy>(opt: option<T>, f: fn(T) -> U) -> option<U> {
#[doc = "Maps a `some` value from one type to another"]; #[doc = "Maps a `some` value from one type to another"];
alt opt { some(x) { some(f(x)) } none { none } } alt opt { some(x) { some(f(x)) } none { none } }
} }
fn chain<T, U>(opt: t<T>, f: fn(T) -> t<U>) -> t<U> { fn chain<T, U>(opt: option<T>, f: fn(T) -> option<U>) -> option<U> {
#[doc = " #[doc = "
Update an optional value by optionally running its content through a Update an optional value by optionally running its content through a
function that returns an option. function that returns an option.
@ -40,37 +40,37 @@ fn chain<T, U>(opt: t<T>, f: fn(T) -> t<U>) -> t<U> {
alt opt { some(x) { f(x) } none { none } } alt opt { some(x) { f(x) } none { none } }
} }
pure fn is_none<T>(opt: t<T>) -> bool { pure fn is_none<T>(opt: option<T>) -> bool {
#[doc = "Returns true if the option equals `none`"]; #[doc = "Returns true if the option equals `none`"];
alt opt { none { true } some(_) { false } } alt opt { none { true } some(_) { false } }
} }
pure fn is_some<T>(opt: t<T>) -> bool { pure fn is_some<T>(opt: option<T>) -> bool {
#[doc = "Returns true if the option contains some value"]; #[doc = "Returns true if the option contains some value"];
!is_none(opt) !is_none(opt)
} }
pure fn from_maybe<T: copy>(def: T, opt: t<T>) -> T { pure fn from_maybe<T: copy>(def: T, opt: option<T>) -> T {
#[doc = "Returns the contained value or a default"]; #[doc = "Returns the contained value or a default"];
alt opt { some(x) { x } none { def } } alt opt { some(x) { x } none { def } }
} }
fn maybe<T, U: copy>(def: U, opt: t<T>, f: fn(T) -> U) -> U { fn maybe<T, U: copy>(def: U, opt: option<T>, f: fn(T) -> U) -> U {
#[doc = "Applies a function to the contained value or returns a default"]; #[doc = "Applies a function to the contained value or returns a default"];
alt opt { none { def } some(t) { f(t) } } alt opt { none { def } some(t) { f(t) } }
} }
fn may<T>(opt: t<T>, f: fn(T)) { fn may<T>(opt: option<T>, f: fn(T)) {
#[doc = "Performs an operation on the contained value or does nothing"]; #[doc = "Performs an operation on the contained value or does nothing"];
alt opt { none { } some(t) { f(t); } } alt opt { none { } some(t) { f(t); } }
} }
fn unwrap<T>(-opt: t<T>) -> T unsafe { fn unwrap<T>(-opt: option<T>) -> T unsafe {
#[doc = " #[doc = "
Moves a value out of an option type and returns it. Moves a value out of an option type and returns it.

View file

@ -21,7 +21,6 @@ import libc::{c_char, c_void, c_int, c_uint, size_t, ssize_t,
import libc::{close, fclose}; import libc::{close, fclose};
import option::{some, none}; import option::{some, none};
import option = option::t;
import getcwd = rustrt::rust_getcwd; import getcwd = rustrt::rust_getcwd;
import consts::*; import consts::*;

View file

@ -1,7 +1,7 @@
#[doc = "A type representing either success or failure"]; #[doc = "A type representing either success or failure"];
#[doc = "The result type"] #[doc = "The result type"]
enum t<T, U> { enum result<T, U> {
#[doc = "Contains the successful result value"] #[doc = "Contains the successful result value"]
ok(T), ok(T),
#[doc = "Contains the error value"] #[doc = "Contains the error value"]
@ -15,7 +15,7 @@ Get the value out of a successful result
If the result is an error If the result is an error
"] "]
fn get<T: copy, U>(res: t<T, U>) -> T { fn get<T: copy, U>(res: result<T, U>) -> T {
alt res { alt res {
ok(t) { t } ok(t) { t }
err(_) { err(_) {
@ -33,7 +33,7 @@ Get the value out of an error result
If the result is not an error If the result is not an error
"] "]
fn get_err<T, U: copy>(res: t<T, U>) -> U { fn get_err<T, U: copy>(res: result<T, U>) -> U {
alt res { alt res {
err(u) { u } err(u) { u }
ok(_) { ok(_) {
@ -43,7 +43,7 @@ fn get_err<T, U: copy>(res: t<T, U>) -> U {
} }
#[doc = "Returns true if the result is `ok`"] #[doc = "Returns true if the result is `ok`"]
pure fn success<T, U>(res: t<T, U>) -> bool { pure fn success<T, U>(res: result<T, U>) -> bool {
alt res { alt res {
ok(_) { true } ok(_) { true }
err(_) { false } err(_) { false }
@ -51,7 +51,7 @@ pure fn success<T, U>(res: t<T, U>) -> bool {
} }
#[doc = "Returns true if the result is `error`"] #[doc = "Returns true if the result is `error`"]
pure fn failure<T, U>(res: t<T, U>) -> bool { pure fn failure<T, U>(res: result<T, U>) -> bool {
!success(res) !success(res)
} }
@ -61,7 +61,7 @@ Convert to the `either` type
`ok` result variants are converted to `either::right` variants, `err` `ok` result variants are converted to `either::right` variants, `err`
result variants are converted to `either::left`. result variants are converted to `either::left`.
"] "]
pure fn to_either<T: copy, U: copy>(res: t<U, T>) -> either::t<T, U> { pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> {
alt res { alt res {
ok(res) { either::right(res) } ok(res) { either::right(res) }
err(fail_) { either::left(fail_) } err(fail_) { either::left(fail_) }
@ -81,8 +81,8 @@ Example:
ok(parse_buf(buf)) ok(parse_buf(buf))
} }
"] "]
fn chain<T, U: copy, V: copy>(res: t<T, V>, op: fn(T) -> t<U, V>) fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>)
-> t<U, V> { -> result<U, V> {
alt res { alt res {
ok(t) { op(t) } ok(t) { op(t) }
err(e) { err(e) } err(e) { err(e) }
@ -91,11 +91,13 @@ fn chain<T, U: copy, V: copy>(res: t<T, V>, op: fn(T) -> t<U, V>)
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
fn op1() -> result::t<int, str> { result::ok(666) } fn op1() -> result::result<int, str> { result::ok(666) }
fn op2(&&i: int) -> result::t<uint, str> { result::ok(i as uint + 1u) } fn op2(&&i: int) -> result::result<uint, str> {
result::ok(i as uint + 1u)
}
fn op3() -> result::t<int, str> { result::err("sadface") } fn op3() -> result::result<int, str> { result::err("sadface") }
#[test] #[test]
fn chain_success() { fn chain_success() {

View file

@ -406,7 +406,7 @@ fn spawn_sched(mode: sched_mode, +f: fn~()) {
run(builder, f); run(builder, f);
} }
fn try<T:send>(+f: fn~() -> T) -> result::t<T,()> { fn try<T:send>(+f: fn~() -> T) -> result<T,()> {
#[doc = " #[doc = "
Execute a function in another task and return either the return value Execute a function in another task and return either the return value
of the function or result::err. of the function or result::err.

View file

@ -25,7 +25,7 @@ form -- for instance, to pass memory back into C -- but great care must be
taken to ensure that a reference to the c_vec::t is still held if needed. taken to ensure that a reference to the c_vec::t is still held if needed.
"]; "];
export t; export c_vec;
export c_vec, c_vec_with_dtor; export c_vec, c_vec_with_dtor;
export get, set; export get, set;
export len; export len;
@ -37,8 +37,8 @@ The type representing a native chunk of memory
Wrapped in a enum for opacity; FIXME #818 when it is possible to have Wrapped in a enum for opacity; FIXME #818 when it is possible to have
truly opaque types, this should be revisited. truly opaque types, this should be revisited.
"] "]
enum t<T> { enum c_vec<T> {
t({ base: *mutable T, len: uint, rsrc: @dtor_res}) c_vec_({ base: *mutable T, len: uint, rsrc: @dtor_res})
} }
resource dtor_res(dtor: option<fn@()>) { resource dtor_res(dtor: option<fn@()>) {
@ -53,22 +53,23 @@ resource dtor_res(dtor: option<fn@()>) {
*/ */
#[doc = " #[doc = "
Create a c_vec::t from a native buffer with a given length. Create a `c_vec` from a native buffer with a given length.
# Arguments # Arguments
* base - A native pointer to a buffer * base - A native pointer to a buffer
* len - The number of elements in the buffer * len - The number of elements in the buffer
"] "]
unsafe fn c_vec<T>(base: *mutable T, len: uint) -> t<T> { unsafe fn c_vec<T>(base: *mutable T, len: uint) -> c_vec<T> {
ret t({base: base, ret c_vec_({
len: len, base: base,
rsrc: @dtor_res(option::none) len: len,
}); rsrc: @dtor_res(option::none)
});
} }
#[doc = " #[doc = "
Create a c_vec::t from a native buffer, with a given length, Create a `c_vec` from a native buffer, with a given length,
and a function to run upon destruction. and a function to run upon destruction.
# Arguments # Arguments
@ -79,11 +80,12 @@ and a function to run upon destruction.
for freeing the buffer, etc. for freeing the buffer, etc.
"] "]
unsafe fn c_vec_with_dtor<T>(base: *mutable T, len: uint, dtor: fn@()) unsafe fn c_vec_with_dtor<T>(base: *mutable T, len: uint, dtor: fn@())
-> t<T> { -> c_vec<T> {
ret t({base: base, ret c_vec_({
len: len, base: base,
rsrc: @dtor_res(option::some(dtor)) len: len,
}); rsrc: @dtor_res(option::some(dtor))
});
} }
/* /*
@ -95,7 +97,7 @@ Retrieves an element at a given index
Fails if `ofs` is greater or equal to the length of the vector Fails if `ofs` is greater or equal to the length of the vector
"] "]
fn get<T: copy>(t: t<T>, ofs: uint) -> T { fn get<T: copy>(t: c_vec<T>, ofs: uint) -> T {
assert ofs < len(t); assert ofs < len(t);
ret unsafe { *ptr::mut_offset((*t).base, ofs) }; ret unsafe { *ptr::mut_offset((*t).base, ofs) };
} }
@ -105,7 +107,7 @@ Sets the value of an element at a given index
Fails if `ofs` is greater or equal to the length of the vector Fails if `ofs` is greater or equal to the length of the vector
"] "]
fn set<T: copy>(t: t<T>, ofs: uint, v: T) { fn set<T: copy>(t: c_vec<T>, ofs: uint, v: T) {
assert ofs < len(t); assert ofs < len(t);
unsafe { *ptr::mut_offset((*t).base, ofs) = v }; unsafe { *ptr::mut_offset((*t).base, ofs) = v };
} }
@ -115,12 +117,12 @@ fn set<T: copy>(t: t<T>, ofs: uint, v: T) {
*/ */
#[doc = "Returns the length of the vector"] #[doc = "Returns the length of the vector"]
fn len<T>(t: t<T>) -> uint { fn len<T>(t: c_vec<T>) -> uint {
ret (*t).len; ret (*t).len;
} }
#[doc = "Returns a pointer to the first element of the vector"] #[doc = "Returns a pointer to the first element of the vector"]
unsafe fn ptr<T>(t: t<T>) -> *mutable T { unsafe fn ptr<T>(t: c_vec<T>) -> *mutable T {
ret (*t).base; ret (*t).base;
} }
@ -128,7 +130,7 @@ unsafe fn ptr<T>(t: t<T>) -> *mutable T {
mod tests { mod tests {
import libc::*; import libc::*;
fn malloc(n: size_t) -> t<u8> { fn malloc(n: size_t) -> c_vec<u8> {
let mem = libc::malloc(n); let mem = libc::malloc(n);
assert mem as int != 0; assert mem as int != 0;

View file

@ -12,7 +12,7 @@ on current cpus.
import tri; import tri;
export t, none, true, false, both; export four, none, true, false, both;
export not, and, or, xor, implies, implies_materially; export not, and, or, xor, implies, implies_materially;
export eq, ne, is_true, is_false; export eq, ne, is_true, is_false;
export from_str, to_str, all_values, to_trit, to_bit; export from_str, to_str, all_values, to_trit, to_bit;
@ -22,58 +22,60 @@ The type of fourrternary logic values
It may be thought of as tuple `(y, x)` of two bools It may be thought of as tuple `(y, x)` of two bools
"] "]
type t = u8; type four = u8;
const b0: u8 = 1u8; const b0: u8 = 1u8;
const b1: u8 = 2u8; const b1: u8 = 2u8;
const b01: u8 = 3u8; const b01: u8 = 3u8;
#[doc = "Logic value `(0, 0)` for bottom (neither true or false)"] #[doc = "Logic value `(0, 0)` for bottom (neither true or false)"]
const none: t = 0u8; const none: four = 0u8;
#[doc = "Logic value `(0, 1)` for truth"] #[doc = "Logic value `(0, 1)` for truth"]
const true: t = 1u8; const true: four = 1u8;
#[doc = "Logic value `(1, 0)` for falsehood"] #[doc = "Logic value `(1, 0)` for falsehood"]
const false: t = 2u8; const false: four = 2u8;
#[doc = "Logic value `(1, 1)` for top (both true and false)"] #[doc = "Logic value `(1, 1)` for top (both true and false)"]
const both: t = 3u8; const both: four = 3u8;
#[doc = " #[doc = "
Negation/Inverse Negation/Inverse
Returns `'(v.y, v.x)` Returns `'(v.y, v.x)`
"] "]
pure fn not(v: t) -> t { ((v << 1u8) | (v >> 1u8)) & b01 } pure fn not(v: four) -> four { ((v << 1u8) | (v >> 1u8)) & b01 }
#[doc = " #[doc = "
Conjunction Conjunction
Returns `(a.x | b.x, a.y & b.y)` Returns `(a.x | b.x, a.y & b.y)`
"] "]
pure fn and(a: t, b: t) -> t { ((a & b) & b0) | ((a | b) & b1) } pure fn and(a: four, b: four) -> four { ((a & b) & b0) | ((a | b) & b1) }
#[doc = " #[doc = "
Disjunction Disjunction
Returns `(a.x & b.x, a.y | b.y)` Returns `(a.x & b.x, a.y | b.y)`
"] "]
pure fn or(a: t, b: t) -> t { ((a | b) & b0) | ((a & b) & b1) } pure fn or(a: four, b: four) -> four { ((a | b) & b0) | ((a & b) & b1) }
#[doc = " #[doc = "
Classic exclusive or Classic exclusive or
Returns `or(and(a, not(b)), and(not(a), b))` Returns `or(and(a, not(b)), and(not(a), b))`
"] "]
pure fn xor(a: t, b: t) -> t { or(and(a, not(b)), and(not(a), b)) } pure fn xor(a: four, b: four) -> four { or(and(a, not(b)), and(not(a), b)) }
#[doc = " #[doc = "
Strong implication (from `a` strongly follows `b`) Strong implication (from `a` strongly follows `b`)
Returns `( x1 & y2, !x1 | x2)` Returns `( x1 & y2, !x1 | x2)`
"] "]
pure fn implies(a: t, b: t) -> t { ((a << 1u8) & b & b1) | (((!a) | b) & b0) } pure fn implies(a: four, b: four) -> four {
((a << 1u8) & b & b1) | (((!a) | b) & b0)
}
#[doc = " #[doc = "
Classic (material) implication in the logic Classic (material) implication in the logic
@ -81,30 +83,30 @@ Classic (material) implication in the logic
Returns `or(not(a), b)` Returns `or(not(a), b)`
"] "]
pure fn implies_materially(a: t, b: t) -> t { or(not(a), b) } pure fn implies_materially(a: four, b: four) -> four { or(not(a), b) }
#[doc = " #[doc = "
Returns true if truth values `a` and `b` are indistinguishable in the logic Returns true if truth values `a` and `b` are indistinguishable in the logic
"] "]
pure fn eq(a: t, b: t) -> bool { a == b } pure fn eq(a: four, b: four) -> bool { a == b }
#[doc = " #[doc = "
Returns true if truth values `a` and `b` are distinguishable in the logic Returns true if truth values `a` and `b` are distinguishable in the logic
"] "]
pure fn ne(a: t, b: t) -> bool { a != b } pure fn ne(a: four, b: four) -> bool { a != b }
#[doc = " #[doc = "
Returns true if `v` represents truth in the logic (is `true` or `both`) Returns true if `v` represents truth in the logic (is `true` or `both`)
"] "]
pure fn is_true(v: t) -> bool { (v & b0) != 0u8 } pure fn is_true(v: four) -> bool { (v & b0) != 0u8 }
#[doc = " #[doc = "
Returns true if `v` represents falsehood in the logic (is `false` or `none`) Returns true if `v` represents falsehood in the logic (is `false` or `none`)
"] "]
pure fn is_false(v: t) -> bool { (v & b0) == 0u8 } pure fn is_false(v: four) -> bool { (v & b0) == 0u8 }
#[doc = "Parse logic value from `s`"] #[doc = "Parse logic value from `s`"]
pure fn from_str(s: str) -> t { pure fn from_str(s: str) -> four {
alt check s { alt check s {
"none" { none } "none" { none }
"false" { four::false } "false" { four::false }
@ -114,7 +116,7 @@ pure fn from_str(s: str) -> t {
} }
#[doc = "Convert `v` into a string"] #[doc = "Convert `v` into a string"]
pure fn to_str(v: t) -> str { pure fn to_str(v: four) -> str {
// FIXME replace with consts as soon as that works // FIXME replace with consts as soon as that works
alt check v { alt check v {
0u8 { "none" } 0u8 { "none" }
@ -128,7 +130,7 @@ pure fn to_str(v: t) -> str {
Iterates over all truth values by passing them to `blk` in an unspecified Iterates over all truth values by passing them to `blk` in an unspecified
order order
"] "]
fn all_values(blk: fn(v: t)) { fn all_values(blk: fn(v: four)) {
blk(both); blk(both);
blk(four::true); blk(four::true);
blk(four::false); blk(four::false);
@ -138,21 +140,21 @@ fn all_values(blk: fn(v: t)) {
#[doc = " #[doc = "
Returns an `u8` whose first bit is set if `if_true(v)` holds Returns an `u8` whose first bit is set if `if_true(v)` holds
"] "]
fn to_bit(v: t) -> u8 { v & b0 } fn to_bit(v: four) -> u8 { v & b0 }
#[doc = " #[doc = "
Returns a trit of `v` (`both` and `none` are both coalesced into Returns a trit of `v` (`both` and `none` are both coalesced into
`trit::unknown`) `trit::unknown`)
"] "]
fn to_trit(v: t) -> tri::t { v & (v ^ not(v)) } fn to_trit(v: four) -> tri::tri { v & (v ^ not(v)) }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
fn eq1(a: four::t, b: four::t) -> bool { four::eq(a , b) } fn eq1(a: four, b: four) -> bool { four::eq(a , b) }
fn ne1(a: four::t, b: four::t) -> bool { four::ne(a , b) } fn ne1(a: four, b: four) -> bool { four::ne(a , b) }
fn eq2(a: four::t, b: four::t) -> bool { eq1( a, b ) && eq1( b, a ) } fn eq2(a: four, b: four) -> bool { eq1( a, b ) && eq1( b, a ) }
#[test] #[test]
fn test_four_req_eq() { fn test_four_req_eq() {
@ -190,7 +192,7 @@ mod tests {
} }
} }
fn to_tup(v: four::t) -> (bool, bool) { fn to_tup(v: four) -> (bool, bool) {
alt check v { alt check v {
0u8 { (false, false) } 0u8 { (false, false) }
1u8 { (false, true) } 1u8 { (false, true) }

View file

@ -45,7 +45,6 @@ name following -o, and accepts both -h and --help as optional flags.
"]; "];
import core::result;
import core::result::{err, ok}; import core::result::{err, ok};
import core::option; import core::option;
import core::option::{some, none}; import core::option::{some, none};
@ -159,7 +158,7 @@ fn fail_str(f: fail_) -> str {
The result of parsing a command line with a set of options The result of parsing a command line with a set of options
(result::t<match, fail_>) (result::t<match, fail_>)
"] "]
type result = result::t<match, fail_>; type result = result::result<match, fail_>;
#[doc = " #[doc = "
Parse command line arguments according to the provided options Parse command line arguments according to the provided options

View file

@ -133,11 +133,11 @@ impl parser for parser {
self.ch self.ch
} }
fn error<T>(msg: str) -> result::t<T, error> { fn error<T>(msg: str) -> result<T, error> {
err({ line: self.line, col: self.col, msg: msg }) err({ line: self.line, col: self.col, msg: msg })
} }
fn parse() -> result::t<json, error> { fn parse() -> result<json, error> {
alt self.parse_value() { alt self.parse_value() {
ok(value) { ok(value) {
// Skip trailing whitespaces. // Skip trailing whitespaces.
@ -153,7 +153,7 @@ impl parser for parser {
} }
} }
fn parse_value() -> result::t<json, error> { fn parse_value() -> result<json, error> {
self.parse_whitespace(); self.parse_whitespace();
if self.eof() { ret self.error("EOF while parsing value"); } if self.eof() { ret self.error("EOF while parsing value"); }
@ -179,7 +179,7 @@ impl parser for parser {
while char::is_whitespace(self.ch) { self.bump(); } while char::is_whitespace(self.ch) { self.bump(); }
} }
fn parse_ident(ident: str, value: json) -> result::t<json, error> { fn parse_ident(ident: str, value: json) -> result<json, error> {
if str::all(ident, { |c| c == self.next_char() }) { if str::all(ident, { |c| c == self.next_char() }) {
self.bump(); self.bump();
ok(value) ok(value)
@ -188,7 +188,7 @@ impl parser for parser {
} }
} }
fn parse_number() -> result::t<json, error> { fn parse_number() -> result<json, error> {
let neg = 1f; let neg = 1f;
if self.ch == '-' { if self.ch == '-' {
@ -218,7 +218,7 @@ impl parser for parser {
ok(num(neg * res)) ok(num(neg * res))
} }
fn parse_integer() -> result::t<float, error> { fn parse_integer() -> result<float, error> {
let res = 0f; let res = 0f;
alt self.ch { alt self.ch {
@ -250,7 +250,7 @@ impl parser for parser {
ok(res) ok(res)
} }
fn parse_decimal(res: float) -> result::t<float, error> { fn parse_decimal(res: float) -> result<float, error> {
self.bump(); self.bump();
// Make sure a digit follows the decimal place. // Make sure a digit follows the decimal place.
@ -276,7 +276,7 @@ impl parser for parser {
ok(res) ok(res)
} }
fn parse_exponent(res: float) -> result::t<float, error> { fn parse_exponent(res: float) -> result<float, error> {
self.bump(); self.bump();
let res = res; let res = res;
@ -317,7 +317,7 @@ impl parser for parser {
ok(res) ok(res)
} }
fn parse_str() -> result::t<str, error> { fn parse_str() -> result<str, error> {
let escape = false; let escape = false;
let res = ""; let res = "";
@ -372,7 +372,7 @@ impl parser for parser {
self.error("EOF while parsing string") self.error("EOF while parsing string")
} }
fn parse_list() -> result::t<json, error> { fn parse_list() -> result<json, error> {
self.bump(); self.bump();
self.parse_whitespace(); self.parse_whitespace();
@ -402,7 +402,7 @@ impl parser for parser {
}; };
} }
fn parse_object() -> result::t<json, error> { fn parse_object() -> result<json, error> {
self.bump(); self.bump();
self.parse_whitespace(); self.parse_whitespace();
@ -454,7 +454,7 @@ impl parser for parser {
} }
#[doc = "Deserializes a json value from an io::reader"] #[doc = "Deserializes a json value from an io::reader"]
fn from_reader(rdr: io::reader) -> result::t<json, error> { fn from_reader(rdr: io::reader) -> result<json, error> {
let parser = { let parser = {
rdr: rdr, rdr: rdr,
mutable ch: rdr.read_char(), mutable ch: rdr.read_char(),
@ -466,7 +466,7 @@ fn from_reader(rdr: io::reader) -> result::t<json, error> {
} }
#[doc = "Deserializes a json value from a string"] #[doc = "Deserializes a json value from a string"]
fn from_str(s: str) -> result::t<json, error> { fn from_str(s: str) -> result<json, error> {
io::with_str_reader(s, from_reader) io::with_str_reader(s, from_reader)
} }

View file

@ -58,7 +58,7 @@ fn test_main(args: [str], tests: [test_desc]) {
type test_opts = {filter: option<str>, run_ignored: bool}; type test_opts = {filter: option<str>, run_ignored: bool};
type opt_res = either::t<test_opts, str>; type opt_res = either<test_opts, str>;
// Parses command line arguments into test options // Parses command line arguments into test options
fn parse_opts(args: [str]) -> opt_res { fn parse_opts(args: [str]) -> opt_res {

View file

@ -10,44 +10,44 @@ all operations are done using bit operations which is fast
on current cpus. on current cpus.
"]; "];
export t, true, false, unknown; export tri, true, false, unknown;
export not, and, or, xor, implies, eq, ne, is_true, is_false; export not, and, or, xor, implies, eq, ne, is_true, is_false;
export from_str, to_str, all_values, to_bit; export from_str, to_str, all_values, to_bit;
#[doc = "The type of ternary logic values"] #[doc = "The type of ternary logic values"]
type t = u8; type tri = u8;
const b0: u8 = 1u8; const b0: u8 = 1u8;
const b1: u8 = 2u8; const b1: u8 = 2u8;
const b01: u8 = 3u8; const b01: u8 = 3u8;
#[doc = "Logic value for unknown (maybe true xor maybe false)"] #[doc = "Logic value for unknown (maybe true xor maybe false)"]
const unknown: t = 0u8; const unknown: tri = 0u8;
#[doc = "Logic value for truth"] #[doc = "Logic value for truth"]
const true: t = 1u8; const true: tri = 1u8;
#[doc = "Logic value for falsehood"] #[doc = "Logic value for falsehood"]
const false: t = 2u8; const false: tri = 2u8;
#[doc = "Negation/Inverse"] #[doc = "Negation/Inverse"]
pure fn not(v: t) -> t { ((v << 1u8) | (v >> 1u8)) & b01 } pure fn not(v: tri) -> tri { ((v << 1u8) | (v >> 1u8)) & b01 }
#[doc = "Conjunction"] #[doc = "Conjunction"]
pure fn and(a: t, b: t) -> t { ((a | b) & b1) | ((a & b) & b0) } pure fn and(a: tri, b: tri) -> tri { ((a | b) & b1) | ((a & b) & b0) }
#[doc = "Disjunction"] #[doc = "Disjunction"]
pure fn or(a: t, b: t) -> t { ((a & b) & b1) | ((a | b) & b0) } pure fn or(a: tri, b: tri) -> tri { ((a & b) & b1) | ((a | b) & b0) }
#[doc = "Exclusive or"] #[doc = "Exclusive or"]
pure fn xor(a: t, b: t) -> t { pure fn xor(a: tri, b: tri) -> tri {
let anb = a & b; let anb = a & b;
let aob = a & not(b); let aob = a & not(b);
ret ((anb & b1) | (anb << 1u8) | (aob >> 1u8) | (aob & b0)) & b01; ret ((anb & b1) | (anb << 1u8) | (aob >> 1u8) | (aob & b0)) & b01;
} }
#[doc = "Classic implication, i.e. from `a` follows `b`"] #[doc = "Classic implication, i.e. from `a` follows `b`"]
pure fn implies(a: t, b: t) -> t { pure fn implies(a: tri, b: tri) -> tri {
ret ((a & b1) >> 1u8) | (b & b0) | ((a << 1u8) & b & b1); ret ((a & b1) >> 1u8) | (b & b0) | ((a << 1u8) & b & b1);
} }
@ -56,38 +56,38 @@ pure fn implies(a: t, b: t) -> t {
true if truth values `a` and `b` are indistinguishable in the logic true if truth values `a` and `b` are indistinguishable in the logic
"] "]
pure fn eq(a: t, b: t) -> bool { a == b } pure fn eq(a: tri, b: tri) -> bool { a == b }
#[doc = " #[doc = "
# Return value # Return value
true if truth values `a` and `b` are distinguishable in the logic true if truth values `a` and `b` are distinguishable in the logic
"] "]
pure fn ne(a: t, b: t) -> bool { a != b } pure fn ne(a: tri, b: tri) -> bool { a != b }
#[doc = " #[doc = "
# Return value # Return value
true if `v` represents truth in the logic true if `v` represents truth in the logic
"] "]
pure fn is_true(v: t) -> bool { v == tri::true } pure fn is_true(v: tri) -> bool { v == tri::true }
#[doc = " #[doc = "
# Return value # Return value
true if `v` represents false in the logic true if `v` represents false in the logic
"] "]
pure fn is_false(v: t) -> bool { v == tri::false } pure fn is_false(v: tri) -> bool { v == tri::false }
#[doc = " #[doc = "
# Return value # Return value
true if `v` represents the unknown state in the logic true if `v` represents the unknown state in the logic
"] "]
pure fn is_unknown(v: t) -> bool { v == unknown } pure fn is_unknown(v: tri) -> bool { v == unknown }
#[doc = "Parse logic value from `s`"] #[doc = "Parse logic value from `s`"]
pure fn from_str(s: str) -> t { pure fn from_str(s: str) -> tri {
alt check s { alt check s {
"unknown" { unknown } "unknown" { unknown }
"true" { tri::true } "true" { tri::true }
@ -96,7 +96,7 @@ pure fn from_str(s: str) -> t {
} }
#[doc = "Convert `v` into a string"] #[doc = "Convert `v` into a string"]
pure fn to_str(v: t) -> str { pure fn to_str(v: tri) -> str {
// FIXME replace with consts as soon as that works // FIXME replace with consts as soon as that works
alt check v { alt check v {
0u8 { "unknown" } 0u8 { "unknown" }
@ -109,7 +109,7 @@ pure fn to_str(v: t) -> str {
Iterates over all truth values by passing them to `blk` Iterates over all truth values by passing them to `blk`
in an unspecified order in an unspecified order
"] "]
fn all_values(blk: fn(v: t)) { fn all_values(blk: fn(v: tri)) {
blk(tri::false); blk(tri::false);
blk(unknown); blk(unknown);
blk(tri::true); blk(tri::true);
@ -120,15 +120,17 @@ fn all_values(blk: fn(v: t)) {
An u8 whose first bit is set if `if_true(v)` holds An u8 whose first bit is set if `if_true(v)` holds
"] "]
fn to_bit(v: t) -> u8 { v & b0 } fn to_bit(v: tri) -> u8 { v & b0 }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
pure fn eq1(a: tri::t, b: tri::t) -> bool { tri::eq(a , b) } pure fn eq1(a: tri::tri, b: tri::tri) -> bool { tri::eq(a , b) }
pure fn ne1(a: tri::t, b: tri::t) -> bool { tri::ne(a , b) } pure fn ne1(a: tri::tri, b: tri::tri) -> bool { tri::ne(a , b) }
pure fn eq2(a: tri::t, b: tri::t) -> bool { eq1( a, b ) && eq1( b, a ) } pure fn eq2(a: tri::tri, b: tri::tri) -> bool {
eq1( a, b ) && eq1( b, a )
}
#[test] #[test]
fn test_eq2() { fn test_eq2() {

View file

@ -231,7 +231,7 @@ fn require_unique_names(sess: session, metas: [@ast::meta_item]) {
} }
} }
fn native_abi(attrs: [ast::attribute]) -> either::t<str, ast::native_abi> { fn native_abi(attrs: [ast::attribute]) -> either<str, ast::native_abi> {
ret alt attr::get_meta_item_value_str_by_name(attrs, "abi") { ret alt attr::get_meta_item_value_str_by_name(attrs, "abi") {
option::none { option::none {
either::right(ast::native_abi_cdecl) either::right(ast::native_abi_cdecl)

View file

@ -261,7 +261,7 @@ fn serialize_20<S: std::serialization::serializer>(s: S, v: uint) {
/*core::option::t<syntax::codemap::span>*/ /*core::option::t<syntax::codemap::span>*/
fn serialize_26<S: std::serialization::serializer>(s: S, fn serialize_26<S: std::serialization::serializer>(s: S,
v: v:
core::option::t<syntax::codemap::span>) { core::option<syntax::codemap::span>) {
s.emit_enum("core::option::t", s.emit_enum("core::option::t",
/*syntax::codemap::span*/ /*syntax::codemap::span*/
@ -291,7 +291,7 @@ fn serialize_25<S: std::serialization::serializer>(s: S,
v: v:
{name: str, {name: str,
span: span:
core::option::t<syntax::codemap::span>,}) { core::option<syntax::codemap::span>,}) {
s.emit_rec(/*str*//*core::option::t<syntax::codemap::span>*/ s.emit_rec(/*str*//*core::option::t<syntax::codemap::span>*/
{|| {||
{ {
@ -311,7 +311,7 @@ fn serialize_24<S: std::serialization::serializer>(s: S,
callie: callie:
{name: str, {name: str,
span: span:
core::option::t<syntax::codemap::span>,},}) { core::option<syntax::codemap::span>,},}) {
s.emit_rec(/*syntax::codemap::span*/ s.emit_rec(/*syntax::codemap::span*/
/*{name: str,span: core::option::t<syntax::codemap::span>}*/ /*{name: str,span: core::option::t<syntax::codemap::span>}*/
{|| {||
@ -1269,7 +1269,7 @@ fn serialize_76<S: std::serialization::serializer>(s: S,
/*core::option::t<@syntax::ast::expr>*/ /*core::option::t<@syntax::ast::expr>*/
fn serialize_79<S: std::serialization::serializer>(s: S, fn serialize_79<S: std::serialization::serializer>(s: S,
v: v:
core::option::t<@syntax::ast::expr>) { core::option<@syntax::ast::expr>) {
s.emit_enum("core::option::t", s.emit_enum("core::option::t",
/*@syntax::ast::expr*/ /*@syntax::ast::expr*/
@ -1297,7 +1297,7 @@ fn serialize_79<S: std::serialization::serializer>(s: S,
/*[core::option::t<@syntax::ast::expr>]*/ /*[core::option::t<@syntax::ast::expr>]*/
fn serialize_80<S: std::serialization::serializer>(s: S, fn serialize_80<S: std::serialization::serializer>(s: S,
v: v:
[core::option::t<@syntax::ast::expr>]) { [core::option<@syntax::ast::expr>]) {
s.emit_vec(vec::len(v), /*core::option::t<@syntax::ast::expr>*/ s.emit_vec(vec::len(v), /*core::option::t<@syntax::ast::expr>*/
{|| {||
vec::iteri(v, vec::iteri(v,
@ -1712,7 +1712,7 @@ fn serialize_85<S: std::serialization::serializer>(s: S,
/*core::option::t<@syntax::ast::pat>*/ /*core::option::t<@syntax::ast::pat>*/
fn serialize_112<S: std::serialization::serializer>(s: S, fn serialize_112<S: std::serialization::serializer>(s: S,
v: v:
core::option::t<@syntax::ast::pat>) { core::option<@syntax::ast::pat>) {
s.emit_enum("core::option::t", s.emit_enum("core::option::t",
/*@syntax::ast::pat*/ /*@syntax::ast::pat*/
@ -1973,7 +1973,7 @@ fn serialize_117<S: std::serialization::serializer>(s: S,
/*core::option::t<syntax::ast::initializer>*/ /*core::option::t<syntax::ast::initializer>*/
fn serialize_116<S: std::serialization::serializer>(s: S, fn serialize_116<S: std::serialization::serializer>(s: S,
v: v:
core::option::t<syntax::ast::initializer>) { core::option<syntax::ast::initializer>) {
s.emit_enum("core::option::t", s.emit_enum("core::option::t",
/*syntax::ast::initializer*/ /*syntax::ast::initializer*/
@ -3950,7 +3950,7 @@ fn serialize_159<S: std::serialization::serializer>(s: S,
/*core::option::t<@syntax::ast::ty>*/ /*core::option::t<@syntax::ast::ty>*/
fn serialize_161<S: std::serialization::serializer>(s: S, fn serialize_161<S: std::serialization::serializer>(s: S,
v: v:
core::option::t<@syntax::ast::ty>) { core::option<@syntax::ast::ty>) {
s.emit_enum("core::option::t", s.emit_enum("core::option::t",
/*@syntax::ast::ty*/ /*@syntax::ast::ty*/
@ -4471,7 +4471,7 @@ fn deserialize_20<S: std::serialization::deserializer>(s: S) -> uint {
} }
/*core::option::t<syntax::codemap::span>*/ /*core::option::t<syntax::codemap::span>*/
fn deserialize_26<S: std::serialization::deserializer>(s: S) -> fn deserialize_26<S: std::serialization::deserializer>(s: S) ->
core::option::t<syntax::codemap::span> { core::option<syntax::codemap::span> {
s.read_enum("core::option::t", s.read_enum("core::option::t",
@ -4492,7 +4492,7 @@ fn deserialize_26<S: std::serialization::deserializer>(s: S) ->
} }
/*{name: str,span: core::option::t<syntax::codemap::span>}*/ /*{name: str,span: core::option::t<syntax::codemap::span>}*/
fn deserialize_25<S: std::serialization::deserializer>(s: S) -> fn deserialize_25<S: std::serialization::deserializer>(s: S) ->
{name: str, span: core::option::t<syntax::codemap::span>,} { {name: str, span: core::option<syntax::codemap::span>,} {
s.read_rec( s.read_rec(
@ -4513,7 +4513,7 @@ fn deserialize_25<S: std::serialization::deserializer>(s: S) ->
/*{call_site: syntax::codemap::span,callie: {name: str,span: core::option::t<syntax::codemap::span>}}*/ /*{call_site: syntax::codemap::span,callie: {name: str,span: core::option::t<syntax::codemap::span>}}*/
fn deserialize_24<S: std::serialization::deserializer>(s: S) -> fn deserialize_24<S: std::serialization::deserializer>(s: S) ->
{call_site: syntax::codemap::span, {call_site: syntax::codemap::span,
callie: {name: str, span: core::option::t<syntax::codemap::span>,},} { callie: {name: str, span: core::option<syntax::codemap::span>,},} {
s.read_rec( s.read_rec(
@ -5501,7 +5501,7 @@ fn deserialize_76<S: std::serialization::deserializer>(s: S) ->
} }
/*core::option::t<@syntax::ast::expr>*/ /*core::option::t<@syntax::ast::expr>*/
fn deserialize_79<S: std::serialization::deserializer>(s: S) -> fn deserialize_79<S: std::serialization::deserializer>(s: S) ->
core::option::t<@syntax::ast::expr> { core::option<@syntax::ast::expr> {
s.read_enum("core::option::t", s.read_enum("core::option::t",
@ -5522,7 +5522,7 @@ fn deserialize_79<S: std::serialization::deserializer>(s: S) ->
} }
/*[core::option::t<@syntax::ast::expr>]*/ /*[core::option::t<@syntax::ast::expr>]*/
fn deserialize_80<S: std::serialization::deserializer>(s: S) -> fn deserialize_80<S: std::serialization::deserializer>(s: S) ->
[core::option::t<@syntax::ast::expr>] { [core::option<@syntax::ast::expr>] {
s.read_vec( s.read_vec(
/*core::option::t<@syntax::ast::expr>*/ /*core::option::t<@syntax::ast::expr>*/
@ -5886,7 +5886,7 @@ fn deserialize_85<S: std::serialization::deserializer>(s: S) ->
} }
/*core::option::t<@syntax::ast::pat>*/ /*core::option::t<@syntax::ast::pat>*/
fn deserialize_112<S: std::serialization::deserializer>(s: S) -> fn deserialize_112<S: std::serialization::deserializer>(s: S) ->
core::option::t<@syntax::ast::pat> { core::option<@syntax::ast::pat> {
s.read_enum("core::option::t", s.read_enum("core::option::t",
@ -6114,7 +6114,7 @@ fn deserialize_117<S: std::serialization::deserializer>(s: S) ->
} }
/*core::option::t<syntax::ast::initializer>*/ /*core::option::t<syntax::ast::initializer>*/
fn deserialize_116<S: std::serialization::deserializer>(s: S) -> fn deserialize_116<S: std::serialization::deserializer>(s: S) ->
core::option::t<syntax::ast::initializer> { core::option<syntax::ast::initializer> {
s.read_enum("core::option::t", s.read_enum("core::option::t",
@ -7890,7 +7890,7 @@ fn deserialize_159<S: std::serialization::deserializer>(s: S) ->
} }
/*core::option::t<@syntax::ast::ty>*/ /*core::option::t<@syntax::ast::ty>*/
fn deserialize_161<S: std::serialization::deserializer>(s: S) -> fn deserialize_161<S: std::serialization::deserializer>(s: S) ->
core::option::t<@syntax::ast::ty> { core::option<@syntax::ast::ty> {
s.read_enum("core::option::t", s.read_enum("core::option::t",

View file

@ -183,7 +183,7 @@ fn allocate_cbox(bcx: block,
fn store_uniq_tydesc(bcx: block, fn store_uniq_tydesc(bcx: block,
cdata_ty: ty::t, cdata_ty: ty::t,
box: ValueRef, box: ValueRef,
&ti: option::t<@tydesc_info>) -> block { &ti: option<@tydesc_info>) -> block {
let ccx = bcx.ccx(); let ccx = bcx.ccx();
let bound_tydesc = GEPi(bcx, box, [0, abi::box_field_tydesc]); let bound_tydesc = GEPi(bcx, box, [0, abi::box_field_tydesc]);
let {bcx, val: td} = base::get_tydesc(bcx, cdata_ty, true, ti); let {bcx, val: td} = base::get_tydesc(bcx, cdata_ty, true, ti);

View file

@ -1509,7 +1509,7 @@ fn arg_mode(cx: ctxt, a: arg) -> ast::rmode { resolved_mode(cx, a.mode) }
// Unifies `m1` and `m2`. Returns unified value or failure code. // Unifies `m1` and `m2`. Returns unified value or failure code.
fn unify_mode(cx: ctxt, m1: ast::mode, m2: ast::mode) fn unify_mode(cx: ctxt, m1: ast::mode, m2: ast::mode)
-> result::t<ast::mode, type_err> { -> result<ast::mode, type_err> {
alt (canon_mode(cx, m1), canon_mode(cx, m2)) { alt (canon_mode(cx, m1), canon_mode(cx, m2)) {
(m1, m2) if (m1 == m2) { (m1, m2) if (m1 == m2) {
result::ok(m1) result::ok(m1)
@ -1758,7 +1758,7 @@ mod unify {
}; };
} }
fn unify_args(cx: @uctxt, e_args: [arg], a_args: [arg], fn unify_args(cx: @uctxt, e_args: [arg], a_args: [arg],
variance: variance) -> either::t<result, [arg]> { variance: variance) -> either<result, [arg]> {
if !vec::same_length(e_args, a_args) { if !vec::same_length(e_args, a_args) {
ret either::left(ures_err(terr_arg_count)); ret either::left(ures_err(terr_arg_count));
} }

View file

@ -1701,7 +1701,7 @@ fn impl_self_ty(tcx: ty::ctxt, did: ast::def_id) -> {n_tps: uint, ty: ty::t} {
fn lookup_method(fcx: @fn_ctxt, expr: @ast::expr, node_id: ast::node_id, fn lookup_method(fcx: @fn_ctxt, expr: @ast::expr, node_id: ast::node_id,
name: ast::ident, ty: ty::t, tps: [ty::t]) name: ast::ident, ty: ty::t, tps: [ty::t])
-> option::t<method_origin> { -> option<method_origin> {
alt lookup_method_inner(fcx, expr, name, ty) { alt lookup_method_inner(fcx, expr, name, ty) {
some({method_ty: fty, n_tps: method_n_tps, substs, origin, self_sub}) { some({method_ty: fty, n_tps: method_n_tps, substs, origin, self_sub}) {
let tcx = fcx.ccx.tcx; let tcx = fcx.ccx.tcx;
@ -1743,9 +1743,9 @@ fn lookup_method(fcx: @fn_ctxt, expr: @ast::expr, node_id: ast::node_id,
fn lookup_method_inner(fcx: @fn_ctxt, expr: @ast::expr, fn lookup_method_inner(fcx: @fn_ctxt, expr: @ast::expr,
name: ast::ident, ty: ty::t) name: ast::ident, ty: ty::t)
-> option::t<{method_ty: ty::t, n_tps: uint, substs: [ty::t], -> option<{method_ty: ty::t, n_tps: uint, substs: [ty::t],
origin: method_origin, origin: method_origin,
self_sub: option::t<self_subst>}> { self_sub: option<self_subst>}> {
let tcx = fcx.ccx.tcx; let tcx = fcx.ccx.tcx;
// First, see whether this is an interface-bounded parameter // First, see whether this is an interface-bounded parameter
alt ty::get(ty).struct { alt ty::get(ty).struct {
@ -2120,8 +2120,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
} }
} }
fn lookup_op_method(fcx: @fn_ctxt, op_ex: @ast::expr, self_t: ty::t, fn lookup_op_method(fcx: @fn_ctxt, op_ex: @ast::expr, self_t: ty::t,
opname: str, args: [option::t<@ast::expr>]) opname: str, args: [option<@ast::expr>])
-> option::t<ty::t> { -> option<ty::t> {
let callee_id = ast_util::op_expr_callee_id(op_ex); let callee_id = ast_util::op_expr_callee_id(op_ex);
alt lookup_method(fcx, op_ex, callee_id, opname, self_t, []) { alt lookup_method(fcx, op_ex, callee_id, opname, self_t, []) {
some(origin) { some(origin) {

View file

@ -291,10 +291,10 @@ enum blk_sort {
type mac = spanned<mac_>; type mac = spanned<mac_>;
type mac_arg = option::t<@expr>; type mac_arg = option<@expr>;
type mac_body_ = {span: span}; type mac_body_ = {span: span};
type mac_body = option::t<mac_body_>; type mac_body = option<mac_body_>;
enum mac_ { enum mac_ {
mac_invoc(@path, mac_arg, mac_body), mac_invoc(@path, mac_arg, mac_body),

View file

@ -643,7 +643,7 @@ fn parse_seq<T: copy>(bra: token::token, ket: token::token,
ret spanned(lo, hi, result); ret spanned(lo, hi, result);
} }
fn have_dollar(p: parser) -> option::t<ast::mac_> { fn have_dollar(p: parser) -> option<ast::mac_> {
alt p.token { alt p.token {
token::DOLLAR_NUM(num) { token::DOLLAR_NUM(num) {
p.bump(); p.bump();
@ -2384,7 +2384,7 @@ else { ret none; }
// A type to distingush between the parsing of item attributes or syntax // A type to distingush between the parsing of item attributes or syntax
// extensions, which both begin with token.POUND // extensions, which both begin with token.POUND
type attr_or_ext = option<either::t<[ast::attribute], @ast::expr>>; type attr_or_ext = option<either<[ast::attribute], @ast::expr>>;
fn parse_outer_attrs_or_ext( fn parse_outer_attrs_or_ext(
p: parser, p: parser,

View file

@ -109,12 +109,12 @@ fn get_sysroot(maybe_sysroot: option<path>) -> path {
} }
} }
fn get_cargo_sysroot() -> result::t<path, str> { fn get_cargo_sysroot() -> result<path, str> {
let path = [get_default_sysroot(), libdir(), "cargo"]; let path = [get_default_sysroot(), libdir(), "cargo"];
result::ok(path::connect_many(path)) result::ok(path::connect_many(path))
} }
fn get_cargo_root() -> result::t<path, str> { fn get_cargo_root() -> result<path, str> {
alt os::getenv("CARGO_ROOT") { alt os::getenv("CARGO_ROOT") {
some(_p) { result::ok(_p) } some(_p) { result::ok(_p) }
none { none {
@ -126,7 +126,7 @@ fn get_cargo_root() -> result::t<path, str> {
} }
} }
fn get_cargo_root_nearest() -> result::t<path, str> { fn get_cargo_root_nearest() -> result<path, str> {
result::chain(get_cargo_root()) { |p| result::chain(get_cargo_root()) { |p|
let cwd = os::getcwd(); let cwd = os::getcwd();
let dirname = path::dirname(cwd); let dirname = path::dirname(cwd);
@ -151,13 +151,13 @@ fn get_cargo_root_nearest() -> result::t<path, str> {
} }
} }
fn get_cargo_lib_path() -> result::t<path, str> { fn get_cargo_lib_path() -> result<path, str> {
result::chain(get_cargo_root()) { |p| result::chain(get_cargo_root()) { |p|
result::ok(path::connect(p, libdir())) result::ok(path::connect(p, libdir()))
} }
} }
fn get_cargo_lib_path_nearest() -> result::t<path, str> { fn get_cargo_lib_path_nearest() -> result<path, str> {
result::chain(get_cargo_root_nearest()) { |p| result::chain(get_cargo_root_nearest()) { |p|
result::ok(path::connect(p, libdir())) result::ok(path::connect(p, libdir()))
} }

View file

@ -86,14 +86,14 @@ fn mock_program_output(_prog: str, _args: [str]) -> {
} }
} }
fn parse_config(args: [str]) -> result::t<config, str> { fn parse_config(args: [str]) -> result<config, str> {
parse_config_(args, run::program_output) parse_config_(args, run::program_output)
} }
fn parse_config_( fn parse_config_(
args: [str], args: [str],
program_output: program_output program_output: program_output
) -> result::t<config, str> { ) -> result<config, str> {
let args = vec::tail(args); let args = vec::tail(args);
let opts = tuple::first(vec::unzip(opts())); let opts = tuple::first(vec::unzip(opts()));
alt getopts::getopts(args, opts) { alt getopts::getopts(args, opts) {
@ -117,7 +117,7 @@ fn config_from_opts(
input_crate: str, input_crate: str,
match: getopts::match, match: getopts::match,
program_output: program_output program_output: program_output
) -> result::t<config, str> { ) -> result<config, str> {
let config = default_config(input_crate); let config = default_config(input_crate);
let result = result::ok(config); let result = result::ok(config);
@ -165,7 +165,7 @@ fn config_from_opts(
ret result; ret result;
} }
fn parse_output_format(output_format: str) -> result::t<output_format, str> { fn parse_output_format(output_format: str) -> result<output_format, str> {
alt output_format { alt output_format {
"markdown" { result::ok(markdown) } "markdown" { result::ok(markdown) }
"html" { result::ok(pandoc_html) } "html" { result::ok(pandoc_html) }
@ -173,7 +173,7 @@ fn parse_output_format(output_format: str) -> result::t<output_format, str> {
} }
} }
fn parse_output_style(output_style: str) -> result::t<output_style, str> { fn parse_output_style(output_style: str) -> result<output_style, str> {
alt output_style { alt output_style {
"doc-per-crate" { result::ok(doc_per_crate) } "doc-per-crate" { result::ok(doc_per_crate) }
"doc-per-mod" { result::ok(doc_per_mod) } "doc-per-mod" { result::ok(doc_per_mod) }
@ -185,7 +185,7 @@ fn maybe_find_pandoc(
config: config, config: config,
maybe_pandoc_cmd: option<str>, maybe_pandoc_cmd: option<str>,
program_output: program_output program_output: program_output
) -> result::t<option<str>, str> { ) -> result<option<str>, str> {
if config.output_format != pandoc_html { if config.output_format != pandoc_html {
ret result::ok(maybe_pandoc_cmd); ret result::ok(maybe_pandoc_cmd);
} }
@ -251,7 +251,7 @@ fn should_error_with_no_pandoc() {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
fn parse_config(args: [str]) -> result::t<config, str> { fn parse_config(args: [str]) -> result<config, str> {
parse_config_(args, mock_program_output) parse_config_(args, mock_program_output)
} }
} }

View file

@ -3,5 +3,5 @@
fn main() { fn main() {
let x: option<uint>; let x: option<uint>;
x = 5; x = 5;
//!^ ERROR mismatched types: expected `core::option::t<uint>` //!^ ERROR mismatched types: expected `core::option::option<uint>`
} }