Make fmt use a bitmask instead of a vector of flags. Closes #1993.

This commit is contained in:
Michael Sullivan 2012-06-28 23:36:00 -07:00
parent 498b3ff57f
commit 7aa43b2599
3 changed files with 22 additions and 26 deletions

View File

@ -9,7 +9,7 @@
# the snapshot runtime (resp. corelib) rather than the runtime
# (resp. corelib) from the working directory.
USE_SNAPSHOT_RUNTIME=0
USE_SNAPSHOT_CORELIB=0
USE_SNAPSHOT_CORELIB=1
USE_SNAPSHOT_STDLIB=0
define TARGET_STAGE_N

View File

@ -264,19 +264,17 @@ mod ct {
// conditions can be evaluated at compile-time. For now though it's cleaner to
// implement it 0this way, I think.
mod rt {
enum flag {
flag_left_justify,
flag_left_zero_pad,
flag_space_for_sign,
flag_sign_always,
flag_alternate,
}
const flag_none : u32 = 0u32;
const flag_left_justify : u32 = 0b00000000000000000000000000000001u32;
const flag_left_zero_pad : u32 = 0b00000000000000000000000000000010u32;
const flag_space_for_sign : u32 = 0b00000000000000000000000000000100u32;
const flag_sign_always : u32 = 0b00000000000000000000000000001000u32;
const flag_alternate : u32 = 0b00000000000000000000000000010000u32;
enum count { count_is(int), count_implied, }
enum ty { ty_default, ty_bits, ty_hex_upper, ty_hex_lower, ty_octal, }
// FIXME (#1993): May not want to use a vector here for flags; instead
// just use a bool per flag.
type conv = {flags: [flag]/~, width: count, precision: count, ty: ty};
type conv = {flags: u32, width: count, precision: count, ty: ty};
fn conv_int(cv: conv, i: int) -> str {
let radix = 10u;
@ -307,7 +305,6 @@ mod rt {
let s = if b { "true" } else { "false" };
// run the boolean conversion through the string conversion logic,
// giving it the same rules for precision, etc.
ret conv_str(cv, s);
}
fn conv_char(cv: conv, c: char) -> str {
@ -430,9 +427,8 @@ mod rt {
}
ret padstr + s;
}
fn have_flag(flags: [flag]/~, f: flag) -> bool {
for vec::each(flags) {|candidate| if candidate == f { ret true; } }
ret false;
fn have_flag(flags: u32, f: u32) -> bool {
flags & f != 0
}
}

View File

@ -50,19 +50,19 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
fn make_rt_conv_expr(cx: ext_ctxt, sp: span, cnv: conv) -> @ast::expr {
fn make_flags(cx: ext_ctxt, sp: span, flags: [flag]/~) -> @ast::expr {
let mut flagexprs: [@ast::expr]/~ = []/~;
let mut tmp_expr = make_rt_path_expr(cx, sp, @"flag_none");
for flags.each {|f|
let mut fstr;
alt f {
flag_left_justify { fstr = "flag_left_justify"; }
flag_left_zero_pad { fstr = "flag_left_zero_pad"; }
flag_space_for_sign { fstr = "flag_space_for_sign"; }
flag_sign_always { fstr = "flag_sign_always"; }
flag_alternate { fstr = "flag_alternate"; }
}
vec::push(flagexprs, make_rt_path_expr(cx, sp, @fstr));
let fstr = alt f {
flag_left_justify { "flag_left_justify" }
flag_left_zero_pad { "flag_left_zero_pad" }
flag_space_for_sign { "flag_space_for_sign" }
flag_sign_always { "flag_sign_always" }
flag_alternate { "flag_alternate" }
};
tmp_expr = mk_binary(cx, sp, ast::bitor, tmp_expr,
make_rt_path_expr(cx, sp, @fstr));
}
ret mk_uniq_vec_e(cx, sp, flagexprs);
ret tmp_expr;
}
fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr {
alt cnt {