aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-12-03 18:03:28 -0800
committerGraydon Hoare <[email protected]>2010-12-03 18:04:18 -0800
commit0c19c8e18f5e145c379fe4b50e5ea8d44fe4969f (patch)
tree36406ee1b92328d4bba26c9b68d89af338deba73 /src/comp/front
parentrustc: Remove LLVM unions and represent tags as (discriminant, byte blob) pairs (diff)
downloadrust-0c19c8e18f5e145c379fe4b50e5ea8d44fe4969f.tar.xz
rust-0c19c8e18f5e145c379fe4b50e5ea8d44fe4969f.zip
Parse layer and effect annotations.
Diffstat (limited to 'src/comp/front')
-rw-r--r--src/comp/front/ast.rs29
-rw-r--r--src/comp/front/parser.rs50
2 files changed, 69 insertions, 10 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 4fbc4f01..f4bfc7a2 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -55,6 +55,18 @@ tag mutability {
imm;
}
+tag layer {
+ layer_value;
+ layer_state;
+ layer_gc;
+}
+
+tag effect {
+ eff_pure;
+ eff_impure;
+ eff_unsafe;
+}
+
tag binop {
add;
sub;
@@ -85,6 +97,11 @@ tag unop {
neg;
}
+tag mode {
+ val;
+ alias;
+}
+
type stmt = spanned[stmt_];
tag stmt_ {
stmt_decl(@decl);
@@ -146,7 +163,9 @@ tag lit_ {
// NB: If you change this, you'll probably want to change the corresponding
// type structure in middle/typeck.rs as well.
+
type ty_field = rec(ident ident, @ty ty);
+type ty_arg = rec(mode mode, @ty ty);
type ty = spanned[ty_];
tag ty_ {
ty_nil;
@@ -160,18 +179,14 @@ tag ty_ {
ty_vec(@ty);
ty_tup(vec[@ty]);
ty_rec(vec[ty_field]);
- ty_fn(vec[rec(mode mode, @ty ty)], @ty); // TODO: effect
+ ty_fn(vec[ty_arg], @ty); // TODO: effect
ty_path(path, option.t[def]);
ty_mutable(@ty);
}
-tag mode {
- val;
- alias;
-}
-
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
-type _fn = rec(vec[arg] inputs,
+type _fn = rec(effect effect,
+ vec[arg] inputs,
@ty output,
block body);
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index f8d3bf07..ba0631ed 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -1161,7 +1161,7 @@ impure fn parse_ty_params(parser p) -> vec[ast.ty_param] {
ret ty_params;
}
-impure fn parse_item_fn(parser p) -> @ast.item {
+impure fn parse_item_fn(parser p, ast.effect eff) -> @ast.item {
auto lo = p.get_span();
expect(p, token.FN);
auto id = parse_ident(p);
@@ -1187,7 +1187,8 @@ impure fn parse_item_fn(parser p) -> @ast.item {
auto body = parse_block(p);
- let ast._fn f = rec(inputs = inputs.node,
+ let ast._fn f = rec(effect = eff,
+ inputs = inputs.node,
output = output,
body = body);
@@ -1305,18 +1306,61 @@ impure fn parse_item_tag(parser p) -> @ast.item {
ret @spanned(lo, hi, item);
}
+impure fn parse_layer(parser p) -> ast.layer {
+ alt (p.peek()) {
+ case (token.STATE) {
+ p.bump();
+ ret ast.layer_state;
+ }
+ case (token.GC) {
+ p.bump();
+ ret ast.layer_gc;
+ }
+ case (_) {
+ ret ast.layer_value;
+ }
+ }
+ fail;
+}
+
+
+impure fn parse_effect(parser p) -> ast.effect {
+ alt (p.peek()) {
+ case (token.IMPURE) {
+ p.bump();
+ ret ast.eff_impure;
+ }
+ case (token.UNSAFE) {
+ p.bump();
+ ret ast.eff_unsafe;
+ }
+ case (_) {
+ ret ast.eff_pure;
+ }
+ }
+ fail;
+}
+
impure fn parse_item(parser p) -> @ast.item {
+ let ast.effect eff = parse_effect(p);
+ let ast.layer lyr = parse_layer(p);
+
alt (p.peek()) {
case (token.FN) {
- ret parse_item_fn(p);
+ check (lyr == ast.layer_value);
+ ret parse_item_fn(p, eff);
}
case (token.MOD) {
+ check (eff == ast.eff_pure);
+ check (lyr == ast.layer_value);
ret parse_item_mod(p);
}
case (token.TYPE) {
+ check (eff == ast.eff_pure);
ret parse_item_type(p);
}
case (token.TAG) {
+ check (eff == ast.eff_pure);
ret parse_item_tag(p);
}
case (?t) {