Commit 5efde076 authored by Marius Wachtler's avatar Marius Wachtler

Compvars: Add CallattrFlags support

parent 9cd8624a
......@@ -210,7 +210,7 @@ public:
const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) override;
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
const std::string* attr, bool clsonly, ArgPassSpec argspec,
const std::string* attr, CallattrFlags flags, ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) override;
ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) override;
......@@ -579,7 +579,7 @@ CompilerVariable* UnknownType::call(IREmitter& emitter, const OpInfo& info, Conc
}
CompilerVariable* UnknownType::callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
const std::string* attr, bool clsonly, ArgPassSpec argspec,
const std::string* attr, CallattrFlags flags, ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) {
bool pass_keywords = (argspec.num_keywords != 0);
......@@ -599,10 +599,17 @@ CompilerVariable* UnknownType::callattr(IREmitter& emitter, const OpInfo& info,
else
func = g.funcs.callattrN;
union {
CallattrFlags flags;
char value;
} flags_to_int;
static_assert(sizeof(CallattrFlags) == sizeof(char), "");
flags_to_int.flags = flags;
std::vector<llvm::Value*> other_args;
other_args.push_back(var->getValue());
other_args.push_back(embedConstantPtr(attr, g.llvm_str_type_ptr));
other_args.push_back(getConstantInt(clsonly, g.i1));
other_args.push_back(getConstantInt(flags_to_int.value, g.i8));
llvm::Value* llvm_argspec = llvm::ConstantInt::get(g.i32, argspec.asInt(), false);
other_args.push_back(llvm_argspec);
......@@ -819,11 +826,11 @@ public:
}
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
const std::string* attr, bool clsonly, ArgPassSpec argspec,
const std::string* attr, CallattrFlags flags, ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_INT);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, clsonly, argspec, args, keyword_names);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
......@@ -1057,11 +1064,11 @@ public:
}
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
const std::string* attr, bool clsonly, ArgPassSpec argspec,
const std::string* attr, CallattrFlags flags, ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, clsonly, argspec, args, keyword_names);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
......@@ -1523,16 +1530,16 @@ public:
}
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
const std::string* attr, bool clsonly, ArgPassSpec argspec,
const std::string* attr, CallattrFlags flags, ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) override {
ConcreteCompilerVariable* called_constant
= tryCallattrConstant(emitter, info, var, attr, clsonly, argspec, args, keyword_names);
= tryCallattrConstant(emitter, info, var, attr, flags.cls_only, argspec, args, keyword_names);
if (called_constant)
return called_constant;
ConcreteCompilerVariable* converted = var->makeConverted(emitter, UNKNOWN);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, clsonly, argspec, args, keyword_names);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
......@@ -1551,6 +1558,7 @@ public:
const std::string& left_side_name = getOpName(op_type);
bool no_attribute = false;
ConcreteCompilerVariable* called_constant
= tryCallattrConstant(emitter, info, var, &left_side_name, true, ArgPassSpec(1, 0, 0, 0),
{ converted_rhs }, NULL, &no_attribute);
......@@ -1741,11 +1749,11 @@ public:
return rtn;
}
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, const std::string* attr, bool clsonly,
ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, const std::string* attr,
CallattrFlags flags, ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, STR);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, clsonly, argspec, args, keyword_names);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
......@@ -1864,11 +1872,11 @@ public:
}
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
const std::string* attr, bool clsonly, ArgPassSpec argspec,
const std::string* attr, CallattrFlags flags, ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_BOOL);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, clsonly, argspec, args, keyword_names);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
......@@ -2037,11 +2045,11 @@ public:
return rtn;
}
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, const std::string* attr, bool clsonly,
ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, const std::string* attr,
CallattrFlags flags, ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) override {
return makeConverted(emitter, var, getConcreteType())
->callattr(emitter, info, attr, clsonly, argspec, args, keyword_names);
->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
}
void serializeToFrame(VAR* var, std::vector<llvm::Value*>& stackmap_args) override {
......@@ -2141,8 +2149,8 @@ public:
return undefVariable();
}
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, const std::string* attr, bool clsonly,
ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, const std::string* attr,
CallattrFlags flags, ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) override {
return undefVariable();
}
......
......@@ -112,7 +112,7 @@ public:
}
virtual CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, const std::string* attr,
bool clsonly, struct ArgPassSpec argspec,
CallattrFlags flags, struct ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) {
printf("callattr not defined for %s\n", debugName().c_str());
......@@ -254,8 +254,9 @@ public:
= 0;
virtual void setattr(IREmitter& emitter, const OpInfo& info, const std::string* attr, CompilerVariable* v) = 0;
virtual void delattr(IREmitter& emitter, const OpInfo& info, const std::string* attr) = 0;
virtual CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, const std::string* attr, bool clsonly,
struct ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
virtual CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, const std::string* attr,
CallattrFlags flags, struct ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) = 0;
virtual CompilerVariable* call(IREmitter& emitter, const OpInfo& info, struct ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
......@@ -330,10 +331,10 @@ public:
type->delattr(emitter, info, this, attr);
}
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, const std::string* attr, bool clsonly,
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, const std::string* attr, CallattrFlags flags,
struct ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
const std::vector<const std::string*>* keyword_names) override {
return type->callattr(emitter, info, this, attr, clsonly, argspec, args, keyword_names);
return type->callattr(emitter, info, this, attr, flags, argspec, args, keyword_names);
}
CompilerVariable* call(IREmitter& emitter, const OpInfo& info, struct ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
......
......@@ -457,8 +457,9 @@ private:
ConcreteCompilerVariable* converted = p.second->makeConverted(emitter, p.second->getBoxType());
// TODO super dumb that it reallocates the name again
CallattrFlags flags = {.cls_only = true, .null_on_nonexistent = false };
CompilerVariable* _r
= rtn->callattr(emitter, getEmptyOpInfo(unw_info), &setitem_str, true, ArgPassSpec(2),
= rtn->callattr(emitter, getEmptyOpInfo(unw_info), &setitem_str, flags, ArgPassSpec(2),
{ makeStr(new std::string(p.first.str())), converted }, NULL);
converted->decvref(emitter);
_r->decvref(emitter);
......@@ -474,8 +475,9 @@ private:
emitter.getBuilder()->SetInsertPoint(was_defined);
ConcreteCompilerVariable* converted = p.second->makeConverted(emitter, p.second->getBoxType());
// TODO super dumb that it reallocates the name again
CallattrFlags flags = {.cls_only = true, .null_on_nonexistent = false };
CompilerVariable* _r
= rtn->callattr(emitter, getEmptyOpInfo(unw_info), &setitem_str, true, ArgPassSpec(2),
= rtn->callattr(emitter, getEmptyOpInfo(unw_info), &setitem_str, flags, ArgPassSpec(2),
{ makeStr(new std::string(p.first.str())), converted }, NULL);
converted->decvref(emitter);
_r->decvref(emitter);
......@@ -744,8 +746,8 @@ private:
CompilerVariable* rtn;
if (is_callattr) {
rtn = func->callattr(emitter, getOpInfoForNode(node, unw_info), attr, callattr_clsonly, argspec, args,
keyword_names);
CallattrFlags flags = {.cls_only = callattr_clsonly, .null_on_nonexistent = false };
rtn = func->callattr(emitter, getOpInfoForNode(node, unw_info), attr, flags, argspec, args, keyword_names);
} else {
rtn = func->call(emitter, getOpInfoForNode(node, unw_info), argspec, args, keyword_names);
}
......@@ -972,8 +974,8 @@ private:
for (int i = 0; i < node->elts.size(); i++) {
CompilerVariable* elt = elts[i];
CompilerVariable* r = rtn->callattr(emitter, getOpInfoForNode(node, unw_info), &add_str, true,
CallattrFlags flags = {.cls_only = true, .null_on_nonexistent = false };
CompilerVariable* r = rtn->callattr(emitter, getOpInfoForNode(node, unw_info), &add_str, flags,
ArgPassSpec(1), { elt }, NULL);
r->decvref(emitter);
elt->decvref(emitter);
......@@ -1636,8 +1638,8 @@ private:
curblock = ss_block;
emitter.getBuilder()->SetInsertPoint(ss_block);
auto r = dest->callattr(emitter, getOpInfoForNode(node, unw_info), &write_str, false, ArgPassSpec(1),
CallattrFlags flags = {.cls_only = false, .null_on_nonexistent = false };
auto r = dest->callattr(emitter, getOpInfoForNode(node, unw_info), &write_str, flags, ArgPassSpec(1),
{ makeStr(&space_str) }, NULL);
r->decvref(emitter);
......@@ -1650,7 +1652,7 @@ private:
llvm::Value* v = emitter.createCall(unw_info, g.funcs.str, converted->getValue());
v = emitter.getBuilder()->CreateBitCast(v, g.llvm_value_type_ptr);
auto s = new ConcreteCompilerVariable(STR, v, true);
r = dest->callattr(emitter, getOpInfoForNode(node, unw_info), &write_str, false, ArgPassSpec(1), { s },
r = dest->callattr(emitter, getOpInfoForNode(node, unw_info), &write_str, flags, ArgPassSpec(1), { s },
NULL);
s->decvref(emitter);
r->decvref(emitter);
......@@ -1658,7 +1660,8 @@ private:
}
if (node->nl) {
auto r = dest->callattr(emitter, getOpInfoForNode(node, unw_info), &write_str, false, ArgPassSpec(1),
CallattrFlags flags = {.cls_only = false, .null_on_nonexistent = false };
auto r = dest->callattr(emitter, getOpInfoForNode(node, unw_info), &write_str, flags, ArgPassSpec(1),
{ makeStr(&newline_str) }, NULL);
r->decvref(emitter);
......
......@@ -559,6 +559,11 @@ struct FrameInfo {
FrameInfo(ExcInfo exc) : exc(exc) {}
};
struct CallattrFlags {
bool cls_only : 1;
bool null_on_nonexistent : 1;
};
}
#endif
......@@ -52,10 +52,6 @@ extern "C" void setattr(Box* obj, const char* attr, Box* attr_val);
extern "C" void delattr(Box* obj, const char* attr);
extern "C" bool nonzero(Box* obj);
extern "C" Box* runtimeCall(Box*, ArgPassSpec, Box*, Box*, Box*, Box**, const std::vector<const std::string*>*);
struct CallattrFlags {
bool cls_only : 1;
bool null_on_nonexistent : 1;
};
extern "C" Box* callattr(Box*, const std::string*, CallattrFlags, ArgPassSpec, Box*, Box*, Box*, Box**,
const std::vector<const std::string*>*);
extern "C" BoxedString* str(Box* obj);
......
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