diff options
| author | Graydon Hoare <[email protected]> | 2010-09-09 15:59:29 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-09-09 15:59:29 -0700 |
| commit | a9e2327a18e782df524c14dc42910d61a4785324 (patch) | |
| tree | 8763224ac3a4c11275dd64257aac47036c97c48d /src/comp | |
| parent | Fixed lost signal notifications. (diff) | |
| download | rust-a9e2327a18e782df524c14dc42910d61a4785324.tar.xz rust-a9e2327a18e782df524c14dc42910d61a4785324.zip | |
Switch tags to purely nominal, removing TY_iso and TY_idx. Seems to mostly work, possibly a little bumpy. Changes a lot.
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/fe/ast.rs | 71 | ||||
| -rw-r--r-- | src/comp/fe/token.rs | 304 | ||||
| -rw-r--r-- | src/comp/util/common.rs | 17 |
3 files changed, 212 insertions, 180 deletions
diff --git a/src/comp/fe/ast.rs b/src/comp/fe/ast.rs index ba084979..7544b40a 100644 --- a/src/comp/fe/ast.rs +++ b/src/comp/fe/ast.rs @@ -10,30 +10,47 @@ type crate = rec( str filename, type block = vec[@stmt]; -type stmt = tag( stmt_block(block), - stmt_decl(@decl), - stmt_ret(option[@lval]) ); - -type decl = tag( decl_local(ident, option[ty]), - decl_item(ident, @item) ); - -type lval = tag( lval_ident(ident), - lval_ext(@lval, ident), - lval_idx(@lval, @atom) ); - -type atom = tag( atom_lit(@lit), atom_lval(@lval) ); - -type lit = tag( lit_char(char), - lit_int(int), - lit_nil(), - lit_bool(bool) ); - -type ty = tag( ty_nil(), - ty_bool(), - ty_int(), - ty_char() ); - -type mode = tag( val(), alias() ); +tag stmt { + stmt_block(block); + stmt_decl(@decl); + stmt_ret(option[@lval]); +} + + +tag decl { + decl_local(ident, option[ty]); + decl_item(ident, @item); +} + +tag lval { + lval_ident(ident); + lval_ext(@lval, ident); + lval_idx(@lval, @atom); +} + +tag atom { + atom_lit(@lit); + atom_lval(@lval); +} + +tag lit { + lit_char(char); + lit_int(int); + lit_nil(); + lit_bool(bool); +} + +tag ty { + ty_nil(); + ty_bool(); + ty_int(); + ty_char(); +} + +tag mode { + val(); + alias(); +} type slot = rec(ty ty, mode mode); @@ -43,8 +60,10 @@ type _fn = rec(vec[rec(slot slot, ident ident)] inputs, type _mod = hashmap[ident,item]; -type item = tag( item_fn(@_fn), - item_mod(@_mod) ); +tag item { + item_fn(@_fn); + item_mod(@_mod); +} // diff --git a/src/comp/fe/token.rs b/src/comp/fe/token.rs index e9e6f222..9a40516e 100644 --- a/src/comp/fe/token.rs +++ b/src/comp/fe/token.rs @@ -3,157 +3,159 @@ import util.common.ty_mach_to_str; import std._int; import std._uint; -type binop = tag - (PLUS(), - MINUS(), - STAR(), - SLASH(), - PERCENT(), - CARET(), - AND(), - OR(), - LSL(), - LSR(), - ASR()); - -type token = tag - (/* Expression-operator symbols. */ - EQ(), - LT(), - LE(), - EQEQ(), - NE(), - GE(), - GT(), - ANDAND(), - OROR(), - NOT(), - TILDE(), - - BINOP(binop), - BINOPEQ(binop), - - AS(), - WITH(), - - /* Structural symbols */ - AT(), - DOT(), - COMMA(), - SEMI(), - COLON(), - RARROW(), - SEND(), - LARROW(), - LPAREN(), - RPAREN(), - LBRACKET(), - RBRACKET(), - LBRACE(), - RBRACE(), - - /* Module and crate keywords */ - MOD(), - USE(), - AUTH(), - META(), - - /* Metaprogramming keywords */ - SYNTAX(), - POUND(), - - /* Statement keywords */ - IF(), - ELSE(), - DO(), - WHILE(), - ALT(), - CASE(), - - FAIL(), - DROP(), - - IN(), - FOR(), - EACH(), - PUT(), - RET(), - BE(), - - /* Type and type-state keywords */ - TYPE(), - CHECK(), - CLAIM(), - PROVE(), - - /* Effect keywords */ - IO(), - STATE(), - UNSAFE(), - - /* Type qualifiers */ - NATIVE(), - AUTO(), - MUTABLE(), - - /* Name management */ - IMPORT(), - EXPORT(), - - /* Value / stmt declarators */ - LET(), - - /* Magic runtime services */ - LOG(), - SPAWN(), - BIND(), - THREAD(), - YIELD(), - JOIN(), - - /* Literals */ - LIT_INT(int), - LIT_UINT(uint), - LIT_MACH_INT(ty_mach, int), - LIT_STR(str), - LIT_CHAR(char), - LIT_BOOL(bool), - - /* Name components */ - IDENT(str), - IDX(int), - UNDERSCORE(), - - /* Reserved type names */ - BOOL(), - INT(), - UINT(), - FLOAT(), - CHAR(), - STR(), - MACH(ty_mach), - - /* Algebraic type constructors */ - REC(), - TUP(), - TAG(), - VEC(), - ANY(), - - /* Callable type constructors */ - FN(), - ITER(), - - /* Object type */ - OBJ(), - - /* Comm and task types */ - CHAN(), - PORT(), - TASK(), - - BRACEQUOTE(str), - EOF()); +tag binop { + 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(); + + BINOP(binop); + BINOPEQ(binop); + + AS(); + WITH(); + + /* Structural symbols */ + AT(); + DOT(); + COMMA(); + SEMI(); + COLON(); + RARROW(); + SEND(); + LARROW(); + LPAREN(); + RPAREN(); + LBRACKET(); + RBRACKET(); + LBRACE(); + RBRACE(); + + /* Module and crate keywords */ + MOD(); + USE(); + AUTH(); + META(); + + /* Metaprogramming keywords */ + SYNTAX(); + POUND(); + + /* Statement keywords */ + IF(); + ELSE(); + DO(); + WHILE(); + ALT(); + CASE(); + + FAIL(); + DROP(); + + IN(); + FOR(); + EACH(); + PUT(); + RET(); + BE(); + + /* Type and type-state keywords */ + TYPE(); + CHECK(); + CLAIM(); + PROVE(); + + /* Effect keywords */ + IO(); + STATE(); + UNSAFE(); + + /* Type qualifiers */ + NATIVE(); + AUTO(); + MUTABLE(); + + /* Name management */ + IMPORT(); + EXPORT(); + + /* Value / stmt declarators */ + LET(); + + /* Magic runtime services */ + LOG(); + SPAWN(); + BIND(); + THREAD(); + YIELD(); + JOIN(); + + /* Literals */ + LIT_INT(int); + LIT_UINT(uint); + LIT_MACH_INT(ty_mach, int); + LIT_STR(str); + LIT_CHAR(char); + LIT_BOOL(bool); + + /* Name components */ + IDENT(str); + IDX(int); + UNDERSCORE(); + + /* Reserved type names */ + BOOL(); + INT(); + UINT(); + FLOAT(); + CHAR(); + STR(); + MACH(ty_mach); + + /* Algebraic type constructors */ + REC(); + TUP(); + TAG(); + VEC(); + ANY(); + + /* Callable type constructors */ + FN(); + ITER(); + + /* Object type */ + OBJ(); + + /* Comm and task types */ + CHAN(); + PORT(); + TASK(); + + BRACEQUOTE(str); + EOF(); +} fn binop_to_str(binop o) -> str { alt (o) { diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs index 9bcb67b2..b3e85ac3 100644 --- a/src/comp/util/common.rs +++ b/src/comp/util/common.rs @@ -3,9 +3,20 @@ import std._uint; type pos = rec(uint line, uint col); type span = rec(str filename, pos lo, pos hi); -type ty_mach = tag( ty_i8(), ty_i16(), ty_i32(), ty_i64(), - ty_u8(), ty_u16(), ty_u32(), ty_u64(), - ty_f32(), ty_f64() ); +tag ty_mach { + ty_i8(); + ty_i16(); + ty_i32(); + ty_i64(); + + ty_u8(); + ty_u16(); + ty_u32(); + ty_u64(); + + ty_f32(); + ty_f64(); +} fn ty_mach_to_str(ty_mach tm) -> str { alt (tm) { |