Skip to content

Commit 72095a1

Browse files
catamorphismgraydon
authored andcommitted
---
yaml --- r: 2375 b: refs/heads/master c: e3a68e2 h: refs/heads/master i: 2373: 7bdd3e2 2371: 38b82c1 2367: b5b6cdc v: v3
1 parent 55fa700 commit 72095a1

File tree

8 files changed

+156
-23
lines changed

8 files changed

+156
-23
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: d9c9982f0aeb9e6e176007ef5c0490dd18834814
2+
refs/heads/master: e3a68e235cd077c35654f79013ad54da46d72fee

trunk/src/comp/front/ast.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,13 @@ type constr = spanned[constr_];
346346
347347
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
348348
type fn_decl = rec(vec[arg] inputs,
349-
@ty output);
349+
@ty output,
350+
purity purity);
351+
tag purity {
352+
pure_fn; // declared with "pred"
353+
impure_fn; // declared with "fn"
354+
}
355+
350356
type _fn = rec(fn_decl decl,
351357
proto proto,
352358
block body);

trunk/src/comp/front/lexer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ fn keyword_table() -> std.map.hashmap[str, token.token] {
141141
keywords.insert("auto", token.AUTO);
142142

143143
keywords.insert("fn", token.FN);
144+
keywords.insert("pred", token.PRED);
144145
keywords.insert("iter", token.ITER);
145146

146147
keywords.insert("import", token.IMPORT);

trunk/src/comp/front/parser.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ fn parse_proto(parser p) -> ast.proto {
242242
alt (p.peek()) {
243243
case (token.ITER) { p.bump(); ret ast.proto_iter; }
244244
case (token.FN) { p.bump(); ret ast.proto_fn; }
245+
case (token.PRED) { p.bump(); ret ast.proto_fn; }
245246
case (?t) { unexpected(p, t); }
246247
}
247248
fail;
@@ -1767,7 +1768,7 @@ fn parse_ty_params(parser p) -> vec[ast.ty_param] {
17671768
ret ty_params;
17681769
}
17691770

1770-
fn parse_fn_decl(parser p) -> ast.fn_decl {
1771+
fn parse_fn_decl(parser p, ast.purity purity) -> ast.fn_decl {
17711772
auto pf = parse_arg;
17721773
let util.common.spanned[vec[ast.arg]] inputs =
17731774
// FIXME: passing parse_arg as an lval doesn't work at the
@@ -1790,11 +1791,12 @@ fn parse_fn_decl(parser p) -> ast.fn_decl {
17901791
} else {
17911792
output = @spanned(inputs.span.lo, inputs.span.hi, ast.ty_nil);
17921793
}
1793-
ret rec(inputs=inputs.node, output=output);
1794+
// FIXME
1795+
ret rec(inputs=inputs.node, output=output, purity=purity);
17941796
}
17951797

1796-
fn parse_fn(parser p, ast.proto proto) -> ast._fn {
1797-
auto decl = parse_fn_decl(p);
1798+
fn parse_fn(parser p, ast.proto proto, ast.purity purity) -> ast._fn {
1799+
auto decl = parse_fn_decl(p, purity);
17981800
auto body = parse_block(p);
17991801
ret rec(decl = decl,
18001802
proto = proto,
@@ -1808,11 +1810,11 @@ fn parse_fn_header(parser p)
18081810
ret tup(id, ty_params);
18091811
}
18101812

1811-
fn parse_item_fn_or_iter(parser p) -> @ast.item {
1813+
fn parse_item_fn_or_iter(parser p, ast.purity purity) -> @ast.item {
18121814
auto lo = p.get_lo_pos();
18131815
auto proto = parse_proto(p);
18141816
auto t = parse_fn_header(p);
1815-
auto f = parse_fn(p, proto);
1817+
auto f = parse_fn(p, proto, purity);
18161818
auto item = ast.item_fn(t._0, f, t._1,
18171819
p.next_def_id(), ast.ann_none);
18181820
ret @spanned(lo, f.body.span.hi, item);
@@ -1830,7 +1832,7 @@ fn parse_method(parser p) -> @ast.method {
18301832
auto lo = p.get_lo_pos();
18311833
auto proto = parse_proto(p);
18321834
auto ident = parse_ident(p);
1833-
auto f = parse_fn(p, proto);
1835+
auto f = parse_fn(p, proto, ast.impure_fn);
18341836
auto meth = rec(ident=ident, meth=f,
18351837
id=p.next_def_id(), ann=ast.ann_none);
18361838
ret @spanned(lo, f.body.span.hi, meth);
@@ -1843,7 +1845,8 @@ fn parse_dtor(parser p) -> @ast.method {
18431845
let vec[ast.arg] inputs = vec();
18441846
let @ast.ty output = @spanned(lo, lo, ast.ty_nil);
18451847
let ast.fn_decl d = rec(inputs=inputs,
1846-
output=output);
1848+
output=output,
1849+
purity=ast.impure_fn);
18471850
let ast._fn f = rec(decl = d,
18481851
proto = ast.proto_fn,
18491852
body = b);
@@ -1946,7 +1949,7 @@ fn parse_item_native_fn(parser p) -> @ast.native_item {
19461949
auto lo = p.get_lo_pos();
19471950
expect(p, token.FN);
19481951
auto t = parse_fn_header(p);
1949-
auto decl = parse_fn_decl(p);
1952+
auto decl = parse_fn_decl(p, ast.impure_fn);
19501953
auto link_name = none[str];
19511954
if (p.peek() == token.EQ) {
19521955
p.bump();
@@ -2155,6 +2158,7 @@ fn peeking_at_item(parser p) -> bool {
21552158
case (token.GC) { ret true; }
21562159
case (token.CONST) { ret true; }
21572160
case (token.FN) { ret true; }
2161+
case (token.PRED) { ret true; }
21582162
case (token.ITER) { ret true; }
21592163
case (token.MOD) { ret true; }
21602164
case (token.TYPE) { ret true; }
@@ -2176,11 +2180,17 @@ fn parse_item(parser p) -> @ast.item {
21762180

21772181
case (token.FN) {
21782182
assert (lyr == ast.layer_value);
2179-
ret parse_item_fn_or_iter(p);
2183+
ret parse_item_fn_or_iter(p, ast.impure_fn);
21802184
}
2185+
2186+
case (token.PRED) {
2187+
assert (lyr == ast.layer_value);
2188+
ret parse_item_fn_or_iter(p, ast.pure_fn);
2189+
}
2190+
21812191
case (token.ITER) {
21822192
assert (lyr == ast.layer_value);
2183-
ret parse_item_fn_or_iter(p);
2193+
ret parse_item_fn_or_iter(p, ast.impure_fn);
21842194
}
21852195
case (token.MOD) {
21862196
assert (lyr == ast.layer_value);

trunk/src/comp/front/token.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ tag token {
156156

157157
/* Callable type constructors */
158158
FN;
159+
PRED;
159160
ITER;
160161

161162
/* Object type and related keywords */
@@ -340,6 +341,7 @@ fn to_str(token t) -> str {
340341

341342
/* Callable type constructors */
342343
case (FN) { ret "fn"; }
344+
case (PRED) { ret "pred"; }
343345
case (ITER) { ret "iter"; }
344346

345347
/* Object type */

trunk/src/comp/middle/fold.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import front.ast.def;
3030
import front.ast.def_id;
3131
import front.ast.ann;
3232
import front.ast.mt;
33+
import front.ast.purity;
3334

3435
import std._uint;
3536
import std._vec;
@@ -301,7 +302,8 @@ type ast_fold[ENV] =
301302

302303
(fn(&ENV e,
303304
vec[arg] inputs,
304-
@ty output) -> ast.fn_decl) fold_fn_decl,
305+
@ty output,
306+
purity p) -> ast.fn_decl) fold_fn_decl,
305307

306308
(fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod,
307309

@@ -900,7 +902,7 @@ fn fold_fn_decl[ENV](&ENV env, ast_fold[ENV] fld,
900902
inputs += vec(fold_arg(env, fld, a));
901903
}
902904
auto output = fold_ty[ENV](env, fld, decl.output);
903-
ret fld.fold_fn_decl(env, inputs, output);
905+
ret fld.fold_fn_decl(env, inputs, output, decl.purity);
904906
}
905907

906908
fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn {
@@ -1542,8 +1544,9 @@ fn identity_fold_block[ENV](&ENV e, &span sp, &ast.block_ blk) -> block {
15421544

15431545
fn identity_fold_fn_decl[ENV](&ENV e,
15441546
vec[arg] inputs,
1545-
@ty output) -> ast.fn_decl {
1546-
ret rec(inputs=inputs, output=output);
1547+
@ty output,
1548+
purity p) -> ast.fn_decl {
1549+
ret rec(inputs=inputs, output=output, purity=p);
15471550
}
15481551

15491552
fn identity_fold_fn[ENV](&ENV e,
@@ -1732,7 +1735,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
17321735
fold_ann = bind identity_fold_ann[ENV](_,_),
17331736

17341737
fold_fn = bind identity_fold_fn[ENV](_,_,_,_),
1735-
fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_),
1738+
fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_,_),
17361739
fold_mod = bind identity_fold_mod[ENV](_,_),
17371740
fold_native_mod = bind identity_fold_native_mod[ENV](_,_),
17381741
fold_crate = bind identity_fold_crate[ENV](_,_,_,_),

0 commit comments

Comments
 (0)