@@ -1047,13 +1047,13 @@ impl<'a> ExecutionEngine<'a> {
10471047 return Err ( obj. err ( ) . unwrap ( ) ) ;
10481048 }
10491049 if let GCRefData :: DYNAMIC_OBJECT ( o) = obj. unwrap ( ) {
1050- // bind the function to the object here
1051- let mut bounded_fn = f. clone ( ) ;
1052- bounded_fn. bounded_object = Some ( g. clone ( ) ) ;
1053- // set the function bounded ref
1054- self . shared_execution_context
1055- . heap
1056- . set ( gc_ref, GCRefData :: FN ( bounded_fn) ) ;
1050+ // // bind the function to the object here
1051+ // let mut bounded_fn = f.clone();
1052+ // bounded_fn.bounded_object = Some(g.clone());
1053+ // // set the function bounded ref
1054+ // self.shared_execution_context
1055+ // .heap
1056+ // .set(gc_ref, GCRefData::FN(bounded_fn));
10571057
10581058 // update the object in the heap
10591059 let mut cloned_obj = o. clone ( ) ;
@@ -1121,8 +1121,8 @@ impl<'a> ExecutionEngine<'a> {
11211121 let obj = stack_access ! ( self , instr. arg_0) ;
11221122 // fixme this is horrible nesting
11231123 match obj {
1124- Object :: GC_REF ( gc_ref ) => {
1125- let result = self . shared_execution_context . heap . deref ( gc_ref ) ;
1124+ Object :: GC_REF ( obj_gc_ref ) => {
1125+ let result = self . shared_execution_context . heap . deref ( obj_gc_ref ) ;
11261126 if result. is_err ( ) {
11271127 return Err ( result. err ( ) . unwrap ( ) ) ;
11281128 }
@@ -1180,44 +1180,42 @@ impl<'a> ExecutionEngine<'a> {
11801180 return Err ( RuntimeError :: INVALID_ACCESS ) ;
11811181 }
11821182
1183- // todo what we can do is, on an access here, allocate a new BoundedMethod heap object and call it?
1184- // we should store a binded method cache for this like cpython
1185- // alternatively, we can bind the obj onto the FunctionObject itself and not create a new data structure,
1186- // may be easier for now
1187-
1188- // // if result is a function and its bound, we should bind it!
1189- // match result.unwrap() {
1190- // Object::GC_REF(gc_ref) => {
1191- // let res = self
1192- // .shared_execution_context
1193- // .heap
1194- // .deref(gc_ref);
1195- // if res.is_err() {
1196- // return Err(res.err().unwrap());
1197- // }
1198- // match res.unwrap() {
1199- // GCRefData::FN(f) => {
1200- // let mut fnn = f.clone();
1201- // fnn.bounded_object = Some(gc_ref.clone());
1202- // stack_set!(
1203- // self,
1204- // instr.arg_2,
1205-
1206- // ),
1207- // }
1208- // _ => stack_set!(
1209- // self,
1210- // instr.arg_2,
1211- // result.unwrap().clone()
1212- // ),
1213- // }
1214- // }
1215- // _ => stack_set!(
1216- // self,
1217- // instr.arg_2,
1218- // result.unwrap().clone()
1219- // ),
1220- // }
1183+ // BINDING HAPPENS HERE
1184+ match result {
1185+ Object :: GC_REF ( method_to_bind_gc_ref) => {
1186+ let deref = self
1187+ . shared_execution_context
1188+ . heap
1189+ . deref ( method_to_bind_gc_ref) ;
1190+ if deref. is_err ( ) {
1191+ return Err ( deref. err ( ) . unwrap ( ) ) ;
1192+ }
1193+ match deref. unwrap ( ) {
1194+ GCRefData :: FN ( mut f) => {
1195+ if f. requires_method_binding {
1196+ f. bounded_object =
1197+ Some ( obj_gc_ref. clone ( ) ) ;
1198+
1199+ // todo we should probably not set the actual object? and instead return another?
1200+ // because now its forever bound?
1201+ let res = self
1202+ . shared_execution_context
1203+ . heap
1204+ . set (
1205+ method_to_bind_gc_ref,
1206+ GCRefData :: FN ( f. clone ( ) ) ,
1207+ ) ;
1208+ if res. is_err ( ) {
1209+ return Err ( res. err ( ) . unwrap ( ) ) ;
1210+ }
1211+ }
1212+ }
1213+ _ => { }
1214+ }
1215+ }
1216+ _ => { }
1217+ }
1218+
12211219 stack_set ! ( self , instr. arg_2, result. clone( ) ) ;
12221220 increment_ip ! ( self ) ;
12231221 }
0 commit comments