Name types after their modules instead of 't'
This commit is contained in:
parent
a38ccf1254
commit
b968c8e6cd
@ -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
|
||||
generic.
|
||||
|
||||
The `option` type given above exists in the core library as
|
||||
`option::t`, and is the way Rust programs express the thing that in C
|
||||
would be a nullable pointer. The nice part is that you have to
|
||||
explicitly unpack an `option` type, so accidental null pointer
|
||||
dereferences become impossible.
|
||||
The `option` type given above exists in the core library and is the
|
||||
way Rust programs express the thing that in C would be a nullable
|
||||
pointer. The nice part is that you have to explicitly unpack an
|
||||
`option` type, so accidental null pointer dereferences become
|
||||
impossible.
|
||||
|
||||
## Type-inference and generics
|
||||
|
||||
@ -1562,7 +1562,7 @@ you really want to have such a statement, you'll have to write it like
|
||||
this:
|
||||
|
||||
~~~~
|
||||
let n2: option::t<int> = option::none;
|
||||
let n2: option<int> = option::none;
|
||||
// or
|
||||
let n = option::none::<int>;
|
||||
~~~~
|
||||
|
@ -167,7 +167,7 @@ fn recv_<T: send>(p: *rust_port) -> T {
|
||||
#[doc = "Receive on one of two ports"]
|
||||
fn select2<A: send, B: send>(
|
||||
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,
|
||||
n_ports: libc::size_t, yield: *libc::uintptr_t) {
|
||||
|
@ -3,7 +3,9 @@
|
||||
// Export various ubiquitous types, constructors, methods.
|
||||
|
||||
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 vec::vec_len;
|
||||
export path, option, some, none, vec_len, unreachable;
|
||||
|
@ -1,13 +1,13 @@
|
||||
#[doc = "A type that represents one of two alternatives"];
|
||||
|
||||
#[doc = "The either type"]
|
||||
enum t<T, U> {
|
||||
enum either<T, U> {
|
||||
left(T),
|
||||
right(U)
|
||||
}
|
||||
|
||||
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 = "
|
||||
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) } }
|
||||
}
|
||||
|
||||
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"];
|
||||
|
||||
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 */ } }
|
||||
}
|
||||
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"];
|
||||
|
||||
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 */ } }
|
||||
}
|
||||
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]} {
|
||||
#[doc = "
|
||||
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 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]; } }
|
||||
}
|
||||
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"];
|
||||
|
||||
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 = "
|
||||
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"];
|
||||
|
||||
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"];
|
||||
|
||||
alt eith { right(_) { true } _ { false } }
|
||||
@ -116,14 +117,14 @@ fn test_lefts() {
|
||||
|
||||
#[test]
|
||||
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);
|
||||
assert (vec::len(result) == 0u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lefts_empty() {
|
||||
let input: [t<int, int>] = [];
|
||||
let input: [either<int, int>] = [];
|
||||
let result = lefts(input);
|
||||
assert (vec::len(result) == 0u);
|
||||
}
|
||||
@ -137,14 +138,14 @@ fn test_rights() {
|
||||
|
||||
#[test]
|
||||
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);
|
||||
assert (vec::len(result) == 0u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rights_empty() {
|
||||
let input: [t<int, int>] = [];
|
||||
let input: [either<int, int>] = [];
|
||||
let result = rights(input);
|
||||
assert (vec::len(result) == 0u);
|
||||
}
|
||||
@ -162,7 +163,7 @@ fn test_partition() {
|
||||
|
||||
#[test]
|
||||
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);
|
||||
assert (vec::len(result.lefts) == 0u);
|
||||
assert (vec::len(result.rights) == 2u);
|
||||
@ -170,7 +171,7 @@ fn test_partition_no_lefts() {
|
||||
|
||||
#[test]
|
||||
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);
|
||||
assert (vec::len(result.lefts) == 2u);
|
||||
assert (vec::len(result.rights) == 0u);
|
||||
@ -178,7 +179,7 @@ fn test_partition_no_rights() {
|
||||
|
||||
#[test]
|
||||
fn test_partition_empty() {
|
||||
let input: [t<int, int>] = [];
|
||||
let input: [either<int, int>] = [];
|
||||
let result = partition(input);
|
||||
assert (vec::len(result.lefts) == 0u);
|
||||
assert (vec::len(result.rights) == 0u);
|
||||
|
@ -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 signbit;
|
||||
|
||||
type t = f32;
|
||||
|
||||
// These are not defined inside consts:: for consistency with
|
||||
// the integer types
|
||||
|
||||
|
@ -21,8 +21,6 @@ export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
|
||||
export signbit;
|
||||
export epsilon;
|
||||
|
||||
type t = f64;
|
||||
|
||||
// These are not defined inside consts:: for consistency with
|
||||
// the integer types
|
||||
|
||||
|
@ -26,8 +26,6 @@ export j0, j1, jn, y0, y1, yn;
|
||||
import m_float = f64;
|
||||
import f64::*;
|
||||
|
||||
type t = float;
|
||||
|
||||
/**
|
||||
* Section: String Conversions
|
||||
*/
|
||||
|
@ -20,8 +20,6 @@ export get;
|
||||
export with;
|
||||
export spawn;
|
||||
|
||||
import either = either::t;
|
||||
|
||||
#[doc = "The future type"]
|
||||
enum future<A> = {
|
||||
mutable v: either<@A, fn@() -> A>
|
||||
|
@ -218,7 +218,7 @@ fn FILE_reader(f: *libc::FILE, cleanup: bool) -> 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|
|
||||
os::as_c_charp("r", {|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])
|
||||
-> result::t<writer, str> {
|
||||
-> result<writer, str> {
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
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 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)})
|
||||
}
|
||||
|
||||
|
||||
// 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|
|
||||
os::as_c_charp("w") {|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;
|
||||
}
|
||||
|
||||
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::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
|
||||
// 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::ok(rdr.read_whole_stream())
|
||||
})
|
||||
|
@ -8,12 +8,12 @@ languages you might use a nullable type, in Rust you would use an option type.
|
||||
"];
|
||||
|
||||
#[doc = "The option type"]
|
||||
enum t<T> {
|
||||
enum option<T> {
|
||||
none,
|
||||
some(T),
|
||||
}
|
||||
|
||||
pure fn get<T: copy>(opt: t<T>) -> T {
|
||||
pure fn get<T: copy>(opt: option<T>) -> T {
|
||||
#[doc = "
|
||||
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"; } }
|
||||
}
|
||||
|
||||
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"];
|
||||
|
||||
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 = "
|
||||
Update an optional value by optionally running its content through a
|
||||
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 } }
|
||||
}
|
||||
|
||||
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`"];
|
||||
|
||||
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"];
|
||||
|
||||
!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"];
|
||||
|
||||
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"];
|
||||
|
||||
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"];
|
||||
|
||||
alt opt { none { } some(t) { f(t); } }
|
||||
}
|
||||
|
||||
fn unwrap<T>(-opt: t<T>) -> T unsafe {
|
||||
fn unwrap<T>(-opt: option<T>) -> T unsafe {
|
||||
#[doc = "
|
||||
Moves a value out of an option type and returns it.
|
||||
|
||||
|
@ -21,7 +21,6 @@ import libc::{c_char, c_void, c_int, c_uint, size_t, ssize_t,
|
||||
import libc::{close, fclose};
|
||||
|
||||
import option::{some, none};
|
||||
import option = option::t;
|
||||
|
||||
import getcwd = rustrt::rust_getcwd;
|
||||
import consts::*;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#[doc = "A type representing either success or failure"];
|
||||
|
||||
#[doc = "The result type"]
|
||||
enum t<T, U> {
|
||||
enum result<T, U> {
|
||||
#[doc = "Contains the successful result value"]
|
||||
ok(T),
|
||||
#[doc = "Contains the error value"]
|
||||
@ -15,7 +15,7 @@ Get the value out of a successful result
|
||||
|
||||
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 {
|
||||
ok(t) { t }
|
||||
err(_) {
|
||||
@ -33,7 +33,7 @@ Get the value out of an error result
|
||||
|
||||
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 {
|
||||
err(u) { u }
|
||||
ok(_) {
|
||||
@ -43,7 +43,7 @@ fn get_err<T, U: copy>(res: t<T, U>) -> U {
|
||||
}
|
||||
|
||||
#[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 {
|
||||
ok(_) { true }
|
||||
err(_) { false }
|
||||
@ -51,7 +51,7 @@ pure fn success<T, U>(res: t<T, U>) -> bool {
|
||||
}
|
||||
|
||||
#[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)
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ Convert to the `either` type
|
||||
`ok` result variants are converted to `either::right` variants, `err`
|
||||
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 {
|
||||
ok(res) { either::right(res) }
|
||||
err(fail_) { either::left(fail_) }
|
||||
@ -81,8 +81,8 @@ Example:
|
||||
ok(parse_buf(buf))
|
||||
}
|
||||
"]
|
||||
fn chain<T, U: copy, V: copy>(res: t<T, V>, op: fn(T) -> t<U, V>)
|
||||
-> t<U, V> {
|
||||
fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>)
|
||||
-> result<U, V> {
|
||||
alt res {
|
||||
ok(t) { op(t) }
|
||||
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)]
|
||||
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]
|
||||
fn chain_success() {
|
||||
|
@ -406,7 +406,7 @@ fn spawn_sched(mode: sched_mode, +f: fn~()) {
|
||||
run(builder, f);
|
||||
}
|
||||
|
||||
fn try<T:send>(+f: fn~() -> T) -> result::t<T,()> {
|
||||
fn try<T:send>(+f: fn~() -> T) -> result<T,()> {
|
||||
#[doc = "
|
||||
Execute a function in another task and return either the return value
|
||||
of the function or result::err.
|
||||
|
@ -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.
|
||||
"];
|
||||
|
||||
export t;
|
||||
export c_vec;
|
||||
export c_vec, c_vec_with_dtor;
|
||||
export get, set;
|
||||
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
|
||||
truly opaque types, this should be revisited.
|
||||
"]
|
||||
enum t<T> {
|
||||
t({ base: *mutable T, len: uint, rsrc: @dtor_res})
|
||||
enum c_vec<T> {
|
||||
c_vec_({ base: *mutable T, len: uint, rsrc: @dtor_res})
|
||||
}
|
||||
|
||||
resource dtor_res(dtor: option<fn@()>) {
|
||||
@ -53,22 +53,23 @@ resource dtor_res(dtor: option<fn@()>) {
|
||||
*/
|
||||
|
||||
#[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
|
||||
|
||||
* base - A native pointer to a buffer
|
||||
* len - The number of elements in the buffer
|
||||
"]
|
||||
unsafe fn c_vec<T>(base: *mutable T, len: uint) -> t<T> {
|
||||
ret t({base: base,
|
||||
len: len,
|
||||
rsrc: @dtor_res(option::none)
|
||||
});
|
||||
unsafe fn c_vec<T>(base: *mutable T, len: uint) -> c_vec<T> {
|
||||
ret c_vec_({
|
||||
base: base,
|
||||
len: len,
|
||||
rsrc: @dtor_res(option::none)
|
||||
});
|
||||
}
|
||||
|
||||
#[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.
|
||||
|
||||
# Arguments
|
||||
@ -79,11 +80,12 @@ and a function to run upon destruction.
|
||||
for freeing the buffer, etc.
|
||||
"]
|
||||
unsafe fn c_vec_with_dtor<T>(base: *mutable T, len: uint, dtor: fn@())
|
||||
-> t<T> {
|
||||
ret t({base: base,
|
||||
len: len,
|
||||
rsrc: @dtor_res(option::some(dtor))
|
||||
});
|
||||
-> c_vec<T> {
|
||||
ret c_vec_({
|
||||
base: base,
|
||||
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
|
||||
"]
|
||||
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);
|
||||
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
|
||||
"]
|
||||
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);
|
||||
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"]
|
||||
fn len<T>(t: t<T>) -> uint {
|
||||
fn len<T>(t: c_vec<T>) -> uint {
|
||||
ret (*t).len;
|
||||
}
|
||||
|
||||
#[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;
|
||||
}
|
||||
|
||||
@ -128,7 +130,7 @@ unsafe fn ptr<T>(t: t<T>) -> *mutable T {
|
||||
mod tests {
|
||||
import libc::*;
|
||||
|
||||
fn malloc(n: size_t) -> t<u8> {
|
||||
fn malloc(n: size_t) -> c_vec<u8> {
|
||||
let mem = libc::malloc(n);
|
||||
|
||||
assert mem as int != 0;
|
||||
|
@ -12,7 +12,7 @@ on current cpus.
|
||||
|
||||
import tri;
|
||||
|
||||
export t, none, true, false, both;
|
||||
export four, none, true, false, both;
|
||||
export not, and, or, xor, implies, implies_materially;
|
||||
export eq, ne, is_true, is_false;
|
||||
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
|
||||
"]
|
||||
type t = u8;
|
||||
type four = u8;
|
||||
|
||||
const b0: u8 = 1u8;
|
||||
const b1: u8 = 2u8;
|
||||
const b01: u8 = 3u8;
|
||||
|
||||
#[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"]
|
||||
const true: t = 1u8;
|
||||
const true: four = 1u8;
|
||||
|
||||
#[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)"]
|
||||
const both: t = 3u8;
|
||||
const both: four = 3u8;
|
||||
|
||||
#[doc = "
|
||||
Negation/Inverse
|
||||
|
||||
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 = "
|
||||
Conjunction
|
||||
|
||||
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 = "
|
||||
Disjunction
|
||||
|
||||
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 = "
|
||||
Classic exclusive or
|
||||
|
||||
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 = "
|
||||
Strong implication (from `a` strongly follows `b`)
|
||||
|
||||
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 = "
|
||||
Classic (material) implication in the logic
|
||||
@ -81,30 +83,30 @@ Classic (material) implication in the logic
|
||||
|
||||
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 = "
|
||||
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 = "
|
||||
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 = "
|
||||
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 = "
|
||||
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`"]
|
||||
pure fn from_str(s: str) -> t {
|
||||
pure fn from_str(s: str) -> four {
|
||||
alt check s {
|
||||
"none" { none }
|
||||
"false" { four::false }
|
||||
@ -114,7 +116,7 @@ pure fn from_str(s: str) -> t {
|
||||
}
|
||||
|
||||
#[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
|
||||
alt check v {
|
||||
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
|
||||
order
|
||||
"]
|
||||
fn all_values(blk: fn(v: t)) {
|
||||
fn all_values(blk: fn(v: four)) {
|
||||
blk(both);
|
||||
blk(four::true);
|
||||
blk(four::false);
|
||||
@ -138,21 +140,21 @@ fn all_values(blk: fn(v: t)) {
|
||||
#[doc = "
|
||||
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 = "
|
||||
Returns a trit of `v` (`both` and `none` are both coalesced into
|
||||
`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)]
|
||||
mod tests {
|
||||
|
||||
fn eq1(a: four::t, b: four::t) -> bool { four::eq(a , b) }
|
||||
fn ne1(a: four::t, b: four::t) -> bool { four::ne(a , b) }
|
||||
fn eq1(a: four, b: four) -> bool { four::eq(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]
|
||||
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 {
|
||||
0u8 { (false, false) }
|
||||
1u8 { (false, true) }
|
||||
|
@ -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::option;
|
||||
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
|
||||
(result::t<match, fail_>)
|
||||
"]
|
||||
type result = result::t<match, fail_>;
|
||||
type result = result::result<match, fail_>;
|
||||
|
||||
#[doc = "
|
||||
Parse command line arguments according to the provided options
|
||||
|
@ -133,11 +133,11 @@ impl parser for parser {
|
||||
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 })
|
||||
}
|
||||
|
||||
fn parse() -> result::t<json, error> {
|
||||
fn parse() -> result<json, error> {
|
||||
alt self.parse_value() {
|
||||
ok(value) {
|
||||
// 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();
|
||||
|
||||
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(); }
|
||||
}
|
||||
|
||||
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() }) {
|
||||
self.bump();
|
||||
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;
|
||||
|
||||
if self.ch == '-' {
|
||||
@ -218,7 +218,7 @@ impl parser for parser {
|
||||
ok(num(neg * res))
|
||||
}
|
||||
|
||||
fn parse_integer() -> result::t<float, error> {
|
||||
fn parse_integer() -> result<float, error> {
|
||||
let res = 0f;
|
||||
|
||||
alt self.ch {
|
||||
@ -250,7 +250,7 @@ impl parser for parser {
|
||||
ok(res)
|
||||
}
|
||||
|
||||
fn parse_decimal(res: float) -> result::t<float, error> {
|
||||
fn parse_decimal(res: float) -> result<float, error> {
|
||||
self.bump();
|
||||
|
||||
// Make sure a digit follows the decimal place.
|
||||
@ -276,7 +276,7 @@ impl parser for parser {
|
||||
ok(res)
|
||||
}
|
||||
|
||||
fn parse_exponent(res: float) -> result::t<float, error> {
|
||||
fn parse_exponent(res: float) -> result<float, error> {
|
||||
self.bump();
|
||||
|
||||
let res = res;
|
||||
@ -317,7 +317,7 @@ impl parser for parser {
|
||||
ok(res)
|
||||
}
|
||||
|
||||
fn parse_str() -> result::t<str, error> {
|
||||
fn parse_str() -> result<str, error> {
|
||||
let escape = false;
|
||||
let res = "";
|
||||
|
||||
@ -372,7 +372,7 @@ impl parser for parser {
|
||||
self.error("EOF while parsing string")
|
||||
}
|
||||
|
||||
fn parse_list() -> result::t<json, error> {
|
||||
fn parse_list() -> result<json, error> {
|
||||
self.bump();
|
||||
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.parse_whitespace();
|
||||
|
||||
@ -454,7 +454,7 @@ impl parser for parser {
|
||||
}
|
||||
|
||||
#[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 = {
|
||||
rdr: rdr,
|
||||
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"]
|
||||
fn from_str(s: str) -> result::t<json, error> {
|
||||
fn from_str(s: str) -> result<json, error> {
|
||||
io::with_str_reader(s, from_reader)
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ fn test_main(args: [str], tests: [test_desc]) {
|
||||
|
||||
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
|
||||
fn parse_opts(args: [str]) -> opt_res {
|
||||
|
@ -10,44 +10,44 @@ all operations are done using bit operations which is fast
|
||||
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 from_str, to_str, all_values, to_bit;
|
||||
|
||||
#[doc = "The type of ternary logic values"]
|
||||
type t = u8;
|
||||
type tri = u8;
|
||||
|
||||
const b0: u8 = 1u8;
|
||||
const b1: u8 = 2u8;
|
||||
const b01: u8 = 3u8;
|
||||
|
||||
#[doc = "Logic value for unknown (maybe true xor maybe false)"]
|
||||
const unknown: t = 0u8;
|
||||
const unknown: tri = 0u8;
|
||||
|
||||
#[doc = "Logic value for truth"]
|
||||
const true: t = 1u8;
|
||||
const true: tri = 1u8;
|
||||
|
||||
#[doc = "Logic value for falsehood"]
|
||||
const false: t = 2u8;
|
||||
const false: tri = 2u8;
|
||||
|
||||
#[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"]
|
||||
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"]
|
||||
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"]
|
||||
pure fn xor(a: t, b: t) -> t {
|
||||
pure fn xor(a: tri, b: tri) -> tri {
|
||||
let anb = a & b;
|
||||
let aob = a & not(b);
|
||||
ret ((anb & b1) | (anb << 1u8) | (aob >> 1u8) | (aob & b0)) & b01;
|
||||
}
|
||||
|
||||
#[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);
|
||||
}
|
||||
|
||||
@ -56,38 +56,38 @@ pure fn implies(a: t, b: t) -> t {
|
||||
|
||||
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 = "
|
||||
# Return value
|
||||
|
||||
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 = "
|
||||
# Return value
|
||||
|
||||
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 = "
|
||||
# Return value
|
||||
|
||||
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 = "
|
||||
# Return value
|
||||
|
||||
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`"]
|
||||
pure fn from_str(s: str) -> t {
|
||||
pure fn from_str(s: str) -> tri {
|
||||
alt check s {
|
||||
"unknown" { unknown }
|
||||
"true" { tri::true }
|
||||
@ -96,7 +96,7 @@ pure fn from_str(s: str) -> t {
|
||||
}
|
||||
|
||||
#[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
|
||||
alt check v {
|
||||
0u8 { "unknown" }
|
||||
@ -109,7 +109,7 @@ pure fn to_str(v: t) -> str {
|
||||
Iterates over all truth values by passing them to `blk`
|
||||
in an unspecified order
|
||||
"]
|
||||
fn all_values(blk: fn(v: t)) {
|
||||
fn all_values(blk: fn(v: tri)) {
|
||||
blk(tri::false);
|
||||
blk(unknown);
|
||||
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
|
||||
"]
|
||||
fn to_bit(v: t) -> u8 { v & b0 }
|
||||
fn to_bit(v: tri) -> u8 { v & b0 }
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
pure fn eq1(a: tri::t, b: tri::t) -> bool { tri::eq(a , b) }
|
||||
pure fn ne1(a: tri::t, b: tri::t) -> bool { tri::ne(a , b) }
|
||||
pure fn eq1(a: tri::tri, b: tri::tri) -> bool { tri::eq(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]
|
||||
fn test_eq2() {
|
||||
|
@ -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") {
|
||||
option::none {
|
||||
either::right(ast::native_abi_cdecl)
|
||||
|
@ -261,7 +261,7 @@ fn serialize_20<S: std::serialization::serializer>(s: S, v: uint) {
|
||||
/*core::option::t<syntax::codemap::span>*/
|
||||
fn serialize_26<S: std::serialization::serializer>(s: S,
|
||||
v:
|
||||
core::option::t<syntax::codemap::span>) {
|
||||
core::option<syntax::codemap::span>) {
|
||||
s.emit_enum("core::option::t",
|
||||
|
||||
/*syntax::codemap::span*/
|
||||
@ -291,7 +291,7 @@ fn serialize_25<S: std::serialization::serializer>(s: S,
|
||||
v:
|
||||
{name: str,
|
||||
span:
|
||||
core::option::t<syntax::codemap::span>,}) {
|
||||
core::option<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:
|
||||
{name: str,
|
||||
span:
|
||||
core::option::t<syntax::codemap::span>,},}) {
|
||||
core::option<syntax::codemap::span>,},}) {
|
||||
s.emit_rec(/*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>*/
|
||||
fn serialize_79<S: std::serialization::serializer>(s: S,
|
||||
v:
|
||||
core::option::t<@syntax::ast::expr>) {
|
||||
core::option<@syntax::ast::expr>) {
|
||||
s.emit_enum("core::option::t",
|
||||
|
||||
/*@syntax::ast::expr*/
|
||||
@ -1297,7 +1297,7 @@ fn serialize_79<S: std::serialization::serializer>(s: S,
|
||||
/*[core::option::t<@syntax::ast::expr>]*/
|
||||
fn serialize_80<S: std::serialization::serializer>(s: S,
|
||||
v:
|
||||
[core::option::t<@syntax::ast::expr>]) {
|
||||
[core::option<@syntax::ast::expr>]) {
|
||||
s.emit_vec(vec::len(v), /*core::option::t<@syntax::ast::expr>*/
|
||||
{||
|
||||
vec::iteri(v,
|
||||
@ -1712,7 +1712,7 @@ fn serialize_85<S: std::serialization::serializer>(s: S,
|
||||
/*core::option::t<@syntax::ast::pat>*/
|
||||
fn serialize_112<S: std::serialization::serializer>(s: S,
|
||||
v:
|
||||
core::option::t<@syntax::ast::pat>) {
|
||||
core::option<@syntax::ast::pat>) {
|
||||
s.emit_enum("core::option::t",
|
||||
|
||||
/*@syntax::ast::pat*/
|
||||
@ -1973,7 +1973,7 @@ fn serialize_117<S: std::serialization::serializer>(s: S,
|
||||
/*core::option::t<syntax::ast::initializer>*/
|
||||
fn serialize_116<S: std::serialization::serializer>(s: S,
|
||||
v:
|
||||
core::option::t<syntax::ast::initializer>) {
|
||||
core::option<syntax::ast::initializer>) {
|
||||
s.emit_enum("core::option::t",
|
||||
|
||||
/*syntax::ast::initializer*/
|
||||
@ -3950,7 +3950,7 @@ fn serialize_159<S: std::serialization::serializer>(s: S,
|
||||
/*core::option::t<@syntax::ast::ty>*/
|
||||
fn serialize_161<S: std::serialization::serializer>(s: S,
|
||||
v:
|
||||
core::option::t<@syntax::ast::ty>) {
|
||||
core::option<@syntax::ast::ty>) {
|
||||
s.emit_enum("core::option::t",
|
||||
|
||||
/*@syntax::ast::ty*/
|
||||
@ -4471,7 +4471,7 @@ fn deserialize_20<S: std::serialization::deserializer>(s: S) -> uint {
|
||||
}
|
||||
/*core::option::t<syntax::codemap::span>*/
|
||||
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",
|
||||
|
||||
|
||||
@ -4492,7 +4492,7 @@ fn deserialize_26<S: std::serialization::deserializer>(s: S) ->
|
||||
}
|
||||
/*{name: str,span: core::option::t<syntax::codemap::span>}*/
|
||||
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(
|
||||
|
||||
@ -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>}}*/
|
||||
fn deserialize_24<S: std::serialization::deserializer>(s: S) ->
|
||||
{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(
|
||||
|
||||
@ -5501,7 +5501,7 @@ fn deserialize_76<S: std::serialization::deserializer>(s: S) ->
|
||||
}
|
||||
/*core::option::t<@syntax::ast::expr>*/
|
||||
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",
|
||||
|
||||
|
||||
@ -5522,7 +5522,7 @@ fn deserialize_79<S: std::serialization::deserializer>(s: S) ->
|
||||
}
|
||||
/*[core::option::t<@syntax::ast::expr>]*/
|
||||
fn deserialize_80<S: std::serialization::deserializer>(s: S) ->
|
||||
[core::option::t<@syntax::ast::expr>] {
|
||||
[core::option<@syntax::ast::expr>] {
|
||||
s.read_vec(
|
||||
|
||||
/*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>*/
|
||||
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",
|
||||
|
||||
|
||||
@ -6114,7 +6114,7 @@ fn deserialize_117<S: std::serialization::deserializer>(s: S) ->
|
||||
}
|
||||
/*core::option::t<syntax::ast::initializer>*/
|
||||
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",
|
||||
|
||||
|
||||
@ -7890,7 +7890,7 @@ fn deserialize_159<S: std::serialization::deserializer>(s: S) ->
|
||||
}
|
||||
/*core::option::t<@syntax::ast::ty>*/
|
||||
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",
|
||||
|
||||
|
||||
|
@ -183,7 +183,7 @@ fn allocate_cbox(bcx: block,
|
||||
fn store_uniq_tydesc(bcx: block,
|
||||
cdata_ty: ty::t,
|
||||
box: ValueRef,
|
||||
&ti: option::t<@tydesc_info>) -> block {
|
||||
&ti: option<@tydesc_info>) -> block {
|
||||
let ccx = bcx.ccx();
|
||||
let bound_tydesc = GEPi(bcx, box, [0, abi::box_field_tydesc]);
|
||||
let {bcx, val: td} = base::get_tydesc(bcx, cdata_ty, true, ti);
|
||||
|
@ -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.
|
||||
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)) {
|
||||
(m1, m2) if (m1 == m2) {
|
||||
result::ok(m1)
|
||||
@ -1758,7 +1758,7 @@ mod unify {
|
||||
};
|
||||
}
|
||||
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) {
|
||||
ret either::left(ures_err(terr_arg_count));
|
||||
}
|
||||
|
@ -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,
|
||||
name: ast::ident, ty: ty::t, tps: [ty::t])
|
||||
-> option::t<method_origin> {
|
||||
-> option<method_origin> {
|
||||
alt lookup_method_inner(fcx, expr, name, ty) {
|
||||
some({method_ty: fty, n_tps: method_n_tps, substs, origin, self_sub}) {
|
||||
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,
|
||||
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,
|
||||
self_sub: option::t<self_subst>}> {
|
||||
self_sub: option<self_subst>}> {
|
||||
let tcx = fcx.ccx.tcx;
|
||||
// First, see whether this is an interface-bounded parameter
|
||||
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,
|
||||
opname: str, args: [option::t<@ast::expr>])
|
||||
-> option::t<ty::t> {
|
||||
opname: str, args: [option<@ast::expr>])
|
||||
-> option<ty::t> {
|
||||
let callee_id = ast_util::op_expr_callee_id(op_ex);
|
||||
alt lookup_method(fcx, op_ex, callee_id, opname, self_t, []) {
|
||||
some(origin) {
|
||||
|
@ -291,10 +291,10 @@ enum blk_sort {
|
||||
|
||||
type mac = spanned<mac_>;
|
||||
|
||||
type mac_arg = option::t<@expr>;
|
||||
type mac_arg = option<@expr>;
|
||||
|
||||
type mac_body_ = {span: span};
|
||||
type mac_body = option::t<mac_body_>;
|
||||
type mac_body = option<mac_body_>;
|
||||
|
||||
enum mac_ {
|
||||
mac_invoc(@path, mac_arg, mac_body),
|
||||
|
@ -643,7 +643,7 @@ fn parse_seq<T: copy>(bra: token::token, ket: token::token,
|
||||
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 {
|
||||
token::DOLLAR_NUM(num) {
|
||||
p.bump();
|
||||
@ -2384,7 +2384,7 @@ else { ret none; }
|
||||
|
||||
// A type to distingush between the parsing of item attributes or syntax
|
||||
// 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(
|
||||
p: parser,
|
||||
|
@ -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"];
|
||||
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") {
|
||||
some(_p) { result::ok(_p) }
|
||||
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|
|
||||
let cwd = os::getcwd();
|
||||
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::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::ok(path::connect(p, libdir()))
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
fn parse_config_(
|
||||
args: [str],
|
||||
program_output: program_output
|
||||
) -> result::t<config, str> {
|
||||
) -> result<config, str> {
|
||||
let args = vec::tail(args);
|
||||
let opts = tuple::first(vec::unzip(opts()));
|
||||
alt getopts::getopts(args, opts) {
|
||||
@ -117,7 +117,7 @@ fn config_from_opts(
|
||||
input_crate: str,
|
||||
match: getopts::match,
|
||||
program_output: program_output
|
||||
) -> result::t<config, str> {
|
||||
) -> result<config, str> {
|
||||
|
||||
let config = default_config(input_crate);
|
||||
let result = result::ok(config);
|
||||
@ -165,7 +165,7 @@ fn config_from_opts(
|
||||
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 {
|
||||
"markdown" { result::ok(markdown) }
|
||||
"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 {
|
||||
"doc-per-crate" { result::ok(doc_per_crate) }
|
||||
"doc-per-mod" { result::ok(doc_per_mod) }
|
||||
@ -185,7 +185,7 @@ fn maybe_find_pandoc(
|
||||
config: config,
|
||||
maybe_pandoc_cmd: option<str>,
|
||||
program_output: program_output
|
||||
) -> result::t<option<str>, str> {
|
||||
) -> result<option<str>, str> {
|
||||
if config.output_format != pandoc_html {
|
||||
ret result::ok(maybe_pandoc_cmd);
|
||||
}
|
||||
@ -251,7 +251,7 @@ fn should_error_with_no_pandoc() {
|
||||
|
||||
#[cfg(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)
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,5 @@
|
||||
fn main() {
|
||||
let x: option<uint>;
|
||||
x = 5;
|
||||
//!^ ERROR mismatched types: expected `core::option::t<uint>`
|
||||
//!^ ERROR mismatched types: expected `core::option::option<uint>`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user