diff --git a/src/comp/front/creader.rs b/src/comp/front/creader.rs index 8ef75e5460ad..42bc51304068 100644 --- a/src/comp/front/creader.rs +++ b/src/comp/front/creader.rs @@ -35,18 +35,18 @@ type str_def = fn(str) -> ast.def_id; type pstate = rec(str rep, mutable uint pos, uint len); -fn peek(@pstate st) -> char { - if (st.pos < st.len) {ret st.rep.(st.pos) as char;} - else {ret ' ';} +fn peek(@pstate st) -> u8 { + if (st.pos < st.len) {ret st.rep.(st.pos) as u8;} + else {ret ' ' as u8;} } -impure fn next(@pstate st) -> char { // ?? somehow not recognized as impure +impure fn next(@pstate st) -> u8 { // ?? somehow not recognized as impure if (st.pos >= st.len) {fail;} auto ch = st.rep.(st.pos); st.pos = st.pos + 1u; - ret ch as char; + ret ch as u8; } -fn parse_ty_str(str rep, str_def sd) -> @ty.t { +impure fn parse_ty_str(str rep, str_def sd) -> @ty.t { auto len = _str.byte_len(rep); auto st = @rec(rep=rep, mutable pos=0u, len=len); auto result = parse_ty(st, sd); @@ -61,7 +61,7 @@ impure fn parse_ty(@pstate st, str_def sd) -> @ty.t { impure fn parse_mt(@pstate st, str_def sd) -> ty.mt { auto mut; - alt (peek(st)) { + alt (peek(st) as char) { case ('m') {next(st); mut = ast.mut;} case ('?') {next(st); mut = ast.maybe_mut;} case (_) {mut=ast.imm;} @@ -70,13 +70,13 @@ impure fn parse_mt(@pstate st, str_def sd) -> ty.mt { } impure fn parse_sty(@pstate st, str_def sd) -> ty.sty { - alt (next(st)) { + alt (next(st) as char) { case ('n') {ret ty.ty_nil;} case ('b') {ret ty.ty_bool;} case ('i') {ret ty.ty_int;} case ('u') {ret ty.ty_uint;} case ('M') { - alt (next(st)) { + alt (next(st) as char) { case ('b') {ret ty.ty_machine(common.ty_u8);} case ('w') {ret ty.ty_machine(common.ty_u16);} case ('l') {ret ty.ty_machine(common.ty_u32);} @@ -92,13 +92,15 @@ impure fn parse_sty(@pstate st, str_def sd) -> ty.sty { case ('c') {ret ty.ty_char;} case ('s') {ret ty.ty_str;} case ('t') { - check(next(st) == '['); + check(next(st) as char == '['); auto def = ""; - while (peek(st) != '|') {def += _str.from_char(next(st));} + while (peek(st) as char != '|') { + def += _str.unsafe_from_byte(next(st)); + } st.pos = st.pos + 1u; let vec[@ty.t] params = vec(); - while (peek(st) != ']') { - params = _vec.push[@ty.t](params, parse_ty(st, sd)); + while (peek(st) as char != ']') { + params += vec(parse_ty(st, sd)); } st.pos = st.pos + 1u; ret ty.ty_tag(sd(def), params); @@ -108,23 +110,24 @@ impure fn parse_sty(@pstate st, str_def sd) -> ty.sty { case ('P') {ret ty.ty_port(parse_ty(st, sd));} case ('C') {ret ty.ty_chan(parse_ty(st, sd));} case ('T') { - check(next(st) == '['); + check(next(st) as char == '['); let vec[ty.mt] params = vec(); - while (peek(st) != ']') { - params = _vec.push[ty.mt](params, parse_mt(st, sd)); + while (peek(st) as char != ']') { + params += vec(parse_mt(st, sd)); } st.pos = st.pos + 1u; ret ty.ty_tup(params); } case ('R') { - check(next(st) == '['); + check(next(st) as char == '['); let vec[ty.field] fields = vec(); - while (peek(st) != ']') { + while (peek(st) as char != ']') { auto name = ""; - while (peek(st) != '=') {name += _str.from_char(next(st));} + while (peek(st) as char != '=') { + name += _str.unsafe_from_byte(next(st)); + } st.pos = st.pos + 1u; - fields = _vec.push[ty.field] - (fields, rec(ident=name, mt=parse_mt(st, sd))); + fields += vec(rec(ident=name, mt=parse_mt(st, sd))); } st.pos = st.pos + 1u; ret ty.ty_rec(fields); @@ -139,7 +142,7 @@ impure fn parse_sty(@pstate st, str_def sd) -> ty.sty { } case ('N') { auto abi; - alt (next(st)) { + alt (next(st) as char) { case ('r') {abi = ast.native_abi_rust;} case ('c') {abi = ast.native_abi_cdecl;} } @@ -147,22 +150,23 @@ impure fn parse_sty(@pstate st, str_def sd) -> ty.sty { ret ty.ty_native_fn(abi,func._0,func._1); } case ('O') { - check(next(st) == '['); + check(next(st) as char == '['); let vec[ty.method] methods = vec(); - while (peek(st) != ']') { + while (peek(st) as char != ']') { auto proto; - alt (next(st)) { + alt (next(st) as char) { case ('W') {proto = ast.proto_iter;} case ('F') {proto = ast.proto_fn;} } auto name = ""; - while (peek(st) != '[') {name += _str.from_char(next(st));} + while (peek(st) as char != '[') { + name += _str.unsafe_from_byte(next(st)); + } auto func = parse_ty_fn(st, sd); - methods = _vec.push[ty.method] - (methods, rec(proto=proto, - ident=name, - inputs=func._0, - output=func._1)); + methods += vec(rec(proto=proto, + ident=name, + inputs=func._0, + output=func._1)); } ret ty.ty_obj(methods); } @@ -174,7 +178,7 @@ impure fn parse_sty(@pstate st, str_def sd) -> ty.sty { impure fn parse_int(@pstate st) -> int { auto n = 0; while (true) { - auto cur = peek(st); + auto cur = peek(st) as char; if (cur < '0' || cur > '9') {break;} st.pos = st.pos + 1u; n *= 10; @@ -184,16 +188,15 @@ impure fn parse_int(@pstate st) -> int { } impure fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], @ty.t) { - check(next(st) == '['); + check(next(st) as char == '['); let vec[ty.arg] inputs = vec(); - while (peek(st) != ']') { + while (peek(st) as char != ']') { auto mode = ast.val; - if (peek(st) == '&') { + if (peek(st) as char == '&') { mode = ast.alias; st.pos = st.pos + 1u; } - inputs = _vec.push[ty.arg] - (inputs, rec(mode=mode, ty=parse_ty(st, sd))); + inputs += vec(rec(mode=mode, ty=parse_ty(st, sd))); } st.pos = st.pos + 1u; ret tup(inputs, parse_ty(st, sd));