@@ -2678,7 +2678,9 @@ fn trans_local_var(cx: @block_ctxt, def: ast::def) -> local_var_result {
2678
2678
ret { val : cx. fcx . llobjfields . get ( did. node ) , kind : owned } ;
2679
2679
}
2680
2680
ast:: def_self ( did) {
2681
- ret lval_owned ( cx, cx. fcx . llenv ) ;
2681
+ let slf = option:: get ( cx. fcx . llself ) ;
2682
+ let ptr = PointerCast ( cx, slf. v , T_ptr ( type_of_or_i8 ( cx, slf. t ) ) ) ;
2683
+ ret { val : ptr, kind : owned} ;
2682
2684
}
2683
2685
_ {
2684
2686
bcx_ccx( cx) . sess . span_unimpl
@@ -2832,21 +2834,29 @@ fn trans_index(cx: @block_ctxt, sp: span, base: @ast::expr, idx: @ast::expr,
2832
2834
ret lval_owned( next_cx, elt) ;
2833
2835
}
2834
2836
2837
+ fn expr_is_lval ( bcx : @block_ctxt , e : @ast:: expr ) -> bool {
2838
+ let ccx = bcx_ccx ( bcx) ;
2839
+ ty:: expr_is_lval ( ccx. method_map , ccx. tcx , e)
2840
+ }
2841
+
2835
2842
// This is for impl methods, not obj methods.
2836
2843
fn trans_method_callee ( bcx : @block_ctxt , e : @ast:: expr , base : @ast:: expr ,
2837
2844
did : ast:: def_id ) -> lval_maybe_callee {
2838
- let bcx = trans_expr ( bcx, base, ignore) ; // FIXME pass self
2839
- lval_static_fn ( bcx, did, e. id )
2845
+ let tz = [ ] , tr = [ ] ;
2846
+ let basety = ty:: expr_ty ( bcx_tcx ( bcx) , base) ;
2847
+ let { bcx, val} = trans_arg_expr ( bcx, { mode: ast:: by_ref, ty: basety} ,
2848
+ type_of_or_i8 ( bcx, basety) , tz, tr, base) ;
2849
+ let val = PointerCast ( bcx, val, T_opaque_boxed_closure_ptr ( bcx_ccx ( bcx) ) ) ;
2850
+ { env: obj_env ( val) with lval_static_fn ( bcx, did, e. id ) }
2840
2851
}
2841
2852
2842
2853
fn trans_callee ( bcx : @block_ctxt , e : @ast:: expr ) -> lval_maybe_callee {
2843
2854
alt e. node {
2844
2855
ast:: expr_path ( p) { ret trans_path ( bcx, p, e. id ) ; }
2845
2856
ast:: expr_field ( base, ident) {
2846
- let method_map = bcx_ccx ( bcx) . method_map ;
2847
2857
// Lval means this is a record field, so not a method
2848
- if !ty :: expr_is_lval ( method_map , bcx_tcx ( bcx) , e) {
2849
- alt method_map. find ( e. id ) {
2858
+ if !expr_is_lval ( bcx, e) {
2859
+ alt bcx_ccx ( bcx ) . method_map . find ( e. id ) {
2850
2860
some ( did) { // An impl method
2851
2861
ret trans_method_callee ( bcx, e, base, did) ;
2852
2862
}
@@ -2858,15 +2868,6 @@ fn trans_callee(bcx: @block_ctxt, e: @ast::expr) -> lval_maybe_callee {
2858
2868
}
2859
2869
}
2860
2870
}
2861
- ast:: expr_self_method ( ident) {
2862
- alt bcx. fcx . llself {
2863
- some ( pair) {
2864
- let fld = trans_object_field_inner ( bcx, pair. v , ident, pair. t ) ;
2865
- ret { bcx : fld. bcx , val : fld. mthptr , kind : owned,
2866
- env : obj_env ( fld. objptr ) , generic : none} ;
2867
- }
2868
- }
2869
- }
2870
2871
_ { }
2871
2872
}
2872
2873
let lv = trans_temp_lval ( bcx, e) ;
@@ -3475,7 +3476,7 @@ fn trans_expr_save_in(bcx: @block_ctxt, e: @ast::expr, dest: ValueRef)
3475
3476
// use trans_temp_expr.
3476
3477
fn trans_temp_lval ( bcx : @block_ctxt , e : @ast:: expr ) -> lval_result {
3477
3478
let bcx = bcx;
3478
- if ty :: expr_is_lval ( bcx_ccx ( bcx) . method_map , bcx_tcx ( bcx ) , e) {
3479
+ if expr_is_lval ( bcx, e) {
3479
3480
ret trans_lval ( bcx, e) ;
3480
3481
} else {
3481
3482
let tcx = bcx_tcx ( bcx) ;
@@ -3513,7 +3514,7 @@ fn trans_temp_expr(bcx: @block_ctxt, e: @ast::expr) -> result {
3513
3514
// - exprs with non-immediate type never get dest=by_val
3514
3515
fn trans_expr ( bcx : @block_ctxt , e : @ast:: expr , dest : dest ) -> @block_ctxt {
3515
3516
let tcx = bcx_tcx ( bcx) ;
3516
- if ty :: expr_is_lval ( bcx_ccx ( bcx) . method_map , tcx , e) {
3517
+ if expr_is_lval ( bcx, e) {
3517
3518
ret lval_to_dps ( bcx, e, dest) ;
3518
3519
}
3519
3520
@@ -3555,7 +3556,7 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
3555
3556
ret trans_closure:: trans_bind ( bcx, f, args, e. id , dest) ;
3556
3557
}
3557
3558
ast:: expr_copy ( a) {
3558
- if !ty :: expr_is_lval ( bcx_ccx ( bcx) . method_map , tcx , a) {
3559
+ if !expr_is_lval ( bcx, a) {
3559
3560
ret trans_expr ( bcx, a, dest) ;
3560
3561
}
3561
3562
else { ret lval_to_dps ( bcx, a, dest) ; }
@@ -3957,9 +3958,7 @@ fn init_local(bcx: @block_ctxt, local: @ast::local) -> @block_ctxt {
3957
3958
let bcx = bcx;
3958
3959
alt local. node . init {
3959
3960
some ( init) {
3960
- if init. op == ast:: init_assign ||
3961
- !ty:: expr_is_lval ( bcx_ccx ( bcx) . method_map , bcx_tcx ( bcx) ,
3962
- init. expr ) {
3961
+ if init. op == ast:: init_assign || !expr_is_lval ( bcx, init. expr ) {
3963
3962
bcx = trans_expr_save_in ( bcx, init. expr , llptr) ;
3964
3963
} else { // This is a move from an lval, must perform an actual move
3965
3964
let sub = trans_lval ( bcx, init. expr ) ;
@@ -4347,15 +4346,15 @@ fn new_fn_ctxt(cx: @local_ctxt, sp: span, llfndecl: ValueRef) -> @fn_ctxt {
4347
4346
// spaces that have been created for them (by code in the llallocas field of
4348
4347
// the function's fn_ctxt). create_llargs_for_fn_args populates the llargs
4349
4348
// field of the fn_ctxt with
4350
- fn create_llargs_for_fn_args ( cx : @fn_ctxt , ty_self : option :: t < ty :: t > ,
4349
+ fn create_llargs_for_fn_args ( cx : @fn_ctxt , ty_self : self_arg ,
4351
4350
args : [ ast:: arg ] , ty_params : [ ast:: ty_param ] ) {
4352
4351
// Skip the implicit arguments 0, and 1. TODO: Pull out 2u and define
4353
4352
// it as a constant, since we're using it in several places in trans this
4354
4353
// way.
4355
4354
let arg_n = 2 u;
4356
4355
alt ty_self {
4357
- some ( tt) { cx. llself = some :: < val_self_pair > ( { v: cx. llenv , t: tt} ) ; }
4358
- none . {
4356
+ obj_self ( tt) | impl_self ( tt ) { cx. llself = some ( { v: cx. llenv , t: tt} ) ; }
4357
+ no_self . {
4359
4358
let i = 0 u;
4360
4359
for tp: ast:: ty_param in ty_params {
4361
4360
let llarg = llvm:: LLVMGetParam ( cx. llfn , arg_n) ;
@@ -4473,19 +4472,23 @@ fn finish_fn(fcx: @fn_ctxt, lltop: BasicBlockRef) {
4473
4472
RetVoid ( ret_cx) ;
4474
4473
}
4475
4474
4475
+ tag self_arg { obj_self( ty:: t) ; impl_self ( ty:: t) ; no_self; }
4476
+
4476
4477
// trans_closure: Builds an LLVM function out of a source function.
4477
4478
// If the function closes over its environment a closure will be
4478
4479
// returned.
4479
4480
fn trans_closure ( cx : @local_ctxt , sp : span , f : ast:: _fn , llfndecl : ValueRef ,
4480
- ty_self : option :: t < ty :: t > , ty_params : [ ast:: ty_param ] ,
4481
+ ty_self : self_arg , ty_params : [ ast:: ty_param ] ,
4481
4482
id : ast:: node_id , maybe_load_env : block ( @fn_ctxt ) ) {
4482
4483
set_uwtable ( llfndecl) ;
4483
4484
4484
4485
// Set up arguments to the function.
4485
4486
let fcx = new_fn_ctxt_w_id ( cx, sp, llfndecl, id, f. decl . cf ) ;
4486
4487
create_llargs_for_fn_args ( fcx, ty_self, f. decl . inputs , ty_params) ;
4487
- alt fcx. llself {
4488
- some ( llself) { populate_fn_ctxt_from_llself ( fcx, llself) ; }
4488
+ alt ty_self {
4489
+ obj_self( _) {
4490
+ populate_fn_ctxt_from_llself ( fcx, option:: get ( fcx. llself ) ) ;
4491
+ }
4489
4492
_ { }
4490
4493
}
4491
4494
@@ -4526,7 +4529,7 @@ fn trans_closure(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
4526
4529
// trans_fn: creates an LLVM function corresponding to a source language
4527
4530
// function.
4528
4531
fn trans_fn ( cx : @local_ctxt , sp : span , f : ast:: _fn , llfndecl : ValueRef ,
4529
- ty_self : option :: t < ty :: t > , ty_params : [ ast:: ty_param ] ,
4532
+ ty_self : self_arg , ty_params : [ ast:: ty_param ] ,
4530
4533
id : ast:: node_id ) {
4531
4534
let do_time = cx. ccx . sess . get_opts ( ) . stats ;
4532
4535
let start = do_time ? time:: get_time ( ) : { sec: 0u32 , usec: 0u32 } ;
@@ -4549,7 +4552,7 @@ fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::_fn,
4549
4552
}
4550
4553
let fcx = new_fn_ctxt ( cx, sp, llctor_decl) ;
4551
4554
let ret_t = ty:: ret_ty_of_fn ( cx. ccx . tcx , ctor_id) ;
4552
- create_llargs_for_fn_args ( fcx, none , dtor. decl . inputs , ty_params) ;
4555
+ create_llargs_for_fn_args ( fcx, no_self , dtor. decl . inputs , ty_params) ;
4553
4556
let bcx = new_top_block_ctxt ( fcx) ;
4554
4557
let lltop = bcx. llbb ;
4555
4558
let arg_t = arg_tys_of_fn ( ccx, ctor_id) [ 0 ] . ty ;
@@ -4608,7 +4611,7 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
4608
4611
}
4609
4612
}
4610
4613
let fcx = new_fn_ctxt ( cx, variant. span , llfndecl) ;
4611
- create_llargs_for_fn_args ( fcx, none , fn_args, ty_params) ;
4614
+ create_llargs_for_fn_args ( fcx, no_self , fn_args, ty_params) ;
4612
4615
let ty_param_substs: [ ty:: t ] = [ ] ;
4613
4616
i = 0 u;
4614
4617
for tp: ast:: ty_param in ty_params {
@@ -4655,13 +4658,15 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
4655
4658
finish_fn ( fcx, lltop) ;
4656
4659
}
4657
4660
4658
- fn trans_impl ( cx : @local_ctxt , name : ast:: ident , methods : [ @ast:: method ] ) {
4661
+ fn trans_impl ( cx : @local_ctxt , name : ast:: ident , methods : [ @ast:: method ] ,
4662
+ id : ast:: node_id ) {
4659
4663
let sub_cx = extend_path ( cx, name) ;
4660
4664
for m in methods {
4661
4665
alt cx. ccx . item_ids . find ( m. node . id ) {
4662
- some ( llfndecl ) {
4666
+ some ( llfn ) {
4663
4667
trans_fn ( extend_path ( sub_cx, m. node . ident ) , m. span , m. node . meth ,
4664
- llfndecl, none, [ ] , m. node . id ) ;
4668
+ llfn, impl_self ( ty:: node_id_to_monotype ( cx. ccx . tcx , id) ) ,
4669
+ [ ] , m. node . id ) ;
4665
4670
}
4666
4671
}
4667
4672
}
@@ -4961,7 +4966,7 @@ fn trans_item(cx: @local_ctxt, item: ast::item) {
4961
4966
let sub_cx = extend_path ( cx, item. ident ) ;
4962
4967
alt cx. ccx . item_ids . find ( item. id ) {
4963
4968
some ( llfndecl) {
4964
- trans_fn ( sub_cx, item. span , f, llfndecl, none , tps, item. id ) ;
4969
+ trans_fn ( sub_cx, item. span , f, llfndecl, no_self , tps, item. id ) ;
4965
4970
}
4966
4971
_ {
4967
4972
cx. ccx . sess . span_fatal ( item. span ,
@@ -4975,14 +4980,14 @@ fn trans_item(cx: @local_ctxt, item: ast::item) {
4975
4980
with * extend_path ( cx, item. ident ) } ;
4976
4981
trans_obj ( sub_cx, item. span , ob, ctor_id, tps) ;
4977
4982
}
4978
- ast:: item_impl ( _, _, ms) { trans_impl ( cx, item. ident , ms) ; }
4983
+ ast:: item_impl ( _, _, ms) { trans_impl ( cx, item. ident , ms, item . id ) ; }
4979
4984
ast:: item_res ( dtor, dtor_id, tps, ctor_id) {
4980
4985
trans_res_ctor ( cx, item. span , dtor, ctor_id, tps) ;
4981
4986
4982
4987
// Create a function for the destructor
4983
4988
alt cx. ccx . item_ids . find ( item. id ) {
4984
4989
some ( lldtor_decl) {
4985
- trans_fn ( cx, item. span , dtor, lldtor_decl, none , tps, dtor_id) ;
4990
+ trans_fn ( cx, item. span , dtor, lldtor_decl, no_self , tps, dtor_id) ;
4986
4991
}
4987
4992
_ {
4988
4993
cx. ccx . sess . span_fatal ( item. span , "unbound dtor in trans_item" ) ;
0 commit comments