Skip to content

Commit 3ba6736

Browse files
committed
More typeck hacking, check if and call exprs, enable fact and deep tests.
1 parent 5955e23 commit 3ba6736

File tree

3 files changed

+240
-146
lines changed

3 files changed

+240
-146
lines changed

src/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ TEST_XFAILS_SELF := $(filter-out \
522522
bool-not.rs \
523523
char.rs \
524524
dead-code-one-arm-if.rs \
525+
deep.rs \
526+
fact.rs \
525527
hello.rs \
526528
int.rs \
527529
item-name-overload.rs \

src/comp/middle/trans.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type glue_fns = rec(ValueRef activate_glue,
4141
ValueRef exit_task_glue,
4242
vec[ValueRef] upcall_glues);
4343

44-
state type trans_ctxt = rec(session.session sess,
44+
state type crate_ctxt = rec(session.session sess,
4545
ModuleRef llmod,
4646
hashmap[str, ValueRef] upcalls,
4747
hashmap[str, ValueRef] fn_names,
@@ -55,7 +55,7 @@ state type fn_ctxt = rec(ValueRef llfn,
5555
ValueRef lltaskptr,
5656
hashmap[ast.def_id, ValueRef] llargs,
5757
hashmap[ast.def_id, ValueRef] lllocals,
58-
@trans_ctxt tcx);
58+
@crate_ctxt ccx);
5959

6060
tag cleanup {
6161
clean(fn(@block_ctxt cx) -> result);
@@ -238,13 +238,13 @@ fn T_taskptr() -> TypeRef {
238238
ret T_ptr(T_task());
239239
}
240240

241-
fn type_of(@trans_ctxt cx, @typeck.ty t) -> TypeRef {
241+
fn type_of(@crate_ctxt cx, @typeck.ty t) -> TypeRef {
242242
let TypeRef llty = type_of_inner(cx, t);
243243
check (llty as int != 0);
244244
ret llty;
245245
}
246246

247-
fn type_of_inner(@trans_ctxt cx, @typeck.ty t) -> TypeRef {
247+
fn type_of_inner(@crate_ctxt cx, @typeck.ty t) -> TypeRef {
248248
alt (t.struct) {
249249
case (typeck.ty_nil) { ret T_nil(); }
250250
case (typeck.ty_bool) { ret T_bool(); }
@@ -334,7 +334,7 @@ fn C_int(int i) -> ValueRef {
334334
ret C_integral(i, T_int());
335335
}
336336

337-
fn C_str(@trans_ctxt cx, str s) -> ValueRef {
337+
fn C_str(@crate_ctxt cx, str s) -> ValueRef {
338338
auto sc = llvm.LLVMConstString(_str.buf(s), _str.byte_len(s), False);
339339
auto g = llvm.LLVMAddGlobal(cx.llmod, val_ty(sc),
340340
_str.buf(cx.names.next("str")));
@@ -395,7 +395,7 @@ fn decl_upcall(ModuleRef llmod, uint _n) -> ValueRef {
395395
ret decl_fastcall_fn(llmod, s, T_fn(args, T_int()));
396396
}
397397

398-
fn get_upcall(@trans_ctxt cx, str name, int n_args) -> ValueRef {
398+
fn get_upcall(@crate_ctxt cx, str name, int n_args) -> ValueRef {
399399
if (cx.upcalls.contains_key(name)) {
400400
ret cx.upcalls.get(name);
401401
}
@@ -409,10 +409,10 @@ fn get_upcall(@trans_ctxt cx, str name, int n_args) -> ValueRef {
409409

410410
fn trans_upcall(@block_ctxt cx, str name, vec[ValueRef] args) -> result {
411411
let int n = _vec.len[ValueRef](args) as int;
412-
let ValueRef llupcall = get_upcall(cx.fcx.tcx, name, n);
412+
let ValueRef llupcall = get_upcall(cx.fcx.ccx, name, n);
413413
llupcall = llvm.LLVMConstPointerCast(llupcall, T_int());
414414

415-
let ValueRef llglue = cx.fcx.tcx.glues.upcall_glues.(n);
415+
let ValueRef llglue = cx.fcx.ccx.glues.upcall_glues.(n);
416416
let vec[ValueRef] call_args = vec(cx.fcx.lltaskptr, llupcall);
417417
for (ValueRef a in args) {
418418
call_args += cx.build.ZExtOrBitCast(a, T_int());
@@ -510,7 +510,7 @@ fn trans_copy_ty(@block_ctxt cx,
510510
ret res(r.bcx, r.bcx.build.Store(src, dst));
511511
}
512512
}
513-
cx.fcx.tcx.sess.unimpl("ty variant in trans_copy_ty");
513+
cx.fcx.ccx.sess.unimpl("ty variant in trans_copy_ty");
514514
fail;
515515
}
516516

@@ -541,7 +541,7 @@ impure fn trans_lit(@block_ctxt cx, &ast.lit lit) -> result {
541541
case (ast.lit_str(?s)) {
542542
auto len = (_str.byte_len(s) as int) + 1;
543543
auto sub = trans_upcall(cx, "upcall_new_str",
544-
vec(p2i(C_str(cx.fcx.tcx, s)),
544+
vec(p2i(C_str(cx.fcx.ccx, s)),
545545
C_int(len)));
546546
sub.val = sub.bcx.build.IntToPtr(sub.val,
547547
T_ptr(T_str(len as uint)));
@@ -551,7 +551,7 @@ impure fn trans_lit(@block_ctxt cx, &ast.lit lit) -> result {
551551
}
552552
}
553553

554-
fn node_type(@trans_ctxt cx, &ast.ann a) -> TypeRef {
554+
fn node_type(@crate_ctxt cx, &ast.ann a) -> TypeRef {
555555
alt (a) {
556556
case (ast.ann_none) {
557557
log "missing type annotation";
@@ -583,7 +583,7 @@ impure fn trans_unary(@block_ctxt cx, ast.unop op,
583583
ret sub;
584584
}
585585
case (ast.box) {
586-
auto e_ty = node_type(cx.fcx.tcx, a);
586+
auto e_ty = node_type(cx.fcx.ccx, a);
587587
auto box_ty = T_box(e_ty);
588588
sub.val = cx.build.Malloc(box_ty);
589589
auto rc = sub.bcx.build.GEP(sub.val,
@@ -592,7 +592,7 @@ impure fn trans_unary(@block_ctxt cx, ast.unop op,
592592
ret res(sub.bcx, cx.build.Store(C_int(1), rc));
593593
}
594594
}
595-
cx.fcx.tcx.sess.unimpl("expr variant in trans_unary");
595+
cx.fcx.ccx.sess.unimpl("expr variant in trans_unary");
596596
fail;
597597
}
598598

@@ -737,7 +737,7 @@ impure fn trans_binary(@block_ctxt cx, ast.binop op,
737737
ret sub;
738738
}
739739
}
740-
cx.fcx.tcx.sess.unimpl("expr variant in trans_binary");
740+
cx.fcx.ccx.sess.unimpl("expr variant in trans_binary");
741741
fail;
742742
}
743743

@@ -864,21 +864,21 @@ fn trans_lval(@block_ctxt cx, &ast.expr e)
864864
true, did);
865865
}
866866
case (ast.def_fn(?did)) {
867-
ret tup(res(cx, cx.fcx.tcx.fn_ids.get(did)),
867+
ret tup(res(cx, cx.fcx.ccx.fn_ids.get(did)),
868868
false, did);
869869
}
870870
case (_) {
871-
cx.fcx.tcx.sess.unimpl("def variant in trans");
871+
cx.fcx.ccx.sess.unimpl("def variant in trans");
872872
}
873873
}
874874
}
875875
case (none[ast.def]) {
876-
cx.fcx.tcx.sess.err("unresolved expr_name in trans");
876+
cx.fcx.ccx.sess.err("unresolved expr_name in trans");
877877
}
878878
}
879879
}
880880
}
881-
cx.fcx.tcx.sess.unimpl("expr variant in trans_lval");
881+
cx.fcx.ccx.sess.unimpl("expr variant in trans_lval");
882882
fail;
883883
}
884884

@@ -963,7 +963,7 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
963963
}
964964

965965
}
966-
cx.fcx.tcx.sess.unimpl("expr variant in trans_expr");
966+
cx.fcx.ccx.sess.unimpl("expr variant in trans_expr");
967967
fail;
968968
}
969969

@@ -999,8 +999,8 @@ impure fn trans_check_expr(@block_ctxt cx, &ast.expr e) -> result {
999999
auto cond_res = trans_expr(cx, e);
10001000

10011001
// FIXME: need pretty-printer.
1002-
auto V_expr_str = p2i(C_str(cx.fcx.tcx, "<expr>"));
1003-
auto V_filename = p2i(C_str(cx.fcx.tcx, e.span.filename));
1002+
auto V_expr_str = p2i(C_str(cx.fcx.ccx, "<expr>"));
1003+
auto V_filename = p2i(C_str(cx.fcx.ccx, e.span.filename));
10041004
auto V_line = e.span.lo.line as int;
10051005
auto args = vec(V_expr_str, V_filename, C_int(V_line));
10061006

@@ -1084,7 +1084,7 @@ impure fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
10841084
}
10851085
}
10861086
case (_) {
1087-
cx.fcx.tcx.sess.unimpl("stmt variant");
1087+
cx.fcx.ccx.sess.unimpl("stmt variant");
10881088
}
10891089
}
10901090
ret sub;
@@ -1103,7 +1103,7 @@ fn new_block_ctxt(@fn_ctxt cx, block_parent parent,
11031103
str name) -> @block_ctxt {
11041104
let BasicBlockRef llbb =
11051105
llvm.LLVMAppendBasicBlock(cx.llfn,
1106-
_str.buf(cx.tcx.names.next(name)));
1106+
_str.buf(cx.ccx.names.next(name)));
11071107

11081108
ret @rec(llbb=llbb,
11091109
build=new_builder(llbb, name),
@@ -1159,7 +1159,7 @@ impure fn trans_block(@block_ctxt cx, &ast.block b) -> result {
11591159
auto bcx = cx;
11601160

11611161
for each (@ast.local local in block_locals(b)) {
1162-
auto ty = node_type(cx.fcx.tcx, local.ann);
1162+
auto ty = node_type(cx.fcx.ccx, local.ann);
11631163
auto val = bcx.build.Alloca(ty);
11641164
cx.fcx.lllocals.insert(local.id, val);
11651165
}
@@ -1179,7 +1179,7 @@ impure fn trans_block(@block_ctxt cx, &ast.block b) -> result {
11791179
ret res(bcx, r.val);
11801180
}
11811181

1182-
fn new_fn_ctxt(@trans_ctxt cx,
1182+
fn new_fn_ctxt(@crate_ctxt cx,
11831183
str name,
11841184
&ast._fn f,
11851185
ast.def_id fid) -> @fn_ctxt {
@@ -1204,15 +1204,15 @@ fn new_fn_ctxt(@trans_ctxt cx,
12041204
lltaskptr=lltaskptr,
12051205
llargs=llargs,
12061206
lllocals=lllocals,
1207-
tcx=cx);
1207+
ccx=cx);
12081208
}
12091209

12101210
fn is_terminated(@block_ctxt cx) -> bool {
12111211
auto inst = llvm.LLVMGetLastInstruction(cx.llbb);
12121212
ret llvm.LLVMIsATerminatorInst(inst) as int != 0;
12131213
}
12141214

1215-
impure fn trans_fn(@trans_ctxt cx, &ast._fn f, ast.def_id fid) {
1215+
impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid) {
12161216

12171217
auto fcx = new_fn_ctxt(cx, cx.path, f, fid);
12181218
auto bcx = new_top_block_ctxt(fcx);
@@ -1224,7 +1224,7 @@ impure fn trans_fn(@trans_ctxt cx, &ast._fn f, ast.def_id fid) {
12241224
}
12251225
}
12261226

1227-
impure fn trans_item(@trans_ctxt cx, &ast.item item) {
1227+
impure fn trans_item(@crate_ctxt cx, &ast.item item) {
12281228
alt (item.node) {
12291229
case (ast.item_fn(?name, ?f, ?fid, _)) {
12301230
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
@@ -1237,14 +1237,14 @@ impure fn trans_item(@trans_ctxt cx, &ast.item item) {
12371237
}
12381238
}
12391239

1240-
impure fn trans_mod(@trans_ctxt cx, &ast._mod m) {
1240+
impure fn trans_mod(@crate_ctxt cx, &ast._mod m) {
12411241
for (@ast.item item in m.items) {
12421242
trans_item(cx, *item);
12431243
}
12441244
}
12451245

12461246

1247-
fn collect_item(&@trans_ctxt cx, @ast.item i) -> @trans_ctxt {
1247+
fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
12481248
alt (i.node) {
12491249
case (ast.item_fn(?name, ?f, ?fid, ?ann)) {
12501250
cx.items.insert(fid, i);
@@ -1262,22 +1262,22 @@ fn collect_item(&@trans_ctxt cx, @ast.item i) -> @trans_ctxt {
12621262
}
12631263

12641264

1265-
fn collect_items(@trans_ctxt cx, @ast.crate crate) {
1265+
fn collect_items(@crate_ctxt cx, @ast.crate crate) {
12661266

1267-
let fold.ast_fold[@trans_ctxt] fld =
1268-
fold.new_identity_fold[@trans_ctxt]();
1267+
let fold.ast_fold[@crate_ctxt] fld =
1268+
fold.new_identity_fold[@crate_ctxt]();
12691269

12701270
fld = @rec( update_env_for_item = bind collect_item(_,_)
12711271
with *fld );
12721272

1273-
fold.fold_crate[@trans_ctxt](cx, fld, crate);
1273+
fold.fold_crate[@crate_ctxt](cx, fld, crate);
12741274
}
12751275

12761276
fn p2i(ValueRef v) -> ValueRef {
12771277
ret llvm.LLVMConstPtrToInt(v, T_int());
12781278
}
12791279

1280-
fn trans_exit_task_glue(@trans_ctxt cx) {
1280+
fn trans_exit_task_glue(@crate_ctxt cx) {
12811281
let vec[TypeRef] T_args = vec();
12821282
let vec[ValueRef] V_args = vec();
12831283

@@ -1287,14 +1287,14 @@ fn trans_exit_task_glue(@trans_ctxt cx) {
12871287
lltaskptr=lltaskptr,
12881288
llargs=new_def_hash[ValueRef](),
12891289
lllocals=new_def_hash[ValueRef](),
1290-
tcx=cx);
1290+
ccx=cx);
12911291

12921292
auto bcx = new_top_block_ctxt(fcx);
12931293
trans_upcall(bcx, "upcall_exit", V_args);
12941294
bcx.build.RetVoid();
12951295
}
12961296

1297-
fn crate_constant(@trans_ctxt cx) -> ValueRef {
1297+
fn crate_constant(@crate_ctxt cx) -> ValueRef {
12981298

12991299
let ValueRef crate_ptr =
13001300
llvm.LLVMAddGlobal(cx.llmod, T_crate(),
@@ -1332,7 +1332,7 @@ fn crate_constant(@trans_ctxt cx) -> ValueRef {
13321332
ret crate_ptr;
13331333
}
13341334

1335-
fn trans_main_fn(@trans_ctxt cx, ValueRef llcrate) {
1335+
fn trans_main_fn(@crate_ctxt cx, ValueRef llcrate) {
13361336
auto T_main_args = vec(T_int(), T_int());
13371337
auto T_rust_start_args = vec(T_int(), T_int(), T_int(), T_int());
13381338

0 commit comments

Comments
 (0)