Index: src/org/python/core/PyBooleanDerived.java =================================================================== --- src/org/python/core/PyBooleanDerived.java (revision 3140) +++ src/org/python/core/PyBooleanDerived.java (working copy) @@ -1,7 +1,17 @@ package org.python.core; -public class PyBooleanDerived extends PyBoolean { +public class PyBooleanDerived extends PyBoolean implements Slotted { + public PyObject getSlot(int index) { + return slots[index]; + } + + public void setSlot(int index,PyObject value) { + slots[index]=value; + } + + private PyObject[]slots; + private PyObject dict; public PyObject fastGetDict() { @@ -12,8 +22,22 @@ return dict; } + public void setDict(PyObject newDict) { + if (newDict instanceof PyStringMap||newDict instanceof PyDictionary) { + dict=newDict; + } else { + throw Py.TypeError("__dict__ must be set to a Dictionary "+newDict.getClass().getName()); + } + } + + public void delDict() { + // deleting an object's instance dict makes it grow a new one + dict=new PyStringMap(); + } + public PyBooleanDerived(PyType subtype,boolean v) { super(subtype,v); + slots=new PyObject[subtype.getNumSlots()]; dict=subtype.instDict(); } Index: src/org/python/modules/random/PyRandom.java =================================================================== --- src/org/python/modules/random/PyRandom.java (revision 3140) +++ src/org/python/modules/random/PyRandom.java (working copy) @@ -22,8 +22,8 @@ import org.python.core.PyNewWrapper; import org.python.core.PyMethodDescr; import org.python.core.PyBuiltinFunction; -import org.python.core.PyBuiltinFunctionNarrow; -import org.python.core.PyBuiltinFunctionWide; +import org.python.core.PyBuiltinMethod; +import org.python.core.PyBuiltinMethodNarrow; public class PyRandom extends PyObject { @@ -33,191 +33,109 @@ public static final String exposed_name="random"; public static void typeSetup(PyObject dict,PyType.Newstyle marker) { - class exposed_random extends PyBuiltinFunctionNarrow { + class exposed_random extends PyBuiltinMethodNarrow { - private PyRandom self; - - public PyObject getSelf() { - return self; + exposed_random(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed_random(PyRandom self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed_random(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed_random((PyRandom)self,info); - } - public PyObject __call__() { - return self.random_random(); + return((PyRandom)self).random_random(); } - public PyObject inst_call(PyObject gself) { - PyRandom self=(PyRandom)gself; - return self.random_random(); - } - } dict.__setitem__("random",new PyMethodDescr("random",PyRandom.class,0,0,new exposed_random(null,null))); - class exposed_seed extends PyBuiltinFunctionNarrow { + class exposed_seed extends PyBuiltinMethodNarrow { - private PyRandom self; - - public PyObject getSelf() { - return self; + exposed_seed(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed_seed(PyRandom self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed_seed(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed_seed((PyRandom)self,info); - } - public PyObject __call__(PyObject arg0) { - return self.random_seed(arg0); + return((PyRandom)self).random_seed(arg0); } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyRandom self=(PyRandom)gself; - return self.random_seed(arg0); - } - public PyObject __call__() { - return self.random_seed(); + return((PyRandom)self).random_seed(); } - public PyObject inst_call(PyObject gself) { - PyRandom self=(PyRandom)gself; - return self.random_seed(); - } - } dict.__setitem__("seed",new PyMethodDescr("seed",PyRandom.class,0,1,new exposed_seed(null,null))); - class exposed_getstate extends PyBuiltinFunctionNarrow { + class exposed_getstate extends PyBuiltinMethodNarrow { - private PyRandom self; - - public PyObject getSelf() { - return self; + exposed_getstate(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed_getstate(PyRandom self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed_getstate(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed_getstate((PyRandom)self,info); - } - public PyObject __call__() { - return self.random_getstate(); + return((PyRandom)self).random_getstate(); } - public PyObject inst_call(PyObject gself) { - PyRandom self=(PyRandom)gself; - return self.random_getstate(); - } - } dict.__setitem__("getstate",new PyMethodDescr("getstate",PyRandom.class,0,0,new exposed_getstate(null,null))); - class exposed_setstate extends PyBuiltinFunctionNarrow { + class exposed_setstate extends PyBuiltinMethodNarrow { - private PyRandom self; - - public PyObject getSelf() { - return self; + exposed_setstate(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed_setstate(PyRandom self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed_setstate(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed_setstate((PyRandom)self,info); - } - public PyObject __call__(PyObject arg0) { - return self.random_setstate(arg0); + return((PyRandom)self).random_setstate(arg0); } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyRandom self=(PyRandom)gself; - return self.random_setstate(arg0); - } - } dict.__setitem__("setstate",new PyMethodDescr("setstate",PyRandom.class,1,1,new exposed_setstate(null,null))); - class exposed_jumpahead extends PyBuiltinFunctionNarrow { + class exposed_jumpahead extends PyBuiltinMethodNarrow { - private PyRandom self; - - public PyObject getSelf() { - return self; + exposed_jumpahead(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed_jumpahead(PyRandom self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed_jumpahead(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed_jumpahead((PyRandom)self,info); - } - public PyObject __call__(PyObject arg0) { - return self.random_jumpahead(arg0); + return((PyRandom)self).random_jumpahead(arg0); } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyRandom self=(PyRandom)gself; - return self.random_jumpahead(arg0); - } - } dict.__setitem__("jumpahead",new PyMethodDescr("jumpahead",PyRandom.class,1,1,new exposed_jumpahead(null,null))); - class exposed___init__ extends PyBuiltinFunctionWide { + class exposed___init__ extends PyBuiltinMethod { - private PyRandom self; - - public PyObject getSelf() { - return self; + exposed___init__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___init__(PyRandom self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___init__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___init__((PyRandom)self,info); - } - - public PyObject inst_call(PyObject self,PyObject[]args) { - return inst_call(self,args,Py.NoKeywords); - } - public PyObject __call__(PyObject[]args) { return __call__(args,Py.NoKeywords); } public PyObject __call__(PyObject[]args,String[]keywords) { - self.random_init(args,keywords); + ((PyRandom)self).random_init(args,keywords); return Py.None; } - public PyObject inst_call(PyObject gself,PyObject[]args,String[]keywords) { - PyRandom self=(PyRandom)gself; - self.random_init(args,keywords); - return Py.None; - } - } dict.__setitem__("__init__",new PyMethodDescr("__init__",PyRandom.class,-1,-1,new exposed___init__(null,null))); dict.__setitem__("__new__",new PyNewWrapper(PyRandom.class,"__new__",-1,-1) { Index: src/org/python/modules/random/PyRandomDerived.java =================================================================== --- src/org/python/modules/random/PyRandomDerived.java (revision 3140) +++ src/org/python/modules/random/PyRandomDerived.java (working copy) @@ -1,8 +1,18 @@ package org.python.modules.random; import org.python.core.*; -public class PyRandomDerived extends PyRandom { +public class PyRandomDerived extends PyRandom implements Slotted { + public PyObject getSlot(int index) { + return slots[index]; + } + + public void setSlot(int index,PyObject value) { + slots[index]=value; + } + + private PyObject[]slots; + private PyObject dict; public PyObject fastGetDict() { @@ -13,8 +23,22 @@ return dict; } + public void setDict(PyObject newDict) { + if (newDict instanceof PyStringMap||newDict instanceof PyDictionary) { + dict=newDict; + } else { + throw Py.TypeError("__dict__ must be set to a Dictionary "+newDict.getClass().getName()); + } + } + + public void delDict() { + // deleting an object's instance dict makes it grow a new one + dict=new PyStringMap(); + } + public PyRandomDerived(PyType subtype) { super(subtype); + slots=new PyObject[subtype.getNumSlots()]; dict=subtype.instDict(); } @@ -66,18 +90,6 @@ return super.__oct__(); } - public PyObject __int__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__int__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyObject) - return(PyObject)res; - throw Py.TypeError("__int__"+" should return a "+"int"); - } - return super.__int__(); - } - public PyFloat __float__() { PyType self_type=getType(); PyObject impl=self_type.lookup("__float__"); @@ -666,6 +678,18 @@ return super.__ixor__(other); } + public PyObject __int__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__int__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) + return(PyObject)res; + throw Py.TypeError("__int__"+" should return an integer"); + } + return super.__int__(); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); @@ -801,21 +825,6 @@ super.__setitem__(key,value); } - public PyObject __getitem__(PyObject key) { // ??? - PyType self_type=getType(); - PyObject impl=self_type.lookup("__getitem__"); - if (impl!=null) { - try { - return impl.__get__(this,self_type).__call__(key); - } catch (PyException exc) { - if (Py.matchException(exc,Py.LookupError)) - return null; - throw exc; - } - } - return super.__getitem__(key); - } - public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); Index: src/templates/gderived-defs =================================================================== --- src/templates/gderived-defs (revision 3140) +++ src/templates/gderived-defs (working copy) @@ -2,7 +2,18 @@ define: (CompilationUnit)derived_class package org.python.core; - public class `concat`(`base,Derived) extends `base { + public class `concat`(`base,Derived) extends `base implements Slotted { + + public PyObject getSlot(int index) { + return slots[index]; + } + + public void setSlot(int index, PyObject value) { + slots[index] = value; + } + + private PyObject[] slots; + `decls; } define: (ClassBodyDeclarations)pair