Commit ee548408 authored by Travis Hance's avatar Travis Hance

getset descriptors, __name__ for type and functions

parent c250a77e
......@@ -1337,15 +1337,6 @@ void fixup_slot_dispatchers(BoxedClass* self) noexcept {
const slotdef* p = slotdefs;
while (p->name)
p = update_one_slot(self, p);
// TODO: CPython handles this by having the __name__ attribute wrap (via a getset object)
// the tp_name field, whereas we're (needlessly?) doing the opposite.
if (!self->tp_name) {
Box* b = self->getattr("__name__");
assert(b);
assert(b->cls == str_cls);
self->tp_name = static_cast<BoxedString*>(b)->s.c_str();
}
}
static PyObject* tp_new_wrapper(PyTypeObject* self, BoxedTuple* args, Box* kwds) noexcept {
......@@ -1771,7 +1762,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
cls->tp_dict = makeAttrWrapper(cls);
assert(cls->tp_name);
cls->giveAttr("__name__", boxStrConstant(cls->tp_name));
// tp_name
// tp_basicsize, tp_itemsize
// tp_doc
......
......@@ -1219,7 +1219,7 @@ private:
KnownClassobjType(BoxedClass* cls) : cls(cls) { assert(cls); }
public:
std::string debugName() override { return "class '" + *getNameOfClass(cls) + "'"; }
std::string debugName() override { return "class '" + std::string(getNameOfClass(cls)) + "'"; }
void assertMatches(BoxedClass* cls) override { assert(cls == this->cls); }
......@@ -1276,7 +1276,7 @@ public:
assert(cls);
// TODO add getTypeName
return "NormalType(" + *getNameOfClass(cls) + ")";
return "NormalType(" + std::string(getNameOfClass(cls)) + ")";
}
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerVariable* var,
ConcreteCompilerType* other_type) override {
......@@ -1332,7 +1332,7 @@ public:
Box* rtattr = cls->getattr(*attr);
if (rtattr == NULL) {
llvm::CallSite call = emitter.createCall2(info.unw_info, g.funcs.raiseAttributeErrorStr,
getStringConstantPtr(*getNameOfClass(cls) + "\0"),
getStringConstantPtr(std::string(getNameOfClass(cls)) + "\0"),
getStringConstantPtr(*attr + '\0'));
call.setDoesNotReturn();
return undefVariable();
......@@ -1383,7 +1383,7 @@ public:
*no_attribute = true;
} else {
llvm::CallSite call = emitter.createCall2(info.unw_info, g.funcs.raiseAttributeErrorStr,
getStringConstantPtr(*getNameOfClass(cls) + "\0"),
getStringConstantPtr(std::string(getNameOfClass(cls)) + "\0"),
getStringConstantPtr(*attr + '\0'));
call.setDoesNotReturn();
}
......
......@@ -324,7 +324,7 @@ EffortLevel::EffortLevel initialEffort();
typedef bool i1;
typedef int64_t i64;
extern "C" const std::string* getNameOfClass(BoxedClass* cls);
const char* getNameOfClass(BoxedClass* cls);
std::string getFullNameOfClass(BoxedClass* cls);
class Rewriter;
......@@ -446,10 +446,8 @@ public:
};
static_assert(offsetof(BoxVar, ob_size) == offsetof(struct _varobject, ob_size), "");
extern "C" const std::string* getTypeName(Box* o);
std::string getFullTypeName(Box* o);
const char* getTypeName(Box* b);
class BoxedClass;
......
......@@ -232,7 +232,7 @@ static void markPhase() {
BoxedClass* cls = b->cls;
if (cls) {
ASSERT(cls->gc_visit, "%s", getTypeName(b)->c_str());
ASSERT(cls->gc_visit, "%s", getTypeName(b));
cls->gc_visit(&visitor, b);
}
}
......@@ -268,7 +268,7 @@ static void markPhase() {
// An arbitrary amount of stuff can happen between the 'new' and
// the call to the constructor (ie the args get evaluated), which
// can trigger a collection.
ASSERT(cls->gc_visit, "%s", getTypeName(b)->c_str());
ASSERT(cls->gc_visit, "%s", getTypeName(b));
cls->gc_visit(&visitor, b);
}
} else if (kind_id == GCKind::HIDDEN_CLASS) {
......
......@@ -300,7 +300,7 @@ static void _doFree(GCAllocation* al) {
if (al->kind_id == GCKind::PYTHON) {
Box* b = (Box*)al->user_data;
ASSERT(b->cls->tp_dealloc == NULL, "%s", getTypeName(b)->c_str());
ASSERT(b->cls->tp_dealloc == NULL, "%s", getTypeName(b));
}
}
......
......@@ -48,8 +48,6 @@ extern "C" Box* boolNew(Box* cls, Box* val) {
}
void setupBool() {
bool_cls->giveAttr("__name__", boxStrConstant("bool"));
bool_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)boolNonzero, BOXED_BOOL, 1)));
bool_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)boolRepr, STR, 1)));
bool_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)boolHash, BOXED_INT, 1)));
......
......@@ -331,13 +331,11 @@ Box* open(Box* arg1, Box* arg2) {
assert(arg2);
if (arg1->cls != str_cls) {
fprintf(stderr, "TypeError: coercing to Unicode: need string of buffer, %s found\n",
getTypeName(arg1)->c_str());
fprintf(stderr, "TypeError: coercing to Unicode: need string of buffer, %s found\n", getTypeName(arg1));
raiseExcHelper(TypeError, "");
}
if (arg2->cls != str_cls) {
fprintf(stderr, "TypeError: coercing to Unicode: need string of buffer, %s found\n",
getTypeName(arg2)->c_str());
fprintf(stderr, "TypeError: coercing to Unicode: need string of buffer, %s found\n", getTypeName(arg2));
raiseExcHelper(TypeError, "");
}
......@@ -368,7 +366,7 @@ extern "C" Box* chr(Box* arg) {
extern "C" Box* ord(Box* arg) {
if (arg->cls != str_cls) {
raiseExcHelper(TypeError, "ord() expected string of length 1, but %s found", getTypeName(arg)->c_str());
raiseExcHelper(TypeError, "ord() expected string of length 1, but %s found", getTypeName(arg));
}
const std::string& s = static_cast<BoxedString*>(arg)->s;
......@@ -381,22 +379,22 @@ extern "C" Box* ord(Box* arg) {
Box* range(Box* start, Box* stop, Box* step) {
i64 istart, istop, istep;
if (stop == NULL) {
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start)->c_str());
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start));
istart = 0;
istop = static_cast<BoxedInt*>(start)->n;
istep = 1;
} else if (step == NULL) {
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start)->c_str());
RELEASE_ASSERT(isSubclass(stop->cls, int_cls), "%s", getTypeName(stop)->c_str());
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start));
RELEASE_ASSERT(isSubclass(stop->cls, int_cls), "%s", getTypeName(stop));
istart = static_cast<BoxedInt*>(start)->n;
istop = static_cast<BoxedInt*>(stop)->n;
istep = 1;
} else {
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start)->c_str());
RELEASE_ASSERT(isSubclass(stop->cls, int_cls), "%s", getTypeName(stop)->c_str());
RELEASE_ASSERT(isSubclass(step->cls, int_cls), "%s", getTypeName(step)->c_str());
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start));
RELEASE_ASSERT(isSubclass(stop->cls, int_cls), "%s", getTypeName(stop));
RELEASE_ASSERT(isSubclass(step->cls, int_cls), "%s", getTypeName(step));
istart = static_cast<BoxedInt*>(start)->n;
istop = static_cast<BoxedInt*>(stop)->n;
......@@ -481,7 +479,7 @@ Box* issubclass_func(Box* child, Box* parent) {
Box* bltinImport(Box* arg) {
if (arg->cls != str_cls) {
raiseExcHelper(TypeError, "__import__() argument 1 must be string, not %s", getTypeName(arg)->c_str());
raiseExcHelper(TypeError, "__import__() argument 1 must be string, not %s", getTypeName(arg));
}
return import(-1, new BoxedTuple({}), &static_cast<BoxedString*>(arg)->s);
......@@ -506,8 +504,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
if (default_value)
return default_value;
else
raiseExcHelper(AttributeError, "'%s' object has no attribute '%s'", getTypeName(obj)->c_str(),
str->s.c_str());
raiseExcHelper(AttributeError, "'%s' object has no attribute '%s'", getTypeName(obj), str->s.c_str());
}
return rtn;
......@@ -635,11 +632,11 @@ Box* exceptionNew2(BoxedClass* cls, Box* message) {
Box* exceptionNew(BoxedClass* cls, BoxedTuple* args) {
if (!isSubclass(cls->cls, type_cls))
raiseExcHelper(TypeError, "exceptions.__new__(X): X is not a type object (%s)", getTypeName(cls)->c_str());
raiseExcHelper(TypeError, "exceptions.__new__(X): X is not a type object (%s)", getTypeName(cls));
if (!isSubclass(cls, BaseException))
raiseExcHelper(TypeError, "BaseException.__new__(%s): %s is not a subtype of BaseException",
getNameOfClass(cls)->c_str(), getNameOfClass(cls)->c_str());
getNameOfClass(cls), getNameOfClass(cls));
BoxedException* rtn = new (cls) BoxedException();
......@@ -669,15 +666,14 @@ Box* exceptionRepr(Box* b) {
assert(message->cls == str_cls);
BoxedString* message_s = static_cast<BoxedString*>(message);
return boxString(*getTypeName(b) + "(" + message_s->s + ",)");
return boxString(std::string(getTypeName(b)) + "(" + message_s->s + ",)");
}
static BoxedClass* makeBuiltinException(BoxedClass* base, const char* name, int size = 0) {
if (size == 0)
size = base->tp_basicsize;
BoxedClass* cls = new BoxedHeapClass(base, NULL, offsetof(BoxedException, attrs), size, false);
cls->giveAttr("__name__", boxStrConstant(name));
BoxedClass* cls = new BoxedHeapClass(base, NULL, offsetof(BoxedException, attrs), size, false, name);
cls->giveAttr("__module__", boxStrConstant("exceptions"));
if (base == object_cls) {
......@@ -697,15 +693,16 @@ extern "C" PyObject* PyErr_NewException(char* name, PyObject* _base, PyObject* d
RELEASE_ASSERT(dict == NULL, "unimplemented");
try {
BoxedClass* base = Exception;
BoxedClass* cls = new BoxedHeapClass(base, NULL, offsetof(BoxedException, attrs), sizeof(BoxedException), true);
char* dot_pos = strchr(name, '.');
RELEASE_ASSERT(dot_pos, "");
int n = strlen(name);
BoxedString* boxedName = boxStrConstantSize(dot_pos + 1, n - (dot_pos - name) - 1);
BoxedClass* base = Exception;
BoxedClass* cls
= new BoxedHeapClass(base, NULL, offsetof(BoxedException, attrs), sizeof(BoxedException), true, boxedName);
cls->giveAttr("__module__", boxStrConstantSize(name, dot_pos - name));
cls->giveAttr("__name__", boxStrConstantSize(dot_pos + 1, n - (dot_pos - name) - 1));
// TODO Not sure if this should be called here
fixup_slot_dispatchers(cls);
return cls;
......@@ -781,7 +778,7 @@ Box* divmod(Box* lhs, Box* rhs) {
Box* execfile(Box* _fn) {
// The "globals" and "locals" arguments aren't implemented for now
if (!isSubclass(_fn->cls, str_cls)) {
raiseExcHelper(TypeError, "must be string, not %s", getTypeName(_fn)->c_str());
raiseExcHelper(TypeError, "must be string, not %s", getTypeName(_fn));
}
BoxedString* fn = static_cast<BoxedString*>(_fn);
......@@ -991,8 +988,7 @@ void setupBuiltins() {
builtins_module->giveAttr("print", new BoxedFunction(boxRTFunction((void*)print, NONE, 0, 0, true, true)));
notimplemented_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(Box), false);
notimplemented_cls->giveAttr("__name__", boxStrConstant("NotImplementedType"));
notimplemented_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(Box), false, "NotImplementedType");
notimplemented_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)notimplementedRepr, STR, 1)));
notimplemented_cls->freeze();
NotImplemented = new (notimplemented_cls) Box();
......@@ -1101,8 +1097,8 @@ void setupBuiltins() {
builtins_module->giveAttr("__import__", new BoxedFunction(boxRTFunction((void*)bltinImport, UNKNOWN, 1)));
enumerate_cls = new BoxedHeapClass(object_cls, &BoxedEnumerate::gcHandler, 0, sizeof(BoxedEnumerate), false);
enumerate_cls->giveAttr("__name__", boxStrConstant("enumerate"));
enumerate_cls
= new BoxedHeapClass(object_cls, &BoxedEnumerate::gcHandler, 0, sizeof(BoxedEnumerate), false, "enumerate");
enumerate_cls->giveAttr(
"__new__",
new BoxedFunction(boxRTFunction((void*)BoxedEnumerate::new_, UNKNOWN, 3, 1, false, false), { boxInt(0) }));
......
......@@ -254,8 +254,7 @@ void setupSys() {
sys_module->giveAttr("maxint", boxInt(PYSTON_INT_MAX));
sys_flags_cls = new BoxedHeapClass(object_cls, BoxedSysFlags::gcHandler, 0, sizeof(BoxedSysFlags), false);
sys_flags_cls->giveAttr("__name__", boxStrConstant("flags"));
sys_flags_cls = new BoxedHeapClass(object_cls, BoxedSysFlags::gcHandler, 0, sizeof(BoxedSysFlags), false, "flags");
sys_flags_cls->giveAttr("__new__",
new BoxedFunction(boxRTFunction((void*)BoxedSysFlags::__new__, UNKNOWN, 1, 0, true, true)));
#define ADD(name) \
......
......@@ -144,8 +144,7 @@ void setupThread() {
thread_module->giveAttr("get_ident", new BoxedFunction(boxRTFunction((void*)getIdent, BOXED_INT, 0)));
thread_module->giveAttr("stack_size", new BoxedFunction(boxRTFunction((void*)stackSize, BOXED_INT, 0)));
thread_lock_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedThreadLock), false);
thread_lock_cls->giveAttr("__name__", boxStrConstant("lock"));
thread_lock_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedThreadLock), false, "lock");
thread_lock_cls->giveAttr("__module__", boxStrConstant("thread"));
thread_lock_cls->giveAttr(
"acquire",
......@@ -157,15 +156,13 @@ void setupThread() {
thread_lock_cls->giveAttr("__exit__", new BoxedFunction(boxRTFunction((void*)BoxedThreadLock::exit, NONE, 4)));
thread_lock_cls->freeze();
thread_local_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedThreadLocal), false);
thread_local_cls->giveAttr("__name__", boxStrConstant("_local"));
thread_local_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedThreadLocal), false, "_local");
thread_local_cls->giveAttr("__module__", boxStrConstant("thread"));
thread_local_cls->freeze();
thread_module->giveAttr("_local", thread_local_cls);
BoxedClass* ThreadError
= new BoxedHeapClass(Exception, NULL, Exception->attrs_offset, Exception->tp_basicsize, false);
ThreadError->giveAttr("__name__", boxStrConstant("error"));
= new BoxedHeapClass(Exception, NULL, Exception->attrs_offset, Exception->tp_basicsize, false, "error");
ThreadError->giveAttr("__module__", boxStrConstant("thread"));
ThreadError->freeze();
......
......@@ -1467,8 +1467,7 @@ Box* BoxedCApiFunction::callInternal(BoxedFunction* func, CallRewriteArgs* rewri
}
void setupCAPI() {
capifunc_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedCApiFunction), false);
capifunc_cls->giveAttr("__name__", boxStrConstant("capifunc"));
capifunc_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedCApiFunction), false, "capifunc");
capifunc_cls->giveAttr("__repr__",
new BoxedFunction(boxRTFunction((void*)BoxedCApiFunction::__repr__, UNKNOWN, 1)));
......@@ -1479,22 +1478,20 @@ void setupCAPI() {
capifunc_cls->freeze();
method_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedMethodDescriptor), false);
method_cls->giveAttr("__name__", boxStrConstant("method"));
method_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedMethodDescriptor), false, "method");
method_cls->giveAttr("__get__",
new BoxedFunction(boxRTFunction((void*)BoxedMethodDescriptor::__get__, UNKNOWN, 3)));
method_cls->giveAttr("__call__", new BoxedFunction(boxRTFunction((void*)BoxedMethodDescriptor::__call__, UNKNOWN, 2,
0, true, true)));
method_cls->freeze();
wrapperdescr_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedWrapperDescriptor), false);
wrapperdescr_cls->giveAttr("__name__", boxStrConstant("wrapper_descriptor"));
wrapperdescr_cls
= new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedWrapperDescriptor), false, "wrapper_descriptor");
wrapperdescr_cls->giveAttr("__get__",
new BoxedFunction(boxRTFunction((void*)BoxedWrapperDescriptor::__get__, UNKNOWN, 3)));
wrapperdescr_cls->freeze();
wrapperobject_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedWrapperObject), false);
wrapperobject_cls->giveAttr("__name__", boxStrConstant("method-wrapper"));
wrapperobject_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedWrapperObject), false, "method-wrapper");
wrapperobject_cls->giveAttr(
"__call__", new BoxedFunction(boxRTFunction((void*)BoxedWrapperObject::__call__, UNKNOWN, 1, 0, true, true)));
wrapperobject_cls->freeze();
......
......@@ -63,12 +63,12 @@ extern "C" int PyClass_IsSubclass(PyObject* klass, PyObject* base) noexcept {
Box* classobjNew(Box* _cls, Box* _name, Box* _bases, Box** _args) {
if (!isSubclass(_cls->cls, type_cls))
raiseExcHelper(TypeError, "classobj.__new__(X): X is not a type object (%s)", getTypeName(_cls)->c_str());
raiseExcHelper(TypeError, "classobj.__new__(X): X is not a type object (%s)", getTypeName(_cls));
BoxedClass* cls = static_cast<BoxedClass*>(_cls);
if (!isSubclass(cls, classobj_cls))
raiseExcHelper(TypeError, "classobj.__new__(%s): %s is not a subtype of classobj", getNameOfClass(cls)->c_str(),
getNameOfClass(cls)->c_str());
raiseExcHelper(TypeError, "classobj.__new__(%s): %s is not a subtype of classobj", getNameOfClass(cls),
getNameOfClass(cls));
if (_name->cls != str_cls)
raiseExcHelper(TypeError, "argument 1 must be string, not %s", getTypeName(_name));
......@@ -129,7 +129,7 @@ Box* classobjCall(Box* _cls, Box* _args, Box* _kwargs) {
Box* classobjStr(Box* _obj) {
if (!isSubclass(_obj->cls, classobj_cls)) {
raiseExcHelper(TypeError, "descriptor '__str__' requires a 'classobj' object but received an '%s'",
getTypeName(_obj)->c_str());
getTypeName(_obj));
}
BoxedClassobj* cls = static_cast<BoxedClassobj*>(_obj);
......@@ -271,11 +271,9 @@ Box* instanceSetitem(Box* _inst, Box* key, Box* value) {
void setupClassobj() {
classobj_cls = new BoxedHeapClass(object_cls, &BoxedClassobj::gcHandler, offsetof(BoxedClassobj, attrs),
sizeof(BoxedClassobj), false);
sizeof(BoxedClassobj), false, "classobj");
instance_cls = new BoxedHeapClass(object_cls, &BoxedInstance::gcHandler, offsetof(BoxedInstance, attrs),
sizeof(BoxedInstance), false);
classobj_cls->giveAttr("__name__", boxStrConstant("classobj"));
sizeof(BoxedInstance), false, "instance");
classobj_cls->giveAttr("__new__",
new BoxedFunction(boxRTFunction((void*)classobjNew, UNKNOWN, 4, 0, false, false)));
......@@ -288,8 +286,6 @@ void setupClassobj() {
classobj_cls->freeze();
instance_cls->giveAttr("__name__", boxStrConstant("instance"));
instance_cls->giveAttr("__getattribute__",
new BoxedFunction(boxRTFunction((void*)instanceGetattribute, UNKNOWN, 2)));
instance_cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)instanceStr, UNKNOWN, 1)));
......
......@@ -252,8 +252,6 @@ Box* complexNew(Box* _cls, Box* real, Box* imag) {
}
void setupComplex() {
complex_cls->giveAttr("__name__", boxStrConstant("complex"));
complex_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)complexNew, UNKNOWN, 3, 2, false, false),
{ boxInt(0), boxInt(0) }));
......
......@@ -168,11 +168,9 @@ static Box* classmethodGet(Box* self, Box* obj, Box* type) {
}
void setupDescr() {
member_cls->giveAttr("__name__", boxStrConstant("member"));
member_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)memberGet, UNKNOWN, 3)));
member_cls->freeze();
property_cls->giveAttr("__name__", boxStrConstant("property"));
property_cls->giveAttr(
"__init__",
new BoxedFunction(boxRTFunction((void*)propertyInit, UNKNOWN, 5, 4, false, false), { NULL, NULL, NULL, NULL }));
......@@ -192,7 +190,6 @@ void setupDescr() {
new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedProperty, prop_doc)));
property_cls->freeze();
staticmethod_cls->giveAttr("__name__", boxStrConstant("staticmethod"));
staticmethod_cls->giveAttr("__init__",
new BoxedFunction(boxRTFunction((void*)staticmethodInit, UNKNOWN, 5, 4, false, false),
{ None, None, None, None }));
......@@ -201,7 +198,6 @@ void setupDescr() {
staticmethod_cls->freeze();
classmethod_cls->giveAttr("__name__", boxStrConstant("classmethod"));
classmethod_cls->giveAttr("__init__",
new BoxedFunction(boxRTFunction((void*)classmethodInit, UNKNOWN, 5, 4, false, false),
{ None, None, None, None }));
......
This diff is collapsed.
......@@ -367,8 +367,6 @@ extern "C" int PyFile_SoftSpace(PyObject* f, int newflag) noexcept {
}
void setupFile() {
file_cls->giveAttr("__name__", boxStrConstant("file"));
file_cls->giveAttr("read",
new BoxedFunction(boxRTFunction((void*)fileRead, STR, 2, 1, false, false), { boxInt(-1) }));
......
......@@ -569,8 +569,7 @@ BoxedFloat* _floatNew(Box* a) {
ArgPassSpec(0), NULL, NULL, NULL, NULL, NULL);
if (!r) {
fprintf(stderr, "TypeError: float() argument must be a string or a number, not '%s'\n",
getTypeName(a)->c_str());
fprintf(stderr, "TypeError: float() argument must be a string or a number, not '%s'\n", getTypeName(a));
raiseExcHelper(TypeError, "");
}
......@@ -583,12 +582,12 @@ BoxedFloat* _floatNew(Box* a) {
Box* floatNew(BoxedClass* _cls, Box* a) {
if (!isSubclass(_cls->cls, type_cls))
raiseExcHelper(TypeError, "float.__new__(X): X is not a type object (%s)", getTypeName(_cls)->c_str());
raiseExcHelper(TypeError, "float.__new__(X): X is not a type object (%s)", getTypeName(_cls));
BoxedClass* cls = static_cast<BoxedClass*>(_cls);
if (!isSubclass(cls, float_cls))
raiseExcHelper(TypeError, "float.__new__(%s): %s is not a subtype of float", getNameOfClass(cls)->c_str(),
getNameOfClass(cls)->c_str());
raiseExcHelper(TypeError, "float.__new__(%s): %s is not a subtype of float", getNameOfClass(cls),
getNameOfClass(cls));
if (cls == float_cls)
......@@ -602,7 +601,7 @@ Box* floatNew(BoxedClass* _cls, Box* a) {
Box* floatStr(BoxedFloat* self) {
if (!isSubclass(self->cls, float_cls))
raiseExcHelper(TypeError, "descriptor '__str__' requires a 'float' object but received a '%s'",
getTypeName(self)->c_str());
getTypeName(self));
return boxString(floatFmt(self->d, 12, 'g'));
}
......@@ -635,8 +634,6 @@ static void _addFunc(const char* name, ConcreteCompilerType* rtn_type, void* flo
}
void setupFloat() {
float_cls->giveAttr("__name__", boxStrConstant("float"));
_addFunc("__add__", BOXED_FLOAT, (void*)floatAddFloat, (void*)floatAddInt, (void*)floatAdd);
float_cls->giveAttr("__radd__", float_cls->getattr("__add__"));
......
......@@ -237,8 +237,7 @@ extern "C" void generatorGCHandler(GCVisitor* v, Box* b) {
void setupGenerator() {
generator_cls = new BoxedHeapClass(object_cls, &generatorGCHandler, offsetof(BoxedGenerator, attrs),
sizeof(BoxedGenerator), false);
generator_cls->giveAttr("__name__", boxStrConstant("generator"));
sizeof(BoxedGenerator), false, "generator");
generator_cls->giveAttr("__iter__",
new BoxedFunction(boxRTFunction((void*)generatorIter, typeFromClass(generator_cls), 1)));
......
......@@ -48,13 +48,13 @@ Box* boxString(std::string&& s) {
}
extern "C" double unboxFloat(Box* b) {
ASSERT(b->cls == float_cls, "%s", getTypeName(b)->c_str());
ASSERT(b->cls == float_cls, "%s", getTypeName(b));
BoxedFloat* f = (BoxedFloat*)b;
return f->d;
}
i64 unboxInt(Box* b) {
ASSERT(b->cls == int_cls, "%s", getTypeName(b)->c_str());
ASSERT(b->cls == int_cls, "%s", getTypeName(b));
return ((BoxedInt*)b)->n;
}
......
......@@ -88,21 +88,21 @@ Box* xrange(Box* cls, Box* start, Box* stop, Box** args) {
Box* step = args[0];
if (stop == NULL) {
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start)->c_str());
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start));
i64 istop = static_cast<BoxedInt*>(start)->n;
return new BoxedXrange(0, istop, 1);
} else if (step == NULL) {
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start)->c_str());
RELEASE_ASSERT(isSubclass(stop->cls, int_cls), "%s", getTypeName(stop)->c_str());
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start));
RELEASE_ASSERT(isSubclass(stop->cls, int_cls), "%s", getTypeName(stop));
i64 istart = static_cast<BoxedInt*>(start)->n;
i64 istop = static_cast<BoxedInt*>(stop)->n;
return new BoxedXrange(istart, istop, 1);
} else {
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start)->c_str());
RELEASE_ASSERT(isSubclass(stop->cls, int_cls), "%s", getTypeName(stop)->c_str());
RELEASE_ASSERT(isSubclass(step->cls, int_cls), "%s", getTypeName(step)->c_str());
RELEASE_ASSERT(isSubclass(start->cls, int_cls), "%s", getTypeName(start));
RELEASE_ASSERT(isSubclass(stop->cls, int_cls), "%s", getTypeName(stop));
RELEASE_ASSERT(isSubclass(step->cls, int_cls), "%s", getTypeName(step));
i64 istart = static_cast<BoxedInt*>(start)->n;
i64 istop = static_cast<BoxedInt*>(stop)->n;
......@@ -120,11 +120,9 @@ Box* xrangeIter(Box* self) {
}
void setupXrange() {
xrange_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedXrange), false);
xrange_cls->giveAttr("__name__", boxStrConstant("xrange"));
xrange_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedXrange), false, "xrange");
xrange_iterator_cls = new BoxedHeapClass(object_cls, &BoxedXrangeIterator::xrangeIteratorGCHandler, 0,
sizeof(BoxedXrangeIterator), false);
xrange_iterator_cls->giveAttr("__name__", boxStrConstant("rangeiterator"));
sizeof(BoxedXrangeIterator), false, "rangeiterator");
xrange_cls->giveAttr(
"__new__",
......
This diff is collapsed.
......@@ -107,16 +107,15 @@ extern "C" PyObject* PySeqIter_New(PyObject* seq) noexcept {
}
void setupIter() {
seqiter_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedSeqIter), false);
seqiter_cls->giveAttr("__name__", boxStrConstant("iterator"));
seqiter_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedSeqIter), false, "iterator");
seqiter_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)seqiterNext, UNKNOWN, 1)));
seqiter_cls->giveAttr("__hasnext__", new BoxedFunction(boxRTFunction((void*)seqiterHasnext, BOXED_BOOL, 1)));
seqiter_cls->freeze();
iterwrapper_cls = new BoxedHeapClass(object_cls, iterwrapperGCVisit, 0, sizeof(BoxedIterWrapper), false);
iterwrapper_cls->giveAttr("__name__", boxStrConstant("iterwrapper"));
iterwrapper_cls
= new BoxedHeapClass(object_cls, iterwrapperGCVisit, 0, sizeof(BoxedIterWrapper), false, "iterwrapper");
iterwrapper_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)iterwrapperNext, UNKNOWN, 1)));
iterwrapper_cls->giveAttr("__hasnext__",
......
......@@ -172,7 +172,7 @@ extern "C" Box* listGetitem(BoxedList* self, Box* slice) {
} else if (slice->cls == slice_cls) {
return listGetitemSlice(self, static_cast<BoxedSlice*>(slice));
} else {
raiseExcHelper(TypeError, "list indices must be integers, not %s", getTypeName(slice)->c_str());
raiseExcHelper(TypeError, "list indices must be integers, not %s", getTypeName(slice));
}
}
......@@ -254,7 +254,7 @@ extern "C" Box* listSetitemSlice(BoxedList* self, BoxedSlice* slice, Box* v) {
assert(0 <= start && start <= stop && stop <= self->size);
RELEASE_ASSERT(v->cls == list_cls, "unsupported %s", getTypeName(v)->c_str());
RELEASE_ASSERT(v->cls == list_cls, "unsupported %s", getTypeName(v));
BoxedList* lv = static_cast<BoxedList*>(v);
RELEASE_ASSERT(self->elts != lv->elts, "Slice self-assignment currently unsupported");
......@@ -281,7 +281,7 @@ extern "C" Box* listSetitem(BoxedList* self, Box* slice, Box* v) {
} else if (slice->cls == slice_cls) {
return listSetitemSlice(self, static_cast<BoxedSlice*>(slice), v);
} else {
raiseExcHelper(TypeError, "list indices must be integers, not %s", getTypeName(slice)->c_str());
raiseExcHelper(TypeError, "list indices must be integers, not %s", getTypeName(slice));
}
}
......@@ -329,7 +329,7 @@ extern "C" Box* listDelitem(BoxedList* self, Box* slice) {
} else if (slice->cls == slice_cls) {
rtn = listDelitemSlice(self, static_cast<BoxedSlice*>(slice));
} else {
raiseExcHelper(TypeError, "list indices must be integers, not %s", getTypeName(slice)->c_str());
raiseExcHelper(TypeError, "list indices must be integers, not %s", getTypeName(slice));
}
self->shrink();
return rtn;
......@@ -365,7 +365,7 @@ extern "C" Box* listInsert(BoxedList* self, Box* idx, Box* v) {
Box* listMul(BoxedList* self, Box* rhs) {
if (rhs->cls != int_cls) {
raiseExcHelper(TypeError, "can't multiply sequence by non-int of type '%s'", getTypeName(rhs)->c_str());
raiseExcHelper(TypeError, "can't multiply sequence by non-int of type '%s'", getTypeName(rhs));
}
LOCK_REGION(self->lock.asRead());
......@@ -414,7 +414,7 @@ Box* listIAdd(BoxedList* self, Box* _rhs) {
Box* listAdd(BoxedList* self, Box* _rhs) {
if (_rhs->cls != list_cls) {
raiseExcHelper(TypeError, "can only concatenate list (not \"%s\") to list", getTypeName(_rhs)->c_str());
raiseExcHelper(TypeError, "can only concatenate list (not \"%s\") to list", getTypeName(_rhs));
}
LOCK_REGION(self->lock.asRead());
......@@ -691,9 +691,8 @@ extern "C" int PyList_SetSlice(PyObject* a, Py_ssize_t ilow, Py_ssize_t ihigh, P
}
void setupList() {
list_iterator_cls = new BoxedHeapClass(object_cls, &listIteratorGCHandler, 0, sizeof(BoxedList), false);
list_cls->giveAttr("__name__", boxStrConstant("list"));
list_iterator_cls
= new BoxedHeapClass(object_cls, &listIteratorGCHandler, 0, sizeof(BoxedList), false, "listiterator");
list_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)listLen, BOXED_INT, 1)));
......@@ -748,9 +747,6 @@ void setupList() {
list_cls->giveAttr("reverse", new BoxedFunction(boxRTFunction((void*)listReverse, NONE, 1)));
list_cls->freeze();
list_iterator_cls->giveAttr("__name__", boxStrConstant("listiterator"));
CLFunction* hasnext = boxRTFunction((void*)listiterHasnextUnboxed, BOOL, 1);
addRTFunction(hasnext, (void*)listiterHasnext, BOXED_BOOL);
list_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext));
......
This diff is collapsed.
This diff is collapsed.
......@@ -251,11 +251,7 @@ Box* setNonzero(BoxedSet* self) {
using namespace pyston::set;
void setupSet() {
set_cls->giveAttr("__name__", boxStrConstant("set"));
frozenset_cls->giveAttr("__name__", boxStrConstant("frozenset"));
set_iterator_cls = new BoxedHeapClass(object_cls, &setIteratorGCHandler, 0, sizeof(BoxedSet), false);
set_iterator_cls->giveAttr("__name__", boxStrConstant("setiterator"));
set_iterator_cls = new BoxedHeapClass(object_cls, &setIteratorGCHandler, 0, sizeof(BoxedSet), false, "setiterator");
set_iterator_cls->giveAttr("__hasnext__",
new BoxedFunction(boxRTFunction((void*)setiteratorHasnext, BOXED_BOOL, 1)));
set_iterator_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)setiteratorNext, UNKNOWN, 1)));
......
......@@ -233,14 +233,14 @@ void raise0() {
ExcInfo::ExcInfo(Box* type, Box* value, Box* traceback) : type(type), value(value), traceback(traceback) {
if (this->type && this->type != None)
RELEASE_ASSERT(isSubclass(this->type->cls, type_cls), "throwing old-style objects not supported yet (%s)",
getTypeName(this->type)->c_str());
getTypeName(this->type));
}
#endif
bool ExcInfo::matches(BoxedClass* cls) const {
assert(this->type);
RELEASE_ASSERT(isSubclass(this->type->cls, type_cls), "throwing old-style objects not supported yet (%s)",
getTypeName(this->type)->c_str());
getTypeName(this->type));
return isSubclass(static_cast<BoxedClass*>(this->type), cls);
}
......@@ -267,7 +267,7 @@ void raise3(Box* arg0, Box* arg1, Box* arg2) {
}
raiseExcHelper(TypeError, "exceptions must be old-style classes or derived from BaseException, not %s",
getTypeName(arg0)->c_str());
getTypeName(arg0));
}
void raiseExcHelper(BoxedClass* cls, const char* msg, ...) {
......@@ -295,16 +295,16 @@ void raiseExcHelper(BoxedClass* cls, const char* msg, ...) {
}
std::string formatException(Box* b) {
const std::string* name = getTypeName(b);
std::string name = getTypeName(b);
BoxedString* r = strOrNull(b);
if (!r)
return *name;
return name;
assert(r->cls == str_cls);
const std::string* msg = &r->s;
if (msg->size())
return *name + ": " + *msg;
return *name;
return name + ": " + *msg;
return name;
}
}
......@@ -274,7 +274,7 @@ extern "C" BoxedString* strAdd(BoxedString* lhs, Box* _rhs) {
assert(lhs->cls == str_cls);
if (_rhs->cls != str_cls) {
raiseExcHelper(TypeError, "cannot concatenate 'str' and '%s' objects", getTypeName(_rhs)->c_str());
raiseExcHelper(TypeError, "cannot concatenate 'str' and '%s' objects", getTypeName(_rhs));
}
BoxedString* rhs = static_cast<BoxedString*>(_rhs);
......@@ -1537,7 +1537,7 @@ Box* strSwapcase(BoxedString* self) {
Box* strContains(BoxedString* self, Box* elt) {
assert(self->cls == str_cls);
if (elt->cls != str_cls)
raiseExcHelper(TypeError, "'in <string>' requires string as left operand, not %s", getTypeName(elt)->c_str());
raiseExcHelper(TypeError, "'in <string>' requires string as left operand, not %s", getTypeName(elt));
BoxedString* sub = static_cast<BoxedString*>(elt);
......@@ -1552,7 +1552,7 @@ Box* strStartswith(BoxedString* self, Box* elt, Box* start, Box** _args) {
if (self->cls != str_cls)
raiseExcHelper(TypeError, "descriptor 'startswith' requires a 'str' object but received a '%s'",
getTypeName(self)->c_str());
getTypeName(self));
if (elt->cls != str_cls)
raiseExcHelper(TypeError, "expected a character buffer object");
......@@ -1597,7 +1597,7 @@ Box* strEndswith(BoxedString* self, Box* elt, Box* start, Box** _args) {
if (self->cls != str_cls)
raiseExcHelper(TypeError, "descriptor 'endswith' requires a 'str' object but received a '%s'",
getTypeName(self)->c_str());
getTypeName(self));
if (elt->cls != str_cls)
raiseExcHelper(TypeError, "expected a character buffer object");
......@@ -1641,8 +1641,7 @@ Box* strEndswith(BoxedString* self, Box* elt, Box* start, Box** _args) {
Box* strFind(BoxedString* self, Box* elt, Box* _start) {
if (self->cls != str_cls)
raiseExcHelper(TypeError, "descriptor 'find' requires a 'str' object but received a '%s'",
getTypeName(self)->c_str());
raiseExcHelper(TypeError, "descriptor 'find' requires a 'str' object but received a '%s'", getTypeName(self));
if (elt->cls != str_cls)
raiseExcHelper(TypeError, "expected a character buffer object");
......@@ -1669,8 +1668,7 @@ Box* strFind(BoxedString* self, Box* elt, Box* _start) {
Box* strRfind(BoxedString* self, Box* elt) {
if (self->cls != str_cls)
raiseExcHelper(TypeError, "descriptor 'rfind' requires a 'str' object but received a '%s'",
getTypeName(self)->c_str());
raiseExcHelper(TypeError, "descriptor 'rfind' requires a 'str' object but received a '%s'", getTypeName(self));
if (elt->cls != str_cls)
raiseExcHelper(TypeError, "expected a character buffer object");
......@@ -1707,7 +1705,7 @@ extern "C" Box* strGetitem(BoxedString* self, Box* slice) {
parseSlice(sslice, self->s.size(), &start, &stop, &step, &length);
return _strSlice(self, start, stop, step, length);
} else {
raiseExcHelper(TypeError, "string indices must be integers, not %s", getTypeName(slice)->c_str());
raiseExcHelper(TypeError, "string indices must be integers, not %s", getTypeName(slice));
}
}
......@@ -1868,8 +1866,8 @@ static PyBufferProcs string_as_buffer = {
};
void setupStr() {
str_iterator_cls = new BoxedHeapClass(object_cls, &strIteratorGCHandler, 0, sizeof(BoxedStringIterator), false);
str_iterator_cls->giveAttr("__name__", boxStrConstant("striterator"));
str_iterator_cls
= new BoxedHeapClass(object_cls, &strIteratorGCHandler, 0, sizeof(BoxedStringIterator), false, "striterator");
str_iterator_cls->giveAttr("__hasnext__",
new BoxedFunction(boxRTFunction((void*)BoxedStringIterator::hasnext, BOXED_BOOL, 1)));
str_iterator_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)BoxedStringIterator::next, STR, 1)));
......@@ -1877,8 +1875,6 @@ void setupStr() {
str_cls->tp_as_buffer = &string_as_buffer;
str_cls->giveAttr("__name__", boxStrConstant("str"));
str_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)strLen, BOXED_INT, 1)));
str_cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)strStr, STR, 1)));
str_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)strRepr, STR, 1)));
......@@ -1970,7 +1966,6 @@ void setupStr() {
"__doc__", boxStrConstant("Type basestring cannot be instantiated; it is the base for str and unicode."));
basestring_cls->giveAttr("__new__",
new BoxedFunction(boxRTFunction((void*)basestringNew, UNKNOWN, 1, 0, true, true)));
basestring_cls->giveAttr("__name__", boxStrConstant("basestring"));
basestring_cls->freeze();
}
......
......@@ -84,10 +84,10 @@ Box* superRepr(Box* _s) {
BoxedSuper* s = static_cast<BoxedSuper*>(_s);
if (s->obj_type) {
return boxString("<super: <class '" + (s->type ? *getNameOfClass(s->type) : "NULL") + "'>, <"
+ *getNameOfClass(s->obj_type) + " object>>");
return boxString("<super: <class '" + std::string(s->type ? getNameOfClass(s->type) : "NULL") + "'>, <"
+ std::string(getNameOfClass(s->obj_type)) + " object>>");
} else {
return boxString("<super: <class '" + (s->type ? *getNameOfClass(s->type) : "NULL") + "'>, <NULL>>");
return boxString("<super: <class '" + std::string(s->type ? getNameOfClass(s->type) : "NULL") + "'>, <NULL>>");
}
}
......@@ -115,7 +115,7 @@ Box* superInit(Box* _self, Box* _type, Box* obj) {
BoxedSuper* self = static_cast<BoxedSuper*>(_self);
if (!isSubclass(_type->cls, type_cls))
raiseExcHelper(TypeError, "must be type, not %s", getTypeName(_type)->c_str());
raiseExcHelper(TypeError, "must be type, not %s", getTypeName(_type));
BoxedClass* type = static_cast<BoxedClass*>(_type);
BoxedClass* obj_type = NULL;
......@@ -132,9 +132,7 @@ Box* superInit(Box* _self, Box* _type, Box* obj) {
}
void setupSuper() {
super_cls = new BoxedHeapClass(object_cls, &BoxedSuper::gcHandler, 0, sizeof(BoxedSuper), false);
super_cls->giveAttr("__name__", boxStrConstant("super"));
super_cls = new BoxedHeapClass(object_cls, &BoxedSuper::gcHandler, 0, sizeof(BoxedSuper), false, "super");
super_cls->giveAttr("__getattribute__", new BoxedFunction(boxRTFunction((void*)superGetattribute, UNKNOWN, 2)));
super_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)superRepr, STR, 1)));
......
......@@ -113,7 +113,7 @@ Box* tupleGetitem(BoxedTuple* self, Box* slice) {
else if (slice->cls == slice_cls)
return tupleGetitemSlice(self, static_cast<BoxedSlice*>(slice));
else
raiseExcHelper(TypeError, "tuple indices must be integers, not %s", getTypeName(slice)->c_str());
raiseExcHelper(TypeError, "tuple indices must be integers, not %s", getTypeName(slice));
}
Box* tupleAdd(BoxedTuple* self, Box* rhs) {
......@@ -130,7 +130,7 @@ Box* tupleAdd(BoxedTuple* self, Box* rhs) {
Box* tupleMul(BoxedTuple* self, Box* rhs) {
if (rhs->cls != int_cls) {
raiseExcHelper(TypeError, "can't multiply sequence by non-int of type '%s'", getTypeName(rhs)->c_str());
raiseExcHelper(TypeError, "can't multiply sequence by non-int of type '%s'", getTypeName(rhs));
}
int n = static_cast<BoxedInt*>(rhs)->n;
......@@ -298,12 +298,12 @@ Box* tupleHash(BoxedTuple* self) {
extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
if (!isSubclass(_cls->cls, type_cls))
raiseExcHelper(TypeError, "tuple.__new__(X): X is not a type object (%s)", getTypeName(_cls)->c_str());
raiseExcHelper(TypeError, "tuple.__new__(X): X is not a type object (%s)", getTypeName(_cls));
BoxedClass* cls = static_cast<BoxedClass*>(_cls);
if (!isSubclass(cls, tuple_cls))
raiseExcHelper(TypeError, "tuple.__new__(%s): %s is not a subtype of tuple", getNameOfClass(cls)->c_str(),
getNameOfClass(cls)->c_str());
raiseExcHelper(TypeError, "tuple.__new__(%s): %s is not a subtype of tuple", getNameOfClass(cls),
getNameOfClass(cls));
RELEASE_ASSERT(cls == tuple_cls, "");
......@@ -382,9 +382,7 @@ extern "C" void tupleIteratorGCHandler(GCVisitor* v, Box* b) {
void setupTuple() {
tuple_iterator_cls = new BoxedHeapClass(object_cls, &tupleIteratorGCHandler, 0, sizeof(BoxedTuple), false);
tuple_cls->giveAttr("__name__", boxStrConstant("tuple"));
tuple_iterator_cls = new BoxedHeapClass(object_cls, &tupleIteratorGCHandler, 0, sizeof(BoxedTuple), false, "tuple");
tuple_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)tupleNew, UNKNOWN, 1, 0, true, true)));
CLFunction* getitem = createRTFunction(2, 0, 0, 0);
......@@ -418,8 +416,6 @@ void setupTuple() {
tuple_cls->freeze();
tuple_iterator_cls->giveAttr("__name__", boxStrConstant("tupleiterator"));
CLFunction* hasnext = boxRTFunction((void*)tupleiterHasnextUnboxed, BOOL, 1);
addRTFunction(hasnext, (void*)tupleiterHasnext, BOXED_BOOL);
tuple_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext));
......
This diff is collapsed.
......@@ -79,7 +79,7 @@ extern "C" {
extern BoxedClass* object_cls, *type_cls, *bool_cls, *int_cls, *long_cls, *float_cls, *str_cls, *function_cls,
*none_cls, *instancemethod_cls, *list_cls, *slice_cls, *module_cls, *dict_cls, *tuple_cls, *file_cls,
*enumerate_cls, *xrange_cls, *member_cls, *method_cls, *closure_cls, *generator_cls, *complex_cls, *basestring_cls,
*unicode_cls, *property_cls, *staticmethod_cls, *classmethod_cls, *attrwrapper_cls;
*unicode_cls, *property_cls, *staticmethod_cls, *classmethod_cls, *attrwrapper_cls, *getset_cls;
}
extern "C" {
extern Box* None, *NotImplemented, *True, *False;
......@@ -232,8 +232,18 @@ public:
PyMappingMethods as_mapping;
PySequenceMethods as_sequence;
PyBufferProcs as_buffer;
PyObject* ht_name, *ht_slots;
BoxedString* ht_name;
PyObject** ht_slots;
BoxedHeapClass(BoxedClass* base, gcvisit_func gc_visit, int attrs_offset, int instance_size, bool is_user_defined,
const std::string& name);
BoxedHeapClass(BoxedClass* base, gcvisit_func gc_visit, int attrs_offset, int instance_size, bool is_user_defined,
BoxedString* name);
// This constructor is only used for bootstrapping purposes to be called for types that
// are initialized before str_cls.
BoxedHeapClass(BoxedClass* base, gcvisit_func gc_visit, int attrs_offset, int instance_size, bool is_user_defined);
};
......@@ -510,6 +520,18 @@ public:
DEFAULT_CLASS(member_cls);
};
class BoxedGetsetDescriptor : public Box {
public:
Box* (*get)(Box*, void*);
int (*set)(Box*, Box*, void*);
void* closure;
BoxedGetsetDescriptor(Box* (*get)(Box*, void*), int (*set)(Box*, Box*, void*), void* closure)
: get(get), set(set), closure(closure) {}
DEFAULT_CLASS(getset_cls);
};
class BoxedProperty : public Box {
public:
Box* prop_get;
......
......@@ -396,8 +396,6 @@ extern "C" const unsigned char _Py_ascii_whitespace[]
void setupUnicode() {
unicode_cls->giveAttr("__name__", boxStrConstant("unicode"));
unicode_cls->freeze();
}
......
# expected: fail
# - arbitrary stuff in classes
# I guess type.__name__ works specially:
class C(object):
__name__ = 1
print C.__name__
......
# expected: fail
# - type.__name__ is a descriptor
class C(object):
pass
......
# expected: fail
# This fails becasue we currently don't support setting for getset descriptors,
# and __name__ is a getset descriptor.
class C(object):
pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment