diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 97a912c4d9cb4..01de70eabfbb8 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -11,6 +11,7 @@ import syntax::print::{pp, pprust}; import util::{ppaux, filesearch}; import back::link; import core::{option, str, vec, int, result}; +import result::{ok, err}; import std::{fs, io, getopts}; import option::{some, none}; import getopts::{optopt, optmulti, optflag, optflagopt, opt_present}; @@ -623,8 +624,8 @@ fn main(args: [str]) { let args = args, binary = vec::shift(args); let match = alt getopts::getopts(args, opts()) { - getopts::success(m) { m } - getopts::failure(f) { + ok(m) { m } + err(f) { early_error(getopts::fail_str(f)) } }; @@ -673,7 +674,7 @@ mod test { fn test_switch_implies_cfg_test() { let match = alt getopts::getopts(["--test"], opts()) { - getopts::success(m) { m } + ok(m) { m } }; let sessopts = build_session_options(match); let sess = build_session(sessopts); @@ -687,7 +688,7 @@ mod test { fn test_switch_implies_cfg_test_unless_cfg_test() { let match = alt getopts::getopts(["--test", "--cfg=test"], opts()) { - getopts::success(m) { m } + ok(m) { m } }; let sessopts = build_session_options(match); let sess = build_session(sessopts); diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index f85edd8378243..3f7ae912e9fe7 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -9,6 +9,9 @@ import str; import vec; import task; +import core::result; +import result::{ok, err}; + import comm::port; import comm::chan; import comm::send; @@ -42,8 +45,8 @@ fn parse_config(args: [str]) -> config { let args_ = vec::tail(args); let match = alt getopts::getopts(args_, opts) { - getopts::success(m) { m } - getopts::failure(f) { fail getopts::fail_str(f) } + ok(m) { m } + err(f) { fail getopts::fail_str(f) } }; ret {compile_lib_path: getopts::opt_str(match, "compile-lib-path"), diff --git a/src/libstd/cmath.rs b/src/libstd/cmath.rs deleted file mode 100644 index 1e4ee49763e98..0000000000000 --- a/src/libstd/cmath.rs +++ /dev/null @@ -1,71 +0,0 @@ -import ctypes::c_int; - -#[link_name = "m"] -#[abi = "cdecl"] -native mod f64 { - - // Alpabetically sorted by link_name - - pure fn acos(n: f64) -> f64; - pure fn asin(n: f64) -> f64; - pure fn atan(n: f64) -> f64; - pure fn atan2(a: f64, b: f64) -> f64; - pure fn ceil(n: f64) -> f64; - pure fn cos(n: f64) -> f64; - pure fn cosh(n: f64) -> f64; - pure fn exp(n: f64) -> f64; - #[link_name="fabs"] pure fn abs(n: f64) -> f64; - pure fn floor(n: f64) -> f64; - pure fn fmod(x: f64, y: f64) -> f64; - pure fn frexp(n: f64, &value: c_int) -> f64; - pure fn ldexp(x: f64, n: c_int) -> f64; - #[link_name="log"] pure fn ln(n: f64) -> f64; - #[link_name="log1p"] pure fn ln1p(n: f64) -> f64; - pure fn log10(n: f64) -> f64; - pure fn log2(n: f64) -> f64; - pure fn modf(n: f64, iptr: *f64) -> f64; - pure fn pow(n: f64, e: f64) -> f64; - pure fn rint(n: f64) -> f64; - pure fn round(n: f64) -> f64; - pure fn sin(n: f64) -> f64; - pure fn sinh(n: f64) -> f64; - pure fn sqrt(n: f64) -> f64; - pure fn tan(n: f64) -> f64; - pure fn tanh(n: f64) -> f64; - pure fn trunc(n: f64) -> f64; -} - -#[link_name = "m"] -#[abi = "cdecl"] -native mod f32 { - - // Alpabetically sorted by link_name - - #[link_name="acosf"] pure fn acos(n: f32) -> f32; - #[link_name="asinf"] pure fn asin(n: f32) -> f32; - #[link_name="atanf"] pure fn atan(n: f32) -> f32; - #[link_name="atan2f"] pure fn atan2(a: f32, b: f32) -> f32; - #[link_name="ceilf"] pure fn ceil(n: f32) -> f32; - #[link_name="cosf"] pure fn cos(n: f32) -> f32; - #[link_name="coshf"] pure fn cosh(n: f32) -> f32; - #[link_name="expf"] pure fn exp(n: f32) -> f32; - #[link_name="fabsf"] pure fn abs(n: f32) -> f32; - #[link_name="floorf"] pure fn floor(n: f32) -> f32; - #[link_name="frexpf"] pure fn frexp(n: f64, &value: c_int) -> f32; - #[link_name="fmodf"] pure fn fmod(x: f32, y: f32) -> f32; - #[link_name="ldexpf"] pure fn ldexp(x: f32, n: c_int) -> f32; - #[link_name="logf"] pure fn ln(n: f32) -> f32; - #[link_name="log1p"] pure fn ln1p(n: f64) -> f64; - #[link_name="log2f"] pure fn log2(n: f32) -> f32; - #[link_name="log10f"] pure fn log10(n: f32) -> f32; - #[link_name="modff"] pure fn modf(n: f32, iptr: *f32) -> f32; - #[link_name="powf"] pure fn pow(n: f32, e: f32) -> f32; - #[link_name="rintf"] pure fn rint(n: f32) -> f32; - #[link_name="roundf"] pure fn round(n: f32) -> f32; - #[link_name="sinf"] pure fn sin(n: f32) -> f32; - #[link_name="sinhf"] pure fn sinh(n: f32) -> f32; - #[link_name="sqrtf"] pure fn sqrt(n: f32) -> f32; - #[link_name="tanf"] pure fn tan(n: f32) -> f32; - #[link_name="tanhf"] pure fn tanh(n: f32) -> f32; - #[link_name="truncf"] pure fn trunc(n: f32) -> f32; -} diff --git a/src/libstd/ctypes.rs b/src/libstd/ctypes.rs deleted file mode 100644 index 509eb3ef05762..0000000000000 --- a/src/libstd/ctypes.rs +++ /dev/null @@ -1,146 +0,0 @@ -/* -Module: ctypes - -Definitions useful for C interop -*/ - -/* -FIXME: Add a test that uses some native code to verify these sizes, -which are not obviously correct for all potential platforms. -*/ - -/* -Type: c_int - -A signed integer with the same size as a C `int` -*/ -type c_int = i32; - -/* -Type: c_uint - -An unsigned integer with the same size as a C `unsigned int` -*/ -type c_uint = u32; - -/* -Type: long - -A signed integer with the same size as a C `long` -*/ -type long = int; - -/* -Type: unsigned - -An unsigned integer with the same size as a C `unsigned int` -*/ -type unsigned = u32; - -/* -Type: ulong - -An unsigned integer with the same size as a C `unsigned long` -*/ -type ulong = uint; - -/* -Type: intptr_t - -A signed integer with the same size as a pointer. This is -guaranteed to always be the same type as a Rust `int` -*/ -type intptr_t = uint; // FIXME: int - -/* -Type: uintptr_t - -An unsigned integer with the same size as a pointer. This is -guaranteed to always be the same type as a Rust `uint`. -*/ -type uintptr_t = uint; -type uint32_t = u32; - -/* -Type: void - -A type, a pointer to which can be used as C `void *` - -Note that this does not directly correspond to the C `void` type, -which is an incomplete type. Using pointers to this type -when interoperating with C void pointers can help in documentation. -*/ -type void = int; - -// machine type equivalents of rust int, uint, float - -/* -Type: m_int - -FIXME: What C type does this represent? -*/ -#[cfg(target_arch="x86")] -type m_int = i32; -#[cfg(target_arch="x86_64")] -type m_int = i64; - -/* -Type: m_uint - -FIXME: What C type does this represent? -*/ -#[cfg(target_arch="x86")] -type m_uint = u32; -#[cfg(target_arch="x86_64")] -type m_uint = u64; - -// This *must* match with "import m_float = fXX" in std::math per arch -/* -Type: m_float - -FIXME: What C type does this represent? -*/ -type m_float = f64; - -/* -Type: size_t - -An unsigned integer corresponding to the C `size_t` -*/ -type size_t = uint; - -/* -Type: ssize_t - -A signed integer correpsonding to the C `ssize_t` -*/ -type ssize_t = int; - -/* -Type: off_t - -An unsigned integer corresponding to the C `off_t` -*/ -type off_t = uint; - -/* -Type: fd_t - -A type that can be used for C file descriptors -*/ -type fd_t = i32; // not actually a C type, but should be. - -/* -Type: pid_t - -A type for representing process ID's, corresponding to C `pid_t` -*/ -type pid_t = i32; - -// enum is implementation-defined, but is 32-bits in practice -/* -Type: enum - -An unsigned integer with the same size as a C enum -*/ -type enum = u32; diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 115bcca8174b3..2443f7664b4e6 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -26,8 +26,8 @@ name following -o, and accepts both -h and --help as optional flags. > optflag("help") > ]; > let match = alt getopts(vec::shift(args), opts) { -> success(m) { m } -> failure(f) { fail fail_str(f) } +> ok(m) { m } +> err(f) { fail fail_str(f) } > }; > if opt_present(match, "h") || opt_present(match, "help") { > print_usage(); @@ -45,8 +45,10 @@ name following -o, and accepts both -h and --help as optional flags. */ +import core::result; +import core::result::{err, ok}; import core::option; -import option::{some, none}; +import core::option::{some, none}; export opt; export reqopt; export optopt; @@ -54,9 +56,6 @@ export optflag; export optflagopt; export optmulti; export getopts; -export result; -export success; -export failure; export match; export fail_; export fail_str; @@ -193,13 +192,14 @@ fn fail_str(f: fail_) -> str { Type: result The result of parsing a command line with a set of options +(result::t) Variants: -success(match) - Returned from getopts on success -failure(fail_) - Returned from getopts on failure +ok(match) - Returned from getopts on success +err(fail_) - Returned from getopts on failure */ -tag result { success(match); failure(fail_); } +type result = result::t; /* Function: getopts @@ -208,9 +208,9 @@ Parse command line arguments according to the provided options Returns: -success(match) - On success. Use functions such as - , etc. to interrogate results. -failure(fail_) - On failure. Use to get an error message. +ok(match) - On success. Use functions such as + , etc. to interrogate results. +err(fail_) - On failure. Use to get an error message. */ fn getopts(args: [str], opts: [opt]) -> result { let n_opts = vec::len::(opts); @@ -258,12 +258,12 @@ fn getopts(args: [str], opts: [opt]) -> result { let optid; alt find_opt(opts, nm) { some(id) { optid = id; } - none. { ret failure(unrecognized_option(name_str(nm))); } + none. { ret err(unrecognized_option(name_str(nm))); } } alt opts[optid].hasarg { no. { if !option::is_none::(i_arg) { - ret failure(unexpected_argument(name_str(nm))); + ret err(unexpected_argument(name_str(nm))); } vals[optid] += [given]; } @@ -279,7 +279,7 @@ fn getopts(args: [str], opts: [opt]) -> result { if !option::is_none::(i_arg) { vals[optid] += [val(option::get::(i_arg))]; } else if i + 1u == l { - ret failure(argument_missing(name_str(nm))); + ret err(argument_missing(name_str(nm))); } else { i += 1u; vals[optid] += [val(args[i])]; } } } @@ -293,17 +293,17 @@ fn getopts(args: [str], opts: [opt]) -> result { let occ = opts[i].occur; if occ == req { if n == 0u { - ret failure(option_missing(name_str(opts[i].name))); + ret err(option_missing(name_str(opts[i].name))); } } if occ != multi { if n > 1u { - ret failure(option_duplicated(name_str(opts[i].name))); + ret err(option_duplicated(name_str(opts[i].name))); } } i += 1u; } - ret success({opts: opts, vals: vals, free: free}); + ret ok({opts: opts, vals: vals, free: free}); } fn opt_vals(m: match, nm: str) -> [optval] { diff --git a/src/libstd/math.rs b/src/libstd/math.rs deleted file mode 100644 index 0f365c44415db..0000000000000 --- a/src/libstd/math.rs +++ /dev/null @@ -1,390 +0,0 @@ -/* - -Module: math - -Floating point operations and constants for `float`s -*/ - -export consts; -export min, max; - -// Currently this module supports from -lmath: -// C95 + log2 + log1p + trunc + round + rint - -export - acos, asin, atan, atan2, ceil, cos, cosh, exp, abs, floor, fmod, frexp, - ldexp, ln, ln1p, log10, log2, modf, rint, round, pow, sin, sinh, sqrt, - tan, tanh, trunc; - -export f64, f32; - -import f64 = math_f64; -import f32 = math_f32; - -// These two must match in width according to architecture - -import ctypes::m_float; -import ctypes::c_int; -import ptr; -import m_float = math_f64; - -/* -Module: consts -*/ -mod consts { - /* - Const: pi - - Archimedes' constant - */ - const pi: float = 3.14159265358979323846264338327950288; - - /* - Const: frac_pi_2 - - pi/2.0 - */ - const frac_pi_2: float = 1.57079632679489661923132169163975144; - - /* - Const: frac_pi_4 - - pi/4.0 - */ - const frac_pi_4: float = 0.785398163397448309615660845819875721; - - /* - Const: frac_1_pi - - 1.0/pi - */ - const frac_1_pi: float = 0.318309886183790671537767526745028724; - - /* - Const: frac_2_pi - - 2.0/pi - */ - const frac_2_pi: float = 0.636619772367581343075535053490057448; - - /* - Const: frac_2_sqrtpi - - 2.0/sqrt(pi) - */ - const frac_2_sqrtpi: float = 1.12837916709551257389615890312154517; - - /* - Const: sqrt2 - - sqrt(2.0) - */ - const sqrt2: float = 1.41421356237309504880168872420969808; - - /* - Const: frac_1_sqrt2 - - 1.0/sqrt(2.0) - */ - const frac_1_sqrt2: float = 0.707106781186547524400844362104849039; - - /* - Const: e - - Euler's number - */ - const e: float = 2.71828182845904523536028747135266250; - - /* - Const: log2_e - - log2(e) - */ - const log2_e: float = 1.44269504088896340735992468100189214; - - /* - Const: log10_e - - log10(e) - */ - const log10_e: float = 0.434294481903251827651128918916605082; - - /* - Const: ln_2 - - ln(2.0) - */ - const ln_2: float = 0.693147180559945309417232121458176568; - - /* - Const: ln_10 - - ln(10.0) - */ - const ln_10: float = 2.30258509299404568401799145468436421; -} - - -// FIXME min/max type specialize via libm when overloading works -// (in theory fmax/fmin, fmaxf, fminf /should/ be faster) - -/* -Function: min - -Returns the minimum of two values -*/ -pure fn min(x: T, y: T) -> T { x < y ? x : y } - -/* -Function: max - -Returns the maximum of two values -*/ -pure fn max(x: T, y: T) -> T { x < y ? y : x } - -/* -Function: acos - -Returns the arccosine of an angle (measured in rad) -*/ -pure fn acos(x: float) -> float - { be m_float::acos(x as m_float) as float } - -/* -Function: asin - -Returns the arcsine of an angle (measured in rad) -*/ -pure fn asin(x: float) -> float - { be m_float::asin(x as m_float) as float } - -/* -Function: atan - -Returns the arctangents of an angle (measured in rad) -*/ -pure fn atan(x: float) -> float - { be m_float::atan(x as m_float) as float } - - -/* -Function: atan2 - -Returns the arctangent of an angle (measured in rad) -*/ -pure fn atan2(y: float, x: float) -> float - { be m_float::atan2(y as m_float, x as m_float) as float } - -/* -Function: ceil - -Returns the smallest integral value less than or equal to `n` -*/ -pure fn ceil(n: float) -> float - { be m_float::ceil(n as m_float) as float } - -/* -Function: cos - -Returns the cosine of an angle `x` (measured in rad) -*/ -pure fn cos(x: float) -> float - { be m_float::cos(x as m_float) as float } - -/* -Function: cosh - -Returns the hyperbolic cosine of `x` - -*/ -pure fn cosh(x: float) -> float - { be m_float::cosh(x as m_float) as float } - - -/* -Function: exp - -Returns `consts::e` to the power of `n* -*/ -pure fn exp(n: float) -> float - { be m_float::exp(n as m_float) as float } - -/* -Function: abs - -Returns the absolute value of `n` -*/ -pure fn abs(n: float) -> float - { be m_float::abs(n as m_float) as float } - -/* -Function: floor - -Returns the largest integral value less than or equal to `n` -*/ -pure fn floor(n: float) -> float - { be m_float::floor(n as m_float) as float } - -/* -Function: fmod - -Returns the floating-point remainder of `x/y` -*/ -pure fn fmod(x: float, y: float) -> float - { be m_float::fmod(x as m_float, y as m_float) as float } - -/* -Function: ln - -Returns the natural logaritm of `n` -*/ -pure fn ln(n: float) -> float - { be m_float::ln(n as m_float) as float } - -/* -Function: ldexp - -Returns `x` multiplied by 2 to the power of `n` -*/ -pure fn ldexp(n: float, i: int) -> float - { be m_float::ldexp(n as m_float, i as c_int) as float } - -/* -Function: ln1p - -Returns the natural logarithm of `1+n` accurately, -even for very small values of `n` -*/ -pure fn ln1p(n: float) -> float - { be m_float::ln1p(n as m_float) as float } - -/* -Function: log10 - -Returns the logarithm to base 10 of `n` -*/ -pure fn log10(n: float) -> float - { be m_float::log10(n as m_float) as float } - -/* -Function: log2 - -Returns the logarithm to base 2 of `n` -*/ -pure fn log2(n: float) -> float - { be m_float::log2(n as m_float) as float } - -/* -Function: modf - -Breaks `n` into integral and fractional parts such that both -have the same sign as `n` - -The integral part is stored in `iptr`. - -Returns: - -The fractional part of `n` -*/ -#[no(warn_trivial_casts)] // FIXME Implement -pure fn modf(n: float, &iptr: float) -> float { unsafe { - be m_float::modf(n as m_float, ptr::addr_of(iptr) as *m_float) as float -} } - -/* -Function: frexp - -Breaks `n` into a normalized fraction and an integral power of 2 - -The inegral part is stored in iptr. - -The functions return a number x such that x has a magnitude in the interval -[1/2, 1) or 0, and `n == x*(2 to the power of exp)`. - -Returns: - -The fractional part of `n` -*/ -pure fn frexp(n: float, &exp: c_int) -> float - { be m_float::frexp(n as m_float, exp) as float } - -/* -Function: pow -*/ -pure fn pow(v: float, e: float) -> float - { be m_float::pow(v as m_float, e as m_float) as float } - - -/* -Function: rint - -Returns the integral value nearest to `x` (according to the -prevailing rounding mode) in floating-point format -*/ -pure fn rint(x: float) -> float - { be m_float::rint(x as m_float) as float } - -/* -Function: round - - -Return the integral value nearest to `x` rounding half-way -cases away from zero, regardless of the current rounding direction. -*/ -pure fn round(x: float) -> float - { be m_float::round(x as m_float) as float } - -/* -Function: sin - -Returns the sine of an angle `x` (measured in rad) -*/ -pure fn sin(x: float) -> float - { be m_float::sin(x as m_float) as float } - -/* -Function: sinh - -Returns the hyperbolic sine of an angle `x` (measured in rad) -*/ -pure fn sinh(x: float) -> float - { be m_float::sinh(x as m_float) as float } - -/* -Function: sqrt - -Returns the square root of `x` -*/ -pure fn sqrt(x: float) -> float - { be m_float::sqrt(x as m_float) as float } - -/* -Function: tan - -Returns the tangent of an angle `x` (measured in rad) - -*/ -pure fn tan(x: float) -> float - { be m_float::tan(x as m_float) as float } - -/* -Function: tanh - -Returns the hyperbolic tangent of an angle `x` (measured in rad) - -*/ -pure fn tanh(x: float) -> float - { be m_float::tanh(x as m_float) as float } - -/* -Function: trunc - -Returns the integral value nearest to but no larger in magnitude than `x` - -*/ -pure fn trunc(x: float) -> float - { be m_float::trunc(x as m_float) as float } - - - - diff --git a/src/libstd/math_f32.rs b/src/libstd/math_f32.rs deleted file mode 100644 index 6c36db51a67c1..0000000000000 --- a/src/libstd/math_f32.rs +++ /dev/null @@ -1,113 +0,0 @@ - -/* -Module: math_f32 - -Floating point operations and constants for `f32` - -This exposes the same operations as `math`, just for `f32` even though -they do not show up in the docs right now! -*/ - -import cmath::f32::*; - -export - acos, asin, atan, atan2, ceil, cos, cosh, exp, abs, floor, fmod, - frexp, ldexp, ln, ln1p, log10, log2, modf, rint, round, pow, sin, - sinh, sqrt, tan, tanh, trunc; - -export consts; - -/* Module: consts */ -mod consts { - - /* - Const: pi - - Archimedes' constant - */ - const pi: f32 = 3.14159265358979323846264338327950288f32; - - /* - Const: frac_pi_2 - - pi/2.0 - */ - const frac_pi_2: f32 = 1.57079632679489661923132169163975144f32; - - /* - Const: frac_pi_4 - - pi/4.0 - */ - const frac_pi_4: f32 = 0.785398163397448309615660845819875721f32; - - /* - Const: frac_1_pi - - 1.0/pi - */ - const frac_1_pi: f32 = 0.318309886183790671537767526745028724f32; - - /* - Const: frac_2_pi - - 2.0/pi - */ - const frac_2_pi: f32 = 0.636619772367581343075535053490057448f32; - - /* - Const: frac_2_sqrtpi - - 2.0/sqrt(pi) - */ - const frac_2_sqrtpi: f32 = 1.12837916709551257389615890312154517f32; - - /* - Const: sqrt2 - - sqrt(2.0) - */ - const sqrt2: f32 = 1.41421356237309504880168872420969808f32; - - /* - Const: frac_1_sqrt2 - - 1.0/sqrt(2.0) - */ - const frac_1_sqrt2: f32 = 0.707106781186547524400844362104849039f32; - - /* - Const: e - - Euler's number - */ - const e: f32 = 2.71828182845904523536028747135266250f32; - - /* - Const: log2_e - - log2(e) - */ - const log2_e: f32 = 1.44269504088896340735992468100189214f32; - - /* - Const: log10_e - - log10(e) - */ - const log10_e: f32 = 0.434294481903251827651128918916605082f32; - - /* - Const: ln_2 - - ln(2.0) - */ - const ln_2: f32 = 0.693147180559945309417232121458176568f32; - - /* - Const: ln_10 - - ln(10.0) - */ - const ln_10: f32 = 2.30258509299404568401799145468436421f32; -} \ No newline at end of file diff --git a/src/libstd/math_f64.rs b/src/libstd/math_f64.rs deleted file mode 100644 index 659bf2c5b1402..0000000000000 --- a/src/libstd/math_f64.rs +++ /dev/null @@ -1,114 +0,0 @@ - -/* -Module: math_f64 - -Floating point operations and constants for `f64`s - -This exposes the same operations as `math`, just for `f64` even though -they do not show up in the docs right now! -*/ - -import cmath::f64::*; - -export - acos, asin, atan, atan2, ceil, cos, cosh, exp, abs, floor, fmod, - frexp, ldexp, ln, ln1p, log10, log2, modf, rint, round, pow, sin, - sinh, sqrt, tan, tanh, trunc; - -export consts; - - -/* Module: consts */ -mod consts { - - /* - Const: pi - - Archimedes' constant - */ - const pi: f64 = 3.14159265358979323846264338327950288f64; - - /* - Const: frac_pi_2 - - pi/2.0 - */ - const frac_pi_2: f64 = 1.57079632679489661923132169163975144f64; - - /* - Const: frac_pi_4 - - pi/4.0 - */ - const frac_pi_4: f64 = 0.785398163397448309615660845819875721f64; - - /* - Const: frac_1_pi - - 1.0/pi - */ - const frac_1_pi: f64 = 0.318309886183790671537767526745028724f64; - - /* - Const: frac_2_pi - - 2.0/pi - */ - const frac_2_pi: f64 = 0.636619772367581343075535053490057448f64; - - /* - Const: frac_2_sqrtpi - - 2.0/sqrt(pi) - */ - const frac_2_sqrtpi: f64 = 1.12837916709551257389615890312154517f64; - - /* - Const: sqrt2 - - sqrt(2.0) - */ - const sqrt2: f64 = 1.41421356237309504880168872420969808f64; - - /* - Const: frac_1_sqrt2 - - 1.0/sqrt(2.0) - */ - const frac_1_sqrt2: f64 = 0.707106781186547524400844362104849039f64; - - /* - Const: e - - Euler's number - */ - const e: f64 = 2.71828182845904523536028747135266250f64; - - /* - Const: log2_e - - log2(e) - */ - const log2_e: f64 = 1.44269504088896340735992468100189214f64; - - /* - Const: log10_e - - log10(e) - */ - const log10_e: f64 = 0.434294481903251827651128918916605082f64; - - /* - Const: ln_2 - - ln(2.0) - */ - const ln_2: f64 = 0.693147180559945309417232121458176568f64; - - /* - Const: ln_10 - - ln(10.0) - */ - const ln_10: f64 = 2.30258509299404568401799145468436421f64; -} \ No newline at end of file diff --git a/src/libstd/mtypes.rs b/src/libstd/mtypes.rs deleted file mode 100644 index cddea420cc836..0000000000000 --- a/src/libstd/mtypes.rs +++ /dev/null @@ -1,64 +0,0 @@ -/* - -Module: mtypes - -Machine type equivalents of rust int, uint, float, and complex. - -Types useful for interop with C when writing bindings that exist -for different types (float, f32, f64, ...; cf float.rs for an example) -*/ - -export m_int, m_uint, m_float; - -// PORT Change this when porting to a new architecture - -/* -Type: m_int - -Machine type equivalent of an int -*/ -#[cfg(target_arch="x86")] -type m_int = i32; -#[cfg(target_arch="x86_64")] -type m_int = i64; - -// PORT Change this when porting to a new architecture - -/* -Type: m_uint - -Machine type equivalent of a uint -*/ -#[cfg(target_arch="x86")] -type m_uint = u32; -#[cfg(target_arch="x86_64")] -type m_uint = u64; - -// PORT *must* match with "import m_float = fXX" in std::math per arch - -/* -Type: m_float - -Machine type equivalent of a float -*/ -type m_float = f64; - -// PORT *must* match "import m_complex = ..." in std::complex per arch - -/* -FIXME Type m_complex - -Machine type representing a complex value that uses floats for -both the real and the imaginary part. -*/ -// type m_complex = complex_c64::t; - -// -// Local Variables: -// mode: rust -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// End: -// diff --git a/src/libstd/test.rs b/src/libstd/test.rs index abf563197a514..a965d60fe72f2 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -9,6 +9,7 @@ import task::task; import core::option; import core::either; import core::vec; +import core::result::{ok, err}; export test_name; export test_fn; @@ -82,8 +83,8 @@ fn parse_opts(args: [str]) : vec::is_not_empty(args) -> opt_res { let opts = [getopts::optflag("ignored")]; let match = alt getopts::getopts(args_, opts) { - getopts::success(m) { m } - getopts::failure(f) { ret either::right(getopts::fail_str(f)) } + ok(m) { m } + err(f) { ret either::right(getopts::fail_str(f)) } }; let filter = diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 482d4e05d5195..76680d9cd5064 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -27,6 +27,9 @@ import comm::chan; import comm::send; import comm::recv; +import core::result; +import result::{ok, err}; + fn fib(n: int) -> int { fn pfib(args: (chan, int)) { let (c, n) = args; @@ -58,8 +61,8 @@ fn parse_opts(argv: [str]) -> config { alt getopts::getopts(opt_args, opts) { - getopts::success(m) { ret {stress: getopts::opt_present(m, "stress")} } - getopts::failure(_) { fail; } + ok(m) { ret {stress: getopts::opt_present(m, "stress")} } + err(_) { fail; } } } diff --git a/src/test/stdtest/getopts.rs b/src/test/stdtest/getopts.rs index 3730a17e1816a..0cccbb4cb6ec8 100644 --- a/src/test/stdtest/getopts.rs +++ b/src/test/stdtest/getopts.rs @@ -2,6 +2,7 @@ import core::*; use std; import opt = std::getopts; +import result::{err, ok}; tag fail_type { argument_missing; @@ -30,7 +31,7 @@ fn test_reqopt_long() { let opts = [opt::reqopt("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { + ok(m) { assert (opt::opt_present(m, "test")); assert (opt::opt_str(m, "test") == "20"); } @@ -44,7 +45,7 @@ fn test_reqopt_long_missing() { let opts = [opt::reqopt("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, option_missing); } + err(f) { check_fail_type(f, option_missing); } _ { fail; } } } @@ -55,7 +56,7 @@ fn test_reqopt_long_no_arg() { let opts = [opt::reqopt("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, argument_missing); } + err(f) { check_fail_type(f, argument_missing); } _ { fail; } } } @@ -66,7 +67,7 @@ fn test_reqopt_long_multi() { let opts = [opt::reqopt("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, option_duplicated); } + err(f) { check_fail_type(f, option_duplicated); } _ { fail; } } } @@ -77,7 +78,7 @@ fn test_reqopt_short() { let opts = [opt::reqopt("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { + ok(m) { assert (opt::opt_present(m, "t")); assert (opt::opt_str(m, "t") == "20"); } @@ -91,7 +92,7 @@ fn test_reqopt_short_missing() { let opts = [opt::reqopt("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, option_missing); } + err(f) { check_fail_type(f, option_missing); } _ { fail; } } } @@ -102,7 +103,7 @@ fn test_reqopt_short_no_arg() { let opts = [opt::reqopt("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, argument_missing); } + err(f) { check_fail_type(f, argument_missing); } _ { fail; } } } @@ -113,7 +114,7 @@ fn test_reqopt_short_multi() { let opts = [opt::reqopt("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, option_duplicated); } + err(f) { check_fail_type(f, option_duplicated); } _ { fail; } } } @@ -126,7 +127,7 @@ fn test_optopt_long() { let opts = [opt::optopt("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { + ok(m) { assert (opt::opt_present(m, "test")); assert (opt::opt_str(m, "test") == "20"); } @@ -140,7 +141,7 @@ fn test_optopt_long_missing() { let opts = [opt::optopt("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { assert (!opt::opt_present(m, "test")); } + ok(m) { assert (!opt::opt_present(m, "test")); } _ { fail; } } } @@ -151,7 +152,7 @@ fn test_optopt_long_no_arg() { let opts = [opt::optopt("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, argument_missing); } + err(f) { check_fail_type(f, argument_missing); } _ { fail; } } } @@ -162,7 +163,7 @@ fn test_optopt_long_multi() { let opts = [opt::optopt("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, option_duplicated); } + err(f) { check_fail_type(f, option_duplicated); } _ { fail; } } } @@ -173,7 +174,7 @@ fn test_optopt_short() { let opts = [opt::optopt("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { + ok(m) { assert (opt::opt_present(m, "t")); assert (opt::opt_str(m, "t") == "20"); } @@ -187,7 +188,7 @@ fn test_optopt_short_missing() { let opts = [opt::optopt("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { assert (!opt::opt_present(m, "t")); } + ok(m) { assert (!opt::opt_present(m, "t")); } _ { fail; } } } @@ -198,7 +199,7 @@ fn test_optopt_short_no_arg() { let opts = [opt::optopt("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, argument_missing); } + err(f) { check_fail_type(f, argument_missing); } _ { fail; } } } @@ -209,7 +210,7 @@ fn test_optopt_short_multi() { let opts = [opt::optopt("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, option_duplicated); } + err(f) { check_fail_type(f, option_duplicated); } _ { fail; } } } @@ -222,7 +223,7 @@ fn test_optflag_long() { let opts = [opt::optflag("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { assert (opt::opt_present(m, "test")); } + ok(m) { assert (opt::opt_present(m, "test")); } _ { fail; } } } @@ -233,7 +234,7 @@ fn test_optflag_long_missing() { let opts = [opt::optflag("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { assert (!opt::opt_present(m, "test")); } + ok(m) { assert (!opt::opt_present(m, "test")); } _ { fail; } } } @@ -244,7 +245,7 @@ fn test_optflag_long_arg() { let opts = [opt::optflag("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { + err(f) { log_err opt::fail_str(f); check_fail_type(f, unexpected_argument); } @@ -258,7 +259,7 @@ fn test_optflag_long_multi() { let opts = [opt::optflag("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, option_duplicated); } + err(f) { check_fail_type(f, option_duplicated); } _ { fail; } } } @@ -269,7 +270,7 @@ fn test_optflag_short() { let opts = [opt::optflag("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { assert (opt::opt_present(m, "t")); } + ok(m) { assert (opt::opt_present(m, "t")); } _ { fail; } } } @@ -280,7 +281,7 @@ fn test_optflag_short_missing() { let opts = [opt::optflag("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { assert (!opt::opt_present(m, "t")); } + ok(m) { assert (!opt::opt_present(m, "t")); } _ { fail; } } } @@ -291,7 +292,7 @@ fn test_optflag_short_arg() { let opts = [opt::optflag("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { + ok(m) { // The next variable after the flag is just a free argument assert (m.free[0] == "20"); @@ -306,7 +307,7 @@ fn test_optflag_short_multi() { let opts = [opt::optflag("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, option_duplicated); } + err(f) { check_fail_type(f, option_duplicated); } _ { fail; } } } @@ -319,7 +320,7 @@ fn test_optmulti_long() { let opts = [opt::optmulti("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { + ok(m) { assert (opt::opt_present(m, "test")); assert (opt::opt_str(m, "test") == "20"); } @@ -333,7 +334,7 @@ fn test_optmulti_long_missing() { let opts = [opt::optmulti("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { assert (!opt::opt_present(m, "test")); } + ok(m) { assert (!opt::opt_present(m, "test")); } _ { fail; } } } @@ -344,7 +345,7 @@ fn test_optmulti_long_no_arg() { let opts = [opt::optmulti("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, argument_missing); } + err(f) { check_fail_type(f, argument_missing); } _ { fail; } } } @@ -355,7 +356,7 @@ fn test_optmulti_long_multi() { let opts = [opt::optmulti("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { + ok(m) { assert (opt::opt_present(m, "test")); assert (opt::opt_str(m, "test") == "20"); assert (opt::opt_strs(m, "test")[0] == "20"); @@ -371,7 +372,7 @@ fn test_optmulti_short() { let opts = [opt::optmulti("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { + ok(m) { assert (opt::opt_present(m, "t")); assert (opt::opt_str(m, "t") == "20"); } @@ -385,7 +386,7 @@ fn test_optmulti_short_missing() { let opts = [opt::optmulti("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { assert (!opt::opt_present(m, "t")); } + ok(m) { assert (!opt::opt_present(m, "t")); } _ { fail; } } } @@ -396,7 +397,7 @@ fn test_optmulti_short_no_arg() { let opts = [opt::optmulti("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, argument_missing); } + err(f) { check_fail_type(f, argument_missing); } _ { fail; } } } @@ -407,7 +408,7 @@ fn test_optmulti_short_multi() { let opts = [opt::optmulti("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { + ok(m) { assert (opt::opt_present(m, "t")); assert (opt::opt_str(m, "t") == "20"); assert (opt::opt_strs(m, "t")[0] == "20"); @@ -423,7 +424,7 @@ fn test_unrecognized_option_long() { let opts = [opt::optmulti("t")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, unrecognized_option); } + err(f) { check_fail_type(f, unrecognized_option); } _ { fail; } } } @@ -434,7 +435,7 @@ fn test_unrecognized_option_short() { let opts = [opt::optmulti("test")]; let rs = opt::getopts(args, opts); alt rs { - opt::failure(f) { check_fail_type(f, unrecognized_option); } + err(f) { check_fail_type(f, unrecognized_option); } _ { fail; } } } @@ -449,7 +450,7 @@ fn test_combined() { opt::optflag("f"), opt::optmulti("m"), opt::optopt("notpresent")]; let rs = opt::getopts(args, opts); alt rs { - opt::success(m) { + ok(m) { assert (m.free[0] == "prog"); assert (m.free[1] == "free1"); assert (opt::opt_str(m, "s") == "20");