Skip to content

Commit cdab115

Browse files
committed
---
yaml --- r: 1287 b: refs/heads/master c: 2d7c2ac h: refs/heads/master i: 1285: 353d603 1283: 2496e15 1279: 74f4be3 v: v3
1 parent 1127115 commit cdab115

File tree

3 files changed

+65
-47
lines changed

3 files changed

+65
-47
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: 65da18faf8eb17cd258d373c316f048d5ca8ee56
2+
refs/heads/master: 2d7c2acf0937a6eee58e053fd2babe7b30062c61

trunk/src/comp/front/parser.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ import util.common.append;
1212
import util.common.span;
1313
import util.common.new_str_hash;
1414

15+
tag restriction {
16+
UNRESTRICTED;
17+
RESTRICT_NO_CALL_EXPRS;
18+
}
19+
1520
state type parser =
1621
state obj {
1722
fn peek() -> token.token;
1823
impure fn bump();
1924
impure fn err(str s);
20-
impure fn restrict(bool r);
21-
fn is_restricted() -> bool;
25+
impure fn restrict(restriction r);
26+
fn get_restriction() -> restriction;
2227
fn get_session() -> session.session;
2328
fn get_span() -> common.span;
2429
fn next_def_id() -> ast.def_id;
@@ -31,7 +36,7 @@ impure fn new_parser(session.session sess,
3136
mutable common.pos lo,
3237
mutable common.pos hi,
3338
mutable ast.def_num def,
34-
mutable bool restricted,
39+
mutable restriction res,
3540
ast.crate_num crate,
3641
lexer.reader rdr)
3742
{
@@ -52,12 +57,12 @@ impure fn new_parser(session.session sess,
5257
sess.span_err(span, m);
5358
}
5459

55-
impure fn restrict(bool r) {
56-
restricted = r;
60+
impure fn restrict(restriction r) {
61+
res = r;
5762
}
5863

59-
fn is_restricted() -> bool {
60-
ret restricted;
64+
fn get_restriction() -> restriction {
65+
ret res;
6166
}
6267

6368
fn get_session() -> session.session {
@@ -78,7 +83,7 @@ impure fn new_parser(session.session sess,
7883
auto rdr = lexer.new_reader(srdr, path);
7984
auto npos = rdr.get_curr_pos();
8085
ret stdio_parser(sess, lexer.next_token(rdr),
81-
npos, npos, 0, false, crate, rdr);
86+
npos, npos, 0, UNRESTRICTED, crate, rdr);
8287
}
8388

8489
impure fn unexpected(parser p, token.token t) {
@@ -283,7 +288,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
283288
}
284289

285290
case (token.IDENT(_)) {
286-
t = ast.ty_path(parse_path(p, true), none[ast.def]);
291+
t = ast.ty_path(parse_path(p, GREEDY), none[ast.def]);
287292
}
288293

289294
case (_) {
@@ -380,7 +385,12 @@ fn is_ident(token.token t) -> bool {
380385
ret false;
381386
}
382387

383-
impure fn parse_path(parser p, bool greedy) -> ast.path {
388+
tag greed {
389+
GREEDY;
390+
MINIMAL;
391+
}
392+
393+
impure fn parse_path(parser p, greed g) -> ast.path {
384394

385395
auto lo = p.get_span();
386396
auto hi = lo;
@@ -394,7 +404,7 @@ impure fn parse_path(parser p, bool greedy) -> ast.path {
394404
ids += i;
395405
p.bump();
396406
if (p.peek() == token.DOT) {
397-
if (greedy) {
407+
if (g == GREEDY) {
398408
p.bump();
399409
check (is_ident(p.peek()));
400410
} else {
@@ -456,7 +466,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
456466
alt (p.peek()) {
457467

458468
case (token.IDENT(_)) {
459-
auto pth = parse_path(p, false);
469+
auto pth = parse_path(p, MINIMAL);
460470
hi = pth.span;
461471
ex = ast.expr_path(pth, none[ast.def], ast.ann_none);
462472
}
@@ -521,7 +531,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
521531

522532
case (token.BIND) {
523533
p.bump();
524-
auto e = parse_restricted_expr(p);
534+
auto e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS);
525535
impure fn parse_expr_opt(parser p) -> option.t[@ast.expr] {
526536
alt (p.peek()) {
527537
case (token.UNDERSCORE) {
@@ -589,7 +599,7 @@ impure fn parse_dot_or_call_expr(parser p) -> @ast.expr {
589599
alt (p.peek()) {
590600

591601
case (token.LPAREN) {
592-
if (p.is_restricted()) {
602+
if (p.get_restriction() == RESTRICT_NO_CALL_EXPRS) {
593603
ret e;
594604
} else {
595605
// Call expr.
@@ -983,18 +993,13 @@ impure fn parse_alt_expr(parser p) -> @ast.expr {
983993
ret @spanned(lo, hi, expr);
984994
}
985995

986-
987-
impure fn parse_restricted_expr(parser p) -> @ast.expr {
988-
ret parse_expr_res(p, true);
989-
}
990-
991996
impure fn parse_expr(parser p) -> @ast.expr {
992-
ret parse_expr_res(p, false);
997+
ret parse_expr_res(p, UNRESTRICTED);
993998
}
994999

995-
impure fn parse_expr_res(parser p, bool restrict) -> @ast.expr {
996-
auto old = p.is_restricted();
997-
p.restrict(restrict);
1000+
impure fn parse_expr_res(parser p, restriction r) -> @ast.expr {
1001+
auto old = p.get_restriction();
1002+
p.restrict(r);
9981003
auto e = parse_expr_inner(p);
9991004
p.restrict(old);
10001005
ret e;

trunk/src/comp/middle/trans.rs

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ tag cleanup {
9393
clean(fn(@block_ctxt cx) -> result);
9494
}
9595

96+
97+
tag block_kind {
98+
SCOPE_BLOCK;
99+
NON_SCOPE_BLOCK;
100+
}
101+
96102
state type block_ctxt = rec(BasicBlockRef llbb,
97103
builder build,
98104
block_parent parent,
99-
bool is_scope,
105+
block_kind kind,
100106
mutable vec[cleanup] cleanups,
101107
@fn_ctxt fcx);
102108

@@ -640,7 +646,7 @@ fn trans_non_gc_free(@block_ctxt cx, ValueRef v) -> result {
640646
}
641647

642648
fn find_scope_cx(@block_ctxt cx) -> @block_ctxt {
643-
if (cx.is_scope) {
649+
if (cx.kind == SCOPE_BLOCK) {
644650
ret cx;
645651
}
646652
alt (cx.parent) {
@@ -1492,8 +1498,13 @@ fn memcpy_ty(@block_ctxt cx,
14921498
}
14931499
}
14941500

1501+
tag copy_action {
1502+
INIT;
1503+
DROP_EXISTING;
1504+
}
1505+
14951506
fn copy_ty(@block_ctxt cx,
1496-
bool is_init,
1507+
copy_action action,
14971508
ValueRef dst,
14981509
ValueRef src,
14991510
@ty.t t) -> result {
@@ -1505,15 +1516,15 @@ fn copy_ty(@block_ctxt cx,
15051516

15061517
} else if (ty.type_is_boxed(t)) {
15071518
auto r = incr_all_refcnts(cx, src, t);
1508-
if (! is_init) {
1519+
if (action == DROP_EXISTING) {
15091520
r = drop_ty(r.bcx, r.bcx.build.Load(dst), t);
15101521
}
15111522
ret res(r.bcx, r.bcx.build.Store(src, dst));
15121523

15131524
} else if (ty.type_is_structural(t) ||
15141525
ty.type_has_dynamic_size(t)) {
15151526
auto r = incr_all_refcnts(cx, src, t);
1516-
if (! is_init) {
1527+
if (action == DROP_EXISTING) {
15171528
r = drop_ty(r.bcx, dst, t);
15181529
}
15191530
ret memcpy_ty(r.bcx, dst, src, t);
@@ -1623,7 +1634,7 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
16231634
vec(C_int(0),
16241635
C_int(abi.box_rc_field_body)));
16251636
sub.bcx.build.Store(C_int(1), rc);
1626-
sub = copy_ty(sub.bcx, true, body, e_val, e_ty);
1637+
sub = copy_ty(sub.bcx, INIT, body, e_val, e_ty);
16271638
ret res(sub.bcx, box);
16281639
}
16291640
case (ast.deref) {
@@ -1815,7 +1826,7 @@ fn trans_for(@block_ctxt cx,
18151826

18161827
cx.build.Br(scope_cx.llbb);
18171828
auto local_res = alloc_local(scope_cx, local);
1818-
auto bcx = copy_ty(local_res.bcx, true, local_res.val, curr, t).bcx;
1829+
auto bcx = copy_ty(local_res.bcx, INIT, local_res.val, curr, t).bcx;
18191830
bcx = trans_block(bcx, body).bcx;
18201831
bcx.build.Br(next_cx.llbb);
18211832
ret res(next_cx, C_nil());
@@ -1955,7 +1966,7 @@ fn trans_pat_binding(@block_ctxt cx, @ast.pat pat, ValueRef llval)
19551966
cx.fcx.lllocals.insert(def_id, dst);
19561967
cx.cleanups += clean(bind drop_slot(_, dst, ty));
19571968

1958-
ret copy_ty(cx, true, dst, llval, ty);
1969+
ret copy_ty(cx, INIT, dst, llval, ty);
19591970
}
19601971
case (ast.pat_tag(_, ?subpats, _, _)) {
19611972
if (_vec.len[@ast.pat](subpats) == 0u) { ret res(cx, llval); }
@@ -2496,7 +2507,7 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
24962507
for (ValueRef v in bound_vals) {
24972508
auto bound = bcx.build.GEP(bindings,
24982509
vec(C_int(0),C_int(i)));
2499-
bcx = copy_ty(r.bcx, true, bound, v, bound_tys.(i)).bcx;
2510+
bcx = copy_ty(r.bcx, INIT, bound, v, bound_tys.(i)).bcx;
25002511
i += 1;
25012512
}
25022513

@@ -2608,7 +2619,7 @@ fn trans_tup(@block_ctxt cx, vec[ast.elt] elts,
26082619
auto t = ty.expr_ty(e.expr);
26092620
auto src_res = trans_expr(r.bcx, e.expr);
26102621
auto dst_elt = r.bcx.build.GEP(tup_val, vec(C_int(0), C_int(i)));
2611-
r = copy_ty(src_res.bcx, true, dst_elt, src_res.val, t);
2622+
r = copy_ty(src_res.bcx, INIT, dst_elt, src_res.val, t);
26122623
i += 1;
26132624
}
26142625
ret res(r.bcx, tup_val);
@@ -2645,7 +2656,7 @@ fn trans_vec(@block_ctxt cx, vec[@ast.expr] args,
26452656
for (@ast.expr e in args) {
26462657
auto src_res = trans_expr(sub.bcx, e);
26472658
auto dst_elt = sub.bcx.build.GEP(body, vec(C_int(0), C_int(i)));
2648-
sub = copy_ty(src_res.bcx, true, dst_elt, src_res.val, unit_ty);
2659+
sub = copy_ty(src_res.bcx, INIT, dst_elt, src_res.val, unit_ty);
26492660
i += 1;
26502661
}
26512662
auto fill = sub.bcx.build.GEP(vec_val,
@@ -2668,7 +2679,7 @@ fn trans_rec(@block_ctxt cx, vec[ast.field] fields,
26682679
auto src_res = trans_expr(r.bcx, f.expr);
26692680
auto dst_elt = r.bcx.build.GEP(rec_val, vec(C_int(0), C_int(i)));
26702681
// FIXME: calculate copy init-ness in typestate.
2671-
r = copy_ty(src_res.bcx, true, dst_elt, src_res.val, t);
2682+
r = copy_ty(src_res.bcx, INIT, dst_elt, src_res.val, t);
26722683
i += 1;
26732684
}
26742685
ret res(r.bcx, rec_val);
@@ -2727,7 +2738,8 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
27272738
auto rhs_res = trans_expr(lhs_res.res.bcx, src);
27282739
auto t = node_ann_type(cx.fcx.ccx, ann);
27292740
// FIXME: calculate copy init-ness in typestate.
2730-
ret copy_ty(rhs_res.bcx, false, lhs_res.res.val, rhs_res.val, t);
2741+
ret copy_ty(rhs_res.bcx, DROP_EXISTING,
2742+
lhs_res.res.val, rhs_res.val, t);
27312743
}
27322744

27332745
case (ast.expr_assign_op(?op, ?dst, ?src, ?ann)) {
@@ -2739,7 +2751,8 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
27392751
auto rhs_res = trans_expr(lhs_res.res.bcx, src);
27402752
auto v = trans_eager_binop(rhs_res.bcx, op, lhs_val, rhs_res.val);
27412753
// FIXME: calculate copy init-ness in typestate.
2742-
ret copy_ty(rhs_res.bcx, false, lhs_res.res.val, v, t);
2754+
ret copy_ty(rhs_res.bcx, DROP_EXISTING,
2755+
lhs_res.res.val, v, t);
27432756
}
27442757

27452758
case (ast.expr_bind(?f, ?args, ?ann)) {
@@ -2889,7 +2902,7 @@ fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
28892902
alt (cx.fcx.llretptr) {
28902903
case (some[ValueRef](?llptr)) {
28912904
// Generic return via tydesc + retptr.
2892-
bcx = copy_ty(bcx, true, llptr, val, t).bcx;
2905+
bcx = copy_ty(bcx, INIT, llptr, val, t).bcx;
28932906
bcx.build.RetVoid();
28942907
}
28952908
case (none[ValueRef]) {
@@ -2921,7 +2934,7 @@ fn init_local(@block_ctxt cx, @ast.local local) -> result {
29212934
alt (local.init) {
29222935
case (some[@ast.expr](?e)) {
29232936
auto sub = trans_expr(bcx, e);
2924-
bcx = copy_ty(sub.bcx, true, llptr, sub.val, ty).bcx;
2937+
bcx = copy_ty(sub.bcx, INIT, llptr, sub.val, ty).bcx;
29252938
}
29262939
case (_) {
29272940
if (middle.ty.type_has_dynamic_size(ty)) {
@@ -2983,7 +2996,7 @@ fn new_builder(BasicBlockRef llbb) -> builder {
29832996
// You probably don't want to use this one. See the
29842997
// next three functions instead.
29852998
fn new_block_ctxt(@fn_ctxt cx, block_parent parent,
2986-
bool is_scope,
2999+
block_kind kind,
29873000
str name) -> @block_ctxt {
29883001
let vec[cleanup] cleanups = vec();
29893002
let BasicBlockRef llbb =
@@ -2993,32 +3006,32 @@ fn new_block_ctxt(@fn_ctxt cx, block_parent parent,
29933006
ret @rec(llbb=llbb,
29943007
build=new_builder(llbb),
29953008
parent=parent,
2996-
is_scope=is_scope,
3009+
kind=kind,
29973010
mutable cleanups=cleanups,
29983011
fcx=cx);
29993012
}
30003013

30013014
// Use this when you're at the top block of a function or the like.
30023015
fn new_top_block_ctxt(@fn_ctxt fcx) -> @block_ctxt {
3003-
ret new_block_ctxt(fcx, parent_none, true, "function top level");
3016+
ret new_block_ctxt(fcx, parent_none, SCOPE_BLOCK, "function top level");
30043017
}
30053018

30063019
// Use this when you're at a curly-brace or similar lexical scope.
30073020
fn new_scope_block_ctxt(@block_ctxt bcx, str n) -> @block_ctxt {
3008-
ret new_block_ctxt(bcx.fcx, parent_some(bcx), true, n);
3021+
ret new_block_ctxt(bcx.fcx, parent_some(bcx), SCOPE_BLOCK, n);
30093022
}
30103023

30113024
// Use this when you're making a general CFG BB within a scope.
30123025
fn new_sub_block_ctxt(@block_ctxt bcx, str n) -> @block_ctxt {
3013-
ret new_block_ctxt(bcx.fcx, parent_some(bcx), false, n);
3026+
ret new_block_ctxt(bcx.fcx, parent_some(bcx), NON_SCOPE_BLOCK, n);
30143027
}
30153028

30163029

30173030
fn trans_block_cleanups(@block_ctxt cx,
30183031
@block_ctxt cleanup_cx) -> @block_ctxt {
30193032
auto bcx = cx;
30203033

3021-
if (!cleanup_cx.is_scope) {
3034+
if (cleanup_cx.kind != SCOPE_BLOCK) {
30223035
check (_vec.len[cleanup](cleanup_cx.cleanups) == 0u);
30233036
}
30243037

@@ -3430,7 +3443,7 @@ fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
34303443
arg = load_scalar_or_boxed(r.bcx, arg, arg_tys.(i).ty);
34313444
auto field = r.bcx.build.GEP(body_fields,
34323445
vec(C_int(0),C_int(i)));
3433-
r = copy_ty(r.bcx, true, field, arg, arg_tys.(i).ty);
3446+
r = copy_ty(r.bcx, INIT, field, arg, arg_tys.(i).ty);
34343447
i += 1;
34353448
}
34363449

0 commit comments

Comments
 (0)