Skip to content

Commit 933c734

Browse files
lkupergraydon
authored andcommitted
---
yaml --- r: 1946 b: refs/heads/master c: ef0c903 h: refs/heads/master v: v3
1 parent 537d739 commit 933c734

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
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: e939d6f17c8dce7c2154c08ee044b749cbba41f4
2+
refs/heads/master: ef0c903f6a25cd9d8c900fbde336d4a4a5b43c56

trunk/src/comp/middle/trans.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4444,6 +4444,70 @@ fn trans_call(@block_ctxt cx, @ast.expr f,
44444444
ret res(bcx, retval);
44454445
}
44464446

4447+
fn trans_call_self(@block_ctxt cx, @ast.expr f,
4448+
option.t[ValueRef] lliterbody,
4449+
vec[@ast.expr] args,
4450+
&ast.ann ann) -> result {
4451+
log "translating a self-call";
4452+
4453+
auto f_res = trans_lval(cx, f);
4454+
auto faddr = f_res.res.val;
4455+
auto llenv = C_null(T_opaque_closure_ptr(cx.fcx.ccx.tn));
4456+
4457+
alt (f_res.llobj) {
4458+
case (some[ValueRef](_)) {
4459+
// It's a vtbl entry.
4460+
faddr = f_res.res.bcx.build.Load(faddr);
4461+
}
4462+
case (none[ValueRef]) {
4463+
// It's a closure.
4464+
auto bcx = f_res.res.bcx;
4465+
auto pair = faddr;
4466+
faddr = bcx.build.GEP(pair, vec(C_int(0),
4467+
C_int(abi.fn_field_code)));
4468+
faddr = bcx.build.Load(faddr);
4469+
4470+
auto llclosure = bcx.build.GEP(pair,
4471+
vec(C_int(0),
4472+
C_int(abi.fn_field_box)));
4473+
llenv = bcx.build.Load(llclosure);
4474+
}
4475+
}
4476+
auto fn_ty = ty.expr_ty(f);
4477+
auto ret_ty = ty.ann_to_type(ann);
4478+
auto args_res = trans_args(f_res.res.bcx,
4479+
llenv, f_res.llobj,
4480+
f_res.generic,
4481+
lliterbody,
4482+
args, fn_ty);
4483+
4484+
auto bcx = args_res._0;
4485+
auto llargs = args_res._1;
4486+
auto llretslot = args_res._2;
4487+
4488+
/*
4489+
log "calling: " + val_str(cx.fcx.ccx.tn, faddr);
4490+
4491+
for (ValueRef arg in llargs) {
4492+
log "arg: " + val_str(cx.fcx.ccx.tn, arg);
4493+
}
4494+
*/
4495+
4496+
bcx.build.FastCall(faddr, llargs);
4497+
auto retval = C_nil();
4498+
4499+
if (!ty.type_is_nil(ret_ty)) {
4500+
retval = load_scalar_or_boxed(bcx, llretslot, ret_ty);
4501+
// Retval doesn't correspond to anything really tangible in the frame,
4502+
// but it's a ref all the same, so we put a note here to drop it when
4503+
// we're done in this scope.
4504+
find_scope_cx(cx).cleanups +=
4505+
vec(clean(bind drop_ty(_, retval, ret_ty)));
4506+
}
4507+
4508+
ret res(bcx, retval);
4509+
}
4510+
44474511
fn trans_tup(@block_ctxt cx, vec[ast.elt] elts,
44484512
&ast.ann ann) -> result {
44494513
auto bcx = cx;
@@ -4680,6 +4744,10 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
46804744
ret trans_call(cx, f, none[ValueRef], args, ann);
46814745
}
46824746

4747+
case (ast.expr_call_self(?f, ?args, ?ann)) {
4748+
ret trans_call_self(cx, f, none[ValueRef], args, ann);
4749+
}
4750+
46834751
case (ast.expr_cast(?e, _, ?ann)) {
46844752
ret trans_cast(cx, e, ann);
46854753
}

trunk/src/comp/pretty/pprust.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,13 @@ impure fn print_expr(ps s, &@ast.expr expr) {
431431
commasep_exprs(s, args);
432432
pclose(s);
433433
}
434+
case (ast.expr_call_self(?func,?args,_)) {
435+
wrd(s.s, "self.");
436+
print_expr(s, func);
437+
popen(s);
438+
commasep_exprs(s, args);
439+
pclose(s);
440+
}
434441
case (ast.expr_bind(?func,?args,_)) {
435442
impure fn print_opt(ps s, &option.t[@ast.expr] expr) {
436443
alt (expr) {

0 commit comments

Comments
 (0)