about summary refs log tree commit diff
path: root/src/comp/front
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2010-11-22 17:41:26 -0800
committerGraydon Hoare <graydon@mozilla.com>2010-11-22 17:41:32 -0800
commite05d7c3ac1e72edff337719fe58da69e959c4cf4 (patch)
treeb040d23dac019f8caf1157b385e4b6f915696815 /src/comp/front
parent3e01b2d529a81ac7b2d7ba3deb5d1f116efc7b34 (diff)
Support mach types in rustc, enable 5 more tests.
Diffstat (limited to 'src/comp/front')
-rw-r--r--src/comp/front/ast.rs2
-rw-r--r--src/comp/front/lexer.rs129
-rw-r--r--src/comp/front/parser.rs4
3 files changed, 101 insertions, 34 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 3a67d2f273c..ddd02a03125 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -4,6 +4,7 @@ import std.option;
 import middle.typeck;
 import util.common.span;
 import util.common.spanned;
+import util.common.ty_mach;
 
 type ident = str;
 
@@ -116,6 +117,7 @@ tag lit_ {
     lit_char(char);
     lit_int(int);
     lit_uint(uint);
+    lit_mach_int(ty_mach, int);
     lit_nil;
     lit_bool(bool);
 }
diff --git a/src/comp/front/lexer.rs b/src/comp/front/lexer.rs
index 38e9367f5a2..0506ce6c360 100644
--- a/src/comp/front/lexer.rs
+++ b/src/comp/front/lexer.rs
@@ -302,9 +302,102 @@ impure fn consume_block_comment(reader rdr) {
     be consume_any_whitespace(rdr);
 }
 
+impure fn scan_number(mutable char c, reader rdr) -> token.token {
+    auto accum_int = 0;
+    auto n = rdr.next();
+
+    if (c == '0' && n == 'x') {
+        rdr.bump();
+        rdr.bump();
+        c = rdr.curr();
+        while (is_hex_digit(c) || c == '_') {
+            if (c != '_') {
+                accum_int *= 16;
+                accum_int += hex_digit_val(c);
+            }
+            rdr.bump();
+            c = rdr.curr();
+        }
+    }
+
+    if (c == '0' && n == 'b') {
+        rdr.bump();
+        rdr.bump();
+        c = rdr.curr();
+        while (is_bin_digit(c) || c == '_') {
+            if (c != '_') {
+                accum_int *= 2;
+                accum_int += bin_digit_value(c);
+            }
+            rdr.bump();
+            c = rdr.curr();
+        }
+    }
+
+    while (is_dec_digit(c) || c == '_') {
+        if (c != '_') {
+            accum_int *= 10;
+            accum_int += dec_digit_val(c);
+        }
+        rdr.bump();
+        c = rdr.curr();
+    }
+
+    if (c == 'u' || c == 'i') {
+        let bool signed = (c == 'i');
+        rdr.bump();
+        c = rdr.curr();
+        if (c == '8') {
+            rdr.bump();
+            if (signed) {
+                ret token.LIT_MACH_INT(common.ty_i8, accum_int);
+            } else {
+                ret token.LIT_MACH_INT(common.ty_u8, accum_int);
+            }
+        }
+
+        n = rdr.next();
+        if (c == '1' && n == '6') {
+            rdr.bump();
+            rdr.bump();
+            if (signed) {
+                ret token.LIT_MACH_INT(common.ty_i16, accum_int);
+            } else {
+                ret token.LIT_MACH_INT(common.ty_u16, accum_int);
+            }
+        }
+        if (c == '3' && n == '2') {
+            rdr.bump();
+            rdr.bump();
+            if (signed) {
+                ret token.LIT_MACH_INT(common.ty_i32, accum_int);
+            } else {
+                ret token.LIT_MACH_INT(common.ty_u32, accum_int);
+            }
+        }
+
+        if (c == '6' && n == '4') {
+            rdr.bump();
+            rdr.bump();
+            if (signed) {
+                ret token.LIT_MACH_INT(common.ty_i64, accum_int);
+            } else {
+                ret token.LIT_MACH_INT(common.ty_u64, accum_int);
+            }
+        }
+
+        if (signed) {
+            ret token.LIT_INT(accum_int);
+        } else {
+            // FIXME: should cast in the target bit-width.
+            ret token.LIT_UINT(accum_int as uint);
+        }
+    }
+    ret token.LIT_INT(accum_int);
+}
+
 impure fn next_token(reader rdr) -> token.token {
     auto accum_str = "";
-    auto accum_int = 0;
 
     consume_any_whitespace(rdr);
 
@@ -328,39 +421,7 @@ impure fn next_token(reader rdr) -> token.token {
     }
 
     if (is_dec_digit(c)) {
-        auto n = rdr.next();
-        if (c == '0' && n == 'x') {
-            rdr.bump();
-            rdr.bump();
-            c = rdr.curr();
-            while (is_hex_digit(c) || c == '_') {
-                accum_int *= 16;
-                accum_int += hex_digit_val(c);
-                rdr.bump();
-                c = rdr.curr();
-            }
-        }
-
-        if (c == '0' && n == 'b') {
-            rdr.bump();
-            rdr.bump();
-            c = rdr.curr();
-            while (is_bin_digit(c) || c == '_') {
-                accum_int *= 2;
-                accum_int += bin_digit_value(c);
-                rdr.bump();
-                c = rdr.curr();
-            }
-        }
-
-        while (is_dec_digit(c) || c == '_') {
-            accum_int *= 10;
-            accum_int += dec_digit_val(c);
-            rdr.bump();
-            c = rdr.curr();
-        }
-
-        ret token.LIT_INT(accum_int);
+        ret scan_number(c, rdr);
     }
 
     impure fn binop(reader rdr, token.binop op) -> token.token {
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 8e47cf77720..732e5b170ae 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -287,6 +287,10 @@ impure fn parse_lit(parser p) -> option.t[ast.lit] {
             p.bump();
             lit = ast.lit_uint(u);
         }
+        case (token.LIT_MACH_INT(?tm, ?i)) {
+            p.bump();
+            lit = ast.lit_mach_int(tm, i);
+        }
         case (token.LIT_CHAR(?c)) {
             p.bump();
             lit = ast.lit_char(c);