Skip to content

Commit 537b864

Browse files
committed
---
yaml --- r: 830 b: refs/heads/master c: 67477b8 h: refs/heads/master v: v3
1 parent 731b370 commit 537b864

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
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: 3aaae2a881ed0e8c74a4a5b36e4fa4624d48eda0
2+
refs/heads/master: 67477b85ae7404508e3a963d68dbfb09a3d247f9

trunk/src/comp/middle/trans.rs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ type glue_fns = rec(ValueRef activate_glue,
4343
state type trans_ctxt = rec(session.session sess,
4444
ModuleRef llmod,
4545
hashmap[str,ValueRef] upcalls,
46-
hashmap[str,ValueRef] fns,
46+
hashmap[str,ValueRef] fn_names,
47+
hashmap[ast.def_id,ValueRef] fn_ids,
4748
@glue_fns glues,
4849
namegen names,
4950
str path);
@@ -667,6 +668,9 @@ fn trans_lval(@block_ctxt cx, &ast.expr e) -> result {
667668
case (ast.def_local(?did)) {
668669
ret res(cx, cx.fcx.lllocals.get(did));
669670
}
671+
case (ast.def_fn(?did)) {
672+
ret res(cx, cx.fcx.tcx.fn_ids.get(did));
673+
}
670674
case (_) {
671675
cx.fcx.tcx.sess.unimpl("def variant in trans");
672676
}
@@ -682,6 +686,20 @@ fn trans_lval(@block_ctxt cx, &ast.expr e) -> result {
682686
fail;
683687
}
684688

689+
fn trans_exprs(@block_ctxt cx, &vec[@ast.expr] es)
690+
-> tup(@block_ctxt, vec[ValueRef]) {
691+
let vec[ValueRef] vs = vec();
692+
let @block_ctxt bcx = cx;
693+
694+
for (@ast.expr e in es) {
695+
auto res = trans_expr(bcx, *e);
696+
vs += res.val;
697+
bcx = res.bcx;
698+
}
699+
700+
ret tup(bcx, vs);
701+
}
702+
685703
fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
686704
alt (e.node) {
687705
case (ast.expr_lit(?lit, _)) {
@@ -723,6 +741,16 @@ fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
723741
cx.build.Store(rhs_res.val, lhs_res.val));
724742
}
725743

744+
case (ast.expr_call(?f, ?args, _)) {
745+
auto f_res = trans_lval(cx, *f);
746+
auto args_res = trans_exprs(f_res.bcx, args);
747+
auto llargs = vec(cx.fcx.lloutptr,
748+
cx.fcx.lltaskptr);
749+
llargs += args_res._1;
750+
ret res(args_res._0,
751+
cx.build.Call(f_res.val, llargs));
752+
}
753+
726754
}
727755
cx.fcx.tcx.sess.unimpl("expr variant in trans_expr");
728756
fail;
@@ -895,14 +923,16 @@ fn trans_block(@block_ctxt cx, &ast.block b) -> result {
895923

896924
fn new_fn_ctxt(@trans_ctxt cx,
897925
str name,
926+
ast.def_id fid,
898927
TypeRef T_out,
899928
vec[TypeRef] T_explicit_args) -> @fn_ctxt {
900929
let vec[TypeRef] args = vec(T_ptr(T_out), // outptr.
901930
T_taskptr() // taskptr
902931
);
903932
args += T_explicit_args;
904933
let ValueRef llfn = decl_cdecl_fn(cx.llmod, name, args, T_void());
905-
cx.fns.insert(cx.path, llfn);
934+
cx.fn_names.insert(cx.path, llfn);
935+
cx.fn_ids.insert(fid, llfn);
906936
let ValueRef lloutptr = llvm.LLVMGetParam(llfn, 0u);
907937
let ValueRef lltaskptr = llvm.LLVMGetParam(llfn, 1u);
908938
let hashmap[ast.def_id, ValueRef] lllocals = new_def_hash[ValueRef]();
@@ -913,20 +943,20 @@ fn new_fn_ctxt(@trans_ctxt cx,
913943
tcx=cx);
914944
}
915945

916-
fn trans_fn(@trans_ctxt cx, &ast._fn f) {
946+
fn trans_fn(@trans_ctxt cx, &ast._fn f, ast.def_id fid) {
917947
let TypeRef out = T_int();
918948
let vec[TypeRef] args = vec();
919949

920-
auto fcx = new_fn_ctxt(cx, cx.path, out, args);
950+
auto fcx = new_fn_ctxt(cx, cx.path, fid, out, args);
921951

922952
trans_block(new_top_block_ctxt(fcx), f.body);
923953
}
924954

925955
fn trans_item(@trans_ctxt cx, &ast.item item) {
926956
alt (item.node) {
927-
case (ast.item_fn(?name, ?f, _)) {
957+
case (ast.item_fn(?name, ?f, ?fid)) {
928958
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
929-
trans_fn(sub_cx, f);
959+
trans_fn(sub_cx, f, fid);
930960
}
931961
case (ast.item_mod(?name, ?m, _)) {
932962
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
@@ -1014,7 +1044,7 @@ fn trans_main_fn(@trans_ctxt cx, ValueRef llcrate) {
10141044

10151045
auto llargc = llvm.LLVMGetParam(llmain, 0u);
10161046
auto llargv = llvm.LLVMGetParam(llmain, 1u);
1017-
auto llrust_main = cx.fns.get("_rust.main");
1047+
auto llrust_main = cx.fn_names.get("_rust.main");
10181048

10191049
//
10201050
// Emit the moral equivalent of:
@@ -1067,7 +1097,8 @@ fn trans_crate(session.session sess, @ast.crate crate) {
10671097
auto cx = @rec(sess = sess,
10681098
llmod = llmod,
10691099
upcalls = new_str_hash[ValueRef](),
1070-
fns = new_str_hash[ValueRef](),
1100+
fn_names = new_str_hash[ValueRef](),
1101+
fn_ids = new_def_hash[ValueRef](),
10711102
glues = glues,
10721103
names = namegen(0),
10731104
path = "_rust");

0 commit comments

Comments
 (0)