Skip to content

Commit d65dd3d

Browse files
committed
---
yaml --- r: 1690 b: refs/heads/master c: 5eca712 h: refs/heads/master v: v3
1 parent b4c06e1 commit d65dd3d

File tree

8 files changed

+328
-281
lines changed

8 files changed

+328
-281
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: ed96688be5ae2c9b433cf8b00a207ce21e630562
2+
refs/heads/master: 5eca7129e3857e3506d12de7591238f8a7d55da1

trunk/src/comp/front/ast.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ tag unop {
168168
bitnot;
169169
not;
170170
neg;
171-
_mutable;
172171
}
173172
174173
fn unop_to_str(unop op) -> str {
@@ -178,7 +177,6 @@ fn unop_to_str(unop op) -> str {
178177
case (bitnot) {ret "~";}
179178
case (not) {ret "!";}
180179
case (neg) {ret "-";}
181-
case (_mutable) {ret "mutable";}
182180
}
183181
}
184182
@@ -215,7 +213,7 @@ type field = rec(mutability mut, ident ident, @expr expr);
215213
216214
type expr = spanned[expr_];
217215
tag expr_ {
218-
expr_vec(vec[@expr], ann);
216+
expr_vec(vec[@expr], mutability, ann);
219217
expr_tup(vec[elt], ann);
220218
expr_rec(vec[field], option.t[@expr], ann);
221219
expr_call(@expr, vec[@expr], ann);
@@ -263,7 +261,8 @@ tag lit_ {
263261
// NB: If you change this, you'll probably want to change the corresponding
264262
// type structure in middle/ty.rs as well.
265263
266-
type ty_field = rec(ident ident, @ty ty);
264+
type mt = rec(@ty ty, mutability mut);
265+
type ty_field = rec(ident ident, mt mt);
267266
type ty_arg = rec(mode mode, @ty ty);
268267
// TODO: effect
269268
type ty_method = rec(proto proto, ident ident,
@@ -277,16 +276,15 @@ tag ty_ {
277276
ty_machine(util.common.ty_mach);
278277
ty_char;
279278
ty_str;
280-
ty_box(@ty);
281-
ty_vec(@ty);
279+
ty_box(mt);
280+
ty_vec(mt);
282281
ty_port(@ty);
283282
ty_chan(@ty);
284-
ty_tup(vec[@ty]);
283+
ty_tup(vec[mt]);
285284
ty_rec(vec[ty_field]);
286285
ty_fn(proto, vec[ty_arg], @ty); // TODO: effect
287286
ty_obj(vec[ty_method]);
288287
ty_path(path, option.t[def]);
289-
ty_mutable(@ty);
290288
ty_type;
291289
ty_constr(@ty, vec[@constr]);
292290
}

trunk/src/comp/front/parser.rs

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ impure fn parse_ty_fn(ast.proto proto, parser p,
189189
if (p.peek() == token.BINOP(token.AND)) {
190190
p.bump();
191191
mode = ast.alias;
192+
193+
if (p.peek() == token.MUTABLE) {
194+
p.bump();
195+
// TODO: handle mutable alias args
196+
}
192197
} else {
193198
mode = ast.val;
194199
}
@@ -262,10 +267,16 @@ impure fn parse_ty_obj(parser p, &mutable ast.span hi) -> ast.ty_ {
262267
ret ast.ty_obj(meths.node);
263268
}
264269

270+
impure fn parse_mt(parser p) -> ast.mt {
271+
auto mut = parse_mutability(p);
272+
auto t = parse_ty(p);
273+
ret rec(ty=t, mut=mut);
274+
}
275+
265276
impure fn parse_ty_field(parser p) -> ast.ty_field {
266-
auto ty = parse_ty(p);
277+
auto mt = parse_mt(p);
267278
auto id = parse_ident(p);
268-
ret rec(ident=id, ty=ty);
279+
ret rec(ident=id, mt=mt);
269280
}
270281

271282
impure fn parse_constr_arg(parser p) -> @ast.constr_arg {
@@ -360,25 +371,25 @@ impure fn parse_ty(parser p) -> @ast.ty {
360371

361372
case (token.AT) {
362373
p.bump();
363-
auto t0 = parse_ty(p);
364-
hi = t0.span;
365-
t = ast.ty_box(t0);
374+
auto mt = parse_mt(p);
375+
hi = mt.ty.span;
376+
t = ast.ty_box(mt);
366377
}
367378

368379
case (token.VEC) {
369380
p.bump();
370381
expect(p, token.LBRACKET);
371-
t = ast.ty_vec(parse_ty(p));
382+
t = ast.ty_vec(parse_mt(p));
372383
hi = p.get_span();
373384
expect(p, token.RBRACKET);
374385
}
375386

376387
case (token.TUP) {
377388
p.bump();
378-
auto f = parse_ty; // FIXME: trans_const_lval bug
379-
auto elems = parse_seq[@ast.ty] (token.LPAREN,
380-
token.RPAREN,
381-
some(token.COMMA), f, p);
389+
auto f = parse_mt; // FIXME: trans_const_lval bug
390+
auto elems = parse_seq[ast.mt] (token.LPAREN,
391+
token.RPAREN,
392+
some(token.COMMA), f, p);
382393
hi = elems.span;
383394
t = ast.ty_tup(elems.node);
384395
}
@@ -395,13 +406,6 @@ impure fn parse_ty(parser p) -> @ast.ty {
395406
t = ast.ty_rec(elems.node);
396407
}
397408

398-
case (token.MUTABLE) {
399-
p.bump();
400-
auto t0 = parse_ty(p);
401-
hi = t0.span;
402-
t = ast.ty_mutable(t0);
403-
}
404-
405409
case (token.FN) {
406410
auto flo = p.get_span();
407411
p.bump();
@@ -463,20 +467,22 @@ impure fn parse_arg(parser p) -> ast.arg {
463467
if (p.peek() == token.BINOP(token.AND)) {
464468
m = ast.alias;
465469
p.bump();
470+
471+
if (p.peek() == token.MUTABLE) {
472+
// TODO: handle mutable alias args
473+
p.bump();
474+
}
466475
}
467476
let @ast.ty t = parse_ty(p);
468477
let ast.ident i = parse_ident(p);
469478
ret rec(mode=m, ty=t, ident=i, id=p.next_def_id());
470479
}
471480

472-
impure fn parse_seq[T](token.token bra,
473-
token.token ket,
474-
option.t[token.token] sep,
475-
(impure fn(parser) -> T) f,
476-
parser p) -> util.common.spanned[vec[T]] {
481+
impure fn parse_seq_to_end[T](token.token ket,
482+
option.t[token.token] sep,
483+
(impure fn(parser) -> T) f,
484+
parser p) -> vec[T] {
477485
let bool first = true;
478-
auto lo = p.get_span();
479-
expect(p, bra);
480486
let vec[T] v = vec();
481487
while (p.peek() != ket) {
482488
alt(sep) {
@@ -494,9 +500,20 @@ impure fn parse_seq[T](token.token bra,
494500
let T t = f(p);
495501
v += vec(t);
496502
}
497-
auto hi = p.get_span();
498503
expect(p, ket);
499-
ret spanned(lo, hi, v);
504+
ret v;
505+
}
506+
507+
impure fn parse_seq[T](token.token bra,
508+
token.token ket,
509+
option.t[token.token] sep,
510+
(impure fn(parser) -> T) f,
511+
parser p) -> util.common.spanned[vec[T]] {
512+
auto lo = p.get_span();
513+
expect(p, bra);
514+
auto result = parse_seq_to_end[T](ket, sep, f, p);
515+
auto hi = p.get_span();
516+
ret spanned(lo, hi, result);
500517
}
501518

502519
impure fn parse_lit(parser p) -> ast.lit {
@@ -667,12 +684,15 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
667684
case (token.VEC) {
668685
p.bump();
669686
auto pf = parse_expr;
670-
auto es = parse_seq[@ast.expr](token.LPAREN,
671-
token.RPAREN,
672-
some(token.COMMA),
673-
pf, p);
674-
hi = es.span;
675-
ex = ast.expr_vec(es.node, ast.ann_none);
687+
688+
expect(p, token.LPAREN);
689+
auto mut = parse_mutability(p);
690+
691+
auto es = parse_seq_to_end[@ast.expr](token.RPAREN,
692+
some(token.COMMA),
693+
pf, p);
694+
hi = p.get_span();
695+
ex = ast.expr_vec(es, mut, ast.ann_none);
676696
}
677697

678698
case (token.REC) {
@@ -1004,13 +1024,6 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr {
10041024
ex = ast.expr_unary(ast.box, e, ast.ann_none);
10051025
}
10061026

1007-
case (token.MUTABLE) {
1008-
p.bump();
1009-
auto e = parse_prefix_expr(p);
1010-
hi = e.span;
1011-
ex = ast.expr_unary(ast._mutable, e, ast.ann_none);
1012-
}
1013-
10141027
case (_) {
10151028
ret parse_dot_or_call_expr(p);
10161029
}
@@ -1558,7 +1571,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
15581571
}
15591572
case (ast.stmt_expr(?e)) {
15601573
alt (e.node) {
1561-
case (ast.expr_vec(_,_)) { ret true; }
1574+
case (ast.expr_vec(_,_,_)) { ret true; }
15621575
case (ast.expr_tup(_,_)) { ret true; }
15631576
case (ast.expr_rec(_,_,_)) { ret true; }
15641577
case (ast.expr_call(_,_,_)) { ret true; }
@@ -1722,6 +1735,7 @@ impure fn parse_item_fn_or_iter(parser p, ast.effect eff) -> @ast.item {
17221735

17231736

17241737
impure fn parse_obj_field(parser p) -> ast.obj_field {
1738+
auto mut = parse_mutability(p); // TODO: store this, use it in typeck
17251739
auto ty = parse_ty(p);
17261740
auto ident = parse_ident(p);
17271741
ret rec(ty=ty, ident=ident, id=p.next_def_id(), ann=ast.ann_none);

0 commit comments

Comments
 (0)