Change all ternary ops to if/then/else

All the files below had at least one instance of the ternary operator
present in the source.  All have been changed to the equivalent
if/then/else expression.
This commit is contained in:
Paul Woolcock
2012-01-29 21:33:08 -05:00
committed by Marijn Haverbeke
parent e1f15a71e3
commit e1251f7b00
18 changed files with 183 additions and 68 deletions

View File

@@ -333,7 +333,11 @@ fn host_triple() -> str {
// grabbing (at compile time) the target triple that this rustc is // grabbing (at compile time) the target triple that this rustc is
// built with and calling that (at runtime) the host triple. // built with and calling that (at runtime) the host triple.
let ht = #env("CFG_HOST_TRIPLE"); let ht = #env("CFG_HOST_TRIPLE");
ret ht != "" ? ht : fail "rustc built without CFG_HOST_TRIPLE"; ret if ht != "" {
ht
} else {
fail "rustc built without CFG_HOST_TRIPLE"
};
} }
fn build_session_options(match: getopts::match, fn build_session_options(match: getopts::match,

View File

@@ -244,7 +244,7 @@ fn mk_path(cx: test_ctxt, path: [ast::ident]) -> [ast::ident] {
_ { false } _ { false }
} }
}; };
(is_std ? [] : ["std"]) + path (if is_std { [] } else { ["std"] }) + path
} }
// The ast::ty of [std::test::test_desc] // The ast::ty of [std::test::test_desc]

View File

@@ -602,23 +602,26 @@ fn pattern_roots(tcx: ty::ctxt, mut: option::t<unsafe_ty>, pat: @ast::pat)
ast::pat_rec(fs, _) { ast::pat_rec(fs, _) {
let ty = ty::node_id_to_type(tcx, pat.id); let ty = ty::node_id_to_type(tcx, pat.id);
for f in fs { for f in fs {
let m = ty::get_field(tcx, ty, f.ident).mt.mut != ast::imm; let m = ty::get_field(tcx, ty, f.ident).mt.mut != ast::imm,
walk(tcx, m ? some(contains(ty)) : mut, f.pat, set); c = if m { some(contains(ty)) } else { mut };
walk(tcx, c, f.pat, set);
} }
} }
ast::pat_box(p) { ast::pat_box(p) {
let ty = ty::node_id_to_type(tcx, pat.id); let ty = ty::node_id_to_type(tcx, pat.id);
let m = alt ty::struct(tcx, ty) { let m = alt ty::struct(tcx, ty) {
ty::ty_box(mt) { mt.mut != ast::imm } ty::ty_box(mt) { mt.mut != ast::imm }
}; },
walk(tcx, m ? some(contains(ty)) : mut, p, set); c = if m {some(contains(ty)) } else { mut };
walk(tcx, c, p, set);
} }
ast::pat_uniq(p) { ast::pat_uniq(p) {
let ty = ty::node_id_to_type(tcx, pat.id); let ty = ty::node_id_to_type(tcx, pat.id);
let m = alt ty::struct(tcx, ty) { let m = alt ty::struct(tcx, ty) {
ty::ty_uniq(mt) { mt.mut != ast::imm } ty::ty_uniq(mt) { mt.mut != ast::imm }
}; },
walk(tcx, m ? some(contains(ty)) : mut, p, set); c = if m { some(contains(ty)) } else { mut };
walk(tcx, c, p, set);
} }
} }
} }

View File

@@ -73,14 +73,14 @@ fn check_expr(sess: session, method_map: typeck::method_map, e: @expr,
expr_lit(@{node: lit_int(v, t), _}) { expr_lit(@{node: lit_int(v, t), _}) {
if t != ty_char { if t != ty_char {
if (v as u64) > ast_util::int_ty_max( if (v as u64) > ast_util::int_ty_max(
t == ty_i ? sess.targ_cfg.int_type : t) { if t == ty_i { sess.targ_cfg.int_type } else { t }) {
sess.span_err(e.span, "literal out of range for its type"); sess.span_err(e.span, "literal out of range for its type");
} }
} }
} }
expr_lit(@{node: lit_uint(v, t), _}) { expr_lit(@{node: lit_uint(v, t), _}) {
if v > ast_util::uint_ty_max( if v > ast_util::uint_ty_max(
t == ty_u ? sess.targ_cfg.uint_type : t) { if t == ty_u { sess.targ_cfg.uint_type } else { t }) {
sess.span_err(e.span, "literal out of range for its type"); sess.span_err(e.span, "literal out of range for its type");
} }
} }

View File

@@ -465,10 +465,16 @@ fn create_composite_type(type_tag: int, name: str, file: ValueRef, line: int,
lli64(align), // align lli64(align), // align
lli64(offset), // offset lli64(offset), // offset
lli32(0), // flags lli32(0), // flags
option::is_none(derived) ? llnull() : // derived from if option::is_none(derived) {
option::get(derived), llnull()
option::is_none(members) ? llnull() : // members } else { // derived from
llmdnode(option::get(members)), option::get(derived)
},
if option::is_none(members) {
llnull()
} else { //members
llmdnode(option::get(members))
},
lli32(0), // runtime language lli32(0), // runtime language
llnull() llnull()
]; ];
@@ -776,7 +782,7 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
let loc = codemap::lookup_char_pos(cx.sess.codemap, let loc = codemap::lookup_char_pos(cx.sess.codemap,
sp.lo); sp.lo);
let file_node = create_file(cx, loc.filename).node; let file_node = create_file(cx, loc.filename).node;
let key = cx.item_symbols.contains_key(fcx.id) ? fcx.id : id; let key = if cx.item_symbols.contains_key(fcx.id) { fcx.id } else { id };
let mangled = cx.item_symbols.get(key); let mangled = cx.item_symbols.get(key);
let ty_node = if cx.sess.opts.extra_debuginfo { let ty_node = if cx.sess.opts.extra_debuginfo {
alt ret_ty.node { alt ret_ty.node {

View File

@@ -1986,7 +1986,7 @@ fn visit_block_with_impl_scope(e: @env, b: ast::blk, sc: iscopes,
_ {} _ {}
} }
} }
let sc = vec::len(impls) > 0u ? cons(@impls, @sc) : sc; let sc = if vec::len(impls) > 0u { cons(@impls, @sc) } else { sc };
visit::visit_block(b, sc, v); visit::visit_block(b, sc, v);
} }
@@ -1998,8 +1998,11 @@ fn visit_mod_with_impl_scope(e: @env, m: ast::_mod, s: span, id: node_id,
} }
for i in m.items { find_impls_in_item(*e, i, impls, none, none); } for i in m.items { find_impls_in_item(*e, i, impls, none, none); }
let impls = @impls; let impls = @impls;
visit::visit_mod(m, s, id, visit::visit_mod(m, s, id, if vec::len(*impls) > 0u {
vec::len(*impls) > 0u ? cons(impls, @sc) : sc, v); cons(impls, @sc)
} else {
sc
}, v);
e.impl_map.insert(id, cons(impls, @nil)); e.impl_map.insert(id, cons(impls, @nil));
} }

View File

@@ -402,8 +402,11 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
let col = pick_col(m); let col = pick_col(m);
let val = vals[col]; let val = vals[col];
let m = has_nested_bindings(m, col) ? let m = if has_nested_bindings(m, col) {
expand_nested_bindings(m, col, val) : m; expand_nested_bindings(m, col, val)
} else {
m
};
let vals_left = let vals_left =
vec::slice(vals, 0u, col) + vec::slice(vals, 0u, col) +
@@ -493,7 +496,11 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
lit(l) { lit(l) {
test_val = Load(bcx, val); test_val = Load(bcx, val);
let pty = ty::node_id_to_type(ccx.tcx, pat_id); let pty = ty::node_id_to_type(ccx.tcx, pat_id);
kind = ty::type_is_integral(ccx.tcx, pty) ? switch : compare; kind = if ty::type_is_integral(ccx.tcx, pty) {
switch
} else {
compare
};
} }
range(_, _) { range(_, _) {
test_val = Load(bcx, val); test_val = Load(bcx, val);

View File

@@ -68,7 +68,7 @@ fn type_of_explicit_args(cx: @crate_ctxt, inputs: [ty::arg]) ->
// that would obviate the need for this check // that would obviate the need for this check
check non_ty_var(cx, arg_ty); check non_ty_var(cx, arg_ty);
let llty = type_of_inner(cx, arg_ty); let llty = type_of_inner(cx, arg_ty);
atys += [arg.mode == ast::by_val ? llty : T_ptr(llty)]; atys += [if arg.mode == ast::by_val { llty } else { T_ptr(llty) }];
} }
ret atys; ret atys;
} }
@@ -2015,8 +2015,11 @@ fn store_temp_expr(cx: @block_ctxt, action: copy_action, dst: ValueRef,
-> @block_ctxt { -> @block_ctxt {
// Lvals in memory are not temporaries. Copy them. // Lvals in memory are not temporaries. Copy them.
if src.kind != temporary && !last_use { if src.kind != temporary && !last_use {
let v = src.kind == owned ? load_if_immediate(cx, src.val, t) let v = if src.kind == owned {
: src.val; load_if_immediate(cx, src.val, t)
} else {
src.val
};
ret copy_val(cx, action, dst, v, t); ret copy_val(cx, action, dst, v, t);
} }
ret move_val(cx, action, dst, src, t); ret move_val(cx, action, dst, src, t);
@@ -3417,7 +3420,7 @@ fn trans_expr_save_in(bcx: @block_ctxt, e: @ast::expr, dest: ValueRef)
-> @block_ctxt { -> @block_ctxt {
let tcx = bcx_tcx(bcx), t = ty::expr_ty(tcx, e); let tcx = bcx_tcx(bcx), t = ty::expr_ty(tcx, e);
let do_ignore = ty::type_is_bot(tcx, t) || ty::type_is_nil(tcx, t); let do_ignore = ty::type_is_bot(tcx, t) || ty::type_is_nil(tcx, t);
ret trans_expr(bcx, e, do_ignore ? ignore : save_in(dest)); ret trans_expr(bcx, e, if do_ignore { ignore } else { save_in(dest) });
} }
// Call this to compile an expression that you need as an intermediate value, // Call this to compile an expression that you need as an intermediate value,
@@ -4256,7 +4259,7 @@ fn trans_block_dps(bcx: @block_ctxt, b: ast::blk, dest: dest)
some(e) { some(e) {
let bt = ty::type_is_bot(bcx_tcx(bcx), ty::expr_ty(bcx_tcx(bcx), e)); let bt = ty::type_is_bot(bcx_tcx(bcx), ty::expr_ty(bcx_tcx(bcx), e));
debuginfo::update_source_pos(bcx, e.span); debuginfo::update_source_pos(bcx, e.span);
bcx = trans_expr(bcx, e, bt ? ignore : dest); bcx = trans_expr(bcx, e, if bt { ignore } else { dest });
} }
_ { assert dest == ignore || bcx.unreachable; } _ { assert dest == ignore || bcx.unreachable; }
} }
@@ -4493,7 +4496,11 @@ fn trans_fn(cx: @local_ctxt, sp: span, decl: ast::fn_decl, body: ast::blk,
llfndecl: ValueRef, ty_self: self_arg, ty_params: [ast::ty_param], llfndecl: ValueRef, ty_self: self_arg, ty_params: [ast::ty_param],
id: ast::node_id) { id: ast::node_id) {
let do_time = cx.ccx.sess.opts.stats; let do_time = cx.ccx.sess.opts.stats;
let start = do_time ? time::get_time() : {sec: 0u32, usec: 0u32}; let start = if do_time {
time::get_time()
} else {
{sec: 0u32, usec: 0u32}
};
let fcx = option::none; let fcx = option::none;
trans_closure(cx, sp, decl, body, llfndecl, ty_self, ty_params, id, trans_closure(cx, sp, decl, body, llfndecl, ty_self, ty_params, id,
{|new_fcx| fcx = option::some(new_fcx);}); {|new_fcx| fcx = option::some(new_fcx);});
@@ -5396,7 +5403,7 @@ fn decl_crate_map(sess: session::session, mapname: str,
let n_subcrates = 1; let n_subcrates = 1;
let cstore = sess.cstore; let cstore = sess.cstore;
while cstore::have_crate_data(cstore, n_subcrates) { n_subcrates += 1; } while cstore::have_crate_data(cstore, n_subcrates) { n_subcrates += 1; }
let mapname = sess.building_library ? mapname : "toplevel"; let mapname = if sess.building_library { mapname } else { "toplevel" };
let sym_name = "_rust_crate_map_" + mapname; let sym_name = "_rust_crate_map_" + mapname;
let arrtype = T_array(int_type, n_subcrates as uint); let arrtype = T_array(int_type, n_subcrates as uint);
let maptype = T_struct([int_type, arrtype]); let maptype = T_struct([int_type, arrtype]);

View File

@@ -149,9 +149,13 @@ fn trans_append(cx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
let ccx = bcx_ccx(cx); let ccx = bcx_ccx(cx);
let unit_ty = ty::sequence_element_type(bcx_tcx(cx), vec_ty); let unit_ty = ty::sequence_element_type(bcx_tcx(cx), vec_ty);
let dynamic = ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty); let dynamic = ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty);
let (lhsptr, rhs) = !dynamic ? (lhsptr, rhs) : let (lhsptr, rhs) =
if !dynamic {
(lhsptr, rhs)
} else {
(PointerCast(cx, lhsptr, T_ptr(T_ptr(ccx.opaque_vec_type))), (PointerCast(cx, lhsptr, T_ptr(T_ptr(ccx.opaque_vec_type))),
PointerCast(cx, rhs, T_ptr(ccx.opaque_vec_type))); PointerCast(cx, rhs, T_ptr(ccx.opaque_vec_type)))
};
let strings = alt ty::struct(bcx_tcx(cx), vec_ty) { let strings = alt ty::struct(bcx_tcx(cx), vec_ty) {
ty::ty_str { true } ty::ty_str { true }
ty::ty_vec(_) { false } ty::ty_vec(_) { false }
@@ -187,7 +191,11 @@ fn trans_append(cx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
copy_val(bcx, INIT, write_ptr, copy_val(bcx, INIT, write_ptr,
load_if_immediate(bcx, addr, unit_ty), load_if_immediate(bcx, addr, unit_ty),
unit_ty); unit_ty);
let incr = dynamic ? unit_sz : C_int(ccx, 1); let incr = if dynamic {
unit_sz
} else {
C_int(ccx, 1)
};
Store(bcx, InBoundsGEP(bcx, write_ptr, [incr]), Store(bcx, InBoundsGEP(bcx, write_ptr, [incr]),
write_ptr_ptr); write_ptr_ptr);
ret bcx; ret bcx;
@@ -244,8 +252,11 @@ fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhs: ValueRef,
let bcx = copy_val(bcx, INIT, write_ptr, let bcx = copy_val(bcx, INIT, write_ptr,
load_if_immediate(bcx, addr, unit_ty), unit_ty); load_if_immediate(bcx, addr, unit_ty), unit_ty);
let incr = let incr =
ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) ? if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
llunitsz : C_int(ccx, 1); llunitsz
} else {
C_int(ccx, 1)
};
Store(bcx, InBoundsGEP(bcx, write_ptr, [incr]), Store(bcx, InBoundsGEP(bcx, write_ptr, [incr]),
write_ptr_ptr); write_ptr_ptr);
ret bcx; ret bcx;

View File

@@ -1578,9 +1578,17 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
fcx.ccx.tcx.sess.span_err( fcx.ccx.tcx.sess.span_err(
sp, #fmt["this function takes %u parameter%s but %u \ sp, #fmt["this function takes %u parameter%s but %u \
parameter%s supplied", expected_arg_count, parameter%s supplied", expected_arg_count,
expected_arg_count == 1u ? "" : "s", if expected_arg_count == 1u {
""
} else {
"s"
},
supplied_arg_count, supplied_arg_count,
supplied_arg_count == 1u ? " was" : "s were"]); if supplied_arg_count == 1u {
" was"
} else {
"s were"
}]);
// HACK: build an arguments list with dummy arguments to // HACK: build an arguments list with dummy arguments to
// check against // check against
let dummy = {mode: ast::by_ref, ty: ty::mk_bot(fcx.ccx.tcx)}; let dummy = {mode: ast::by_ref, ty: ty::mk_bot(fcx.ccx.tcx)};

View File

@@ -305,10 +305,42 @@ fn lit_to_const(lit: @lit) -> const_val {
fn compare_const_vals(a: const_val, b: const_val) -> int { fn compare_const_vals(a: const_val, b: const_val) -> int {
alt (a, b) { alt (a, b) {
(const_int(a), const_int(b)) { a == b ? 0 : a < b ? -1 : 1 } (const_int(a), const_int(b)) {
(const_uint(a), const_uint(b)) { a == b ? 0 : a < b ? -1 : 1 } if a == b {
(const_float(a), const_float(b)) { a == b ? 0 : a < b ? -1 : 1 } 0
(const_str(a), const_str(b)) { a == b ? 0 : a < b ? -1 : 1 } } else if a < b {
-1
} else {
1
}
}
(const_uint(a), const_uint(b)) {
if a == b {
0
} else if a < b {
-1
} else {
1
}
}
(const_float(a), const_float(b)) {
if a == b {
0
} else if a < b {
-1
} else {
1
}
}
(const_str(a), const_str(b)) {
if a == b {
0
} else if a < b {
-1
} else {
1
}
}
} }
} }

View File

@@ -197,31 +197,31 @@ fn scan_number(c: char, rdr: reader) -> token::token {
c = rdr.curr; c = rdr.curr;
n = rdr.next(); n = rdr.next();
if c == 'u' || c == 'i' { if c == 'u' || c == 'i' {
let signed = c == 'i', tp = signed ? either::left(ast::ty_i) let signed = c == 'i', tp = if signed { either::left(ast::ty_i) }
: either::right(ast::ty_u); else { either::right(ast::ty_u) };
rdr.bump(); rdr.bump();
c = rdr.curr; c = rdr.curr;
if c == '8' { if c == '8' {
rdr.bump(); rdr.bump();
tp = signed ? either::left(ast::ty_i8) tp = if signed { either::left(ast::ty_i8) }
: either::right(ast::ty_u8); else { either::right(ast::ty_u8) };
} }
n = rdr.next(); n = rdr.next();
if c == '1' && n == '6' { if c == '1' && n == '6' {
rdr.bump(); rdr.bump();
rdr.bump(); rdr.bump();
tp = signed ? either::left(ast::ty_i16) tp = if signed { either::left(ast::ty_i16) }
: either::right(ast::ty_u16); else { either::right(ast::ty_u16) };
} else if c == '3' && n == '2' { } else if c == '3' && n == '2' {
rdr.bump(); rdr.bump();
rdr.bump(); rdr.bump();
tp = signed ? either::left(ast::ty_i32) tp = if signed { either::left(ast::ty_i32) }
: either::right(ast::ty_u32); else { either::right(ast::ty_u32) };
} else if c == '6' && n == '4' { } else if c == '6' && n == '4' {
rdr.bump(); rdr.bump();
rdr.bump(); rdr.bump();
tp = signed ? either::left(ast::ty_i64) tp = if signed { either::left(ast::ty_i64) }
: either::right(ast::ty_u64); else { either::right(ast::ty_u64) };
} }
let parsed = u64::from_str(num_str, base as u64); let parsed = u64::from_str(num_str, base as u64);
alt tp { alt tp {

View File

@@ -538,8 +538,11 @@ fn parse_arg(p: parser) -> ast::arg {
fn parse_fn_block_arg(p: parser) -> ast::arg { fn parse_fn_block_arg(p: parser) -> ast::arg {
let m = parse_arg_mode(p); let m = parse_arg_mode(p);
let i = parse_value_ident(p); let i = parse_value_ident(p);
let t = eat(p, token::COLON) ? parse_ty(p, false) : let t = if eat(p, token::COLON) {
@spanned(p.span.lo, p.span.hi, ast::ty_infer); parse_ty(p, false)
} else {
@spanned(p.span.lo, p.span.hi, ast::ty_infer)
};
ret {mode: m, ty: t, ident: i, id: p.get_id()}; ret {mode: m, ty: t, ident: i, id: p.get_id()};
} }
@@ -676,7 +679,12 @@ fn parse_path(p: parser) -> @ast::path {
fn parse_path_and_ty_param_substs(p: parser, colons: bool) -> @ast::path { fn parse_path_and_ty_param_substs(p: parser, colons: bool) -> @ast::path {
let lo = p.span.lo; let lo = p.span.lo;
let path = parse_path(p); let path = parse_path(p);
if colons ? eat(p, token::MOD_SEP) : p.token == token::LT { let b = if colons {
eat(p, token::MOD_SEP)
} else {
p.token == token::LT
};
if b {
let seq = parse_seq_lt_gt(some(token::COMMA), let seq = parse_seq_lt_gt(some(token::COMMA),
{|p| parse_ty(p, false)}, p); {|p| parse_ty(p, false)}, p);
@spanned(lo, seq.span.hi, {types: seq.node with path.node}) @spanned(lo, seq.span.hi, {types: seq.node with path.node})
@@ -1504,7 +1512,11 @@ fn parse_pat(p: parser) -> @ast::pat {
_ { true } _ { true }
} { } {
let name = parse_path(p); let name = parse_path(p);
let sub = eat(p, token::AT) ? some(parse_pat(p)) : none; let sub = if eat(p, token::AT) {
some(parse_pat(p))
} else {
none
};
pat = ast::pat_ident(name, sub); pat = ast::pat_ident(name, sub);
} else { } else {
let enum_path = parse_path_and_ty_param_substs(p, true); let enum_path = parse_path_and_ty_param_substs(p, true);
@@ -1546,7 +1558,11 @@ fn parse_local(p: parser, allow_init: bool) -> @ast::local {
fn parse_let(p: parser) -> @ast::decl { fn parse_let(p: parser) -> @ast::decl {
fn parse_let_style(p: parser) -> ast::let_style { fn parse_let_style(p: parser) -> ast::let_style {
eat(p, token::BINOP(token::AND)) ? ast::let_ref : ast::let_copy if eat(p, token::BINOP(token::AND)) {
ast::let_ref
} else {
ast::let_copy
}
} }
let lo = p.span.lo; let lo = p.span.lo;
let locals = [(parse_let_style(p), parse_local(p, true))]; let locals = [(parse_let_style(p), parse_local(p, true))];
@@ -1786,11 +1802,19 @@ fn parse_fn_decl(p: parser, purity: ast::purity)
} }
fn parse_fn_block_decl(p: parser) -> ast::fn_decl { fn parse_fn_block_decl(p: parser) -> ast::fn_decl {
let inputs = eat(p, token::OROR) ? [] : let inputs = if eat(p, token::OROR) {
parse_seq(token::BINOP(token::OR), token::BINOP(token::OR), []
seq_sep(token::COMMA), parse_fn_block_arg, p).node; } else {
let output = eat(p, token::RARROW) ? parse_ty(p, false) : parse_seq(token::BINOP(token::OR),
@spanned(p.span.lo, p.span.hi, ast::ty_infer); token::BINOP(token::OR),
seq_sep(token::COMMA),
parse_fn_block_arg, p).node
};
let output = if eat(p, token::RARROW) {
parse_ty(p, false)
} else {
@spanned(p.span.lo, p.span.hi, ast::ty_infer)
};
ret {inputs: inputs, ret {inputs: inputs,
output: output, output: output,
purity: ast::impure_fn, purity: ast::impure_fn,

View File

@@ -24,10 +24,10 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
str { str {
let modestr = alt input.mode { let modestr = alt input.mode {
ast::by_ref { ast::by_ref {
ty::type_is_immediate(cx, input.ty) ? "&&" : "" if ty::type_is_immediate(cx, input.ty) { "&&" } else { "" }
} }
ast::by_val { ast::by_val {
ty::type_is_immediate(cx, input.ty) ? "" : "++" if ty::type_is_immediate(cx, input.ty) { "" } else { "++" }
} }
_ { mode_str(input.mode) } _ { mode_str(input.mode) }
}; };

View File

@@ -46,7 +46,7 @@ exact - Whether to enforce the exact number of significant digits
*/ */
fn to_str_common(num: float, digits: uint, exact: bool) -> str { fn to_str_common(num: float, digits: uint, exact: bool) -> str {
if is_NaN(num) { ret "NaN"; } if is_NaN(num) { ret "NaN"; }
let (num, accum) = num < 0.0 ? (-num, "-") : (num, ""); let (num, accum) = if num < 0.0 { (-num, "-") } else { (num, "") };
let trunc = num as uint; let trunc = num as uint;
let frac = num - (trunc as float); let frac = num - (trunc as float);
accum += uint::str(trunc); accum += uint::str(trunc);

View File

@@ -7,14 +7,14 @@ Function: min
Returns the minimum of two values Returns the minimum of two values
*/ */
pure fn min<T: copy>(x: T, y: T) -> T { x < y ? x : y } pure fn min<T: copy>(x: T, y: T) -> T { if x < y { x } else { y} }
/* /*
Function: max Function: max
Returns the maximum of two values Returns the maximum of two values
*/ */
pure fn max<T: copy>(x: T, y: T) -> T { x < y ? y : x } pure fn max<T: copy>(x: T, y: T) -> T { if x < y { y } else { x } }
#[test] #[test]
fn test_max_min() { fn test_max_min() {

View File

@@ -65,7 +65,7 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
let j = 0u, q = 0x6ed9eba1u32; let j = 0u, q = 0x6ed9eba1u32;
while j < 8u { while j < 8u {
let jj = j > 2u ? j - 3u : j; let jj = if j > 2u { j - 3u } else { j };
a = rot(3, a + (b ^ c ^ d) + x[jj] + q); a = rot(3, a + (b ^ c ^ d) + x[jj] + q);
d = rot(9, d + (a ^ b ^ c) + x[jj + 8u] + q); d = rot(9, d + (a ^ b ^ c) + x[jj + 8u] + q);
c = rot(11, c + (d ^ a ^ b) + x[jj + 4u] + q); c = rot(11, c + (d ^ a ^ b) + x[jj + 4u] + q);

View File

@@ -24,7 +24,17 @@ fn test7() -> uint {
(*regs < 2) as uint (*regs < 2) as uint
} }
fn test8() -> int { let val = @0; alt true { true { } } if *val < 1 { 0 } else { 1 } } fn test8() -> int {
let val = @0;
alt true {
true { }
}
if *val < 1 {
0
} else {
1
}
}
fn test9() { let regs = @mutable 0; alt true { true { } } *regs += 1; } fn test9() { let regs = @mutable 0; alt true { true { } } *regs += 1; }