Commit 02ff68f2 authored by Kevin Modzelewski's avatar Kevin Modzelewski

I guess setattr has been completely moved to the Rewriter2

parent d4d92177
......@@ -802,6 +802,7 @@ $(call make_search,oprofcg_%)
opreportcg:
opreport lib-image:pyston_oprof -l -t 0.2 -a --callgraph
.PHONY: watch_% watch wdbg_%
watch_%:
@ ( ulimit -t 60; ulimit -d $(MAK_MEM_KB); ulimit -v $(MAK_MEM_KB); \
TARGET=$(dir $@)$(patsubst watch_%,%,$(notdir $@)); \
......@@ -810,6 +811,7 @@ watch_%:
Makefile $$(find .. \( -name '*.cpp' -o -name '*.h' -o -name '*.py' \) ); do clear; $(MAKE) $$TARGET; done )
# Makefile $$(find \( -name '*.cpp' -o -name '*.h' -o -name '*.py' \) -o -type d ); do clear; $(MAKE) $(patsubst watch_%,%,$@); done )
# -r . ; do clear; $(MAKE) $(patsubst watch_%,%,$@); done
watch: watch_pyston_dbg
wdbg_%:
$(MAKE) $(patsubst wdbg_%,watch_dbg_%,$@) GDB_CMDS="--ex quit"
......
......@@ -302,7 +302,6 @@ private:
};
class SetattrRewriteArgs;
class SetattrRewriteArgs2;
class GetattrRewriteArgs;
class GetattrRewriteArgs2;
......@@ -329,11 +328,10 @@ public:
HCAttrs* getAttrs();
void setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite_args,
SetattrRewriteArgs2* rewrite_args2);
void setattr(const std::string& attr, Box* val, SetattrRewriteArgs2* rewrite_args2);
void giveAttr(const std::string& attr, Box* val) {
assert(this->getattr(attr) == NULL);
this->setattr(attr, val, NULL, NULL);
this->setattr(attr, val, NULL);
}
Box* getattr(const std::string& attr, GetattrRewriteArgs* rewrite_args, GetattrRewriteArgs2* rewrite_args2);
......
......@@ -65,7 +65,7 @@ void setupBool() {
bool_cls->giveAttr("__neg__", new BoxedFunction(boxRTFunction((void*)boolNeg, NULL, 1, false)));
bool_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)boolNonzero, NULL, 1, false)));
bool_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)boolRepr, NULL, 1, false)));
bool_cls->setattr("__str__", bool_cls->getattr("__repr__"), NULL, NULL);
bool_cls->giveAttr("__str__", bool_cls->getattr("__repr__"));
CLFunction* __new__ = boxRTFunction((void*)boolNew1, NULL, 1, false);
addRTFunction(__new__, (void*)boolNew2, NULL, 2, false);
......
......@@ -386,7 +386,7 @@ static BoxedClass* makeBuiltinException(const char* name) {
void setupBuiltins() {
builtins_module = createModule("__builtin__", "__builtin__");
builtins_module->setattr("None", None, NULL, NULL);
builtins_module->giveAttr("None", None);
notimplemented_cls = new BoxedClass(0, sizeof(Box), false);
notimplemented_cls->giveAttr("__name__", boxStrConstant("NotImplementedType"));
......@@ -456,8 +456,8 @@ void setupBuiltins() {
builtins_module->giveAttr("sorted", new BoxedFunction(boxRTFunction((void*)sorted, NULL, 1, false)));
builtins_module->setattr("True", True, NULL, NULL);
builtins_module->setattr("False", False, NULL, NULL);
builtins_module->giveAttr("True", True);
builtins_module->giveAttr("False", False);
CLFunction* range_clf = boxRTFunction((void*)range1, NULL, 1, false);
addRTFunction(range_clf, (void*)range2, NULL, 2, false);
......@@ -476,17 +476,17 @@ void setupBuiltins() {
builtins_module->giveAttr("map", new BoxedFunction(boxRTFunction((void*)map2, LIST, 2, false)));
builtins_module->giveAttr("zip", new BoxedFunction(boxRTFunction((void*)zip2, LIST, 2, false)));
builtins_module->setattr("str", str_cls, NULL, NULL);
builtins_module->setattr("int", int_cls, NULL, NULL);
builtins_module->setattr("float", float_cls, NULL, NULL);
builtins_module->setattr("list", list_cls, NULL, NULL);
builtins_module->setattr("slice", slice_cls, NULL, NULL);
builtins_module->setattr("type", type_cls, NULL, NULL);
builtins_module->setattr("file", file_cls, NULL, NULL);
builtins_module->setattr("bool", bool_cls, NULL, NULL);
builtins_module->setattr("dict", dict_cls, NULL, NULL);
builtins_module->setattr("set", set_cls, NULL, NULL);
builtins_module->setattr("tuple", tuple_cls, NULL, NULL);
builtins_module->setattr("instancemethod", instancemethod_cls, NULL, NULL);
builtins_module->giveAttr("str", str_cls);
builtins_module->giveAttr("int", int_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("tuple", tuple_cls);
builtins_module->giveAttr("instancemethod", instancemethod_cls);
}
}
......@@ -125,7 +125,7 @@ void setupCAPI() {
capifunc_cls->giveAttr("__repr__",
new BoxedFunction(boxRTFunction((void*)BoxedCApiFunction::__repr__, NULL, 1, false)));
capifunc_cls->setattr("__str__", capifunc_cls->getattr("__repr__"), NULL, NULL);
capifunc_cls->giveAttr("__str__", capifunc_cls->getattr("__repr__"));
capifunc_cls->giveAttr("__call__",
new BoxedFunction(boxRTFunction((void*)BoxedCApiFunction::__call__, NULL, 1, true)));
......
......@@ -152,16 +152,16 @@ void setupDict() {
// dict_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)dictNew, NULL, 1, false)));
// dict_cls->giveAttr("__init__", new BoxedFunction(boxRTFunction((void*)dictInit, NULL, 1, false)));
dict_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)dictRepr, NULL, 1, false)));
dict_cls->setattr("__str__", dict_cls->getattr("__repr__"), NULL, NULL);
dict_cls->giveAttr("__str__", dict_cls->getattr("__repr__"));
dict_cls->giveAttr("items", new BoxedFunction(boxRTFunction((void*)dictItems, NULL, 1, false)));
dict_cls->setattr("iteritems", dict_cls->getattr("items"), NULL, NULL);
dict_cls->giveAttr("iteritems", dict_cls->getattr("items"));
dict_cls->giveAttr("values", new BoxedFunction(boxRTFunction((void*)dictValues, NULL, 1, false)));
dict_cls->setattr("itervalues", dict_cls->getattr("values"), NULL, NULL);
dict_cls->giveAttr("itervalues", dict_cls->getattr("values"));
dict_cls->giveAttr("keys", new BoxedFunction(boxRTFunction((void*)dictKeys, NULL, 1, false)));
dict_cls->setattr("iterkeys", dict_cls->getattr("keys"), NULL, NULL);
dict_cls->giveAttr("iterkeys", dict_cls->getattr("keys"));
CLFunction* pop = boxRTFunction((void*)dictPop2, UNKNOWN, 2, false);
addRTFunction(pop, (void*)dictPop3, UNKNOWN, 3, false);
......
......@@ -182,7 +182,7 @@ void setupFile() {
file_cls->giveAttr("close", new BoxedFunction(boxRTFunction((void*)fileClose, NULL, 1, false)));
file_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)fileRepr, NULL, 1, false)));
file_cls->setattr("__str__", file_cls->getattr("__repr__"), NULL, NULL);
file_cls->giveAttr("__str__", file_cls->getattr("__repr__"));
file_cls->giveAttr("__enter__", new BoxedFunction(boxRTFunction((void*)fileEnter, NULL, 1, false)));
file_cls->giveAttr("__exit__", new BoxedFunction(boxRTFunction((void*)fileExit, NULL, 4, false)));
......
......@@ -565,7 +565,7 @@ void setupFloat() {
float_cls->giveAttr("__name__", boxStrConstant("float"));
_addFunc("__add__", BOXED_FLOAT, (void*)floatAddFloat, (void*)floatAddInt, (void*)floatAdd);
float_cls->setattr("__radd__", float_cls->getattr("__add__"), NULL, NULL);
float_cls->giveAttr("__radd__", float_cls->getattr("__add__"));
_addFunc("__div__", BOXED_FLOAT, (void*)floatDivFloat, (void*)floatDivInt, (void*)floatDiv);
_addFunc("__rdiv__", BOXED_FLOAT, (void*)floatRDivFloat, (void*)floatRDivInt, (void*)floatRDiv);
......@@ -581,7 +581,7 @@ void setupFloat() {
_addFunc("__mod__", BOXED_FLOAT, (void*)floatModFloat, (void*)floatModInt, (void*)floatMod);
_addFunc("__rmod__", BOXED_FLOAT, (void*)floatRModFloat, (void*)floatRModInt, (void*)floatRMod);
_addFunc("__mul__", BOXED_FLOAT, (void*)floatMulFloat, (void*)floatMulInt, (void*)floatMul);
float_cls->setattr("__rmul__", float_cls->getattr("__mul__"), NULL, NULL);
float_cls->giveAttr("__rmul__", float_cls->getattr("__mul__"));
_addFunc("__pow__", BOXED_FLOAT, (void*)floatPowFloat, (void*)floatPowInt, (void*)floatPow);
_addFunc("__sub__", BOXED_FLOAT, (void*)floatSubFloat, (void*)floatSubInt, (void*)floatSub);
......
......@@ -533,7 +533,7 @@ void setupInt() {
int_cls->giveAttr("__neg__", new BoxedFunction(boxRTFunction((void*)intNeg, BOXED_INT, 1, false)));
int_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)intNonzero, BOXED_BOOL, 1, false)));
int_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)intRepr, STR, 1, false)));
int_cls->setattr("__str__", int_cls->getattr("__repr__"), NULL, NULL);
int_cls->giveAttr("__str__", int_cls->getattr("__repr__"));
int_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)intHash, BOXED_INT, 1, false)));
int_cls->giveAttr("__divmod__", new BoxedFunction(boxRTFunction((void*)intDivmod, BOXED_TUPLE, 2, false)));
......
......@@ -449,7 +449,7 @@ void setupList() {
new BoxedFunction(boxRTFunction((void*)listIter, typeFromClass(list_iterator_cls), 1, false)));
list_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)listRepr, STR, 1, false)));
list_cls->setattr("__str__", list_cls->getattr("__repr__"), NULL, NULL);
list_cls->giveAttr("__str__", list_cls->getattr("__repr__"));
list_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)listNonzero, BOXED_BOOL, 1, false)));
CLFunction* pop = boxRTFunction((void*)listPop1, NULL, 1, false);
......
......@@ -81,15 +81,6 @@ struct GetattrRewriteArgs2 {
out_success(false), out_rtn(RewriterVarUsage2::empty()), obj_hcls_guarded(false) {}
};
struct SetattrRewriteArgs {
Rewriter* rewriter;
RewriterVar obj, attrval;
bool out_success;
SetattrRewriteArgs(Rewriter* rewriter, const RewriterVar& obj, const RewriterVar& attrval)
: rewriter(rewriter), obj(obj), attrval(attrval), out_success(false) {}
};
struct SetattrRewriteArgs2 {
Rewriter2* rewriter;
RewriterVarUsage2 obj, attrval;
......@@ -275,9 +266,10 @@ extern "C" void checkUnpackingLength(i64 expected, i64 given) {
BoxedClass::BoxedClass(int attrs_offset, int instance_size, bool is_user_defined)
: Box(&type_flavor, type_cls), attrs_offset(attrs_offset), instance_size(instance_size), is_constant(false),
is_user_defined(is_user_defined) {
assert(instance_size % sizeof(void*) == 0); // Not critical I suppose, but probably signals a bug
if (attrs_offset) {
assert(instance_size >= attrs_offset + sizeof(HCAttrs));
assert(attrs_offset % sizeof(void*) == 0);
assert(attrs_offset % sizeof(void*) == 0); // Not critical I suppose, but probably signals a bug
}
}
......@@ -404,8 +396,7 @@ Box* Box::getattr(const std::string& attr, GetattrRewriteArgs* rewrite_args, Get
return rtn;
}
void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite_args,
SetattrRewriteArgs2* rewrite_args2) {
void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs2* rewrite_args2) {
assert(cls->instancesHaveAttrs());
// Have to guard on the memory layout of this object.
......@@ -417,8 +408,6 @@ void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite
// Only matters if we end up getting multiple classes with the same
// structure (ex user class) and the same hidden classes, because
// otherwise the guard will fail anyway.;
if (rewrite_args)
rewrite_args->obj.addAttrGuard(BOX_CLS_OFFSET, (intptr_t)cls);
if (rewrite_args2)
rewrite_args2->obj.addAttrGuard(BOX_CLS_OFFSET, (intptr_t)cls);
......@@ -431,7 +420,6 @@ void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite
if ((this->cls == type_cls) && (attr == getattr_str || attr == getattribute_str)) {
// Will have to embed the clear in the IC, so just disable the patching for now:
rewrite_args = NULL;
rewrite_args2 = NULL;
// TODO should put this clearing behavior somewhere else, since there are probably more
......@@ -446,11 +434,6 @@ void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite
int offset = hcls->getOffset(attr);
if (rewrite_args) {
rewrite_args->obj.addAttrGuard(cls->attrs_offset + HCATTRS_HCLS_OFFSET, (intptr_t)hcls);
rewrite_args->rewriter->addDecision(offset == -1 ? 1 : 0);
}
if (rewrite_args2) {
rewrite_args2->obj.addAttrGuard(cls->attrs_offset + HCATTRS_HCLS_OFFSET, (intptr_t)hcls);
......@@ -464,13 +447,6 @@ void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite
Box* prev = attrs->attr_list->attrs[offset];
attrs->attr_list->attrs[offset] = val;
if (rewrite_args) {
RewriterVar r_hattrs = rewrite_args->obj.getAttr(cls->attrs_offset + HCATTRS_ATTRS_OFFSET, 1);
r_hattrs.setAttr(offset * sizeof(Box*) + ATTRLIST_ATTRS_OFFSET, rewrite_args->attrval);
rewrite_args->out_success = true;
}
if (rewrite_args2) {
RewriterVarUsage2 r_hattrs = rewrite_args2->obj.getAttr(cls->attrs_offset + HCATTRS_ATTRS_OFFSET,
......@@ -496,11 +472,6 @@ void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite
}
#endif
if (rewrite_args) {
rewrite_args->obj.push();
rewrite_args->attrval.push();
}
RewriterVar r_new_array;
......@@ -509,12 +480,6 @@ void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite
if (numattrs == 0) {
attrs->attr_list = (HCAttrs::AttrList*)rt_alloc(new_size);
attrs->attr_list->gc_header.kind_id = untracked_kind.kind_id;
if (rewrite_args) {
rewrite_args->rewriter->loadConst(0, new_size);
r_new_array = rewrite_args->rewriter->call((void*)rt_alloc);
RewriterVar r_flavor = rewrite_args->rewriter->loadConst(0, (intptr_t)untracked_kind.kind_id);
r_new_array.setAttr(ATTRLIST_KIND_OFFSET, r_flavor);
}
if (rewrite_args2) {
RewriterVarUsage2 r_newsize = rewrite_args2->rewriter->loadConst(new_size, Location::forArg(0));
r_new_array2 = rewrite_args2->rewriter->call(false, (void*)rt_alloc, std::move(r_newsize));
......@@ -523,11 +488,6 @@ void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite
}
} else {
attrs->attr_list = (HCAttrs::AttrList*)rt_realloc(attrs->attr_list, new_size);
if (rewrite_args) {
rewrite_args->obj.getAttr(cls->attrs_offset + HCATTRS_ATTRS_OFFSET, 0);
rewrite_args->rewriter->loadConst(1, new_size);
r_new_array = rewrite_args->rewriter->call((void*)rt_realloc);
}
if (rewrite_args2) {
RewriterVarUsage2 r_oldarray = rewrite_args2->obj.getAttr(cls->attrs_offset + HCATTRS_ATTRS_OFFSET,
RewriterVarUsage2::NoKill, Location::forArg(0));
......@@ -541,15 +501,6 @@ void Box::setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite
// see a consistent state between the hcls and the attr_list
attrs->hcls = new_hcls;
if (rewrite_args) {
RewriterVar attrval = rewrite_args->rewriter->pop(0);
RewriterVar obj = rewrite_args->rewriter->pop(2);
obj.setAttr(cls->attrs_offset + HCATTRS_ATTRS_OFFSET, r_new_array);
r_new_array.setAttr(numattrs * sizeof(Box*) + ATTRLIST_ATTRS_OFFSET, attrval);
RewriterVar hcls = rewrite_args->rewriter->loadConst(1, (intptr_t)new_hcls);
obj.setAttr(cls->attrs_offset + HCATTRS_HCLS_OFFSET, hcls);
rewrite_args->out_success = true;
}
if (rewrite_args2) {
r_new_array2.setAttr(numattrs * sizeof(Box*) + ATTRLIST_ATTRS_OFFSET, std::move(rewrite_args2->attrval));
rewrite_args2->obj.setAttr(cls->attrs_offset + HCATTRS_ATTRS_OFFSET, std::move(r_new_array2));
......@@ -915,7 +866,7 @@ extern "C" void setattr(Box* obj, const char* attr, Box* attr_val) {
if (rewriter.get()) {
// rewriter->trap();
SetattrRewriteArgs2 rewrite_args(rewriter.get(), rewriter->getArg(0), rewriter->getArg(2), false);
obj->setattr(attr, attr_val, NULL, &rewrite_args);
obj->setattr(attr, attr_val, &rewrite_args);
if (rewrite_args.out_success) {
rewriter->commit();
} else {
......@@ -923,7 +874,7 @@ extern "C" void setattr(Box* obj, const char* attr, Box* attr_val) {
rewrite_args.attrval.setDoneUsing();
}
} else {
obj->setattr(attr, attr_val, NULL, NULL);
obj->setattr(attr, attr_val, NULL);
}
}
......
......@@ -203,7 +203,7 @@ void setupTuple() {
tuple_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)tupleHash, BOXED_INT, 1, false)));
tuple_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)tupleLen, NULL, 1, false)));
tuple_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)tupleRepr, NULL, 1, false)));
tuple_cls->setattr("__str__", tuple_cls->getattr("__repr__"), NULL, NULL);
tuple_cls->giveAttr("__str__", tuple_cls->getattr("__repr__"));
tuple_cls->freeze();
}
......
......@@ -417,17 +417,17 @@ void setupRuntime() {
type_cls->giveAttr("__call__", new BoxedFunction(boxRTFunction((void*)typeCall, NULL, 1, true)));
type_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)typeNew, NULL, 2, true)));
type_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)typeRepr, NULL, 1, true)));
type_cls->setattr("__str__", type_cls->getattr("__repr__"), NULL, NULL);
type_cls->giveAttr("__str__", type_cls->getattr("__repr__"));
type_cls->freeze();
none_cls->giveAttr("__name__", boxStrConstant("NoneType"));
none_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)noneRepr, NULL, 1, false)));
none_cls->setattr("__str__", none_cls->getattr("__repr__"), NULL, NULL);
none_cls->giveAttr("__str__", none_cls->getattr("__repr__"));
none_cls->freeze();
module_cls->giveAttr("__name__", boxStrConstant("module"));
module_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)moduleRepr, NULL, 1, false)));
module_cls->setattr("__str__", module_cls->getattr("__repr__"), NULL, NULL);
module_cls->giveAttr("__str__", module_cls->getattr("__repr__"));
module_cls->freeze();
member_cls->giveAttr("__name__", boxStrConstant("member"));
......@@ -445,7 +445,7 @@ void setupRuntime() {
function_cls->giveAttr("__name__", boxStrConstant("function"));
function_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)functionRepr, NULL, 1, false)));
function_cls->setattr("__str__", function_cls->getattr("__repr__"), NULL, NULL);
function_cls->giveAttr("__str__", function_cls->getattr("__repr__"));
function_cls->freeze();
instancemethod_cls->giveAttr("__name__", boxStrConstant("instancemethod"));
......@@ -459,7 +459,7 @@ void setupRuntime() {
addRTFunction(slice_new, (void*)sliceNew4, NULL, 4, false);
slice_cls->giveAttr("__new__", new BoxedFunction(slice_new));
slice_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)sliceRepr, NULL, 1, true)));
slice_cls->setattr("__str__", slice_cls->getattr("__repr__"), NULL, NULL);
slice_cls->giveAttr("__str__", slice_cls->getattr("__repr__"));
slice_cls->giveAttr("start", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, SLICE_START_OFFSET));
slice_cls->giveAttr("stop", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, SLICE_STOP_OFFSET));
slice_cls->giveAttr("step", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, SLICE_STEP_OFFSET));
......
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