From 80307576245aabf00285db020bbfbc4c3a891766 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 27 Jul 2010 19:21:51 -0700 Subject: Switch machine-type lexemes to use suffixes. Remove support for foo(bar) as a cast notation. Closes #129. --- src/Makefile | 2 + src/boot/driver/main.ml | 1 + src/boot/driver/session.ml | 3 +- src/boot/fe/ast.ml | 17 ++++--- src/boot/fe/cexp.ml | 4 +- src/boot/fe/lexer.mll | 50 ++++++++++++++---- src/boot/fe/pexp.ml | 104 ++------------------------------------ src/boot/fe/token.ml | 16 ++++-- src/boot/llvm/lltrans.ml | 6 +-- src/boot/me/semant.ml | 2 +- src/boot/me/trans.ml | 6 +-- src/boot/me/type.ml | 2 +- src/comp/fe/lexer.rs | 2 +- src/lib/_int.rs | 12 ++--- src/lib/_io.rs | 10 ++-- src/lib/_u8.rs | 2 +- src/lib/_vec.rs | 10 ++-- src/lib/deque.rs | 44 ++++++++-------- src/lib/map.rs | 30 +++++------ src/test/run-pass/i32-sub.rs | 6 +-- src/test/run-pass/i8-incr.rs | 8 +-- src/test/run-pass/u32-decr.rs | 6 +-- src/test/run-pass/u8-incr-decr.rs | 8 +-- src/test/run-pass/u8-incr.rs | 12 ++--- 24 files changed, 156 insertions(+), 207 deletions(-) diff --git a/src/Makefile b/src/Makefile index e9c9a5bb..c1e7ce41 100644 --- a/src/Makefile +++ b/src/Makefile @@ -416,6 +416,8 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \ generic-recursive-tag.rs \ generic-tag-alt.rs \ generic-tag.rs \ + i32-sub.rs \ + i8-incr.rs \ import.rs \ inner-module.rs \ iter-range.rs \ diff --git a/src/boot/driver/main.ml b/src/boot/driver/main.ml index b9045485..9af7ee0b 100644 --- a/src/boot/driver/main.ml +++ b/src/boot/driver/main.ml @@ -50,6 +50,7 @@ let (sess:Session.sess) = Session.sess_log_obj = false; Session.sess_log_lib = false; Session.sess_log_out = stdout; + Session.sess_log_err = stderr; Session.sess_trace_block = false; Session.sess_trace_drop = false; Session.sess_trace_tag = false; diff --git a/src/boot/driver/session.ml b/src/boot/driver/session.ml index 210dd7be..d9e57b02 100644 --- a/src/boot/driver/session.ml +++ b/src/boot/driver/session.ml @@ -32,6 +32,7 @@ type sess = mutable sess_log_obj: bool; mutable sess_log_lib: bool; mutable sess_log_out: out_channel; + mutable sess_log_err: out_channel; mutable sess_trace_block: bool; mutable sess_trace_drop: bool; mutable sess_trace_tag: bool; @@ -79,7 +80,7 @@ let log name flag chan = let fail sess = sess.sess_failed <- true; - Printf.fprintf sess.sess_log_out + Printf.fprintf sess.sess_log_err ;; diff --git a/src/boot/fe/ast.ml b/src/boot/fe/ast.ml index 767a6426..651b1e65 100644 --- a/src/boot/fe/ast.ml +++ b/src/boot/fe/ast.ml @@ -333,10 +333,11 @@ and expr = and lit = | LIT_nil | LIT_bool of bool - | LIT_mach of (ty_mach * int64 * string) - | LIT_int of (int64 * string) - | LIT_uint of (int64 * string) + | LIT_mach_int of (ty_mach * int64) + | LIT_int of int64 + | LIT_uint of int64 | LIT_char of int + (* FIXME: No support for LIT_mach_float or LIT_float yet. *) and lval_component = @@ -835,13 +836,15 @@ and fmt_lit (ff:Format.formatter) (l:lit) : unit = | LIT_nil -> fmt ff "()" | LIT_bool true -> fmt ff "true" | LIT_bool false -> fmt ff "false" - | LIT_mach (m, _, s) -> + | LIT_mach_int (m, i) -> begin + fmt ff "%Ld" i; fmt_mach ff m; - fmt ff "(%s)" s end - | LIT_int (_,s) -> fmt ff "%s" s - | LIT_uint (_,s) -> fmt ff "%s" s + | LIT_int i -> fmt ff "%Ld" i + | LIT_uint i -> + fmt ff "%Ld" i; + fmt ff "u" | LIT_char c -> fmt ff "'%s'" (Common.escaped_char c) and fmt_domain (ff:Format.formatter) (d:domain) : unit = diff --git a/src/boot/fe/cexp.ml b/src/boot/fe/cexp.ml index 5d3a99ef..fc849b28 100644 --- a/src/boot/fe/cexp.ml +++ b/src/boot/fe/cexp.ml @@ -527,7 +527,9 @@ and eval_pexp (env:env) (exp:Pexp.pexp) : pval = | Pexp.PEXP_lit (Ast.LIT_bool b) -> PVAL_bool b - | Pexp.PEXP_lit (Ast.LIT_int (i, _)) -> + | Pexp.PEXP_lit (Ast.LIT_int i) + | Pexp.PEXP_lit (Ast.LIT_uint i) + | Pexp.PEXP_lit (Ast.LIT_mach_int (_, i)) -> PVAL_num i | Pexp.PEXP_str s -> diff --git a/src/boot/fe/lexer.mll b/src/boot/fe/lexer.mll index 090da25f..bb1d881e 100644 --- a/src/boot/fe/lexer.mll +++ b/src/boot/fe/lexer.mll @@ -22,7 +22,24 @@ Lexing.pos_bol = p.Lexing.pos_cnum } ;; + let mach_suf_table = Hashtbl.create 0 + ;; + let _ = + List.iter (fun (suf, ty) -> Common.htab_put mach_suf_table suf ty) + [ ("u8", Common.TY_u8); + ("i8", Common.TY_i8); + ("u16", Common.TY_u16); + ("i16", Common.TY_i16); + ("u32", Common.TY_u32); + ("i32", Common.TY_i32); + ("u64", Common.TY_u64); + ("i64", Common.TY_i64); + ("f32", Common.TY_f32); + ("f64", Common.TY_f64); ] + ;; + let keyword_table = Hashtbl.create 100 + ;; let _ = List.iter (fun (kwd, tok) -> Common.htab_put keyword_table kwd tok) [ ("mod", MOD); @@ -129,6 +146,9 @@ let dec = decdig ['0'-'9' '_']* let exp = ['e''E']['-''+']? dec let flo = (dec '.' dec (exp?)) | (dec exp) +let mach_float_suf = "f32"|"f64" +let mach_int_suf = ['u''i']('8'|"16"|"32"|"64") + let ws = [ ' ' '\t' '\r' ] let id = ['a'-'z' 'A'-'Z' '_']['a'-'z' 'A'-'Z' '0'-'9' '_']* @@ -197,19 +217,29 @@ rule token = parse { try Hashtbl.find keyword_table i with - Not_found -> IDENT (i) - } + Not_found -> IDENT (i) } + +| (bin|hex|dec) as n { LIT_INT (Int64.of_string n) } +| ((bin|hex|dec) as n) 'u' { LIT_UINT (Int64.of_string n) } +| ((bin|hex|dec) as n) + (mach_int_suf as s) { try + let tm = + Hashtbl.find mach_suf_table s + in + LIT_MACH_INT + (tm, Int64.of_string n) + with + Not_found -> + fail lexbuf + "bad mach-int suffix" } -| bin as n { LIT_INT (Int64.of_string n, n) } -| hex as n { LIT_INT (Int64.of_string n, n) } -| dec as n { LIT_INT (Int64.of_string n, n) } -| flo as n { LIT_FLO n } +| flo as n { LIT_FLOAT (float_of_string n) } -| '\'' { char lexbuf } -| '"' { let buf = Buffer.create 32 in - str buf lexbuf } +| '\'' { char lexbuf } +| '"' { let buf = Buffer.create 32 in + str buf lexbuf } -| eof { EOF } +| eof { EOF } and str buf = parse _ as ch diff --git a/src/boot/fe/pexp.ml b/src/boot/fe/pexp.ml index 72fa9d7e..1532a47a 100644 --- a/src/boot/fe/pexp.ml +++ b/src/boot/fe/pexp.ml @@ -466,7 +466,9 @@ and parse_rec_body (ps:pstate) : pexp' = (*((Ast.ident * pexp) array) =*) and parse_lit (ps:pstate) : Ast.lit = match peek ps with - LIT_INT (n,s) -> (bump ps; Ast.LIT_int (n,s)) + LIT_INT i -> (bump ps; Ast.LIT_int i) + | LIT_UINT i -> (bump ps; Ast.LIT_uint i) + | LIT_MACH_INT (tm, i) -> (bump ps; Ast.LIT_mach_int (tm, i)) | LIT_CHAR c -> (bump ps; Ast.LIT_char c) | LIT_BOOL b -> (bump ps; Ast.LIT_bool b) | _ -> raise (unexpected ps) @@ -602,106 +604,6 @@ and parse_bottom_pexp (ps:pstate) : pexp = let bpos = lexpos ps in span ps apos bpos (PEXP_lval (PLVAL_ext_deref inner)) - | (INT | UINT | CHAR | BOOL) as tok -> - begin - bump ps; - expect ps LPAREN; - match peek ps with - (LIT_INT _ | LIT_CHAR _ | LIT_BOOL _) as tok2 -> - bump ps; - expect ps RPAREN; - let i = match tok2 with - LIT_INT i -> i - | LIT_CHAR c -> (Int64.of_int c, - Common.escaped_char c) - | LIT_BOOL b -> if b then (1L, "1") else (0L, "0") - | _ -> bug () "expected int/char literal" - in - let bpos = lexpos ps in - span ps apos bpos - (PEXP_lit - (match tok with - INT -> Ast.LIT_int i - | UINT -> Ast.LIT_uint i - | CHAR -> - Ast.LIT_char - (Int64.to_int (fst i)) - | BOOL -> Ast.LIT_bool (fst i <> 0L) - | _ -> bug () "expected int/uint/char/bool token")) - - | _ -> - let pexp = parse_pexp ps in - expect ps RPAREN; - let bpos = lexpos ps in - let t = - match tok with - INT -> Ast.TY_int - | UINT -> Ast.TY_uint - | CHAR -> Ast.TY_char - | BOOL -> Ast.TY_bool - | _ -> bug () "expected int/uint/char/bool token" - in - let t = span ps apos bpos t in - span ps apos bpos - (PEXP_unop ((Ast.UNOP_cast t), pexp)) - end - - | MACH m -> - let literal (num, str) = - let _ = bump ps in - let _ = expect ps RPAREN in - let bpos = lexpos ps in - let check_range (lo:int64) (hi:int64) : unit = - if (num < lo) or (num > hi) - then raise (err (Printf.sprintf - "integral literal %Ld out of range [%Ld,%Ld]" - num lo hi) ps) - else () - in - begin - match m with - TY_u8 -> check_range 0L 0xffL - | TY_u16 -> check_range 0L 0xffffL - | TY_u32 -> check_range 0L 0xffffffffL - (* | TY_u64 -> ... *) - | TY_i8 -> check_range (-128L) 127L - | TY_i16 -> check_range (-32768L) 32767L - | TY_i32 -> check_range (-2147483648L) 2147483647L - (* - | TY_i64 -> ... - | TY_f32 -> ... - | TY_f64 -> ... - *) - | _ -> () - end; - span ps apos bpos - (PEXP_lit - (Ast.LIT_mach - (m, num, str))) - - in - begin - bump ps; - expect ps LPAREN; - match peek ps with - LIT_INT (n,s) -> literal (n,s) - | MINUS -> - begin - bump ps; - match peek ps with - LIT_INT (n,s) -> - literal (Int64.neg n, "-" ^ s) - | _ -> raise (unexpected ps) - end - | _ -> - let pexp = parse_pexp ps in - expect ps RPAREN; - let bpos = lexpos ps in - let t = span ps apos bpos (Ast.TY_mach m) in - span ps apos bpos - (PEXP_unop ((Ast.UNOP_cast t), pexp)) - end - | POUND -> bump ps; let name = parse_name ps in diff --git a/src/boot/fe/token.ml b/src/boot/fe/token.ml index cb3bb0b0..64aef2a4 100644 --- a/src/boot/fe/token.ml +++ b/src/boot/fe/token.ml @@ -103,8 +103,11 @@ type token = | JOIN (* Literals *) - | LIT_INT of (int64 * string) - | LIT_FLO of string + | LIT_INT of int64 + | LIT_UINT of int64 + | LIT_FLOAT of float + | LIT_MACH_INT of Common.ty_mach * int64 + | LIT_MACH_FLOAT of Common.ty_mach * float | LIT_STR of string | LIT_CHAR of int | LIT_BOOL of bool @@ -253,8 +256,13 @@ let rec string_of_tok t = | JOIN -> "join" (* Literals *) - | LIT_INT (_,s) -> s - | LIT_FLO n -> n + | LIT_INT i -> Int64.to_string i + | LIT_UINT i -> (Int64.to_string i) ^ "u" + | LIT_FLOAT s -> string_of_float s + | LIT_MACH_INT (tm, i) -> + (Int64.to_string i) ^ (Common.string_of_ty_mach tm) + | LIT_MACH_FLOAT (tm, f) -> + (string_of_float f) ^ (Common.string_of_ty_mach tm) | LIT_STR s -> ("\"" ^ (String.escaped s) ^ "\"") | LIT_CHAR c -> ("'" ^ (Common.escaped_char c) ^ "'") | LIT_BOOL b -> if b then "true" else "false" diff --git a/src/boot/llvm/lltrans.ml b/src/boot/llvm/lltrans.ml index e191ce01..ee192725 100644 --- a/src/boot/llvm/lltrans.ml +++ b/src/boot/llvm/lltrans.ml @@ -746,12 +746,12 @@ let trans_crate Ast.LIT_nil -> llnil | Ast.LIT_bool value -> Llvm.const_int (Llvm.i1_type llctx) (if value then 1 else 0) - | Ast.LIT_mach (mty, value, _) -> + | Ast.LIT_mach_int (mty, value) -> let llty = trans_mach_ty mty in Llvm.const_of_int64 llty value (mach_is_signed mty) - | Ast.LIT_int (value, _) -> + | Ast.LIT_int value -> Llvm.const_of_int64 (Llvm.i32_type llctx) value true - | Ast.LIT_uint (value, _) -> + | Ast.LIT_uint value -> Llvm.const_of_int64 (Llvm.i32_type llctx) value false | Ast.LIT_char ch -> Llvm.const_int (Llvm.i32_type llctx) ch diff --git a/src/boot/me/semant.ml b/src/boot/me/semant.ml index 7a9aa922..16331e36 100644 --- a/src/boot/me/semant.ml +++ b/src/boot/me/semant.ml @@ -1204,7 +1204,7 @@ let rec atom_type (cx:ctxt) (at:Ast.atom) : Ast.ty = | Ast.ATOM_literal {node=(Ast.LIT_bool _); id=_} -> Ast.TY_bool | Ast.ATOM_literal {node=(Ast.LIT_char _); id=_} -> Ast.TY_char | Ast.ATOM_literal {node=(Ast.LIT_nil); id=_} -> Ast.TY_nil - | Ast.ATOM_literal {node=(Ast.LIT_mach (m,_,_)); id=_} -> Ast.TY_mach m + | Ast.ATOM_literal {node=(Ast.LIT_mach_int (m,_)); id=_} -> Ast.TY_mach m | Ast.ATOM_lval lv -> lval_ty cx lv ;; diff --git a/src/boot/me/trans.ml b/src/boot/me/trans.ml index 5584b485..55ccadf7 100644 --- a/src/boot/me/trans.ml +++ b/src/boot/me/trans.ml @@ -1268,9 +1268,9 @@ let trans_visitor | Ast.LIT_bool false -> imm_false | Ast.LIT_bool true -> imm_true | Ast.LIT_char c -> imm_of_ty (Int64.of_int c) TY_u32 - | Ast.LIT_int (i, _) -> simm i - | Ast.LIT_uint (i, _) -> imm i - | Ast.LIT_mach (m, n, _) -> imm_of_ty n m + | Ast.LIT_int i -> simm i + | Ast.LIT_uint i -> imm i + | Ast.LIT_mach_int (m, n) -> imm_of_ty n m and trans_atom (atom:Ast.atom) : Il.operand = iflog diff --git a/src/boot/me/type.ml b/src/boot/me/type.ml index ce5cf9f4..57fdc457 100644 --- a/src/boot/me/type.ml +++ b/src/boot/me/type.ml @@ -223,7 +223,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) = match lit with Ast.LIT_nil -> Ast.TY_nil | Ast.LIT_bool _ -> Ast.TY_bool - | Ast.LIT_mach (mty, _, _) -> Ast.TY_mach mty + | Ast.LIT_mach_int (mty, _) -> Ast.TY_mach mty | Ast.LIT_int _ -> Ast.TY_int | Ast.LIT_uint _ -> Ast.TY_uint | Ast.LIT_char _ -> Ast.TY_char diff --git a/src/comp/fe/lexer.rs b/src/comp/fe/lexer.rs index 37684c22..87809b3b 100644 --- a/src/comp/fe/lexer.rs +++ b/src/comp/fe/lexer.rs @@ -3,7 +3,7 @@ import std._io.buf_reader; iter buffers(buf_reader rdr) -> vec[u8] { while (true) { let vec[u8] v = rdr.read(); - if (std._vec.len[u8](v) == uint(0)) { + if (std._vec.len[u8](v) == 0u) { ret; } put v; diff --git a/src/lib/_int.rs b/src/lib/_int.rs index b6399669..29144a82 100644 --- a/src/lib/_int.rs +++ b/src/lib/_int.rs @@ -23,19 +23,19 @@ iter range(mutable int lo, int hi) -> int { iter urange(mutable uint lo, uint hi) -> uint { while (lo < hi) { put lo; - lo += uint(1); + lo += 1u; } } fn next_power_of_two(uint n) -> uint { // FIXME change |* uint(4)| below to |* uint(8) / uint(2)| and watch the // world explode. - let uint halfbits = sys.rustrt.size_of[uint]() * uint(4); - let uint tmp = n - uint(1); - let uint shift = uint(1); + let uint halfbits = sys.rustrt.size_of[uint]() * 4u; + let uint tmp = n - 1u; + let uint shift = 1u; while (shift <= halfbits) { tmp |= tmp >> shift; - shift <<= uint(1); + shift <<= 1u; } - ret tmp + uint(1); + ret tmp + 1u; } diff --git a/src/lib/_io.rs b/src/lib/_io.rs index e171e617..94021aa6 100644 --- a/src/lib/_io.rs +++ b/src/lib/_io.rs @@ -3,15 +3,15 @@ type buf_reader = unsafe obj { }; fn default_bufsz() -> uint { - ret uint(4096); + ret 4096u; } fn new_buf() -> vec[u8] { let vec[u8] v = vec(); let uint i = default_bufsz(); - while (i > uint(0)) { - i -= uint(1); - v += vec(u8(0)); + while (i > 0u) { + i -= 1u; + v += vec(0u8); } // FIXME (issue #93): should be: // ret _vec.alloc[u8](default_bufsz()); @@ -25,7 +25,7 @@ fn new_buf_reader(str s) -> buf_reader { fn read() -> vec[u8] { // Ensure our buf is singly-referenced. - if (_vec.rustrt.refcount[u8](buf) != uint(1)) { + if (_vec.rustrt.refcount[u8](buf) != 1u) { buf = new_buf(); } diff --git a/src/lib/_u8.rs b/src/lib/_u8.rs index e1f671e7..7749e30e 100644 --- a/src/lib/_u8.rs +++ b/src/lib/_u8.rs @@ -14,7 +14,7 @@ fn gt(u8 x, u8 y) -> bool { ret x > y; } iter range(mutable u8 lo, u8 hi) -> u8 { while (lo < hi) { put lo; - lo += u8(1); + lo += 1u8; } } diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs index 849e750a..0008295f 100644 --- a/src/lib/_vec.rs +++ b/src/lib/_vec.rs @@ -21,8 +21,8 @@ type init_op[T] = fn(uint i) -> T; fn init_fn[T](&init_op[T] op, uint n_elts) -> vec[T] { let vec[T] v = alloc[T](n_elts); let uint i = n_elts; - while (i > uint(0)) { - i -= uint(1); + while (i > 0u) { + i -= 1u; v += vec(op(i)); } ret v; @@ -38,8 +38,8 @@ fn init_elt[T](&T t, uint n_elts) -> vec[T] { */ let vec[T] v = alloc[T](n_elts); let uint i = n_elts; - while (i > uint(0)) { - i -= uint(1); + while (i > 0u) { + i -= 1u; v += vec(t); } ret v; @@ -59,7 +59,7 @@ fn slice[T](vec[T] v, int start, int end) -> vec[T] { check(start <= end); // FIXME #108: This doesn't work yet. //check(end <= int(len[T](v))); - auto result = alloc[T](uint(end - start)); + auto result = alloc[T]((end - start) as uint); let mutable int i = start; while (i < end) { result += vec(v.(i)); diff --git a/src/lib/deque.rs b/src/lib/deque.rs index b41c051f..699b3f0d 100644 --- a/src/lib/deque.rs +++ b/src/lib/deque.rs @@ -23,7 +23,7 @@ fn create[T]() -> t[T] { type cell[T] = mutable util.option[T]; - let uint initial_capacity = uint(32); // 2^5 + let uint initial_capacity = 32u; // 2^5 /** * Grow is only called on full elts, so nelts is also len(elts), unlike @@ -34,13 +34,13 @@ fn create[T]() -> t[T] { fn fill[T](uint i, uint nelts, uint lo, &vec[cell[T]] old) -> cell[T] { if (i < nelts) { - ret old.(int((lo + i) % nelts)); + ret old.(((lo + i) % nelts) as int); } else { ret util.none[T](); } } - let uint nalloc = _int.next_power_of_two(nelts + uint(1)); + let uint nalloc = _int.next_power_of_two(nelts + 1u); let _vec.init_op[cell[T]] copy_op = bind fill[T](_, nelts, lo, elts); ret _vec.init_fn[cell[T]](copy_op, nalloc); } @@ -52,7 +52,7 @@ fn create[T]() -> t[T] { */ fn get[T](&vec[cell[T]] elts, uint i) -> T { - alt (elts.(int(i))) { + alt (elts.(i as int)) { case (util.some[T](t)) { ret t; } case (_) { fail; } } @@ -68,33 +68,33 @@ fn create[T]() -> t[T] { fn add_front(&T t) { let uint oldlo = lo; - if (lo == uint(0)) { - lo = _vec.len[cell[T]](elts) - uint(1); + if (lo == 0u) { + lo = _vec.len[cell[T]](elts) - 1u; } else { - lo -= uint(1); + lo -= 1u; } if (lo == hi) { elts = grow[T](nelts, oldlo, elts); - lo = _vec.len[cell[T]](elts) - uint(1); - hi = nelts - uint(1); + lo = _vec.len[cell[T]](elts) - 1u; + hi = nelts - 1u; } - elts.(int(lo)) = util.some[T](t); - nelts += uint(1); + elts.(lo as int) = util.some[T](t); + nelts += 1u; } fn add_back(&T t) { - hi = (hi + uint(1)) % _vec.len[cell[T]](elts); + hi = (hi + 1u) % _vec.len[cell[T]](elts); if (lo == hi) { elts = grow[T](nelts, lo, elts); - lo = uint(0); + lo = 0u; hi = nelts; } - elts.(int(hi)) = util.some[T](t); - nelts += uint(1); + elts.(hi as int) = util.some[T](t); + nelts += 1u; } /** @@ -103,19 +103,19 @@ fn create[T]() -> t[T] { */ fn pop_front() -> T { let T t = get[T](elts, lo); - elts.(int(lo)) = util.none[T](); - lo = (lo + uint(1)) % _vec.len[cell[T]](elts); + elts.(lo as int) = util.none[T](); + lo = (lo + 1u) % _vec.len[cell[T]](elts); ret t; } fn pop_back() -> T { let T t = get[T](elts, hi); - elts.(int(hi)) = util.none[T](); + elts.(hi as int) = util.none[T](); - if (hi == uint(0)) { - hi = _vec.len[cell[T]](elts) - uint(1); + if (hi == 0u) { + hi = _vec.len[cell[T]](elts) - 1u; } else { - hi -= uint(1); + hi -= 1u; } ret t; @@ -133,5 +133,5 @@ fn create[T]() -> t[T] { let vec[cell[T]] v = _vec.init_elt[cell[T]](util.none[T](), initial_capacity); - ret deque[T](uint(0), uint(0), uint(0), v); + ret deque[T](0u, 0u, 0u, v); } diff --git a/src/lib/map.rs b/src/lib/map.rs index 06139bb7..540dfd00 100644 --- a/src/lib/map.rs +++ b/src/lib/map.rs @@ -23,7 +23,7 @@ type hashmap[K, V] = obj { fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] { - let uint initial_capacity = uint(32); // 2^5 + let uint initial_capacity = 32u; // 2^5 let util.rational load_factor = rec(num=3, den=4); type bucket[V] = tag(nil(), deleted(), some(V)); @@ -43,13 +43,13 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] { // fixed key. fn hashl[K](hashfn[K] hasher, uint nbkts, &K key) -> uint { - ret (hasher(key) >>> (sys.rustrt.size_of[uint]() * uint(8) / uint(2))) + ret (hasher(key) >>> (sys.rustrt.size_of[uint]() * 8u / 2u)) % nbkts; } fn hashr[K](hashfn[K] hasher, uint nbkts, &K key) -> uint { - ret ((((~ uint(0)) >>> (sys.rustrt.size_of[uint]() * uint(8) / uint(2))) - & hasher(key)) * uint(2) + uint(1)) + ret ((((~ 0u) >>> (sys.rustrt.size_of[uint]() * 8u / 2u)) + & hasher(key)) * 2u + 1u) % nbkts; } @@ -63,10 +63,10 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] { &K key) -> util.option[V] { - let uint i = uint(0); + let uint i = 0u; while (i < nbkts) { // Pending fix to issue #94, remove uint coercion. - let int j = int(hash[K](hasher, nbkts, key, i)); + let int j = (hash[K](hasher, nbkts, key, i)) as int; alt (bkts.(j)) { case (some[V](val)) { ret util.some[V](val); @@ -75,7 +75,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] { ret util.none[V](); } case (deleted[V]()) { - i += uint(1); + i += 1u; } } } @@ -91,17 +91,17 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] { { fn insert(&K key, &V val) { // FIXME grow the table and rehash if we ought to. - let uint i = uint(0); + let uint i = 0u; while (i < nbkts) { // Issue #94, as in find_common() - let int j = int(hash[K](hasher, nbkts, key, i)); + let int j = (hash[K](hasher, nbkts, key, i)) as int; alt (bkts.(j)) { case (some[V](_)) { - i += uint(1); + i += 1u; } case (_) { bkts.(j) = some[V](val); - nelts += uint(1); + nelts += 1u; ret; } } @@ -129,17 +129,17 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] { } fn remove(&K key) -> util.option[V] { - let uint i = uint(0); + let uint i = 0u; while (i < nbkts) { // Issue #94, as in find_common() - let int j = int(hash[K](hasher, nbkts, key, i)); + let int j = (hash[K](hasher, nbkts, key, i)) as int; alt (bkts.(j)) { case (some[V](val)) { bkts.(j) = deleted[V](); ret util.some[V](val); } case (deleted[V]()) { - nelts += uint(1); + nelts += 1u; } case (nil[V]()) { ret util.none[V](); @@ -155,5 +155,5 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] { let vec[mutable bucket[V]] bkts = _vec.init_elt[mutable bucket[V]](nil[V](), initial_capacity); - ret hashmap[K, V](hasher, eqer, bkts, uint(0), uint(0), load_factor); + ret hashmap[K, V](hasher, eqer, bkts, 0u, 0u, load_factor); } diff --git a/src/test/run-pass/i32-sub.rs b/src/test/run-pass/i32-sub.rs index 99bd3936..3f00acb1 100644 --- a/src/test/run-pass/i32-sub.rs +++ b/src/test/run-pass/i32-sub.rs @@ -1,8 +1,8 @@ // -*- rust -*- fn main() { - let i32 x = i32(-400); - x = i32(0) - x; - check(x == i32(400)); + let i32 x = -400_i32; + x = 0_i32 - x; + check(x == 400_i32); } diff --git a/src/test/run-pass/i8-incr.rs b/src/test/run-pass/i8-incr.rs index 57029a13..fb387d31 100644 --- a/src/test/run-pass/i8-incr.rs +++ b/src/test/run-pass/i8-incr.rs @@ -1,9 +1,9 @@ // -*- rust -*- fn main() { - let i8 x = i8(-12); - let i8 y = i8(-12); - x = x + i8(1); - x = x - i8(1); + let i8 x = -12i8; + let i8 y = -12i8; + x = x + 1i8; + x = x - 1i8; check(x == y); } diff --git a/src/test/run-pass/u32-decr.rs b/src/test/run-pass/u32-decr.rs index cdafa0bf..1ff511aa 100644 --- a/src/test/run-pass/u32-decr.rs +++ b/src/test/run-pass/u32-decr.rs @@ -1,8 +1,8 @@ // -*- rust -*- fn main() { - let u32 word = (200000 as u32); - word = word - (1 as u32); - check(word == (199999 as u32)); + let u32 word = (200000u32); + word = word - (1u32); + check(word == (199999u32)); } diff --git a/src/test/run-pass/u8-incr-decr.rs b/src/test/run-pass/u8-incr-decr.rs index b4028f50..f89325fc 100644 --- a/src/test/run-pass/u8-incr-decr.rs +++ b/src/test/run-pass/u8-incr-decr.rs @@ -4,9 +4,9 @@ // in the rest of the generated code so they're easily grep-able. fn main() { - let u8 x = 19 as u8; // 0x13 - let u8 y = 35 as u8; // 0x23 - x = x + (7 as u8); // 0x7 - y = y - (9 as u8); // 0x9 + let u8 x = 19u8; // 0x13 + let u8 y = 35u8; // 0x23 + x = x + (7u8); // 0x7 + y = y - (9u8); // 0x9 check(x == y); } diff --git a/src/test/run-pass/u8-incr.rs b/src/test/run-pass/u8-incr.rs index 146801e9..602d83c6 100644 --- a/src/test/run-pass/u8-incr.rs +++ b/src/test/run-pass/u8-incr.rs @@ -1,12 +1,12 @@ // -*- rust -*- fn main() { - let u8 x = 12 as u8; - let u8 y = 12 as u8; - x = x + (1 as u8); - x = x - (1 as u8); + let u8 x = 12u8; + let u8 y = 12u8; + x = x + (1u8); + x = x - (1u8); check(x == y); - //x = 14 as u8; - //x = x + 1 as u8; + // x = 14u8; + // x = x + 1u8; } -- cgit v1.2.3