Skip to content

Commit 07f70c3

Browse files
committed
---
yaml --- r: 622 b: refs/heads/master c: 6ec8c21 h: refs/heads/master v: v3
1 parent d6892e1 commit 07f70c3

File tree

4 files changed

+18
-151
lines changed

4 files changed

+18
-151
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: 9f0eaa65817303b8768c80454734144c176fda43
2+
refs/heads/master: 6ec8c210168120abc6cf95cf5bda5e0df824447a

trunk/src/comp/fe/lexer.rs

Lines changed: 10 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import std._io.stdio_reader;
22
import std._str;
33
import std.map;
44
import std.map.hashmap;
5-
import util.common;
65

76
fn new_str_hash[V]() -> map.hashmap[str,V] {
87
let map.hashfn[str] hasher = _str.hash;
@@ -96,80 +95,6 @@ fn new_reader(stdio_reader rdr, str filename) -> reader
9695
keywords.insert("ret", token.RET());
9796
keywords.insert("be", token.BE());
9897

99-
keywords.insert("fail", token.FAIL());
100-
keywords.insert("drop", token.DROP());
101-
102-
keywords.insert("type", token.TYPE());
103-
keywords.insert("check", token.CHECK());
104-
keywords.insert("claim", token.CLAIM());
105-
keywords.insert("prove", token.PROVE());
106-
107-
keywords.insert("io", token.IO());
108-
keywords.insert("state", token.STATE());
109-
keywords.insert("unsafe", token.UNSAFE());
110-
111-
keywords.insert("native", token.NATIVE());
112-
keywords.insert("mutable", token.MUTABLE());
113-
keywords.insert("auto", token.AUTO());
114-
115-
keywords.insert("fn", token.FN());
116-
keywords.insert("iter", token.ITER());
117-
118-
keywords.insert("import", token.IMPORT());
119-
keywords.insert("export", token.EXPORT());
120-
121-
keywords.insert("let", token.LET());
122-
123-
keywords.insert("log", token.LOG());
124-
keywords.insert("spawn", token.SPAWN());
125-
keywords.insert("thread", token.THREAD());
126-
keywords.insert("yield", token.YIELD());
127-
keywords.insert("join", token.JOIN());
128-
129-
keywords.insert("bool", token.BOOL());
130-
131-
keywords.insert("int", token.INT());
132-
keywords.insert("uint", token.UINT());
133-
keywords.insert("float", token.FLOAT());
134-
135-
keywords.insert("char", token.CHAR());
136-
keywords.insert("str", token.STR());
137-
138-
139-
keywords.insert("rec", token.REC());
140-
keywords.insert("tup", token.TUP());
141-
keywords.insert("tag", token.TAG());
142-
keywords.insert("vec", token.VEC());
143-
keywords.insert("any", token.ANY());
144-
145-
keywords.insert("obj", token.OBJ());
146-
147-
keywords.insert("port", token.PORT());
148-
keywords.insert("chan", token.CHAN());
149-
150-
keywords.insert("task", token.TASK());
151-
152-
keywords.insert("true", token.LIT_BOOL(true));
153-
keywords.insert("false", token.LIT_BOOL(false));
154-
155-
keywords.insert("in", token.IN());
156-
157-
keywords.insert("as", token.AS());
158-
keywords.insert("with", token.WITH());
159-
160-
keywords.insert("bind", token.BIND());
161-
162-
keywords.insert("u8", token.MACH(common.ty_u8()));
163-
keywords.insert("u16", token.MACH(common.ty_u16()));
164-
keywords.insert("u32", token.MACH(common.ty_u32()));
165-
keywords.insert("u64", token.MACH(common.ty_u64()));
166-
keywords.insert("i8", token.MACH(common.ty_i8()));
167-
keywords.insert("i16", token.MACH(common.ty_i16()));
168-
keywords.insert("i32", token.MACH(common.ty_i32()));
169-
keywords.insert("i64", token.MACH(common.ty_i64()));
170-
keywords.insert("f32", token.MACH(common.ty_f32()));
171-
keywords.insert("f64", token.MACH(common.ty_f64()));
172-
17398
ret reader(rdr, filename, rdr.getc() as char, rdr.getc() as char,
17499
1u, 1u, keywords, reserved);
175100
}
@@ -200,31 +125,6 @@ fn is_bin_digit(char c) -> bool {
200125
ret c == '0' || c == '1';
201126
}
202127

203-
fn dec_digit_val(char c) -> int {
204-
ret (c as int) - ('0' as int);
205-
}
206-
207-
fn hex_digit_val(char c) -> int {
208-
if (in_range(c, '0', '9')) {
209-
ret (c as int) - ('0' as int);
210-
}
211-
212-
if (in_range(c, 'a', 'f')) {
213-
ret (c as int) - ('a' as int);
214-
}
215-
216-
if (in_range(c, 'A', 'F')) {
217-
ret (c as int) - ('A' as int);
218-
}
219-
220-
fail;
221-
}
222-
223-
fn bin_digit_value(char c) -> int {
224-
if (c == 0) { ret 0; }
225-
ret 1;
226-
}
227-
228128
fn is_whitespace(char c) -> bool {
229129
ret c == ' ' || c == '\t' || c == '\r' || c == '\n';
230130
}
@@ -259,54 +159,27 @@ fn next_token(reader rdr) -> token.token {
259159
auto c = rdr.curr();
260160

261161
if (is_alpha(c)) {
262-
while (is_alpha(c) || c == '_') {
162+
while (is_alpha(rdr.curr())) {
163+
c = rdr.curr();
263164
accum_str += (c as u8);
264165
rdr.bump();
265-
c = rdr.curr();
266166
}
267-
268-
auto kwds = rdr.get_keywords();
269-
if (kwds.contains_key(accum_str)) {
270-
ret kwds.get(accum_str);
271-
}
272-
273167
ret token.IDENT(accum_str);
274168
}
275169

276170
if (is_dec_digit(c)) {
277-
auto n = rdr.next();
278-
if (c == '0' && n == 'x') {
279-
rdr.bump();
280-
rdr.bump();
281-
c = rdr.curr();
282-
while (is_hex_digit(c) || c == '_') {
283-
accum_int *= 16;
284-
accum_int += hex_digit_val(v);
285-
rdr.bump();
171+
if (c == '0') {
172+
log "fixme: leading zero";
173+
fail;
174+
} else {
175+
while (is_dec_digit(c)) {
286176
c = rdr.curr();
287-
}
288-
}
289-
290-
if (c == '0' && n == 'b') {
291-
rdr.bump();
292-
rdr.bump();
293-
c = rdr.curr();
294-
while (is_hex_digit(c) || c == '_') {
295-
accum_int *= 2;
296-
accum_int += bit_value(c);
177+
accum_int *= 10;
178+
accum_int += (c as int) - ('0' as int);
297179
rdr.bump();
298-
c = rdr.curr();
299180
}
181+
ret token.LIT_INT(accum_int);
300182
}
301-
302-
while (is_dec_digit(c) || c == '_') {
303-
accum_int *= 10;
304-
accum_int += dec_digit_val(v);
305-
rdr.bump();
306-
c = rdr.curr();
307-
}
308-
309-
ret token.LIT_INT(accum_int);
310183
}
311184

312185

@@ -333,7 +206,6 @@ fn next_token(reader rdr) -> token.token {
333206
case (']') { rdr.bump(); ret token.RBRACKET(); }
334207
case ('@') { rdr.bump(); ret token.AT(); }
335208
case ('#') { rdr.bump(); ret token.POUND(); }
336-
case ('_') { rdr.bump(); ret token.UNDERSCORE(); }
337209

338210
// Multi-byte tokens.
339211
case ('=') {

trunk/src/comp/fe/token.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,8 @@ fn to_str(token t) -> str {
275275
}
276276
case (LIT_CHAR(c)) {
277277
// FIXME: escape and encode.
278-
auto tmp = "'";
279-
tmp += c as u8;
280-
tmp += '\'' as u8;
278+
auto tmp = "";
279+
tmp += (c as u8);
281280
ret tmp;
282281
}
283282

@@ -286,7 +285,7 @@ fn to_str(token t) -> str {
286285
}
287286

288287
/* Name components */
289-
case (IDENT(s)) { auto si = "ident:"; si += s; ret si; }
288+
case (IDENT(s)) { ret s; }
290289
case (IDX(i)) { ret "_" + _int.to_str(i, 10u); }
291290
case (UNDERSCORE()) { ret "_"; }
292291

trunk/src/comp/util/common.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11

22
type ty_mach = tag( ty_i8(), ty_i16(), ty_i32(), ty_i64(),
33
ty_u8(), ty_u16(), ty_u32(), ty_u64(),
4-
ty_f32(), ty_f64() );
4+
ty_f32(), ty_f16() );
55

66
fn ty_mach_to_str(ty_mach tm) -> str {
77
alt (tm) {
88
case (ty_u8()) { ret "u8"; }
9-
case (ty_u16()) { ret "u16"; }
10-
case (ty_u32()) { ret "u32"; }
11-
case (ty_u64()) { ret "u64"; }
12-
139
case (ty_i8()) { ret "i8"; }
10+
case (ty_u16()) { ret "u16"; }
1411
case (ty_i16()) { ret "i16"; }
12+
case (ty_u32()) { ret "u32"; }
1513
case (ty_i32()) { ret "i32"; }
14+
case (ty_u64()) { ret "u64"; }
1615
case (ty_i64()) { ret "i64"; }
17-
18-
case (ty_f32()) { ret "f32"; }
19-
case (ty_f64()) { ret "f64"; }
2016
}
2117
}
2218

0 commit comments

Comments
 (0)