Commit 798c4da8 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Move doc+name from the function ctor to code ctor

since this is where it's supposed to live.  The function ctor
copies these fields from the code object.
parent 2affae97
......@@ -922,8 +922,9 @@ wdbg_%:
.PHONY: head_%
HEAD := 40
HEAD_SKIP := 6
head_%:
@ bash -c "set -o pipefail; script -e -q -c '$(MAKE) $(dir $@)$(patsubst head_%,%,$(notdir $@))' /dev/null | head -n$(HEAD)"
@ bash -c "set -o pipefail; script -e -q -c '$(MAKE) $(dir $@)$(patsubst head_%,%,$(notdir $@))' /dev/null | tail -n+$(HEAD_SKIP) | head -n$(HEAD)"
head: head_pyston_dbg
.PHONY: hwatch_%
hwatch_%:
......
......@@ -93,17 +93,20 @@ void setupBool() {
static PyNumberMethods bool_as_number;
bool_cls->tp_as_number = &bool_as_number;
bool_cls->giveAttr("__nonzero__", new BoxedFunction(BoxedCode::create((void*)boolNonzero, BOXED_BOOL, 1)));
bool_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)boolRepr<CXX>, STR, 1)));
bool_cls->giveAttr("__hash__", new BoxedFunction(BoxedCode::create((void*)boolHash, BOXED_INT, 1)));
bool_cls->giveAttr("__nonzero__",
new BoxedFunction(BoxedCode::create((void*)boolNonzero, BOXED_BOOL, 1, "bool.__nonzero__")));
bool_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)boolRepr<CXX>, STR, 1, "bool.__repr__")));
bool_cls->giveAttr("__hash__",
new BoxedFunction(BoxedCode::create((void*)boolHash, BOXED_INT, 1, "bool.__hash__")));
bool_cls->giveAttr("__new__",
new BoxedFunction(BoxedCode::create((void*)boolNew, UNKNOWN, 2, false, false), { Py_None }));
bool_cls->giveAttr(
"__new__",
new BoxedFunction(BoxedCode::create((void*)boolNew, UNKNOWN, 2, false, false, "bool.__new__"), { Py_None }));
// TODO: type specialize
bool_cls->giveAttr("__and__", new BoxedFunction(BoxedCode::create((void*)boolAnd, UNKNOWN, 2)));
bool_cls->giveAttr("__or__", new BoxedFunction(BoxedCode::create((void*)boolOr, UNKNOWN, 2)));
bool_cls->giveAttr("__xor__", new BoxedFunction(BoxedCode::create((void*)boolXor, UNKNOWN, 2)));
bool_cls->giveAttr("__and__", new BoxedFunction(BoxedCode::create((void*)boolAnd, UNKNOWN, 2, "bool.__and__")));
bool_cls->giveAttr("__or__", new BoxedFunction(BoxedCode::create((void*)boolOr, UNKNOWN, 2, "bool.__or__")));
bool_cls->giveAttr("__xor__", new BoxedFunction(BoxedCode::create((void*)boolXor, UNKNOWN, 2, "bool.__xor__")));
bool_cls->freeze();
bool_cls->tp_hash = (hashfunc)bool_hash;
......
This diff is collapsed.
......@@ -67,12 +67,12 @@ void setupPyston() {
pyston_module = createModule(autoDecref(boxString("__pyston__")));
pyston_module->giveAttr(
"setOption", new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)setOption, UNKNOWN, 2), "setOption"));
"setOption", new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)setOption, UNKNOWN, 2, "setOption")));
pyston_module->giveAttr(
"clearStats", new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)clearStats, NONE, 0), "clearStats"));
"clearStats", new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)clearStats, NONE, 0, "clearStats")));
pyston_module->giveAttr("dumpStats",
new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)dumpStats, NONE, 1, false, false),
"dumpStats", { Py_False }));
new BoxedBuiltinFunctionOrMethod(
BoxedCode::create((void*)dumpStats, NONE, 1, false, false, "dumpStats"), { Py_False }));
}
}
......@@ -814,14 +814,13 @@ void setupSys() {
sys_module->giveAttr("argv", new BoxedList());
sys_module->giveAttr("exc_info",
new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)sysExcInfo, BOXED_TUPLE, 0),
"exc_info", exc_info_doc));
sys_module->giveAttr("exc_clear", new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)sysExcClear, NONE, 0),
"exc_clear", exc_clear_doc));
sys_module->giveAttr("exit",
new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)sysExit, NONE, 1, false, false),
"exit", { Py_None }, NULL, exit_doc));
sys_module->giveAttr("exc_info", new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)sysExcInfo, BOXED_TUPLE,
0, "exc_info", exc_info_doc)));
sys_module->giveAttr("exc_clear", new BoxedBuiltinFunctionOrMethod(
BoxedCode::create((void*)sysExcClear, NONE, 0, "exc_clear", exc_clear_doc)));
sys_module->giveAttr(
"exit", new BoxedBuiltinFunctionOrMethod(
BoxedCode::create((void*)sysExit, NONE, 1, false, false, "exit", exit_doc), { Py_None }, NULL));
sys_module->giveAttr("warnoptions", new BoxedList());
sys_module->giveAttrBorrowed("py3kwarning", Py_False);
......@@ -831,20 +830,22 @@ void setupSys() {
sys_module->giveAttr("executable", boxString(Py_GetProgramFullPath()));
sys_module->giveAttr("_getframe",
new BoxedFunction(BoxedCode::create((void*)sysGetFrame, UNKNOWN, 1, false, false), { NULL }));
sys_module->giveAttr("_current_frames", new BoxedFunction(BoxedCode::create((void*)sysCurrentFrames, UNKNOWN, 0)));
sys_module->giveAttr(
"_getframe",
new BoxedFunction(BoxedCode::create((void*)sysGetFrame, UNKNOWN, 1, false, false, "_getframe"), { NULL }));
sys_module->giveAttr("_current_frames",
new BoxedFunction(BoxedCode::create((void*)sysCurrentFrames, UNKNOWN, 0, "_current_frames")));
sys_module->giveAttr("getdefaultencoding",
new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)sysGetDefaultEncoding, STR, 0),
"getdefaultencoding", getdefaultencoding_doc));
new BoxedBuiltinFunctionOrMethod(BoxedCode::create(
(void*)sysGetDefaultEncoding, STR, 0, "getdefaultencoding", getdefaultencoding_doc)));
sys_module->giveAttr("getfilesystemencoding",
new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)sysGetFilesystemEncoding, STR, 0),
"getfilesystemencoding", getfilesystemencoding_doc));
sys_module->giveAttr("getfilesystemencoding", new BoxedBuiltinFunctionOrMethod(BoxedCode::create(
(void*)sysGetFilesystemEncoding, STR, 0, "getfilesystemencoding",
getfilesystemencoding_doc)));
sys_module->giveAttr("getrecursionlimit",
new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)sysGetRecursionLimit, UNKNOWN, 0),
"getrecursionlimit", getrecursionlimit_doc));
new BoxedBuiltinFunctionOrMethod(BoxedCode::create(
(void*)sysGetRecursionLimit, UNKNOWN, 0, "getrecursionlimit", getrecursionlimit_doc)));
// As we don't support compile() etc yet force 'dont_write_bytecode' to true.
sys_module->giveAttrBorrowed("dont_write_bytecode", Py_True);
......
......@@ -218,33 +218,35 @@ void setupThread() {
thread_module->giveAttr(
"start_new_thread",
new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)startNewThread, BOXED_INT, 3, false, false),
"start_new_thread", { NULL }));
new BoxedBuiltinFunctionOrMethod(
BoxedCode::create((void*)startNewThread, BOXED_INT, 3, false, false, "start_new_thread"), { NULL }));
thread_module->giveAttr("allocate_lock", new BoxedBuiltinFunctionOrMethod(
BoxedCode::create((void*)allocateLock, UNKNOWN, 0), "allocate_lock"));
BoxedCode::create((void*)allocateLock, UNKNOWN, 0, "allocate_lock")));
thread_module->giveAttr(
"get_ident", new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)getIdent, BOXED_INT, 0), "get_ident"));
"get_ident", new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)getIdent, BOXED_INT, 0, "get_ident")));
thread_module->giveAttr("stack_size", new BoxedBuiltinFunctionOrMethod(
BoxedCode::create((void*)stackSize, BOXED_INT, 0), "stack_size"));
BoxedCode::create((void*)stackSize, BOXED_INT, 0, "stack_size")));
thread_module->giveAttr(
"_count", new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)threadCount, BOXED_INT, 0), "_count"));
"_count", new BoxedBuiltinFunctionOrMethod(BoxedCode::create((void*)threadCount, BOXED_INT, 0, "_count")));
thread_lock_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedThreadLock), false, "lock", true,
BoxedThreadLock::dealloc, NULL, false);
thread_lock_cls->instances_are_nonzero = true;
thread_lock_cls->giveAttr("__module__", boxString("thread"));
thread_lock_cls->giveAttr(
"acquire", new BoxedFunction(BoxedCode::create((void*)BoxedThreadLock::acquire, BOXED_BOOL, 2, false, false),
{ autoDecref(boxInt(1)) }));
thread_lock_cls->giveAttr("release",
new BoxedFunction(BoxedCode::create((void*)BoxedThreadLock::release, NONE, 1)));
thread_lock_cls->giveAttr("acquire",
new BoxedFunction(BoxedCode::create((void*)BoxedThreadLock::acquire, BOXED_BOOL, 2, false,
false, "thread_lock.acquire"),
{ autoDecref(boxInt(1)) }));
thread_lock_cls->giveAttr("release", new BoxedFunction(BoxedCode::create((void*)BoxedThreadLock::release, NONE, 1,
"thread_lock.release")));
thread_lock_cls->giveAttrBorrowed("acquire_lock", thread_lock_cls->getattr(getStaticString("acquire")));
thread_lock_cls->giveAttrBorrowed("release_lock", thread_lock_cls->getattr(getStaticString("release")));
thread_lock_cls->giveAttrBorrowed("__enter__", thread_lock_cls->getattr(getStaticString("acquire")));
thread_lock_cls->giveAttr("__exit__", new BoxedFunction(BoxedCode::create((void*)BoxedThreadLock::exit, NONE, 4)));
thread_lock_cls->giveAttr("locked",
new BoxedFunction(BoxedCode::create((void*)BoxedThreadLock::locked, BOXED_BOOL, 1)));
thread_lock_cls->giveAttr("__exit__", new BoxedFunction(BoxedCode::create((void*)BoxedThreadLock::exit, NONE, 4,
"thread_lock.__exit__")));
thread_lock_cls->giveAttr("locked", new BoxedFunction(BoxedCode::create((void*)BoxedThreadLock::locked, BOXED_BOOL,
1, "thread_lock.locked")));
thread_lock_cls->giveAttrBorrowed("locked_lock", thread_lock_cls->getattr(getStaticString("locked")));
thread_lock_cls->freeze();
......
......@@ -1769,10 +1769,11 @@ extern "C" int PyNumber_CoerceEx(PyObject** pv, PyObject** pw) noexcept {
}
void setupCAPI() {
capifunc_cls->giveAttr("__repr__",
new BoxedFunction(BoxedCode::create((void*)BoxedCApiFunction::__repr__<CXX>, UNKNOWN, 1)));
capifunc_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)BoxedCApiFunction::__repr__<CXX>,
UNKNOWN, 1, "capifunc.__repr__")));
auto capi_call = new BoxedFunction(BoxedCode::create((void*)BoxedCApiFunction::__call__, UNKNOWN, 1, true, true));
auto capi_call = new BoxedFunction(
BoxedCode::create((void*)BoxedCApiFunction::__call__, UNKNOWN, 1, true, true, "capifunc.__call__"));
capifunc_cls->giveAttr("__call__", capi_call);
capifunc_cls->tpp_call.capi_val = BoxedCApiFunction::tppCall<CAPI>;
capifunc_cls->tpp_call.cxx_val = BoxedCApiFunction::tppCall<CXX>;
......
This diff is collapsed.
......@@ -129,13 +129,15 @@ BoxedCode::BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, int fi
internal_callable(NULL, NULL) {
}
BoxedCode::BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, const ParamNames& param_names)
BoxedCode::BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, const char* name, const char* doc,
const ParamNames& param_names)
: source(nullptr),
// TODO what to do with these?
// TODO what to do with this?
filename(nullptr),
name(nullptr),
name(boxString(name)),
// TODO what to do with this?
firstlineno(-1),
_doc(nullptr),
_doc(doc[0] == '\0' ? incref(Py_None) : boxString(doc)),
param_names(param_names),
takes_varargs(takes_varargs),
......
This diff is collapsed.
......@@ -593,15 +593,22 @@ void setupDescr() {
property_cls->instances_are_nonzero = true;
property_cls->giveAttr(
"__init__", new BoxedFunction(BoxedCode::create((void*)propertyInit, UNKNOWN, 5, false, false,
ParamNames({ "", "fget", "fset", "fdel", "doc" }, "", "")),
{ Py_None, Py_None, Py_None, NULL }));
property_cls->giveAttr("__get__", new BoxedFunction(BoxedCode::create((void*)propertyGet, UNKNOWN, 3)));
property_cls->giveAttr("__set__", new BoxedFunction(BoxedCode::create((void*)propertySet, UNKNOWN, 3)));
property_cls->giveAttr("__delete__", new BoxedFunction(BoxedCode::create((void*)propertyDel, UNKNOWN, 2)));
property_cls->giveAttr("getter", new BoxedFunction(BoxedCode::create((void*)propertyGetter, UNKNOWN, 2)));
property_cls->giveAttr("setter", new BoxedFunction(BoxedCode::create((void*)propertySetter, UNKNOWN, 2)));
property_cls->giveAttr("deleter", new BoxedFunction(BoxedCode::create((void*)propertyDeleter, UNKNOWN, 2)));
"__init__",
new BoxedFunction(BoxedCode::create((void*)propertyInit, UNKNOWN, 5, false, false, "property.__init__", "",
ParamNames({ "", "fget", "fset", "fdel", "doc" }, "", "")),
{ Py_None, Py_None, Py_None, NULL }));
property_cls->giveAttr("__get__",
new BoxedFunction(BoxedCode::create((void*)propertyGet, UNKNOWN, 3, "property.__get__")));
property_cls->giveAttr("__set__",
new BoxedFunction(BoxedCode::create((void*)propertySet, UNKNOWN, 3, "property.__set__")));
property_cls->giveAttr("__delete__",
new BoxedFunction(BoxedCode::create((void*)propertyDel, UNKNOWN, 2, "property.__delete__")));
property_cls->giveAttr("getter",
new BoxedFunction(BoxedCode::create((void*)propertyGetter, UNKNOWN, 2, "property.getter")));
property_cls->giveAttr("setter",
new BoxedFunction(BoxedCode::create((void*)propertySetter, UNKNOWN, 2, "property.setter")));
property_cls->giveAttr(
"deleter", new BoxedFunction(BoxedCode::create((void*)propertyDeleter, UNKNOWN, 2, "property.deleter")));
property_cls->giveAttrMember("fget", T_OBJECT, offsetof(BoxedProperty, prop_get));
property_cls->giveAttrMember("fset", T_OBJECT, offsetof(BoxedProperty, prop_set));
property_cls->giveAttrMember("fdel", T_OBJECT, offsetof(BoxedProperty, prop_del));
......@@ -609,20 +616,22 @@ void setupDescr() {
property_cls->freeze();
staticmethod_cls->giveAttrMember("__func__", T_OBJECT, offsetof(BoxedStaticmethod, sm_callable));
staticmethod_cls->giveAttr("__init__",
new BoxedFunction(BoxedCode::create((void*)staticmethodInit, UNKNOWN, 5, false, false),
{ Py_None, Py_None, Py_None, Py_None }));
staticmethod_cls->giveAttr(
"__get__", new BoxedFunction(BoxedCode::create((void*)staticmethodGet, UNKNOWN, 3, false, false), { Py_None }));
staticmethod_cls->giveAttr("__init__", new BoxedFunction(BoxedCode::create((void*)staticmethodInit, UNKNOWN, 5,
false, false, "staticmethod.__init__"),
{ Py_None, Py_None, Py_None, Py_None }));
staticmethod_cls->giveAttr("__get__", new BoxedFunction(BoxedCode::create((void*)staticmethodGet, UNKNOWN, 3, false,
false, "staticmethod.__get__"),
{ Py_None }));
staticmethod_cls->freeze();
classmethod_cls->giveAttrMember("__func__", T_OBJECT, offsetof(BoxedClassmethod, cm_callable));
classmethod_cls->giveAttr("__init__",
new BoxedFunction(BoxedCode::create((void*)classmethodInit, UNKNOWN, 5, false, false),
{ Py_None, Py_None, Py_None, Py_None }));
classmethod_cls->giveAttr(
"__get__", new BoxedFunction(BoxedCode::create((void*)classmethodGet, UNKNOWN, 3, false, false), { Py_None }));
classmethod_cls->giveAttr("__init__", new BoxedFunction(BoxedCode::create((void*)classmethodInit, UNKNOWN, 5, false,
false, "classmethod.__init__"),
{ Py_None, Py_None, Py_None, Py_None }));
classmethod_cls->giveAttr("__get__", new BoxedFunction(BoxedCode::create((void*)classmethodGet, UNKNOWN, 3, false,
false, "classmethod.__get__"),
{ Py_None }));
classmethod_cls->freeze();
PyType_Ready(&PyGetSetDescr_Type);
......
......@@ -1137,72 +1137,88 @@ void setupDict() {
dict_cls->tp_compare = (cmpfunc)dict_compare;
dict_cls->tp_richcompare = dict_richcompare;
dict_cls->giveAttr("__len__", new BoxedFunction(BoxedCode::create((void*)dictLen, BOXED_INT, 1)));
dict_cls->giveAttr("__new__", new BoxedFunction(BoxedCode::create((void*)dictNew, UNKNOWN, 1, true, true)));
dict_cls->giveAttr("__init__", new BoxedFunction(BoxedCode::create((void*)dictInit, NONE, 1, true, true)));
dict_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)dictRepr, STR, 1)));
dict_cls->giveAttr("__eq__", new BoxedFunction(BoxedCode::create((void*)dictEq, UNKNOWN, 2)));
dict_cls->giveAttr("__ne__", new BoxedFunction(BoxedCode::create((void*)dictNe, UNKNOWN, 2)));
dict_cls->giveAttr("__len__", new BoxedFunction(BoxedCode::create((void*)dictLen, BOXED_INT, 1, "dict.__len__")));
dict_cls->giveAttr("__new__",
new BoxedFunction(BoxedCode::create((void*)dictNew, UNKNOWN, 1, true, true, "dict.__new__")));
dict_cls->giveAttr("__init__",
new BoxedFunction(BoxedCode::create((void*)dictInit, NONE, 1, true, true, "dict.__init__")));
dict_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)dictRepr, STR, 1, "dict.__repr__")));
dict_cls->giveAttr("__eq__", new BoxedFunction(BoxedCode::create((void*)dictEq, UNKNOWN, 2, "dict.__eq__")));
dict_cls->giveAttr("__ne__", new BoxedFunction(BoxedCode::create((void*)dictNe, UNKNOWN, 2, "dict.__ne__")));
dict_cls->giveAttr("__hash__", incref(Py_None));
dict_cls->giveAttr("__iter__",
new BoxedFunction(BoxedCode::create((void*)dictIterKeys, typeFromClass(dictiterkey_cls), 1)));
dict_cls->giveAttr("__iter__", new BoxedFunction(BoxedCode::create(
(void*)dictIterKeys, typeFromClass(dictiterkey_cls), 1, "dict.__iter__")));
dict_cls->giveAttr("update", new BoxedFunction(BoxedCode::create((void*)dictUpdate, NONE, 1, true, true)));
dict_cls->giveAttr("update",
new BoxedFunction(BoxedCode::create((void*)dictUpdate, NONE, 1, true, true, "dict.update")));
dict_cls->giveAttr("clear", new BoxedFunction(BoxedCode::create((void*)dictClear, NONE, 1)));
dict_cls->giveAttr("copy", new BoxedFunction(BoxedCode::create((void*)dictCopy, DICT, 1)));
dict_cls->giveAttr("clear", new BoxedFunction(BoxedCode::create((void*)dictClear, NONE, 1, "dict.clear")));
dict_cls->giveAttr("copy", new BoxedFunction(BoxedCode::create((void*)dictCopy, DICT, 1, "dict.copy")));
dict_cls->giveAttr("has_key", new BoxedFunction(BoxedCode::create((void*)dictContains, BOXED_BOOL, 2)));
dict_cls->giveAttr("items", new BoxedFunction(BoxedCode::create((void*)dictItems, LIST, 1)));
dict_cls->giveAttr("iteritems",
new BoxedFunction(BoxedCode::create((void*)dictIterItems, typeFromClass(dictiteritem_cls), 1)));
dict_cls->giveAttr("has_key",
new BoxedFunction(BoxedCode::create((void*)dictContains, BOXED_BOOL, 2, "dict.has_key")));
dict_cls->giveAttr("items", new BoxedFunction(BoxedCode::create((void*)dictItems, LIST, 1, "dict.items")));
dict_cls->giveAttr("iteritems", new BoxedFunction(BoxedCode::create(
(void*)dictIterItems, typeFromClass(dictiteritem_cls), 1, "dict.iteritems")));
dict_cls->giveAttr("values", new BoxedFunction(BoxedCode::create((void*)dictValues, LIST, 1)));
dict_cls->giveAttr(
"itervalues", new BoxedFunction(BoxedCode::create((void*)dictIterValues, typeFromClass(dictitervalue_cls), 1)));
dict_cls->giveAttr("values", new BoxedFunction(BoxedCode::create((void*)dictValues, LIST, 1, "dict.values")));
dict_cls->giveAttr("itervalues",
new BoxedFunction(BoxedCode::create((void*)dictIterValues, typeFromClass(dictitervalue_cls), 1,
"dict.itervalues")));
dict_cls->giveAttr("keys", new BoxedFunction(BoxedCode::create((void*)dictKeys, LIST, 1)));
dict_cls->giveAttr("keys", new BoxedFunction(BoxedCode::create((void*)dictKeys, LIST, 1, "dict.keys")));
dict_cls->giveAttrBorrowed("iterkeys", dict_cls->getattr(autoDecref(internStringMortal("__iter__"))));
dict_cls->giveAttr("pop", new BoxedFunction(BoxedCode::create((void*)dictPop, UNKNOWN, 3, false, false), { NULL }));
dict_cls->giveAttr("popitem", new BoxedFunction(BoxedCode::create((void*)dictPopitem, BOXED_TUPLE, 1)));
dict_cls->giveAttr(
"pop", new BoxedFunction(BoxedCode::create((void*)dictPop, UNKNOWN, 3, false, false, "dict.pop"), { NULL }));
dict_cls->giveAttr("popitem",
new BoxedFunction(BoxedCode::create((void*)dictPopitem, BOXED_TUPLE, 1, "dict.popitem")));
auto* fromkeys_func = new BoxedFunction(BoxedCode::create((void*)dictFromkeys, DICT, 3, false, false), { Py_None });
auto* fromkeys_func = new BoxedFunction(
BoxedCode::create((void*)dictFromkeys, DICT, 3, false, false, "dict.fromkeys"), { Py_None });
dict_cls->giveAttr("fromkeys", boxInstanceMethod(dict_cls, fromkeys_func, dict_cls));
Py_DECREF(fromkeys_func);
dict_cls->giveAttr("viewkeys", new BoxedFunction(BoxedCode::create((void*)dictViewKeys, UNKNOWN, 1)));
dict_cls->giveAttr("viewvalues", new BoxedFunction(BoxedCode::create((void*)dictViewValues, UNKNOWN, 1)));
dict_cls->giveAttr("viewitems", new BoxedFunction(BoxedCode::create((void*)dictViewItems, UNKNOWN, 1)));
dict_cls->giveAttr("get",
new BoxedFunction(BoxedCode::create((void*)dictGet, UNKNOWN, 3, false, false), { Py_None }));
dict_cls->giveAttr("viewkeys",
new BoxedFunction(BoxedCode::create((void*)dictViewKeys, UNKNOWN, 1, "dict.viewkeys")));
dict_cls->giveAttr("viewvalues",
new BoxedFunction(BoxedCode::create((void*)dictViewValues, UNKNOWN, 1, "dict.viewvalues")));
dict_cls->giveAttr("viewitems",
new BoxedFunction(BoxedCode::create((void*)dictViewItems, UNKNOWN, 1, "dict.viewitems")));
dict_cls->giveAttr(
"setdefault",
new BoxedFunction(BoxedCode::create((void*)dictSetdefault, UNKNOWN, 3, false, false), { Py_None }));
"get", new BoxedFunction(BoxedCode::create((void*)dictGet, UNKNOWN, 3, false, false, "dict.get"), { Py_None }));
dict_cls->giveAttr("setdefault", new BoxedFunction(BoxedCode::create((void*)dictSetdefault, UNKNOWN, 3, false,
false, "dict.setdefault"),
{ Py_None }));
auto dict_getitem = BoxedCode::create((void*)dictGetitem<CXX>, UNKNOWN, 2, ParamNames::empty(), CXX);
auto dict_getitem
= BoxedCode::create((void*)dictGetitem<CXX>, UNKNOWN, 2, "dict.__getitem__", "", ParamNames::empty(), CXX);
dict_getitem->addVersion((void*)dictGetitem<CAPI>, UNKNOWN, CAPI);
dict_cls->giveAttr("__getitem__", new BoxedFunction(dict_getitem));
dict_cls->giveAttr("__setitem__", new BoxedFunction(BoxedCode::create((void*)dictSetitem, NONE, 3)));
dict_cls->giveAttr("__delitem__", new BoxedFunction(BoxedCode::create((void*)dictDelitem, UNKNOWN, 2)));
dict_cls->giveAttr("__contains__", new BoxedFunction(BoxedCode::create((void*)dictContains, BOXED_BOOL, 2)));
dict_cls->giveAttr("__setitem__",
new BoxedFunction(BoxedCode::create((void*)dictSetitem, NONE, 3, "dict.__setitem__")));
dict_cls->giveAttr("__delitem__",
new BoxedFunction(BoxedCode::create((void*)dictDelitem, UNKNOWN, 2, "dict.__delitem__")));
dict_cls->giveAttr("__contains__",
new BoxedFunction(BoxedCode::create((void*)dictContains, BOXED_BOOL, 2, "dict.__contains__")));
dict_cls->giveAttr("__nonzero__", new BoxedFunction(BoxedCode::create((void*)dictNonzero, BOXED_BOOL, 1)));
dict_cls->giveAttr("__nonzero__",
new BoxedFunction(BoxedCode::create((void*)dictNonzero, BOXED_BOOL, 1, "dict.__nonzero__")));
add_operators(dict_cls);
dict_cls->freeze();
// create the dictonary iterator types
for (BoxedClass* iter_type : { dictiterkey_cls, dictitervalue_cls, dictiteritem_cls }) {
BoxedCode* hasnext = BoxedCode::create((void*)dictIterHasnextUnboxed, BOOL, 1);
BoxedCode* hasnext = BoxedCode::create((void*)dictIterHasnextUnboxed, BOOL, 1, "dict.__hasnext__");
hasnext->addVersion((void*)dictIterHasnext, BOXED_BOOL);
iter_type->giveAttr("__hasnext__", new BoxedFunction(hasnext));
iter_type->giveAttr("__iter__",
new BoxedFunction(BoxedCode::create((void*)dictIterIter, typeFromClass(iter_type), 1)));
iter_type->giveAttr("next", new BoxedFunction(BoxedCode::create((void*)dictIterNext, UNKNOWN, 1)));
iter_type->giveAttr("__iter__", new BoxedFunction(BoxedCode::create((void*)dictIterIter,
typeFromClass(iter_type), 1, "__iter__")));
iter_type->giveAttr("next", new BoxedFunction(BoxedCode::create((void*)dictIterNext, UNKNOWN, 1, "next")));
iter_type->freeze();
iter_type->tp_iter = PyObject_SelfIter;
iter_type->tp_iternext = dictiter_next;
......
......@@ -877,7 +877,7 @@ static void _addFunc(const char* name, ConcreteCompilerType* rtn_type, void* flo
v_uu.push_back(UNKNOWN);
v_uu.push_back(UNKNOWN);
BoxedCode* code = new BoxedCode(2, false, false);
BoxedCode* code = new BoxedCode(2, false, false, name);
code->addVersion(float_func, rtn_type, v_ff);
code->addVersion(int_func, rtn_type, v_fi);
code->addVersion(boxed_func, UNKNOWN, v_uu);
......@@ -890,7 +890,7 @@ static void _addFuncPow(const char* name, ConcreteCompilerType* rtn_type, void*
std::vector<ConcreteCompilerType*> v_fiu{ BOXED_FLOAT, BOXED_INT, UNKNOWN };
std::vector<ConcreteCompilerType*> v_fuu{ BOXED_FLOAT, UNKNOWN, UNKNOWN };
BoxedCode* code = new BoxedCode(3, false, false);
BoxedCode* code = new BoxedCode(3, false, false, name);
code->addVersion(float_func, rtn_type, v_ffu);
code->addVersion(int_func, rtn_type, v_fiu);
code->addVersion(boxed_func, UNKNOWN, v_fuu);
......@@ -949,8 +949,9 @@ void setupFloat() {
static PyNumberMethods float_as_number;
float_cls->tp_as_number = &float_as_number;
float_cls->giveAttr("__getnewargs__", new BoxedFunction(BoxedCode::create((void*)float_getnewargs, UNKNOWN, 1,
ParamNames::empty(), CAPI)));
float_cls->giveAttr("__getnewargs__",
new BoxedFunction(BoxedCode::create((void*)float_getnewargs, UNKNOWN, 1, "float.__getnewargs__",
"", ParamNames::empty(), CAPI)));
_addFunc("__add__", BOXED_FLOAT, (void*)floatAddFloat, (void*)floatAddInt, (void*)floatAdd);
float_cls->giveAttrBorrowed("__radd__", float_cls->getattr(autoDecref(internStringMortal("__add__"))));
......@@ -958,9 +959,11 @@ void setupFloat() {
_addFunc("__div__", BOXED_FLOAT, (void*)floatDivFloat, (void*)floatDivInt, (void*)floatDiv);
_addFunc("__rdiv__", BOXED_FLOAT, (void*)floatRDivFloat, (void*)floatRDivInt, (void*)floatRDiv);
_addFunc("__floordiv__", BOXED_FLOAT, (void*)floatFloorDivFloat, (void*)floatFloorDivInt, (void*)floatFloorDiv);
float_cls->giveAttr("__rfloordiv__", new BoxedFunction(BoxedCode::create((void*)floatRFloorDiv, UNKNOWN, 2)));
float_cls->giveAttr("__rfloordiv__",
new BoxedFunction(BoxedCode::create((void*)floatRFloorDiv, UNKNOWN, 2, "float.__rfloordiv__")));
_addFunc("__truediv__", BOXED_FLOAT, (void*)floatDivFloat, (void*)floatDivInt, (void*)floatTruediv);
float_cls->giveAttr("__rtruediv__", new BoxedFunction(BoxedCode::create((void*)floatRTruediv, UNKNOWN, 2)));
float_cls->giveAttr("__rtruediv__",
new BoxedFunction(BoxedCode::create((void*)floatRTruediv, UNKNOWN, 2, "float.__rtruediv__")));
_addFunc("__mod__", BOXED_FLOAT, (void*)floatModFloat, (void*)floatModInt, (void*)floatMod);
_addFunc("__rmod__", BOXED_FLOAT, (void*)floatRModFloat, (void*)floatRModInt, (void*)floatRMod);
......@@ -968,46 +971,60 @@ void setupFloat() {
float_cls->giveAttrBorrowed("__rmul__", float_cls->getattr(autoDecref(internStringMortal("__mul__"))));
_addFuncPow("__pow__", BOXED_FLOAT, (void*)floatPowFloat, (void*)floatPowInt, (void*)floatPow);
float_cls->giveAttr("__rpow__", new BoxedFunction(BoxedCode::create((void*)floatRPow, UNKNOWN, 2)));
float_cls->giveAttr("__rpow__",
new BoxedFunction(BoxedCode::create((void*)floatRPow, UNKNOWN, 2, "float.__rpow__")));
_addFunc("__sub__", BOXED_FLOAT, (void*)floatSubFloat, (void*)floatSubInt, (void*)floatSub);
_addFunc("__rsub__", BOXED_FLOAT, (void*)floatRSubFloat, (void*)floatRSubInt, (void*)floatRSub);
float_cls->giveAttr("__divmod__", new BoxedFunction(BoxedCode::create((void*)floatDivmod, UNKNOWN, 2)));
float_cls->giveAttr("__rdivmod__", new BoxedFunction(BoxedCode::create((void*)floatRDivmod, UNKNOWN, 2)));
float_cls->giveAttr("__divmod__",
new BoxedFunction(BoxedCode::create((void*)floatDivmod, UNKNOWN, 2, "float.__divmod__")));
float_cls->giveAttr("__rdivmod__",
new BoxedFunction(BoxedCode::create((void*)floatRDivmod, UNKNOWN, 2, "float.__rdivmod__")));
auto float_new
= BoxedCode::create((void*)floatNew<CXX>, UNKNOWN, 2, false, false, ParamNames({ "", "x" }, "", ""), CXX);
auto float_new = BoxedCode::create((void*)floatNew<CXX>, UNKNOWN, 2, false, false, "float.__new__", "",
ParamNames({ "", "x" }, "", ""), CXX);
float_new->addVersion((void*)floatNew<CAPI>, UNKNOWN, CAPI);
float_cls->giveAttr("__new__", new BoxedFunction(float_new, { autoDecref(boxFloat(0.0)) }));
float_cls->giveAttr("__eq__", new BoxedFunction(BoxedCode::create((void*)floatEq, UNKNOWN, 2)));
float_cls->giveAttr("__ne__", new BoxedFunction(BoxedCode::create((void*)floatNe, UNKNOWN, 2)));
float_cls->giveAttr("__le__", new BoxedFunction(BoxedCode::create((void*)floatLe, UNKNOWN, 2)));
float_cls->giveAttr("__lt__", new BoxedFunction(BoxedCode::create((void*)floatLt, UNKNOWN, 2)));
float_cls->giveAttr("__ge__", new BoxedFunction(BoxedCode::create((void*)floatGe, UNKNOWN, 2)));
float_cls->giveAttr("__gt__", new BoxedFunction(BoxedCode::create((void*)floatGt, UNKNOWN, 2)));
float_cls->giveAttr("__neg__", new BoxedFunction(BoxedCode::create((void*)floatNeg, BOXED_FLOAT, 1)));
float_cls->giveAttr("__pos__", new BoxedFunction(BoxedCode::create((void*)floatPos, BOXED_FLOAT, 1)));
float_cls->giveAttr("__abs__", new BoxedFunction(BoxedCode::create((void*)floatAbs, BOXED_FLOAT, 1)));
BoxedCode* nonzero = BoxedCode::create((void*)floatNonzeroUnboxed, BOOL, 1);
float_cls->giveAttr("__eq__", new BoxedFunction(BoxedCode::create((void*)floatEq, UNKNOWN, 2, "float.__eq__")));
float_cls->giveAttr("__ne__", new BoxedFunction(BoxedCode::create((void*)floatNe, UNKNOWN, 2, "float.__ne__")));
float_cls->giveAttr("__le__", new BoxedFunction(BoxedCode::create((void*)floatLe, UNKNOWN, 2, "float.__le__")));
float_cls->giveAttr("__lt__", new BoxedFunction(BoxedCode::create((void*)floatLt, UNKNOWN, 2, "float.__lt__")));
float_cls->giveAttr("__ge__", new BoxedFunction(BoxedCode::create((void*)floatGe, UNKNOWN, 2, "float.__ge__")));
float_cls->giveAttr("__gt__", new BoxedFunction(BoxedCode::create((void*)floatGt, UNKNOWN, 2, "float.__gt__")));
float_cls->giveAttr("__neg__",
new BoxedFunction(BoxedCode::create((void*)floatNeg, BOXED_FLOAT, 1, "float.__neg__")));
float_cls->giveAttr("__pos__",
new BoxedFunction(BoxedCode::create((void*)floatPos, BOXED_FLOAT, 1, "float.__pos__")));
float_cls->giveAttr("__abs__",
new BoxedFunction(BoxedCode::create((void*)floatAbs, BOXED_FLOAT, 1, "float.__abs__")));
BoxedCode* nonzero = BoxedCode::create((void*)floatNonzeroUnboxed, BOOL, 1, "float.__nonzero__");
nonzero->addVersion((void*)floatNonzero, UNKNOWN);
float_cls->giveAttr("__nonzero__", new BoxedFunction(nonzero));
// float_cls->giveAttr("__nonzero__", new BoxedFunction(BoxedCode::create((void*)floatNonzero, NULL, 1)));
float_cls->giveAttr("__float__", new BoxedFunction(BoxedCode::create((void*)floatFloat, BOXED_FLOAT, 1)));
float_cls->giveAttr("__str__", new BoxedFunction(BoxedCode::create((void*)floatStr<CXX>, STR, 1)));
float_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)floatRepr<CXX>, STR, 1)));
float_cls->giveAttr("__coerce__", new BoxedFunction(BoxedCode::create((void*)floatCoerce, UNKNOWN, 2)));
float_cls->giveAttr("__trunc__", new BoxedFunction(BoxedCode::create((void*)floatTrunc, UNKNOWN, 1)));
float_cls->giveAttr("__int__", new BoxedFunction(BoxedCode::create((void*)floatInt, UNKNOWN, 1)));
float_cls->giveAttr("__long__", new BoxedFunction(BoxedCode::create((void*)floatLong, UNKNOWN, 1)));
float_cls->giveAttr("__hash__", new BoxedFunction(BoxedCode::create((void*)floatHash, BOXED_INT, 1)));
// float_cls->giveAttr("__nonzero__", new BoxedFunction(BoxedCode::create((void*)floatNonzero, NULL, 1,
// "float.__nonzero__")));
float_cls->giveAttr("__float__",
new BoxedFunction(BoxedCode::create((void*)floatFloat, BOXED_FLOAT, 1, "float.__float__")));
float_cls->giveAttr("__str__", new BoxedFunction(BoxedCode::create((void*)floatStr<CXX>, STR, 1, "float.__str__")));
float_cls->giveAttr("__repr__",
new BoxedFunction(BoxedCode::create((void*)floatRepr<CXX>, STR, 1, "float.__repr__")));
float_cls->giveAttr("__coerce__",
new BoxedFunction(BoxedCode::create((void*)floatCoerce, UNKNOWN, 2, "float.__coerce__")));
float_cls->giveAttr("__trunc__",
new BoxedFunction(BoxedCode::create((void*)floatTrunc, UNKNOWN, 1, "float.__trunc__")));
float_cls->giveAttr("__int__", new BoxedFunction(BoxedCode::create((void*)floatInt, UNKNOWN, 1, "float.__int__")));
float_cls->giveAttr("__long__",
new BoxedFunction(BoxedCode::create((void*)floatLong, UNKNOWN, 1, "float.__long__")));
float_cls->giveAttr("__hash__",
new BoxedFunction(BoxedCode::create((void*)floatHash, BOXED_INT, 1, "float.__hash__")));
float_cls->giveAttrDescriptor("real", float_conjugate, NULL);
float_cls->giveAttrDescriptor("imag", float0, NULL);
float_cls->giveAttr("conjugate", new BoxedFunction(BoxedCode::create((void*)float_conjugate, BOXED_FLOAT, 1,
ParamNames::empty(), CAPI)));
float_cls->giveAttr("conjugate",
new BoxedFunction(BoxedCode::create((void*)float_conjugate, BOXED_FLOAT, 1, "float.conjugate",
"", ParamNames::empty(), CAPI)));
float_cls->giveAttr("__doc__", boxString("float(x) -> floating point number\n"
"\n"
......
......@@ -715,26 +715,28 @@ void setupGenerator() {
generator_cls = BoxedClass::create(type_cls, object_cls, 0, offsetof(BoxedGenerator, weakreflist),
sizeof(BoxedGenerator), false, "generator", false, (destructor)generator_dealloc,
NULL, true, (traverseproc)generator_traverse, NOCLEAR);
generator_cls->giveAttr(
"__iter__", new BoxedFunction(BoxedCode::create((void*)generatorIter, typeFromClass(generator_cls), 1)));
generator_cls->giveAttr("__iter__",
new BoxedFunction(BoxedCode::create((void*)generatorIter, typeFromClass(generator_cls), 1,
"generator.__iter__")));
auto generator_close = BoxedCode::create((void*)generatorClose<CXX>, UNKNOWN, 1);
auto generator_close = BoxedCode::create((void*)generatorClose<CXX>, UNKNOWN, 1, "generator.close");
generator_close->addVersion((void*)generatorClose<CAPI>, UNKNOWN, CAPI);
generator_cls->giveAttr("close", new BoxedFunction(generator_close));
auto generator_next = BoxedCode::create((void*)generatorNext<CXX>, UNKNOWN, 1, ParamNames::empty(), CXX);
auto generator_next
= BoxedCode::create((void*)generatorNext<CXX>, UNKNOWN, 1, "generatro.next", "", ParamNames::empty(), CXX);
generator_next->addVersion((void*)generatorNext<CAPI>, UNKNOWN, CAPI);
generator_cls->giveAttr("next", new BoxedFunction(generator_next));
BoxedCode* hasnext = BoxedCode::create((void*)generatorHasnextUnboxed, BOOL, 1);
BoxedCode* hasnext = BoxedCode::create((void*)generatorHasnextUnboxed, BOOL, 1, "generator.__hasnext__");
hasnext->addVersion((void*)generatorHasnext, BOXED_BOOL);
generator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext));
auto generator_send = BoxedCode::create((void*)generatorSend<CXX>, UNKNOWN, 2);
auto generator_send = BoxedCode::create((void*)generatorSend<CXX>, UNKNOWN, 2, "generator.send");
generator_send->addVersion((void*)generatorSend<CAPI>, UNKNOWN, CAPI);
generator_cls->giveAttr("send", new BoxedFunction(generator_send));
auto generator_throw = BoxedCode::create((void*)generatorThrow<CXX>, UNKNOWN, 4, false, false);
auto generator_throw = BoxedCode::create((void*)generatorThrow<CXX>, UNKNOWN, 4, false, false, "generator.throw");
generator_throw->addVersion((void*)generatorThrow<CAPI>, UNKNOWN, CAPI);
generator_cls->giveAttr("throw", new BoxedFunction(generator_throw, { NULL, NULL }));
......
......@@ -267,27 +267,35 @@ void setupXrange() {
static PySequenceMethods xrange_as_sequence;
xrange_cls->tp_as_sequence = &xrange_as_sequence;
xrange_cls->giveAttr("__new__",
new BoxedFunction(BoxedCode::create((void*)xrange, typeFromClass(xrange_cls), 4, false, false),
{ NULL, NULL }));
xrange_cls->giveAttr(
"__iter__", new BoxedFunction(BoxedCode::create((void*)xrangeIter, typeFromClass(xrange_iterator_cls), 1)));
xrange_cls->giveAttr("__reversed__", new BoxedFunction(BoxedCode::create((void*)xrangeReversed,
typeFromClass(xrange_iterator_cls), 1)));
xrange_cls->giveAttr("__new__", new BoxedFunction(BoxedCode::create((void*)xrange, typeFromClass(xrange_cls), 4,
false, false, "xrange.__new__"),
{ NULL, NULL }));
xrange_cls->giveAttr("__iter__", new BoxedFunction(BoxedCode::create(
(void*)xrangeIter, typeFromClass(xrange_iterator_cls), 1, "xrange.__iter__")));
xrange_cls->giveAttr("__reversed__",
new BoxedFunction(BoxedCode::create((void*)xrangeReversed, typeFromClass(xrange_iterator_cls),
1, "xrange.__reversed__")));
xrange_cls->giveAttr("__getitem__", new BoxedFunction(BoxedCode::create((void*)xrangeGetitem, BOXED_INT, 2)));
xrange_cls->giveAttr(
"__getitem__", new BoxedFunction(BoxedCode::create((void*)xrangeGetitem, BOXED_INT, 2, "xrange.__getitem__")));
xrange_cls->giveAttr("__len__", new BoxedFunction(BoxedCode::create((void*)xrangeLen, BOXED_INT, 1)));
xrange_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)xrangeRepr, STR, 1)));
xrange_cls->giveAttr("__reduce__", new BoxedFunction(BoxedCode::create((void*)xrangeReduce, BOXED_TUPLE, 1)));
xrange_cls->giveAttr("__len__",
new BoxedFunction(BoxedCode::create((void*)xrangeLen, BOXED_INT, 1, "xrange.__len__")));
xrange_cls->giveAttr("__repr__",
new BoxedFunction(BoxedCode::create((void*)xrangeRepr, STR, 1, "xrange.__repr__")));
xrange_cls->giveAttr(
"__reduce__", new BoxedFunction(BoxedCode::create((void*)xrangeReduce, BOXED_TUPLE, 1, "xrange.__reduce__")));
BoxedCode* hasnext = BoxedCode::create((void*)BoxedXrangeIterator::xrangeIteratorHasnextUnboxed, BOOL, 1);
BoxedCode* hasnext
= BoxedCode::create((void*)BoxedXrangeIterator::xrangeIteratorHasnextUnboxed, BOOL, 1, "xrange.__hasnext__");
hasnext->addVersion((void*)BoxedXrangeIterator::xrangeIteratorHasnext, BOXED_BOOL);
xrange_iterator_cls->giveAttr(
"__iter__", new BoxedFunction(BoxedCode::create((void*)xrangeIterIter, typeFromClass(xrange_iterator_cls), 1)));
"__iter__", new BoxedFunction(BoxedCode::create((void*)xrangeIterIter, typeFromClass(xrange_iterator_cls), 1,
"xrange.__iter__")));
xrange_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext));
BoxedCode* next = BoxedCode::create((void*)BoxedXrangeIterator::xrangeIteratorNextUnboxed, UNBOXED_INT, 1);
BoxedCode* next
= BoxedCode::create((void*)BoxedXrangeIterator::xrangeIteratorNextUnboxed, UNBOXED_INT, 1, "xrange.next");
next->addVersion((void*)BoxedXrangeIterator::xrangeIteratorNext, BOXED_INT);
xrange_iterator_cls->giveAttr("next", new BoxedFunction(next));
......
This diff is collapsed.
......@@ -210,11 +210,12 @@ void setupIter() {
(destructor)BoxedSeqIter::dealloc, NULL, true,
(traverseproc)BoxedSeqIter::traverse, NOCLEAR);
seqiter_cls->giveAttr("next", new BoxedFunction(BoxedCode::create((void*)seqiterNext, UNKNOWN, 1)));
BoxedCode* hasnext = BoxedCode::create((void*)seqiterHasnextUnboxed, BOOL, 1);
seqiter_cls->giveAttr("next", new BoxedFunction(BoxedCode::create((void*)seqiterNext, UNKNOWN, 1, "seqiter.next")));
BoxedCode* hasnext = BoxedCode::create((void*)seqiterHasnextUnboxed, BOOL, 1, "seqiter.__hasnext__");
hasnext->addVersion((void*)seqiterHasnext, BOXED_BOOL);
seqiter_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext));
seqiter_cls->giveAttr("__iter__", new BoxedFunction(BoxedCode::create((void*)seqiterIter, UNKNOWN, 1)));
seqiter_cls->giveAttr("__iter__",
new BoxedFunction(BoxedCode::create((void*)seqiterIter, UNKNOWN, 1, "seqiter.__iter__")));
seqiter_cls->freeze();
seqiter_cls->tpp_hasnext = seqiterHasnextUnboxed;
......@@ -225,10 +226,12 @@ void setupIter() {
(destructor)BoxedSeqIter::dealloc, NULL, true,
(traverseproc)BoxedSeqIter::traverse, NOCLEAR);
seqreviter_cls->giveAttr("next", new BoxedFunction(BoxedCode::create((void*)seqiterNext, UNKNOWN, 1)));
seqreviter_cls->giveAttr("__hasnext__",
new BoxedFunction(BoxedCode::create((void*)seqreviterHasnext, BOXED_BOOL, 1)));
seqreviter_cls->giveAttr("__iter__", new BoxedFunction(BoxedCode::create((void*)seqiterIter, UNKNOWN, 1)));
seqreviter_cls->giveAttr("next",
new BoxedFunction(BoxedCode::create((void*)seqiterNext, UNKNOWN, 1, "seqreviter.next")));
seqreviter_cls->giveAttr("__hasnext__", new BoxedFunction(BoxedCode::create((void*)seqreviterHasnext, BOXED_BOOL, 1,
"seqreviter.__hasnext__")));
seqreviter_cls->giveAttr(
"__iter__", new BoxedFunction(BoxedCode::create((void*)seqiterIter, UNKNOWN, 1, "seqreviter.__iter__")));
seqreviter_cls->freeze();
seqreviter_cls->tp_iter = PyObject_SelfIter;
......@@ -238,9 +241,10 @@ void setupIter() {
false, (destructor)BoxedIterWrapper::dealloc, NULL, true,
(traverseproc)BoxedIterWrapper::traverse, NOCLEAR);
iterwrapper_cls->giveAttr("next", new BoxedFunction(BoxedCode::create((void*)iterwrapperNext, UNKNOWN, 1)));
iterwrapper_cls->giveAttr("__hasnext__",
new BoxedFunction(BoxedCode::create((void*)iterwrapperHasnext, BOXED_BOOL, 1)));
iterwrapper_cls->giveAttr(
"next", new BoxedFunction(BoxedCode::create((void*)iterwrapperNext, UNKNOWN, 1, "iterwrapper.next")));
iterwrapper_cls->giveAttr("__hasnext__", new BoxedFunction(BoxedCode::create((void*)iterwrapperHasnext, BOXED_BOOL,
1, "iterwrapper.__hasnext__")));
iterwrapper_cls->freeze();
iterwrapper_cls->tpp_hasnext = iterwrapperHasnextUnboxed;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -254,11 +254,13 @@ void setupSuper() {
// super_cls->giveAttr("__getattribute__", new BoxedFunction(BoxedCode::create((void*)superGetattribute,
// UNKNOWN, 2)));
super_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)superRepr, STR, 1)));
super_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)superRepr, STR, 1, "super.__repr__")));
super_cls->giveAttr("__init__",
new BoxedFunction(BoxedCode::create((void*)superInit, UNKNOWN, 3, false, false), { NULL }));
super_cls->giveAttr("__get__", new BoxedFunction(BoxedCode::create((void*)superGet<CXX>, UNKNOWN, 3)));
super_cls->giveAttr(
"__init__",
new BoxedFunction(BoxedCode::create((void*)superInit, UNKNOWN, 3, false, false, "super.__init__"), { NULL }));
super_cls->giveAttr("__get__",
new BoxedFunction(BoxedCode::create((void*)superGet<CXX>, UNKNOWN, 3, "super.__get__")));
super_cls->giveAttrMember("__thisclass__", T_OBJECT, offsetof(BoxedSuper, type));
super_cls->giveAttrMember("__self__", T_OBJECT, offsetof(BoxedSuper, obj));
......
......@@ -772,8 +772,9 @@ void setupTuple() {
"tupleiterator", false, (destructor)BoxedTupleIterator::dealloc, NULL, true,
(traverseproc)BoxedTupleIterator::traverse, NOCLEAR);
tuple_cls->giveAttr("__new__", new BoxedFunction(BoxedCode::create((void*)tupleNew, UNKNOWN, 1, true, true)));
BoxedCode* getitem = new BoxedCode(2, 0, 0);
tuple_cls->giveAttr("__new__",
new BoxedFunction(BoxedCode::create((void*)tupleNew, UNKNOWN, 1, true, true, "tuple.__new__")));
BoxedCode* getitem = new BoxedCode(2, 0, 0, "tuple.__getitem__");
getitem->addVersion((void*)tupleGetitemInt, UNKNOWN, std::vector<ConcreteCompilerType*>{ UNKNOWN, BOXED_INT });
getitem->addVersion((void*)tupleGetitemSlice, UNKNOWN, std::vector<ConcreteCompilerType*>{ UNKNOWN, SLICE });
getitem->addVersion((void*)tupleGetitem<CXX>, UNKNOWN, std::vector<ConcreteCompilerType*>{ UNKNOWN, UNKNOWN }, CXX);
......@@ -781,30 +782,36 @@ void setupTuple() {
CAPI);
tuple_cls->giveAttr("__getitem__", new BoxedFunction(getitem));
tuple_cls->giveAttr("__contains__", new BoxedFunction(BoxedCode::create((void*)tupleContains, BOXED_BOOL, 2)));
tuple_cls->giveAttr("index", new BoxedFunction(BoxedCode::create((void*)tupleIndex, BOXED_INT, 4, false, false),
{ autoDecref(boxInt(0)),
autoDecref(boxInt(std::numeric_limits<Py_ssize_t>::max())) }));
tuple_cls->giveAttr("count", new BoxedFunction(BoxedCode::create((void*)tupleCount, BOXED_INT, 2)));
tuple_cls->giveAttr("__contains__", new BoxedFunction(BoxedCode::create((void*)tupleContains, BOXED_BOOL, 2,
"tuple.__contains__")));
tuple_cls->giveAttr(
"index",
new BoxedFunction(BoxedCode::create((void*)tupleIndex, BOXED_INT, 4, false, false, "tuple.index"),
{ autoDecref(boxInt(0)), autoDecref(boxInt(std::numeric_limits<Py_ssize_t>::max())) }));
tuple_cls->giveAttr("count", new BoxedFunction(BoxedCode::create((void*)tupleCount, BOXED_INT, 2, "tuple.count")));
tuple_cls->giveAttr("__iter__",
new BoxedFunction(BoxedCode::create((void*)tupleIter, typeFromClass(tuple_iterator_cls), 1)));
tuple_cls->giveAttr("__iter__", new BoxedFunction(BoxedCode::create(
(void*)tupleIter, typeFromClass(tuple_iterator_cls), 1, "tuple.__iter__")));
tuple_cls->tp_richcompare = tuplerichcompare;
tuple_cls->giveAttr("__nonzero__", new BoxedFunction(BoxedCode::create((void*)tupleNonzero, BOXED_BOOL, 1)));
tuple_cls->giveAttr("__nonzero__",
new BoxedFunction(BoxedCode::create((void*)tupleNonzero, BOXED_BOOL, 1, "tuple.__nonzero__")));
tuple_cls->giveAttr("__len__", new BoxedFunction(BoxedCode::create((void*)tupleLen, BOXED_INT, 1)));
tuple_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)tupleRepr, STR, 1)));
tuple_cls->giveAttr("__len__",
new BoxedFunction(BoxedCode::create((void*)tupleLen, BOXED_INT, 1, "tuple.__len__")));
tuple_cls->giveAttr("__repr__", new BoxedFunction(BoxedCode::create((void*)tupleRepr, STR, 1, "tuple.__repr__")));
// Return type is UNKNOWN as it could be NotImplemented.
tuple_cls->giveAttr("__add__", new BoxedFunction(BoxedCode::create((void*)tupleAdd, UNKNOWN, 2)));
tuple_cls->giveAttr("__mul__", new BoxedFunction(BoxedCode::create((void*)tupleMul, UNKNOWN, 2)));
tuple_cls->giveAttr("__rmul__", new BoxedFunction(BoxedCode::create((void*)tupleMul, UNKNOWN, 2)));
tuple_cls->giveAttr("__add__", new BoxedFunction(BoxedCode::create((void*)tupleAdd, UNKNOWN, 2, "tuple.__add__")));
tuple_cls->giveAttr("__mul__", new BoxedFunction(BoxedCode::create((void*)tupleMul, UNKNOWN, 2, "tuple.__mul__")));
tuple_cls->giveAttr("__rmul__",
new BoxedFunction(BoxedCode::create((void*)tupleMul, UNKNOWN, 2, "tuple.__rmul__")));
tuple_cls->giveAttr("__getnewargs__", new BoxedFunction(BoxedCode::create((void*)tuple_getnewargs, UNKNOWN, 1,
ParamNames::empty(), CAPI)));
tuple_cls->giveAttr("__getnewargs__",
new BoxedFunction(BoxedCode::create((void*)tuple_getnewargs, UNKNOWN, 1, "tuple.__getnewargs__",
"", ParamNames::empty(), CAPI)));
tuple_cls->tp_hash = (hashfunc)tuple_hash;
tuple_cls->tp_as_sequence->sq_slice = (ssizessizeargfunc)&tupleslice;
......@@ -823,12 +830,14 @@ void setupTuple() {
tuple_cls->tp_as_mapping->mp_length = (lenfunc)tuplelength;
tuple_cls->tp_as_mapping->mp_subscript = (binaryfunc)tupleGetitem<CAPI>;
BoxedCode* hasnext = BoxedCode::create((void*)tupleiterHasnextUnboxed, BOOL, 1);
BoxedCode* hasnext = BoxedCode::create((void*)tupleiterHasnextUnboxed, BOOL, 1, "tuple.__hasnext__");
hasnext->addVersion((void*)tupleiterHasnext, BOXED_BOOL);
tuple_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext));
tuple_iterator_cls->giveAttr(
"__iter__", new BoxedFunction(BoxedCode::create((void*)tupleIterIter, typeFromClass(tuple_iterator_cls), 1)));
tuple_iterator_cls->giveAttr("next", new BoxedFunction(BoxedCode::create((void*)tupleiterNext, UNKNOWN, 1)));
"__iter__", new BoxedFunction(BoxedCode::create((void*)tupleIterIter, typeFromClass(tuple_iterator_cls), 1,
"tuple_iterator.__iter__")));
tuple_iterator_cls->giveAttr(
"next", new BoxedFunction(BoxedCode::create((void*)tupleiterNext, UNKNOWN, 1, "tuple_iterator.next")));
tuple_iterator_cls->freeze();
tuple_iterator_cls->tpp_hasnext = tupleiterHasnextUnboxed;
......
This diff is collapsed.
......@@ -1111,10 +1111,14 @@ public:
Box**, const std::vector<BoxedString*>*> InternalCallable;
InternalCallable internal_callable;
// Constructor for Python code objects:
BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, int firstlineno, std::unique_ptr<SourceInfo> source,
ParamNames param_names, BoxedString* filename, BoxedString* name, Box* doc);
BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, const ParamNames& param_names = ParamNames::empty());
~BoxedCode();
// Constructor for code objects created by the runtime:
BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, const char* name, const char* doc = "",
const ParamNames& param_names = ParamNames::empty());
// The dummy constructor for PyCode_New:
BoxedCode(BoxedString* filename, BoxedString* name, int firstline);
......@@ -1141,21 +1145,22 @@ public:
// Helper function, meant for the C++ runtime, which allocates a BoxedCode object and calls addVersion
// once to it.
static BoxedCode* create(void* f, ConcreteCompilerType* rtn_type, int nargs, bool takes_varargs, bool takes_kwargs,
const char* name, const char* doc = "",
const ParamNames& param_names = ParamNames::empty(),
ExceptionStyle exception_style = CXX) {
assert(!param_names.takes_param_names || nargs == param_names.numNormalArgs());
assert(takes_varargs || !param_names.has_vararg_name);
assert(takes_kwargs || !param_names.has_kwarg_name);
BoxedCode* code = new BoxedCode(nargs, takes_varargs, takes_kwargs, param_names);
BoxedCode* code = new BoxedCode(nargs, takes_varargs, takes_kwargs, name, doc, param_names);
code->addVersion(f, rtn_type, exception_style);
return code;
}
static BoxedCode* create(void* f, ConcreteCompilerType* rtn_type, int nargs,
static BoxedCode* create(void* f, ConcreteCompilerType* rtn_type, int nargs, const char* name, const char* doc = "",
const ParamNames& param_names = ParamNames::empty(),
ExceptionStyle exception_style = CXX) {
return create(f, rtn_type, nargs, false, false, param_names, exception_style);
return create(f, rtn_type, nargs, false, false, name, doc, param_names, exception_style);
}
// tries to free the bjit allocated code. returns true on success
......@@ -1220,9 +1225,9 @@ public:
class BoxedBuiltinFunctionOrMethod : public BoxedFunctionBase {
public:
BoxedBuiltinFunctionOrMethod(STOLEN(BoxedCode*) code, const char* name, const char* doc = NULL);
BoxedBuiltinFunctionOrMethod(STOLEN(BoxedCode*) code, const char* name, std::initializer_list<Box*> defaults,
BoxedClosure* closure = NULL, const char* doc = NULL);
BoxedBuiltinFunctionOrMethod(STOLEN(BoxedCode*) code);
BoxedBuiltinFunctionOrMethod(STOLEN(BoxedCode*) code, std::initializer_list<Box*> defaults,
BoxedClosure* closure = NULL);
DEFAULT_CLASS_SIMPLE(builtin_function_or_method_cls, true);
};
......
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