Lucian Brănescu-Mihăilă avatar Lucian Brănescu-Mihăilă committed c3a311a

Cleanups, but doesn't help with tests passing.

Comments (0)

Files changed (4)

objects/src/instance.winxed

         // if sub is a parrot Sub, it'll get executed
         // if sub is an instance with __call__, this invoke will get called,
         //   all the way down to a Sub somewhere
-        return sub(p:[flat], n:[flat,named]);
+        return sub(self, p:[flat], n:[flat,named]);
     }
 
     function find_method[vtable](string name) {
         var protoclass = class Python.instance;
         ${ getattribute dict, self, protoclass, '__dict__' };
     
-        for(var i in ['__dict__', '__bases__', '__class__', '__new__'])
-            if(i == name && exists dict[i])
-                return dict[i];
+        if(name == '__dict__')
+            return dict;
 
         // let object classes override it
         // since this is only used for boostrapping, bases are ignored
 
         }
 
-        //TODO check for missing
         return dict[name];
     }
 

objects/src/type.winxed

                  return attr.__dict__['__get__'](attr, obj);
              }
         }
+        
+        var chain = get_mro(cls);
 
         // then attr on actual obj
         if(exists obj.__dict__[key]) {
             // if obj is a class
             if(id(cls) == id(t)) {
                  
-                var chain = get_mro(cls);
-                // TODO check the class, also for descriptors
-                // TODO also check its bases
+                for(var i in chain) {
+                    if(exists i.__dict__['__get__'])
+                        attr = i.__dict__['__get__'](i, obj);
+                }
             }
 
             return attr;
         }
 
         // then on the obj's class
-        // TODO also base classes
-        if(exists cls.__dict__[key]) {
-            var attr = cls.__dict__[key];
+        for(var i in chain) {
+            if(exists i.__dict__[key]) {
+                var attr = i.__dict__[key];
             
-            // if non-data descriptor
-            if(exists attr.__dict__['__get__'])
-                return attr.__dict__['__get__'](attr, obj);
+                // if non-data descriptor
+                if(exists attr.__dict__['__get__'])
+                    return attr.__dict__['__get__'](attr, obj);
 
-            return attr;
+                return attr;
+            }
         }
 
         // throw AttributeError
     };
 
     t.__setattr__ = function(obj, key, val) {
+        say('calling setattr override');
         var cls = obj.__dict__['__class__'];
     
         if(exists cls.__dict__[key]) {
+            say('using data descriptor');
             var attr = cls.__dict__[key];
 
-            if(exists attr.__dict__['__set__'])
+            if(exists attr.__dict__['__set__']) {
                 attr.__dict__['__set__'](attr, obj, val);
+                return;
+            }
         }
 
         obj.__dict__[key] = val;

objects/t/instance.t

         var c = new Python.instance;
 
         i.__class__ = c;
-        c.__call__ = function(){return 42;};
+        c.__call__ = function(self){return 42;};
 
         self.assert.equal(i(), 42);
     }
         :(var t, var o) = boot();
 	
         o.a = 42;
-	say(o.__dict__['__name__']);
-	self.assert.equal(o.__dict__['a'], 42);
+        say(o.__dict__['__name__']);
+        self.assert.equal(o.__dict__['a'], 42);
     }
 
     function get_attr() {
         :(var t, var o) = boot();
 
         o.a = 42;
-	self.assert.equal(o.a, 42);
+        self.assert.equal(o.a, 42);
     }
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.