Commit fabde965 authored by Kevin Modzelewski's avatar Kevin Modzelewski

got some more running

parent 2c20ac1d
......@@ -2654,6 +2654,7 @@ static int add_members(PyTypeObject* type, PyMemberDef* memb) noexcept {
return -1;
type->setattr(name, descr, NULL);
Py_DECREF(descr);
Py_DECREF(name);
}
return 0;
}
......@@ -2670,6 +2671,7 @@ static int add_getset(PyTypeObject* type, PyGetSetDef* gsp) noexcept {
return -1;
type->setattr(name, descr, NULL);
Py_DECREF(descr);
Py_DECREF(name);
}
return 0;
}
......
......@@ -1838,7 +1838,7 @@ With two arguments, equivalent to x**y. With three arguments,\n\
equivalent to (x**y) % z, but may be more efficient (e.g. for longs).");
void setupBuiltins() {
builtins_module = createModule(boxString("__builtin__"), NULL,
builtins_module = createModule(autoDecref(boxString("__builtin__")), NULL,
"Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is "
"the `nil' object; Ellipsis represents `...' in slices.");
......@@ -1847,10 +1847,11 @@ void setupBuiltins() {
Ellipsis = new (ellipsis_cls) Box();
assert(Ellipsis->cls);
builtins_module->giveAttr("Ellipsis", Ellipsis);
builtins_module->giveAttr("None", None);
constants.push_back(Ellipsis);
builtins_module->giveAttrBorrowed("Ellipsis", Ellipsis);
builtins_module->giveAttrBorrowed("None", None);
builtins_module->giveAttr("__debug__", False);
builtins_module->giveAttrBorrowed("__debug__", False);
builtins_module->giveAttr(
"print", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)print, NONE, 0, true, true), "print",
......@@ -1862,7 +1863,8 @@ void setupBuiltins() {
notimplemented_cls->freeze();
NotImplemented = new (notimplemented_cls) Box();
builtins_module->giveAttr("NotImplemented", NotImplemented);
constants.push_back(NotImplemented);
builtins_module->giveAttrBorrowed("NotImplemented", NotImplemented);
builtins_module->giveAttr(
"all", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)all, BOXED_BOOL, 1), "all", all_doc));
......@@ -1907,7 +1909,7 @@ void setupBuiltins() {
builtins_module->giveAttr(
"sum", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)sum, UNKNOWN, 2, false, false), "sum",
{ boxInt(0) }, NULL, sum_doc));
{ autoDecref(boxInt(0)) }, NULL, sum_doc));
id_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)id, BOXED_INT, 1), "id", id_doc);
builtins_module->giveAttr("id", id_obj);
......@@ -1920,7 +1922,7 @@ void setupBuiltins() {
trap_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)trap, UNKNOWN, 0), "trap");
builtins_module->giveAttr("trap", trap_obj);
builtins_module->giveAttr("dump", new BoxedBuiltinFunctionOrMethod(
FunctionMetadata::create((void*)pydump, UNKNOWN, 2), "dump", { boxInt(0) }));
FunctionMetadata::create((void*)pydump, UNKNOWN, 2), "dump", { autoDecref(boxInt(0)) }));
builtins_module->giveAttr("dumpAddr", new BoxedBuiltinFunctionOrMethod(
FunctionMetadata::create((void*)pydumpAddr, UNKNOWN, 1), "dumpAddr"));
......@@ -1962,15 +1964,15 @@ void setupBuiltins() {
FunctionMetadata* import_func
= FunctionMetadata::create((void*)bltinImport, UNKNOWN, 5, false, false,
ParamNames({ "name", "globals", "locals", "fromlist", "level" }, "", ""));
builtins_module->giveAttr("__import__", new BoxedBuiltinFunctionOrMethod(import_func, "__import__",
{ None, None, None, new BoxedInt(-1) },
NULL, import_doc));
builtins_module->giveAttr(
"__import__", new BoxedBuiltinFunctionOrMethod(import_func, "__import__",
{ None, None, None, autoDecref(boxInt(-1)) }, NULL, import_doc));
enumerate_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedEnumerate),
false, "enumerate");
enumerate_cls->giveAttr(
"__new__", new BoxedFunction(FunctionMetadata::create((void*)BoxedEnumerate::new_, UNKNOWN, 3, false, false),
{ boxInt(0) }));
{ autoDecref(boxInt(0)) }));
enumerate_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create((void*)BoxedEnumerate::iter,
typeFromClass(enumerate_cls), 1)));
enumerate_cls->giveAttr("next",
......@@ -1979,7 +1981,7 @@ void setupBuiltins() {
new BoxedFunction(FunctionMetadata::create((void*)BoxedEnumerate::hasnext, BOXED_BOOL, 1)));
enumerate_cls->freeze();
enumerate_cls->tp_iter = PyObject_SelfIter;
builtins_module->giveAttr("enumerate", enumerate_cls);
builtins_module->giveAttrBorrowed("enumerate", enumerate_cls);
FunctionMetadata* sorted_func
......@@ -1988,8 +1990,8 @@ void setupBuiltins() {
builtins_module->giveAttr(
"sorted", new BoxedBuiltinFunctionOrMethod(sorted_func, "sorted", { None, None, False }, NULL, sorted_doc));
builtins_module->giveAttr("True", True);
builtins_module->giveAttr("False", False);
builtins_module->giveAttrBorrowed("True", True);
builtins_module->giveAttrBorrowed("False", False);
range_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)range, LIST, 3, false, false), "range",
{ NULL, NULL }, NULL, range_doc);
......@@ -1997,16 +1999,16 @@ void setupBuiltins() {
auto* round_obj
= new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)builtinRound, BOXED_FLOAT, 2, false, false),
"round", { boxInt(0) }, NULL, round_doc);
"round", { autoDecref(boxInt(0)) }, NULL, round_doc);
builtins_module->giveAttr("round", round_obj);
setupXrange();
builtins_module->giveAttr("xrange", xrange_cls);
builtins_module->giveAttrBorrowed("xrange", xrange_cls);
open_obj = new BoxedBuiltinFunctionOrMethod(
FunctionMetadata::create((void*)open, typeFromClass(file_cls), 3, false, false,
ParamNames({ "name", "mode", "buffering" }, "", "")),
"open", { boxString("r"), boxInt(-1) }, NULL, open_doc);
"open", { autoDecref(boxString("r")), autoDecref(boxInt(-1)) }, NULL, open_doc);
builtins_module->giveAttr("open", open_obj);
builtins_module->giveAttr(
......@@ -2035,8 +2037,9 @@ void setupBuiltins() {
FunctionMetadata* compile_func = new FunctionMetadata(
5, false, false, ParamNames({ "source", "filename", "mode", "flags", "dont_inherit" }, "", ""));
compile_func->addVersion((void*)compile, UNKNOWN, { UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN });
builtins_module->giveAttr("compile", new BoxedBuiltinFunctionOrMethod(compile_func, "compile",
{ boxInt(0), boxInt(0) }, NULL, compile_doc));
builtins_module->giveAttr(
"compile", new BoxedBuiltinFunctionOrMethod(
compile_func, "compile", { autoDecref(boxInt(0)), autoDecref(boxInt(0)) }, NULL, compile_doc));
builtins_module->giveAttr("map", new BoxedBuiltinFunctionOrMethod(
FunctionMetadata::create((void*)map, LIST, 1, true, false), "map", map_doc));
......@@ -2054,40 +2057,40 @@ void setupBuiltins() {
builtins_module->giveAttr(
"vars", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)vars, UNKNOWN, 1, false, false),
"vars", { NULL }, NULL, vars_doc));
builtins_module->giveAttr("object", object_cls);
builtins_module->giveAttr("str", str_cls);
builtins_module->giveAttr("bytes", str_cls);
builtins_module->giveAttrBorrowed("object", object_cls);
builtins_module->giveAttrBorrowed("str", str_cls);
builtins_module->giveAttrBorrowed("bytes", str_cls);
assert(unicode_cls);
builtins_module->giveAttr("unicode", unicode_cls);
builtins_module->giveAttr("basestring", basestring_cls);
builtins_module->giveAttrBorrowed("unicode", unicode_cls);
builtins_module->giveAttrBorrowed("basestring", basestring_cls);
// builtins_module->giveAttr("unicode", unicode_cls);
builtins_module->giveAttr("int", int_cls);
builtins_module->giveAttr("long", long_cls);
builtins_module->giveAttr("float", float_cls);
builtins_module->giveAttr("list", list_cls);
builtins_module->giveAttr("slice", slice_cls);
builtins_module->giveAttr("type", type_cls);
builtins_module->giveAttr("file", file_cls);
builtins_module->giveAttr("bool", bool_cls);
builtins_module->giveAttr("dict", dict_cls);
builtins_module->giveAttr("set", set_cls);
builtins_module->giveAttr("frozenset", frozenset_cls);
builtins_module->giveAttr("tuple", tuple_cls);
builtins_module->giveAttr("complex", complex_cls);
builtins_module->giveAttr("super", super_cls);
builtins_module->giveAttr("property", property_cls);
builtins_module->giveAttr("staticmethod", staticmethod_cls);
builtins_module->giveAttr("classmethod", classmethod_cls);
builtins_module->giveAttrBorrowed("int", int_cls);
builtins_module->giveAttrBorrowed("long", long_cls);
builtins_module->giveAttrBorrowed("float", float_cls);
builtins_module->giveAttrBorrowed("list", list_cls);
builtins_module->giveAttrBorrowed("slice", slice_cls);
builtins_module->giveAttrBorrowed("type", type_cls);
builtins_module->giveAttrBorrowed("file", file_cls);
builtins_module->giveAttrBorrowed("bool", bool_cls);
builtins_module->giveAttrBorrowed("dict", dict_cls);
builtins_module->giveAttrBorrowed("set", set_cls);
builtins_module->giveAttrBorrowed("frozenset", frozenset_cls);
builtins_module->giveAttrBorrowed("tuple", tuple_cls);
builtins_module->giveAttrBorrowed("complex", complex_cls);
builtins_module->giveAttrBorrowed("super", super_cls);
builtins_module->giveAttrBorrowed("property", property_cls);
builtins_module->giveAttrBorrowed("staticmethod", staticmethod_cls);
builtins_module->giveAttrBorrowed("classmethod", classmethod_cls);
assert(memoryview_cls);
Py_TYPE(&PyMemoryView_Type) = &PyType_Type;
PyType_Ready(&PyMemoryView_Type);
builtins_module->giveAttr("memoryview", memoryview_cls);
builtins_module->giveAttrBorrowed("memoryview", memoryview_cls);
PyType_Ready(&PyByteArray_Type);
builtins_module->giveAttr("bytearray", &PyByteArray_Type);
builtins_module->giveAttrBorrowed("bytearray", &PyByteArray_Type);
Py_TYPE(&PyBuffer_Type) = &PyType_Type;
PyType_Ready(&PyBuffer_Type);
builtins_module->giveAttr("buffer", &PyBuffer_Type);
builtins_module->giveAttrBorrowed("buffer", &PyBuffer_Type);
builtins_module->giveAttr(
"eval", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)eval, UNKNOWN, 3, false, false),
......
......@@ -113,7 +113,7 @@ extern "C" int PyCode_GetArgCount(PyCodeObject* op) noexcept {
void setupCode() {
code_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedCode), false, "code");
code_cls->giveAttr("__new__", None); // Hacky way of preventing users from instantiating this
code_cls->giveAttrBorrowed("__new__", None); // Hacky way of preventing users from instantiating this
code_cls->giveAttr("co_name", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::name, NULL, NULL));
code_cls->giveAttr("co_filename", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::filename, NULL, NULL));
......
......@@ -272,7 +272,7 @@ void setupXrange() {
xrange_iterator_cls->giveAttr("next", new BoxedFunction(next));
// TODO this is pretty hacky, but stuff the iterator cls into xrange to make sure it gets decref'd at the end
xrange_cls->giveAttr("__iterator_cls__", xrange_iterator_cls);
xrange_cls->giveAttrBorrowed("__iterator_cls__", xrange_iterator_cls);
xrange_cls->freeze();
xrange_cls->tp_iter = xrangeIter;
......
......@@ -373,7 +373,7 @@ BoxedBuiltinFunctionOrMethod::BoxedBuiltinFunctionOrMethod(FunctionMetadata* md,
: BoxedBuiltinFunctionOrMethod(md, name, {}) {
Py_DECREF(this->doc);
this->doc = doc ? boxString(doc) : None;
this->doc = doc ? boxString(doc) : incref(None);
}
BoxedBuiltinFunctionOrMethod::BoxedBuiltinFunctionOrMethod(FunctionMetadata* md, const char* name,
......@@ -3781,40 +3781,19 @@ void setupRuntime() {
setupClassobj();
setupSuper();
_PyUnicode_Init();
// XXX
PyType_ClearCache();
_Py_ReleaseInternedStrings();
_PyUnicode_Fini();
for (auto b : classes)
b->clearAttrs();
for (auto b : constants) {
b->clearAttrs();
Py_DECREF(b);
}
for (auto b : classes) {
if (b->tp_mro) {
Py_DECREF(b->tp_mro);
}
Py_DECREF(b);
}
PRINT_TOTAL_REFS();
exit(0);
// XXX
setupDescr();
setupTraceback();
setupCode();
setupFrame();
function_cls->giveAttr("__dict__", dict_descr);
function_cls->giveAttrBorrowed("__dict__", dict_descr);
function_cls->giveAttr("__name__", new (pyston_getset_cls) BoxedGetsetDescriptor(funcName, funcSetName, NULL));
function_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)functionRepr, STR, 1)));
function_cls->giveAttr("__module__", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT,
offsetof(BoxedFunction, modname), false));
function_cls->giveAttr(
"__doc__", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedFunction, doc), false));
function_cls->giveAttr("func_doc", function_cls->getattr(internStringMortal("__doc__")));
function_cls->giveAttrBorrowed("func_doc", function_cls->getattr(getStaticString("__doc__")));
function_cls->giveAttr("__globals__", new (pyston_getset_cls) BoxedGetsetDescriptor(functionGlobals, NULL, NULL));
function_cls->giveAttr("__get__", new BoxedFunction(FunctionMetadata::create((void*)functionGet, UNKNOWN, 3)));
function_cls->giveAttr("__call__",
......@@ -3823,12 +3802,12 @@ void setupRuntime() {
new BoxedFunction(FunctionMetadata::create((void*)functionNonzero, BOXED_BOOL, 1)));
function_cls->giveAttr("func_code",
new (pyston_getset_cls) BoxedGetsetDescriptor(functionCode, functionSetCode, NULL));
function_cls->giveAttr("__code__", function_cls->getattr(internStringMortal("func_code")));
function_cls->giveAttr("func_name", function_cls->getattr(internStringMortal("__name__")));
function_cls->giveAttrBorrowed("__code__", function_cls->getattr(getStaticString("func_code")));
function_cls->giveAttrBorrowed("func_name", function_cls->getattr(getStaticString("__name__")));
function_cls->giveAttr("func_defaults",
new (pyston_getset_cls) BoxedGetsetDescriptor(functionDefaults, functionSetDefaults, NULL));
function_cls->giveAttr("__defaults__", function_cls->getattr(internStringMortal("func_defaults")));
function_cls->giveAttr("func_globals", function_cls->getattr(internStringMortal("__globals__")));
function_cls->giveAttrBorrowed("__defaults__", function_cls->getattr(getStaticString("func_defaults")));
function_cls->giveAttrBorrowed("func_globals", function_cls->getattr(getStaticString("__globals__")));
function_cls->freeze();
function_cls->tp_descr_get = function_descr_get;
......@@ -3861,10 +3840,10 @@ void setupRuntime() {
"__call__", new BoxedFunction(FunctionMetadata::create((void*)instancemethodCall, UNKNOWN, 1, true, true)));
instancemethod_cls->giveAttr(
"im_func", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedInstanceMethod, func)));
instancemethod_cls->giveAttr("__func__", instancemethod_cls->getattr(internStringMortal("im_func")));
instancemethod_cls->giveAttrBorrowed("__func__", instancemethod_cls->getattr(getStaticString("im_func")));
instancemethod_cls->giveAttr(
"im_self", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedInstanceMethod, obj)));
instancemethod_cls->giveAttr("__self__", instancemethod_cls->getattr(internStringMortal("im_self")));
instancemethod_cls->giveAttrBorrowed("__self__", instancemethod_cls->getattr(getStaticString("im_self")));
instancemethod_cls->freeze();
instancemethod_cls->giveAttr("im_class", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT,
......@@ -3943,12 +3922,32 @@ void setupRuntime() {
attrwrapperiter_cls->tp_iternext = AttrWrapperIter::next_capi;
setupBuiltins();
_PyExc_Init();
setupThread();
initgc();
setupImport();
setupPyston();
setupAST();
//_PyExc_Init();
//setupThread();
//initgc();
//setupImport();
//setupPyston();
//setupAST();
// XXX
PyType_ClearCache();
_Py_ReleaseInternedStrings();
_PyUnicode_Fini();
for (auto b : classes)
b->clearAttrs();
for (auto b : constants) {
b->clearAttrs();
Py_DECREF(b);
}
for (auto b : classes) {
if (b->tp_mro) {
Py_DECREF(b->tp_mro);
}
Py_DECREF(b);
}
PRINT_TOTAL_REFS();
exit(0);
// XXX
PyType_Ready(&PyByteArrayIter_Type);
PyType_Ready(&PyCapsule_Type);
......
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