aboutsummaryrefslogtreecommitdiff
path: root/src/comp/fe/token.rs
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-09-20 23:56:43 -0700
committerGraydon Hoare <[email protected]>2010-09-20 23:56:43 -0700
commitc5f4789d5b75d3098665b17d318144cb7c54f42a (patch)
tree2d0ef3ef0e85aa7f2453d8bae762c89552a99ed9 /src/comp/fe/token.rs
parentWrap long lines. (diff)
downloadrust-c5f4789d5b75d3098665b17d318144cb7c54f42a.tar.xz
rust-c5f4789d5b75d3098665b17d318144cb7c54f42a.zip
Bind pattern slots with ?, drop parens from 0-ary tag constructors, translate 0-ary constructors as constants. Rustc loses ~300kb.
Diffstat (limited to 'src/comp/fe/token.rs')
-rw-r--r--src/comp/fe/token.rs418
1 files changed, 209 insertions, 209 deletions
diff --git a/src/comp/fe/token.rs b/src/comp/fe/token.rs
index 85e33b64..ca58d4fe 100644
--- a/src/comp/fe/token.rs
+++ b/src/comp/fe/token.rs
@@ -4,114 +4,114 @@ import std._int;
import std._uint;
tag binop {
- PLUS();
- MINUS();
- STAR();
- SLASH();
- PERCENT();
- CARET();
- AND();
- OR();
- LSL();
- LSR();
- ASR();
+ PLUS;
+ MINUS;
+ STAR;
+ SLASH;
+ PERCENT;
+ CARET;
+ AND;
+ OR;
+ LSL;
+ LSR;
+ ASR;
}
tag token {
/* Expression-operator symbols. */
- EQ();
- LT();
- LE();
- EQEQ();
- NE();
- GE();
- GT();
- ANDAND();
- OROR();
- NOT();
- TILDE();
+ EQ;
+ LT;
+ LE;
+ EQEQ;
+ NE;
+ GE;
+ GT;
+ ANDAND;
+ OROR;
+ NOT;
+ TILDE;
BINOP(binop);
BINOPEQ(binop);
- AS();
- WITH();
+ AS;
+ WITH;
/* Structural symbols */
- AT();
- DOT();
- COMMA();
- SEMI();
- COLON();
- RARROW();
- SEND();
- LARROW();
- LPAREN();
- RPAREN();
- LBRACKET();
- RBRACKET();
- LBRACE();
- RBRACE();
+ AT;
+ DOT;
+ COMMA;
+ SEMI;
+ COLON;
+ RARROW;
+ SEND;
+ LARROW;
+ LPAREN;
+ RPAREN;
+ LBRACKET;
+ RBRACKET;
+ LBRACE;
+ RBRACE;
/* Module and crate keywords */
- MOD();
- USE();
- AUTH();
- META();
+ MOD;
+ USE;
+ AUTH;
+ META;
/* Metaprogramming keywords */
- SYNTAX();
- POUND();
+ SYNTAX;
+ POUND;
/* Statement keywords */
- IF();
- ELSE();
- DO();
- WHILE();
- ALT();
- CASE();
-
- FAIL();
- DROP();
-
- IN();
- FOR();
- EACH();
- PUT();
- RET();
- BE();
+ IF;
+ ELSE;
+ DO;
+ WHILE;
+ ALT;
+ CASE;
+
+ FAIL;
+ DROP;
+
+ IN;
+ FOR;
+ EACH;
+ PUT;
+ RET;
+ BE;
/* Type and type-state keywords */
- TYPE();
- CHECK();
- CLAIM();
- PROVE();
+ TYPE;
+ CHECK;
+ CLAIM;
+ PROVE;
/* Effect keywords */
- IO();
- STATE();
- UNSAFE();
+ IO;
+ STATE;
+ UNSAFE;
/* Type qualifiers */
- NATIVE();
- AUTO();
- MUTABLE();
+ NATIVE;
+ AUTO;
+ MUTABLE;
/* Name management */
- IMPORT();
- EXPORT();
+ IMPORT;
+ EXPORT;
/* Value / stmt declarators */
- LET();
- CONST();
+ LET;
+ CONST;
/* Magic runtime services */
- LOG();
- SPAWN();
- BIND();
- THREAD();
- YIELD();
- JOIN();
+ LOG;
+ SPAWN;
+ BIND;
+ THREAD;
+ YIELD;
+ JOIN;
/* Literals */
LIT_INT(int);
@@ -124,167 +124,167 @@ tag token {
/* Name components */
IDENT(str);
IDX(int);
- UNDERSCORE();
+ UNDERSCORE;
/* Reserved type names */
- BOOL();
- INT();
- UINT();
- FLOAT();
- CHAR();
- STR();
+ BOOL;
+ INT;
+ UINT;
+ FLOAT;
+ CHAR;
+ STR;
MACH(ty_mach);
/* Algebraic type constructors */
- REC();
- TUP();
- TAG();
- VEC();
- ANY();
+ REC;
+ TUP;
+ TAG;
+ VEC;
+ ANY;
/* Callable type constructors */
- FN();
- ITER();
+ FN;
+ ITER;
/* Object type */
- OBJ();
+ OBJ;
/* Comm and task types */
- CHAN();
- PORT();
- TASK();
+ CHAN;
+ PORT;
+ TASK;
BRACEQUOTE(str);
- EOF();
+ EOF;
}
fn binop_to_str(binop o) -> str {
alt (o) {
- case (PLUS()) { ret "+"; }
- case (MINUS()) { ret "-"; }
- case (STAR()) { ret "*"; }
- case (SLASH()) { ret "/"; }
- case (PERCENT()) { ret "%"; }
- case (CARET()) { ret "^"; }
- case (AND()) { ret "&"; }
- case (OR()) { ret "|"; }
- case (LSL()) { ret "<<"; }
- case (LSR()) { ret ">>"; }
- case (ASR()) { ret ">>>"; }
+ case (PLUS) { ret "+"; }
+ case (MINUS) { ret "-"; }
+ case (STAR) { ret "*"; }
+ case (SLASH) { ret "/"; }
+ case (PERCENT) { ret "%"; }
+ case (CARET) { ret "^"; }
+ case (AND) { ret "&"; }
+ case (OR) { ret "|"; }
+ case (LSL) { ret "<<"; }
+ case (LSR) { ret ">>"; }
+ case (ASR) { ret ">>>"; }
}
}
fn to_str(token t) -> str {
alt (t) {
- case (EQ()) { ret "="; }
- case (LT()) { ret "<"; }
- case (LE()) { ret "<="; }
- case (EQEQ()) { ret "=="; }
- case (NE()) { ret "!="; }
- case (GE()) { ret ">="; }
- case (GT()) { ret ">"; }
- case (NOT()) { ret "!"; }
- case (TILDE()) { ret "~"; }
- case (OROR()) { ret "||"; }
- case (ANDAND()) { ret "&&"; }
+ case (EQ) { ret "="; }
+ case (LT) { ret "<"; }
+ case (LE) { ret "<="; }
+ case (EQEQ) { ret "=="; }
+ case (NE) { ret "!="; }
+ case (GE) { ret ">="; }
+ case (GT) { ret ">"; }
+ case (NOT) { ret "!"; }
+ case (TILDE) { ret "~"; }
+ case (OROR) { ret "||"; }
+ case (ANDAND) { ret "&&"; }
- case (BINOP(op)) { ret binop_to_str(op); }
- case (BINOPEQ(op)) { ret binop_to_str(op) + "="; }
+ case (BINOP(?op)) { ret binop_to_str(op); }
+ case (BINOPEQ(?op)) { ret binop_to_str(op) + "="; }
- case (AS()) { ret "as"; }
- case (WITH()) { ret "with"; }
+ case (AS) { ret "as"; }
+ case (WITH) { ret "with"; }
/* Structural symbols */
- case (AT()) { ret "@"; }
- case (DOT()) { ret "."; }
- case (COMMA()) { ret ","; }
- case (SEMI()) { ret ";"; }
- case (COLON()) { ret ":"; }
- case (RARROW()) { ret "->"; }
- case (SEND()) { ret "<|"; }
- case (LARROW()) { ret "<-"; }
- case (LPAREN()) { ret "("; }
- case (RPAREN()) { ret ")"; }
- case (LBRACKET()) { ret "["; }
- case (RBRACKET()) { ret "]"; }
- case (LBRACE()) { ret "{"; }
- case (RBRACE()) { ret "}"; }
+ case (AT) { ret "@"; }
+ case (DOT) { ret "."; }
+ case (COMMA) { ret ","; }
+ case (SEMI) { ret ";"; }
+ case (COLON) { ret ":"; }
+ case (RARROW) { ret "->"; }
+ case (SEND) { ret "<|"; }
+ case (LARROW) { ret "<-"; }
+ case (LPAREN) { ret "("; }
+ case (RPAREN) { ret ")"; }
+ case (LBRACKET) { ret "["; }
+ case (RBRACKET) { ret "]"; }
+ case (LBRACE) { ret "{"; }
+ case (RBRACE) { ret "}"; }
/* Module and crate keywords */
- case (MOD()) { ret "mod"; }
- case (USE()) { ret "use"; }
- case (AUTH()) { ret "auth"; }
- case (META()) { ret "meta"; }
+ case (MOD) { ret "mod"; }
+ case (USE) { ret "use"; }
+ case (AUTH) { ret "auth"; }
+ case (META) { ret "meta"; }
/* Metaprogramming keywords */
- case (SYNTAX()) { ret "syntax"; }
- case (POUND()) { ret "#"; }
+ case (SYNTAX) { ret "syntax"; }
+ case (POUND) { ret "#"; }
/* Statement keywords */
- case (IF()) { ret "if"; }
- case (ELSE()) { ret "else"; }
- case (DO()) { ret "do"; }
- case (WHILE()) { ret "while"; }
- case (ALT()) { ret "alt"; }
- case (CASE()) { ret "case"; }
-
- case (FAIL()) { ret "fail"; }
- case (DROP()) { ret "drop"; }
-
- case (IN()) { ret "in"; }
- case (FOR()) { ret "for"; }
- case (EACH()) { ret "each"; }
- case (PUT()) { ret "put"; }
- case (RET()) { ret "ret"; }
- case (BE()) { ret "be"; }
+ case (IF) { ret "if"; }
+ case (ELSE) { ret "else"; }
+ case (DO) { ret "do"; }
+ case (WHILE) { ret "while"; }
+ case (ALT) { ret "alt"; }
+ case (CASE) { ret "case"; }
+
+ case (FAIL) { ret "fail"; }
+ case (DROP) { ret "drop"; }
+
+ case (IN) { ret "in"; }
+ case (FOR) { ret "for"; }
+ case (EACH) { ret "each"; }
+ case (PUT) { ret "put"; }
+ case (RET) { ret "ret"; }
+ case (BE) { ret "be"; }
/* Type and type-state keywords */
- case (TYPE()) { ret "type"; }
- case (CHECK()) { ret "check"; }
- case (CLAIM()) { ret "claim"; }
- case (PROVE()) { ret "prove"; }
+ case (TYPE) { ret "type"; }
+ case (CHECK) { ret "check"; }
+ case (CLAIM) { ret "claim"; }
+ case (PROVE) { ret "prove"; }
/* Effect keywords */
- case (IO()) { ret "io"; }
- case (STATE()) { ret "state"; }
- case (UNSAFE()) { ret "unsafe"; }
+ case (IO) { ret "io"; }
+ case (STATE) { ret "state"; }
+ case (UNSAFE) { ret "unsafe"; }
/* Type qualifiers */
- case (NATIVE()) { ret "native"; }
- case (AUTO()) { ret "auto"; }
- case (MUTABLE()) { ret "mutable"; }
+ case (NATIVE) { ret "native"; }
+ case (AUTO) { ret "auto"; }
+ case (MUTABLE) { ret "mutable"; }
/* Name management */
- case (IMPORT()) { ret "import"; }
- case (EXPORT()) { ret "export"; }
+ case (IMPORT) { ret "import"; }
+ case (EXPORT) { ret "export"; }
/* Value / stmt declarators */
- case (LET()) { ret "let"; }
- case (CONST()) { ret "const"; }
+ case (LET) { ret "let"; }
+ case (CONST) { ret "const"; }
/* Magic runtime services */
- case (LOG()) { ret "log"; }
- case (SPAWN()) { ret "spawn"; }
- case (BIND()) { ret "bind"; }
- case (THREAD()) { ret "thread"; }
- case (YIELD()) { ret "yield"; }
- case (JOIN()) { ret "join"; }
+ case (LOG) { ret "log"; }
+ case (SPAWN) { ret "spawn"; }
+ case (BIND) { ret "bind"; }
+ case (THREAD) { ret "thread"; }
+ case (YIELD) { ret "yield"; }
+ case (JOIN) { ret "join"; }
/* Literals */
- case (LIT_INT(i)) { ret _int.to_str(i, 10u); }
- case (LIT_UINT(u)) { ret _uint.to_str(u, 10u); }
- case (LIT_MACH_INT(tm, i)) {
+ case (LIT_INT(?i)) { ret _int.to_str(i, 10u); }
+ case (LIT_UINT(?u)) { ret _uint.to_str(u, 10u); }
+ case (LIT_MACH_INT(?tm, ?i)) {
ret _int.to_str(i, 10u)
+ "_" + ty_mach_to_str(tm);
}
- case (LIT_STR(s)) {
+ case (LIT_STR(?s)) {
// FIXME: escape.
ret "\"" + s + "\"";
}
- case (LIT_CHAR(c)) {
+ case (LIT_CHAR(?c)) {
// FIXME: escape and encode.
auto tmp = "'";
tmp += c as u8;
@@ -292,45 +292,45 @@ fn to_str(token t) -> str {
ret tmp;
}
- case (LIT_BOOL(b)) {
+ case (LIT_BOOL(?b)) {
if (b) { ret "true"; } else { ret "false"; }
}
/* Name components */
- case (IDENT(s)) { auto si = "ident:"; si += s; ret si; }
- case (IDX(i)) { ret "_" + _int.to_str(i, 10u); }
- case (UNDERSCORE()) { ret "_"; }
+ case (IDENT(?s)) { auto si = "ident:"; si += s; ret si; }
+ case (IDX(?i)) { ret "_" + _int.to_str(i, 10u); }
+ case (UNDERSCORE) { ret "_"; }
/* Reserved type names */
- case (BOOL()) { ret "bool"; }
- case (INT()) { ret "int"; }
- case (UINT()) { ret "uint"; }
- case (FLOAT()) { ret "float"; }
- case (CHAR()) { ret "char"; }
- case (STR()) { ret "str"; }
- case (MACH(tm)) { ret ty_mach_to_str(tm); }
+ case (BOOL) { ret "bool"; }
+ case (INT) { ret "int"; }
+ case (UINT) { ret "uint"; }
+ case (FLOAT) { ret "float"; }
+ case (CHAR) { ret "char"; }
+ case (STR) { ret "str"; }
+ case (MACH(?tm)) { ret ty_mach_to_str(tm); }
/* Algebraic type constructors */
- case (REC()) { ret "rec"; }
- case (TUP()) { ret "tup"; }
- case (TAG()) { ret "tag"; }
- case (VEC()) { ret "vec"; }
- case (ANY()) { ret "any"; }
+ case (REC) { ret "rec"; }
+ case (TUP) { ret "tup"; }
+ case (TAG) { ret "tag"; }
+ case (VEC) { ret "vec"; }
+ case (ANY) { ret "any"; }
/* Callable type constructors */
- case (FN()) { ret "fn"; }
- case (ITER()) { ret "iter"; }
+ case (FN) { ret "fn"; }
+ case (ITER) { ret "iter"; }
/* Object type */
- case (OBJ()) { ret "obj"; }
+ case (OBJ) { ret "obj"; }
/* Comm and task types */
- case (CHAN()) { ret "chan"; }
- case (PORT()) { ret "port"; }
- case (TASK()) { ret "task"; }
+ case (CHAN) { ret "chan"; }
+ case (PORT) { ret "port"; }
+ case (TASK) { ret "task"; }
case (BRACEQUOTE(_)) { ret "<bracequote>"; }
- case (EOF()) { ret "<eof>"; }
+ case (EOF) { ret "<eof>"; }
}
}