Skip to content

Commit 8e6fcad

Browse files
committed
---
yaml --- r: 941 b: refs/heads/master c: e05d7c3 h: refs/heads/master i: 939: 59b8c0d v: v3
1 parent f7e017a commit 8e6fcad

File tree

7 files changed

+131
-35
lines changed

7 files changed

+131
-35
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 3e01b2d529a81ac7b2d7ba3deb5d1f116efc7b34
2+
refs/heads/master: e05d7c3ac1e72edff337719fe58da69e959c4cf4

trunk/src/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,15 @@ TEST_XFAILS_SELF := $(filter-out \
529529
fact.rs \
530530
hello.rs \
531531
int.rs \
532+
i32-sub.rs \
533+
i8-incr.rs \
532534
item-name-overload.rs \
533535
lazy-init.rs \
534536
multiline-comment.rs \
535537
return-nil.rs \
538+
u32-decr.rs \
539+
u8-incr.rs \
540+
u8-incr-decr.rs \
536541
uint.rs \
537542
unit.rs \
538543
while-and-do-while.rs \

trunk/src/comp/front/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import std.option;
44
import middle.typeck;
55
import util.common.span;
66
import util.common.spanned;
7+
import util.common.ty_mach;
78

89
type ident = str;
910

@@ -116,6 +117,7 @@ tag lit_ {
116117
lit_char(char);
117118
lit_int(int);
118119
lit_uint(uint);
120+
lit_mach_int(ty_mach, int);
119121
lit_nil;
120122
lit_bool(bool);
121123
}

trunk/src/comp/front/lexer.rs

Lines changed: 95 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,102 @@ impure fn consume_block_comment(reader rdr) {
302302
be consume_any_whitespace(rdr);
303303
}
304304

305+
impure fn scan_number(mutable char c, reader rdr) -> token.token {
306+
auto accum_int = 0;
307+
auto n = rdr.next();
308+
309+
if (c == '0' && n == 'x') {
310+
rdr.bump();
311+
rdr.bump();
312+
c = rdr.curr();
313+
while (is_hex_digit(c) || c == '_') {
314+
if (c != '_') {
315+
accum_int *= 16;
316+
accum_int += hex_digit_val(c);
317+
}
318+
rdr.bump();
319+
c = rdr.curr();
320+
}
321+
}
322+
323+
if (c == '0' && n == 'b') {
324+
rdr.bump();
325+
rdr.bump();
326+
c = rdr.curr();
327+
while (is_bin_digit(c) || c == '_') {
328+
if (c != '_') {
329+
accum_int *= 2;
330+
accum_int += bin_digit_value(c);
331+
}
332+
rdr.bump();
333+
c = rdr.curr();
334+
}
335+
}
336+
337+
while (is_dec_digit(c) || c == '_') {
338+
if (c != '_') {
339+
accum_int *= 10;
340+
accum_int += dec_digit_val(c);
341+
}
342+
rdr.bump();
343+
c = rdr.curr();
344+
}
345+
346+
if (c == 'u' || c == 'i') {
347+
let bool signed = (c == 'i');
348+
rdr.bump();
349+
c = rdr.curr();
350+
if (c == '8') {
351+
rdr.bump();
352+
if (signed) {
353+
ret token.LIT_MACH_INT(common.ty_i8, accum_int);
354+
} else {
355+
ret token.LIT_MACH_INT(common.ty_u8, accum_int);
356+
}
357+
}
358+
359+
n = rdr.next();
360+
if (c == '1' && n == '6') {
361+
rdr.bump();
362+
rdr.bump();
363+
if (signed) {
364+
ret token.LIT_MACH_INT(common.ty_i16, accum_int);
365+
} else {
366+
ret token.LIT_MACH_INT(common.ty_u16, accum_int);
367+
}
368+
}
369+
if (c == '3' && n == '2') {
370+
rdr.bump();
371+
rdr.bump();
372+
if (signed) {
373+
ret token.LIT_MACH_INT(common.ty_i32, accum_int);
374+
} else {
375+
ret token.LIT_MACH_INT(common.ty_u32, accum_int);
376+
}
377+
}
378+
379+
if (c == '6' && n == '4') {
380+
rdr.bump();
381+
rdr.bump();
382+
if (signed) {
383+
ret token.LIT_MACH_INT(common.ty_i64, accum_int);
384+
} else {
385+
ret token.LIT_MACH_INT(common.ty_u64, accum_int);
386+
}
387+
}
388+
389+
if (signed) {
390+
ret token.LIT_INT(accum_int);
391+
} else {
392+
// FIXME: should cast in the target bit-width.
393+
ret token.LIT_UINT(accum_int as uint);
394+
}
395+
}
396+
ret token.LIT_INT(accum_int);
397+
}
398+
305399
impure fn next_token(reader rdr) -> token.token {
306400
auto accum_str = "";
307-
auto accum_int = 0;
308401

309402
consume_any_whitespace(rdr);
310403

@@ -328,39 +421,7 @@ impure fn next_token(reader rdr) -> token.token {
328421
}
329422

330423
if (is_dec_digit(c)) {
331-
auto n = rdr.next();
332-
if (c == '0' && n == 'x') {
333-
rdr.bump();
334-
rdr.bump();
335-
c = rdr.curr();
336-
while (is_hex_digit(c) || c == '_') {
337-
accum_int *= 16;
338-
accum_int += hex_digit_val(c);
339-
rdr.bump();
340-
c = rdr.curr();
341-
}
342-
}
343-
344-
if (c == '0' && n == 'b') {
345-
rdr.bump();
346-
rdr.bump();
347-
c = rdr.curr();
348-
while (is_bin_digit(c) || c == '_') {
349-
accum_int *= 2;
350-
accum_int += bin_digit_value(c);
351-
rdr.bump();
352-
c = rdr.curr();
353-
}
354-
}
355-
356-
while (is_dec_digit(c) || c == '_') {
357-
accum_int *= 10;
358-
accum_int += dec_digit_val(c);
359-
rdr.bump();
360-
c = rdr.curr();
361-
}
362-
363-
ret token.LIT_INT(accum_int);
424+
ret scan_number(c, rdr);
364425
}
365426

366427
impure fn binop(reader rdr, token.binop op) -> token.token {

trunk/src/comp/front/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ impure fn parse_lit(parser p) -> option.t[ast.lit] {
287287
p.bump();
288288
lit = ast.lit_uint(u);
289289
}
290+
case (token.LIT_MACH_INT(?tm, ?i)) {
291+
p.bump();
292+
lit = ast.lit_mach_int(tm, i);
293+
}
290294
case (token.LIT_CHAR(?c)) {
291295
p.bump();
292296
lit = ast.lit_char(c);

trunk/src/comp/middle/trans.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,27 @@ impure fn trans_lit(@block_ctxt cx, &ast.lit lit) -> result {
529529
case (ast.lit_uint(?u)) {
530530
ret res(cx, C_int(u as int));
531531
}
532+
case (ast.lit_mach_int(?tm, ?i)) {
533+
// FIXME: the entire handling of mach types falls apart
534+
// if target int width is larger than host, at the moment;
535+
// re-do the mach-int types using 'big' when that works.
536+
auto t = T_int();
537+
alt (tm) {
538+
case (common.ty_u8) { t = T_i8(); }
539+
case (common.ty_u16) { t = T_i16(); }
540+
case (common.ty_u32) { t = T_i32(); }
541+
case (common.ty_u64) { t = T_i64(); }
542+
543+
case (common.ty_i8) { t = T_i8(); }
544+
case (common.ty_i16) { t = T_i16(); }
545+
case (common.ty_i32) { t = T_i32(); }
546+
case (common.ty_i64) { t = T_i64(); }
547+
case (_) {
548+
cx.fcx.ccx.sess.bug("bad mach int literal type");
549+
}
550+
}
551+
ret res(cx, C_integral(i, t));
552+
}
532553
case (ast.lit_char(?c)) {
533554
ret res(cx, C_integral(c as int, T_char()));
534555
}

trunk/src/comp/middle/typeck.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,9 @@ fn check_lit(@ast.lit lit) -> @ty {
944944
case (ast.lit_char(_)) { sty = ty_char; }
945945
case (ast.lit_int(_)) { sty = ty_int; }
946946
case (ast.lit_uint(_)) { sty = ty_uint; }
947+
case (ast.lit_mach_int(?tm, _)) {
948+
sty = ty_machine(tm);
949+
}
947950
case (ast.lit_nil) { sty = ty_nil; }
948951
case (ast.lit_bool(_)) { sty = ty_bool; }
949952
}

0 commit comments

Comments
 (0)