Skip to content

Commit f6e6daf

Browse files
brsongraydon
authored andcommitted
---
yaml --- r: 1638 b: refs/heads/master c: 7464237 h: refs/heads/master v: v3
1 parent c04f4a8 commit f6e6daf

File tree

5 files changed

+166
-3
lines changed

5 files changed

+166
-3
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: a3cca65f6d77d9d7d27b3ace84da4730030ffd59
2+
refs/heads/master: 7464237256990c4a346cbaaa7ce3d2d9e8fe8d5c

trunk/src/comp/front/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ tag ty_ {
278278
ty_str;
279279
ty_box(@ty);
280280
ty_vec(@ty);
281+
ty_port(@ty);
282+
ty_chan(@ty);
281283
ty_tup(vec[@ty]);
282284
ty_rec(vec[ty_field]);
283285
ty_fn(proto, vec[ty_arg], @ty); // TODO: effect
284286
ty_obj(vec[ty_method]);
285-
ty_chan(@ty);
286-
ty_port(@ty);
287287
ty_path(path, option.t[def]);
288288
ty_mutable(@ty);
289289
ty_type;

trunk/src/comp/middle/fold.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ type ast_fold[ENV] =
179179
(fn(&ENV e, &span sp,
180180
@expr e) -> @expr) fold_expr_check_expr,
181181

182+
(fn(&ENV e, &span sp,
183+
ann a) -> @expr) fold_expr_port,
184+
185+
(fn(&ENV e, &span sp,
186+
@expr e, ann a) -> @expr) fold_expr_chan,
187+
188+
(fn(&ENV e, &span sp,
189+
@expr lhs, @expr rhs, ann a) -> @expr) fold_expr_send,
190+
191+
(fn(&ENV e, &span sp,
192+
@expr lhs, @expr rhs, ann a) -> @expr) fold_expr_recv,
193+
182194
// Decl folds.
183195
(fn(&ENV e, &span sp,
184196
@ast.local local) -> @decl) fold_decl_local,
@@ -717,6 +729,26 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr {
717729
ret fld.fold_expr_check_expr(env_, e.span, ee);
718730
}
719731

732+
case (ast.expr_port(?t)) {
733+
ret fld.fold_expr_port(env_, e.span, t);
734+
}
735+
736+
case (ast.expr_chan(?x, ?t)) {
737+
auto ee = fold_expr(env_, fld, x);
738+
ret fld.fold_expr_chan(env_, e.span, ee, t);
739+
}
740+
741+
case (ast.expr_send(?lhs, ?rhs, ?t)) {
742+
auto llhs = fold_expr(env_, fld, lhs);
743+
auto rrhs = fold_expr(env_, fld, rhs);
744+
ret fld.fold_expr_send(env_, e.span, llhs, rrhs, t);
745+
}
746+
747+
case (ast.expr_recv(?lhs, ?rhs, ?t)) {
748+
auto llhs = fold_expr(env_, fld, lhs);
749+
auto rrhs = fold_expr(env_, fld, rhs);
750+
ret fld.fold_expr_recv(env_, e.span, llhs, rrhs, t);
751+
}
720752
}
721753

722754
fail;
@@ -1255,6 +1287,23 @@ fn identity_fold_expr_check_expr[ENV](&ENV e, &span sp, @expr x) -> @expr {
12551287
ret @respan(sp, ast.expr_check_expr(x));
12561288
}
12571289

1290+
fn identity_fold_expr_port[ENV](&ENV e, &span sp, ann a) -> @expr {
1291+
ret @respan(sp, ast.expr_port(a));
1292+
}
1293+
1294+
fn identity_fold_expr_chan[ENV](&ENV e, &span sp, @expr x, ann a) -> @expr {
1295+
ret @respan(sp, ast.expr_chan(x, a));
1296+
}
1297+
1298+
fn identity_fold_expr_send[ENV](&ENV e, &span sp,
1299+
@expr lhs, @expr rhs, ann a) -> @expr {
1300+
ret @respan(sp, ast.expr_send(lhs, rhs, a));
1301+
}
1302+
1303+
fn identity_fold_expr_recv[ENV](&ENV e, &span sp,
1304+
@expr lhs, @expr rhs, ann a) -> @expr {
1305+
ret @respan(sp, ast.expr_recv(lhs, rhs, a));
1306+
}
12581307

12591308
// Decl identities.
12601309

@@ -1527,6 +1576,10 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
15271576
fold_expr_log = bind identity_fold_expr_log[ENV](_,_,_),
15281577
fold_expr_check_expr
15291578
= bind identity_fold_expr_check_expr[ENV](_,_,_),
1579+
fold_expr_port = bind identity_fold_expr_port[ENV](_,_,_),
1580+
fold_expr_chan = bind identity_fold_expr_chan[ENV](_,_,_,_),
1581+
fold_expr_send = bind identity_fold_expr_send[ENV](_,_,_,_,_),
1582+
fold_expr_recv = bind identity_fold_expr_recv[ENV](_,_,_,_,_),
15301583

15311584
fold_decl_local = bind identity_fold_decl_local[ENV](_,_,_),
15321585
fold_decl_item = bind identity_fold_decl_item[ENV](_,_,_),

trunk/src/comp/middle/ty.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ tag sty {
3838
ty_tag(ast.def_id, vec[@t]);
3939
ty_box(@t);
4040
ty_vec(@t);
41+
ty_port(@t);
42+
ty_chan(@t);
4143
ty_tup(vec[@t]);
4244
ty_rec(vec[field]);
4345
ty_fn(ast.proto, vec[arg], @t); // TODO: effect
@@ -240,6 +242,12 @@ fn fold_ty(ty_fold fld, @t ty) -> @t {
240242
case (ty_vec(?subty)) {
241243
ret rewrap(ty, ty_vec(fold_ty(fld, subty)));
242244
}
245+
case (ty_port(?subty)) {
246+
ret rewrap(ty, ty_port(fold_ty(fld, subty)));
247+
}
248+
case (ty_chan(?subty)) {
249+
ret rewrap(ty, ty_chan(fold_ty(fld, subty)));
250+
}
243251
case (ty_tag(?tid, ?subtys)) {
244252
let vec[@t] new_subtys = vec();
245253
for (@t subty in subtys) {
@@ -1159,6 +1167,52 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
11591167
}
11601168
}
11611169

1170+
case (ty.ty_port(?expected_sub)) {
1171+
alt (actual.struct) {
1172+
case (ty.ty_port(?actual_sub)) {
1173+
auto result = unify_step(bindings,
1174+
expected_sub,
1175+
actual_sub,
1176+
handler);
1177+
alt (result) {
1178+
case (ures_ok(?result_sub)) {
1179+
ret ures_ok(plain_ty(ty.ty_port(result_sub)));
1180+
}
1181+
case (_) {
1182+
ret result;
1183+
}
1184+
}
1185+
}
1186+
1187+
case (_) {
1188+
ret ures_err(terr_mismatch, expected, actual);
1189+
}
1190+
}
1191+
}
1192+
1193+
case (ty.ty_chan(?expected_sub)) {
1194+
alt (actual.struct) {
1195+
case (ty.ty_chan(?actual_sub)) {
1196+
auto result = unify_step(bindings,
1197+
expected_sub,
1198+
actual_sub,
1199+
handler);
1200+
alt (result) {
1201+
case (ures_ok(?result_sub)) {
1202+
ret ures_ok(plain_ty(ty.ty_chan(result_sub)));
1203+
}
1204+
case (_) {
1205+
ret result;
1206+
}
1207+
}
1208+
}
1209+
1210+
case (_) {
1211+
ret ures_err(terr_mismatch, expected, actual);
1212+
}
1213+
}
1214+
}
1215+
11621216
case (ty.ty_tup(?expected_elems)) {
11631217
alt (actual.struct) {
11641218
case (ty.ty_tup(?actual_elems)) {

trunk/src/comp/middle/typeck.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
308308
case (ast.ty_str) { sty = ty.ty_str; }
309309
case (ast.ty_box(?t)) { sty = ty.ty_box(ast_ty_to_ty(getter, t)); }
310310
case (ast.ty_vec(?t)) { sty = ty.ty_vec(ast_ty_to_ty(getter, t)); }
311+
312+
case (ast.ty_port(?t)) {
313+
sty = ty.ty_port(ast_ty_to_ty(getter, t));
314+
}
315+
316+
case (ast.ty_chan(?t)) {
317+
sty = ty.ty_chan(ast_ty_to_ty(getter, t));
318+
}
319+
311320
case (ast.ty_tup(?fields)) {
312321
let vec[@ty.t] flds = vec();
313322
for (@ast.ty field in fields) {
@@ -1387,6 +1396,28 @@ fn demand_expr_full(&@fn_ctxt fcx, @ty.t expected, @ast.expr e,
13871396
case (ast.expr_put(_)) { e_1 = e.node; }
13881397
case (ast.expr_be(_)) { e_1 = e.node; }
13891398
case (ast.expr_check_expr(_)) { e_1 = e.node; }
1399+
1400+
case (ast.expr_port(?ann)) {
1401+
auto t = demand(fcx, e.span, expected, ann_to_type(ann));
1402+
e_1 = ast.expr_port(ast.ann_type(t, none[vec[@ty.t]]));
1403+
}
1404+
1405+
case (ast.expr_chan(?es, ?ann)) {
1406+
auto t = demand(fcx, e.span, expected, ann_to_type(ann));
1407+
let @ast.expr es_1;
1408+
alt (t.struct) {
1409+
case (ty.ty_chan(?subty)) {
1410+
auto pt = plain_ty(ty.ty_port(subty));
1411+
es_1 = demand_expr(fcx, pt, es);
1412+
}
1413+
case (_) {
1414+
log "chan expr doesn't have a chan type!";
1415+
fail;
1416+
}
1417+
}
1418+
e_1 = ast.expr_chan(es_1, ast.ann_type(t, none[vec[@ty.t]]));
1419+
}
1420+
13901421
case (_) {
13911422
fcx.ccx.sess.unimpl("type unification for expression variant");
13921423
fail;
@@ -2257,6 +2288,31 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
22572288
}
22582289
}
22592290

2291+
case (ast.expr_port(_)) {
2292+
auto t = next_ty_var(fcx.ccx);
2293+
auto pt = plain_ty(ty.ty_port(t));
2294+
auto ann = ast.ann_type(pt, none[vec[@ty.t]]);
2295+
ret @fold.respan[ast.expr_](expr.span, ast.expr_port(ann));
2296+
}
2297+
2298+
case (ast.expr_chan(?x, _)) {
2299+
auto expr_1 = check_expr(fcx, x);
2300+
auto port_t = expr_ty(expr_1);
2301+
alt (port_t.struct) {
2302+
case (ty.ty_port(?subtype)) {
2303+
auto ct = plain_ty(ty.ty_chan(subtype));
2304+
auto ann = ast.ann_type(ct, none[vec[@ty.t]]);
2305+
ret @fold.respan[ast.expr_](expr.span,
2306+
ast.expr_chan(expr_1, ann));
2307+
}
2308+
case (_) {
2309+
fcx.ccx.sess.span_err(expr.span,
2310+
"bad port type: "
2311+
+ ty_to_str(port_t));
2312+
}
2313+
}
2314+
}
2315+
22602316
case (_) {
22612317
fcx.ccx.sess.unimpl("expr type in typeck.check_expr");
22622318
// TODO

0 commit comments

Comments
 (0)