diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/c_vec.rs | 42 | ||||
| -rw-r--r-- | src/libstd/four.rs | 52 | ||||
| -rw-r--r-- | src/libstd/getopts.rs | 3 | ||||
| -rw-r--r-- | src/libstd/json.rs | 26 | ||||
| -rw-r--r-- | src/libstd/test.rs | 2 | ||||
| -rw-r--r-- | src/libstd/tri.rs | 46 |
6 files changed, 88 insertions, 83 deletions
diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index 532f2903af3..28ee44690ee 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -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; diff --git a/src/libstd/four.rs b/src/libstd/four.rs index 744dc0a4c91..e2565d67306 100644 --- a/src/libstd/four.rs +++ b/src/libstd/four.rs @@ -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) } diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 19d941fe9f8..8d6aade9fad 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -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 diff --git a/src/libstd/json.rs b/src/libstd/json.rs index ca3d9f8b4d7..4e197d30c95 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -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) } diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 009da2e440d..d28912bae12 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -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 { diff --git a/src/libstd/tri.rs b/src/libstd/tri.rs index b40444a8a07..95eea29dc7e 100644 --- a/src/libstd/tri.rs +++ b/src/libstd/tri.rs @@ -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() { |
