Skip to content

Commit 06c6375

Browse files
committed
---
yaml --- r: 1327 b: refs/heads/master c: 8ef2297 h: refs/heads/master i: 1325: 1337340 1323: 864640b 1319: 5782a07 1311: b8502fb v: v3
1 parent 23b96af commit 06c6375

File tree

8 files changed

+89
-99
lines changed

8 files changed

+89
-99
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: 3fedb18c0af0bd9fa5e4973936003c0b57e4d3e8
2+
refs/heads/master: 8ef22972dbe50b2e05c8983769a638fd5b6a23b5

trunk/src/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ TEST_XFAILS_RUSTC := $(filter-out \
447447
div-mod.rs \
448448
drop-bind-thunk-args.rs \
449449
drop-on-ret.rs \
450-
else-if.rs \
451450
fact.rs \
452451
fn-lval.rs \
453452
fun-call-variants.rs \

trunk/src/comp/front/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ tag expr_ {
149149
expr_unary(unop, @expr, ann);
150150
expr_lit(@lit, ann);
151151
expr_cast(@expr, @ty, ann);
152-
expr_if(@expr, block, option.t[@expr], ann);
152+
expr_if(@expr, block, option.t[block], ann);
153153
expr_while(@expr, block, ann);
154154
expr_for(@decl, @expr, block, ann);
155155
expr_do_while(block, @expr, ann);
@@ -197,6 +197,7 @@ tag ty_ {
197197
ty_obj(vec[ty_method]);
198198
ty_path(path, option.t[def]);
199199
ty_mutable(@ty);
200+
ty_type;
200201
}
201202

202203
type arg = rec(mode mode, @ty ty, ident ident, def_id id);

trunk/src/comp/front/parser.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -891,33 +891,20 @@ impure fn parse_if_expr(parser p) -> @ast.expr {
891891
auto cond = parse_expr(p);
892892
expect(p, token.RPAREN);
893893
auto thn = parse_block(p);
894-
let option.t[@ast.expr] els = none[@ast.expr];
894+
let option.t[ast.block] els = none[ast.block];
895895
hi = thn.span;
896896
alt (p.peek()) {
897897
case (token.ELSE) {
898-
auto elexpr = parse_else_expr(p);
899-
els = some(elexpr);
900-
hi = elexpr.span;
898+
p.bump();
899+
auto eblk = parse_block(p);
900+
els = some(eblk);
901+
hi = eblk.span;
901902
}
902903
case (_) { /* fall through */ }
903904
}
904905
ret @spanned(lo, hi, ast.expr_if(cond, thn, els, ast.ann_none));
905906
}
906907

907-
impure fn parse_else_expr(parser p) -> @ast.expr {
908-
expect(p, token.ELSE);
909-
alt (p.peek()) {
910-
case (token.IF) {
911-
ret parse_if_expr(p);
912-
}
913-
case (_) {
914-
auto blk = parse_block(p);
915-
ret @spanned(blk.span, blk.span,
916-
ast.expr_block(blk, ast.ann_none));
917-
}
918-
}
919-
}
920-
921908
impure fn parse_head_local(parser p) -> @ast.decl {
922909
auto lo = p.get_span();
923910
let @ast.local local;

trunk/src/comp/middle/fold.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type ast_fold[ENV] =
100100

101101
(fn(&ENV e, &span sp,
102102
@expr cond, &block thn,
103-
&option.t[@expr] els,
103+
&option.t[block] els,
104104
ann a) -> @expr) fold_expr_if,
105105

106106
(fn(&ENV e, &span sp,
@@ -504,10 +504,10 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr {
504504
case (ast.expr_if(?cnd, ?thn, ?els, ?t)) {
505505
auto ccnd = fold_expr(env_, fld, cnd);
506506
auto tthn = fold_block(env_, fld, thn);
507-
auto eels = none[@expr];
507+
auto eels = none[block];
508508
alt (els) {
509-
case (some[@expr](?e)) {
510-
eels = some(fold_expr(env_, fld, e));
509+
case (some[block](?b)) {
510+
eels = some(fold_block(env_, fld, b));
511511
}
512512
case (_) { /* fall through */ }
513513
}
@@ -961,7 +961,7 @@ fn identity_fold_expr_cast[ENV](&ENV env, &span sp, @ast.expr e,
961961

962962
fn identity_fold_expr_if[ENV](&ENV env, &span sp,
963963
@expr cond, &block thn,
964-
&option.t[@expr] els, ann a) -> @expr {
964+
&option.t[block] els, ann a) -> @expr {
965965
ret @respan(sp, ast.expr_if(cond, thn, els, a));
966966
}
967967

trunk/src/comp/middle/trans.rs

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
471471
case (ty.ty_param(_)) {
472472
ret T_typaram_ptr();
473473
}
474+
case (ty.ty_type) { ret T_ptr(T_tydesc()); }
474475
}
475476
fail;
476477
}
@@ -997,7 +998,7 @@ fn get_tydesc(&@block_ctxt cx, @ty.t t) -> result {
997998
vec(p2i(bcx.fcx.ccx.crate_ptr),
998999
sz.val,
9991000
align.val,
1000-
C_int(n_params as int),
1001+
C_int((1u + n_params) as int),
10011002
bcx.build.PtrToInt(tydescs, T_int())));
10021003

10031004
ret res(v.bcx, v.bcx.build.IntToPtr(v.val, T_ptr(T_tydesc())));
@@ -1931,7 +1932,7 @@ fn join_results(@block_ctxt parent_cx,
19311932
}
19321933

19331934
fn trans_if(@block_ctxt cx, @ast.expr cond,
1934-
&ast.block thn, &option.t[@ast.expr] els) -> result {
1935+
&ast.block thn, &option.t[ast.block] els) -> result {
19351936

19361937
auto cond_res = trans_expr(cx, cond);
19371938

@@ -1942,19 +1943,8 @@ fn trans_if(@block_ctxt cx, @ast.expr cond,
19421943
auto else_res = res(else_cx, C_nil());
19431944

19441945
alt (els) {
1945-
case (some[@ast.expr](?elexpr)) {
1946-
// FIXME: Shouldn't need to unwrap the block here,
1947-
// instead just use 'else_res = trans_expr(else_cx, elexpr)',
1948-
// but either a) trans_expr doesn't handle expr_block
1949-
// correctly or b) I have no idea what I'm doing...
1950-
alt (elexpr.node) {
1951-
case (ast.expr_if(_, _, _, _)) {
1952-
else_res = trans_expr(else_cx, elexpr);
1953-
}
1954-
case (ast.expr_block(?b, _)) {
1955-
else_res = trans_block(else_cx, b);
1956-
}
1957-
}
1946+
case (some[ast.block](?eblk)) {
1947+
else_res = trans_block(else_cx, eblk);
19581948
}
19591949
case (_) { /* fall through */ }
19601950
}
@@ -2204,6 +2194,34 @@ fn lval_val(@block_ctxt cx, ValueRef val) -> lval_result {
22042194
llobj=none[ValueRef]);
22052195
}
22062196

2197+
fn lval_generic_fn(@block_ctxt cx,
2198+
ty.ty_params_and_ty tpt,
2199+
ast.def_id fn_id,
2200+
&ast.ann ann)
2201+
-> lval_result {
2202+
2203+
check (cx.fcx.ccx.fn_pairs.contains_key(fn_id));
2204+
auto lv = lval_val(cx, cx.fcx.ccx.fn_pairs.get(fn_id));
2205+
auto monoty = node_ann_type(cx.fcx.ccx, ann);
2206+
auto tys = ty.resolve_ty_params(tpt, monoty);
2207+
2208+
if (_vec.len[@ty.t](tys) != 0u) {
2209+
auto bcx = cx;
2210+
let vec[ValueRef] tydescs = vec();
2211+
for (@ty.t t in tys) {
2212+
auto td = get_tydesc(bcx, t);
2213+
bcx = td.bcx;
2214+
append[ValueRef](tydescs, td.val);
2215+
}
2216+
auto gen = rec( item_type = tpt._1,
2217+
tydescs = tydescs );
2218+
lv = rec(res = res(bcx, lv.res.val),
2219+
generic = some[generic_info](gen)
2220+
with lv);
2221+
}
2222+
ret lv;
2223+
}
2224+
22072225
fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
22082226
&ast.ann ann) -> lval_result {
22092227
alt (dopt) {
@@ -2226,39 +2244,33 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
22262244
ret lval_mem(cx, cx.fcx.llobjfields.get(did));
22272245
}
22282246
case (ast.def_fn(?did)) {
2229-
check (cx.fcx.ccx.fn_pairs.contains_key(did));
2230-
check (cx.fcx.ccx.item_ids.contains_key(did));
2231-
2247+
check (cx.fcx.ccx.items.contains_key(did));
22322248
auto fn_item = cx.fcx.ccx.items.get(did);
2233-
auto lv = lval_val(cx, cx.fcx.ccx.fn_pairs.get(did));
2234-
auto monoty = node_ann_type(cx.fcx.ccx, ann);
2235-
auto tys = ty.resolve_ty_params(fn_item, monoty);
2236-
2237-
if (_vec.len[@ty.t](tys) != 0u) {
2238-
auto bcx = cx;
2239-
let vec[ValueRef] tydescs = vec();
2240-
for (@ty.t t in tys) {
2241-
auto td = get_tydesc(bcx, t);
2242-
bcx = td.bcx;
2243-
append[ValueRef](tydescs, td.val);
2244-
}
2245-
auto gen = rec( item_type = ty.item_ty(fn_item)._1,
2246-
tydescs = tydescs );
2247-
lv = rec(res = res(bcx, lv.res.val),
2248-
generic = some[generic_info](gen)
2249-
with lv);
2250-
}
2251-
2252-
ret lv;
2249+
ret lval_generic_fn(cx, ty.item_ty(fn_item), did, ann);
22532250
}
22542251
case (ast.def_obj(?did)) {
2255-
check (cx.fcx.ccx.fn_pairs.contains_key(did));
2256-
ret lval_val(cx, cx.fcx.ccx.fn_pairs.get(did));
2252+
check (cx.fcx.ccx.items.contains_key(did));
2253+
auto fn_item = cx.fcx.ccx.items.get(did);
2254+
ret lval_generic_fn(cx, ty.item_ty(fn_item), did, ann);
22572255
}
22582256
case (ast.def_variant(?tid, ?vid)) {
22592257
check (cx.fcx.ccx.tags.contains_key(tid));
22602258
if (cx.fcx.ccx.fn_pairs.contains_key(vid)) {
2261-
ret lval_val(cx, cx.fcx.ccx.fn_pairs.get(vid));
2259+
check (cx.fcx.ccx.items.contains_key(tid));
2260+
auto tag_item = cx.fcx.ccx.items.get(tid);
2261+
auto params = ty.item_ty(tag_item)._0;
2262+
auto fty = ty.plain_ty(ty.ty_nil);
2263+
alt (tag_item.node) {
2264+
case (ast.item_tag(_, ?variants, _, _)) {
2265+
for (ast.variant v in variants) {
2266+
if (v.id == vid) {
2267+
fty = node_ann_type(cx.fcx.ccx,
2268+
v.ann);
2269+
}
2270+
}
2271+
}
2272+
}
2273+
ret lval_generic_fn(cx, tup(params, fty), vid, ann);
22622274
} else {
22632275
// Nullary variants are just scalar constants.
22642276
check (cx.fcx.ccx.item_ids.contains_key(vid));
@@ -3809,15 +3821,13 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
38093821

38103822
alt (i.node) {
38113823
case (ast.item_fn(?name, ?f, _, ?fid, ?ann)) {
3812-
// TODO: type-params
38133824
cx.items.insert(fid, i);
38143825
if (! cx.obj_methods.contains_key(fid)) {
38153826
decl_fn_and_pair(cx, "fn", name, ann, fid);
38163827
}
38173828
}
38183829

38193830
case (ast.item_obj(?name, ?ob, _, ?oid, ?ann)) {
3820-
// TODO: type-params
38213831
cx.items.insert(oid, i);
38223832
decl_fn_and_pair(cx, "obj_ctor", name, ann, oid);
38233833
for (@ast.method m in ob.methods) {

trunk/src/comp/middle/ty.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ tag sty {
4242
ty_var(int); // ephemeral type var
4343
ty_local(ast.def_id); // type of a local var
4444
ty_param(ast.def_id); // fn type param
45+
ty_type;
4546
// TODO: ty_fn_arg(@t), for a possibly-aliased function argument
4647
}
4748

@@ -103,6 +104,7 @@ fn ast_ty_to_str(&@ast.ty ty) -> str {
103104
case (ast.ty_str) { s = "str"; }
104105
case (ast.ty_box(?t)) { s = "@" + ast_ty_to_str(t); }
105106
case (ast.ty_vec(?t)) { s = "vec[" + ast_ty_to_str(t) + "]"; }
107+
case (ast.ty_type) { s = "type"; }
106108

107109
case (ast.ty_tup(?elts)) {
108110
auto f = ast_ty_to_str;
@@ -138,6 +140,7 @@ fn ast_ty_to_str(&@ast.ty ty) -> str {
138140
s = "mutable " + ast_ty_to_str(t);
139141
}
140142

143+
141144
case (_) {
142145
fail; // FIXME: typestate bug
143146
}
@@ -215,6 +218,7 @@ fn ty_to_str(&@t typ) -> str {
215218
case (ty_str) { s = "str"; }
216219
case (ty_box(?t)) { s = "@" + ty_to_str(t); }
217220
case (ty_vec(?t)) { s = "vec[" + ty_to_str(t) + "]"; }
221+
case (ty_type) { s = "type"; }
218222

219223
case (ty_tup(?elems)) {
220224
auto f = ty_to_str;
@@ -281,6 +285,7 @@ fn fold_ty(ty_fold fld, @t ty) -> @t {
281285
case (ty_char) { ret fld.fold_simple_ty(ty); }
282286
case (ty_str) { ret fld.fold_simple_ty(ty); }
283287
case (ty_tag(_)) { ret fld.fold_simple_ty(ty); }
288+
case (ty_type) { ret fld.fold_simple_ty(ty); }
284289
case (ty_box(?subty)) {
285290
ret rewrap(ty, ty_box(fold_ty(fld, subty)));
286291
}
@@ -363,6 +368,7 @@ fn type_is_structural(@t ty) -> bool {
363368

364369
fn type_is_tup_like(@t ty) -> bool {
365370
alt (ty.struct) {
371+
case (ty_box(_)) { ret true; }
366372
case (ty_tup(_)) { ret true; }
367373
case (ty_rec(_)) { ret true; }
368374
case (ty_tag(_)) { ret true; }
@@ -402,6 +408,7 @@ fn type_is_scalar(@t ty) -> bool {
402408
case (ty_uint) { ret true; }
403409
case (ty_machine(_)) { ret true; }
404410
case (ty_char) { ret true; }
411+
case (ty_type) { ret true; }
405412
case (_) { ret false; }
406413
}
407414
fail;
@@ -571,7 +578,8 @@ fn is_fn_ty(@t fty) -> bool {
571578

572579
// Given an item, returns the associated type as well as a list of the IDs of
573580
// its type parameters.
574-
fn item_ty(@ast.item it) -> tup(vec[ast.def_id], @t) {
581+
type ty_params_and_ty = tup(vec[ast.def_id], @t);
582+
fn item_ty(@ast.item it) -> ty_params_and_ty {
575583
let vec[ast.ty_param] ty_params;
576584
auto result_ty;
577585
alt (it.node) {
@@ -938,6 +946,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
938946
case (ty.ty_machine(_)) { ret struct_cmp(expected, actual); }
939947
case (ty.ty_char) { ret struct_cmp(expected, actual); }
940948
case (ty.ty_str) { ret struct_cmp(expected, actual); }
949+
case (ty.ty_type) { ret struct_cmp(expected, actual); }
941950

942951
case (ty.ty_tag(?expected_id)) {
943952
alt (actual.struct) {
@@ -1233,7 +1242,8 @@ fn type_err_to_str(&ty.type_err err) -> str {
12331242

12341243
// Type parameter resolution, used in translation
12351244

1236-
fn resolve_ty_params(@ast.item item, @t monoty) -> vec[@t] {
1245+
fn resolve_ty_params(ty_params_and_ty ty_params_and_polyty,
1246+
@t monoty) -> vec[@t] {
12371247
obj resolve_ty_params_handler(@hashmap[ast.def_id,@t] bindings) {
12381248
fn resolve_local(ast.def_id id) -> @t { log "resolve local"; fail; }
12391249
fn record_local(ast.def_id id, @t ty) { log "record local"; fail; }
@@ -1249,8 +1259,6 @@ fn resolve_ty_params(@ast.item item, @t monoty) -> vec[@t] {
12491259
}
12501260
}
12511261

1252-
auto ty_params_and_polyty = item_ty(item);
1253-
12541262
auto bindings = @new_def_hash[@t]();
12551263
auto handler = resolve_ty_params_handler(bindings);
12561264

0 commit comments

Comments
 (0)