From 70e5457d7c99d3b273c3ef9edaebee1324be85c7 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 4 Apr 2011 15:44:15 -0700 Subject: Make box prefix operator and box type carry mutability flag. --- src/comp/front/ast.rs | 7 +++++-- src/comp/front/parser.rs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/comp/front') diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 46666a34..61450a1b 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -188,7 +188,7 @@ fn binop_to_str(binop op) -> str { tag unop { - box; + box(mutability); deref; bitnot; not; @@ -197,7 +197,10 @@ tag unop { fn unop_to_str(unop op) -> str { alt (op) { - case (box) {ret "@";} + case (box(?mt)) { + if (mt == mut) { ret "@mutable"; } + ret "@"; + } case (deref) {ret "*";} case (bitnot) {ret "~";} case (not) {ret "!";} diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 4c3e6cf0..1e0a9042 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1074,9 +1074,10 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr { case (token.AT) { p.bump(); + auto m = parse_mutability(p); auto e = parse_prefix_expr(p); hi = e.span; - ex = ast.expr_unary(ast.box, e, ast.ann_none); + ex = ast.expr_unary(ast.box(m), e, ast.ann_none); } case (_) { -- cgit v1.2.3 From b8bb2e118e9815316320f946ef3fc7e6909ed7c9 Mon Sep 17 00:00:00 2001 From: Lindsey Kuper Date: Tue, 5 Apr 2011 14:18:44 -0700 Subject: Further on the path toward self-awareness. Mostly: * Merciless refactoring of trans.rs so that trans_call can work for self-calls as well as other kinds of calls Also: * Various changes to go with having idents, rather than exprs, in expr_call_self AST nodes * Added missing case for SELF token to token.to_str() --- src/comp/front/ast.rs | 2 +- src/comp/front/parser.rs | 4 +++- src/comp/front/token.rs | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/comp/front') diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 61450a1b..d41e6d60 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -258,7 +258,7 @@ tag expr_ { expr_tup(vec[elt], ann); expr_rec(vec[field], option.t[@expr], ann); expr_call(@expr, vec[@expr], ann); - expr_call_self(@expr, vec[@expr], ann); + expr_call_self(ident, vec[@expr], ann); expr_bind(@expr, vec[option.t[@expr]], ann); expr_spawn(spawn_dom, option.t[str], @expr, vec[@expr], ann); expr_binary(binop, @expr, @expr, ann); diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 1e0a9042..31e470be 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -887,10 +887,12 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr { } case (token.SELF) { + log "parsing a self-call..."; + p.bump(); expect(p, token.DOT); // The rest is a call expression. - auto e = parse_bottom_expr(p); + auto e = parse_ident(p); auto pf = parse_expr; auto es = parse_seq[@ast.expr](token.LPAREN, token.RPAREN, diff --git a/src/comp/front/token.rs b/src/comp/front/token.rs index 5ac9d662..dcfafadf 100644 --- a/src/comp/front/token.rs +++ b/src/comp/front/token.rs @@ -348,6 +348,8 @@ fn to_str(token t) -> str { /* Object type */ case (OBJ) { ret "obj"; } + case (SELF) { ret "self"; } + /* Comm and task types */ case (CHAN) { ret "chan"; } -- cgit v1.2.3 From 4fc8de196977a0e5bb4f733f7aaeb1162e880eaa Mon Sep 17 00:00:00 2001 From: Lindsey Kuper Date: Tue, 5 Apr 2011 16:17:47 -0700 Subject: Last pieces of self-call support. The last few pieces of the hack that lets us use trans.trans_call() to translate self-calls, plus a fix for the parser buy that was preventing self-call expressions from getting past parsing. test/run-pass/obj-self.rs works now (as in it actually prints "hi!" twice!). --- src/comp/front/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/comp/front') diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 31e470be..27fdc7fe 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -899,7 +899,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr { some(token.COMMA), pf, p); hi = es.span; - auto ex = ast.expr_call_self(e, es.node, ast.ann_none); + ex = ast.expr_call_self(e, es.node, ast.ann_none); } case (_) { -- cgit v1.2.3