Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/codegen/ast_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,10 +1150,10 @@ Value ASTInterpreter::visit_call(AST_Call* node) {
ArgPassSpec argspec(node->args.size(), node->keywords.size(), node->starargs, node->kwargs);

if (is_callattr) {
return callattr(func.o, attr.getBox(),
CallattrFlags({.cls_only = callattr_clsonly, .null_on_nonexistent = false }), argspec,
args.size() > 0 ? args[0] : 0, args.size() > 1 ? args[1] : 0, args.size() > 2 ? args[2] : 0,
args.size() > 3 ? &args[3] : 0, &keywords);
CallattrFlags callattr_flags{.cls_only = callattr_clsonly, .null_on_nonexistent = false, .argspec = argspec };
return callattr(func.o, attr.getBox(), callattr_flags, args.size() > 0 ? args[0] : 0,
args.size() > 1 ? args[1] : 0, args.size() > 2 ? args[2] : 0, args.size() > 3 ? &args[3] : 0,
&keywords);
} else {
return runtimeCall(func.o, argspec, args.size() > 0 ? args[0] : 0, args.size() > 1 ? args[1] : 0,
args.size() > 2 ? args[2] : 0, args.size() > 3 ? &args[3] : 0, &keywords);
Expand Down
47 changes: 22 additions & 25 deletions src/codegen/compvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class UnknownType : public ConcreteCompilerType {
const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override;
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr,
CallattrFlags flags, ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
CallattrFlags flags, const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override;
ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) override;
ConcreteCompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) override;
Expand Down Expand Up @@ -359,8 +359,8 @@ class UnknownType : public ConcreteCompilerType {
CompilerVariable* getPystonIter(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) override {
static BoxedString* iter_box = static_cast<BoxedString*>(PyString_InternFromString("__iter__"));

CallattrFlags flags = {.cls_only = true, .null_on_nonexistent = true };
CompilerVariable* iter_call = var->callattr(emitter, info, iter_box, flags, ArgPassSpec(0), {}, 0);
CallattrFlags flags = {.cls_only = true, .null_on_nonexistent = true, .argspec = ArgPassSpec(0) };
CompilerVariable* iter_call = var->callattr(emitter, info, iter_box, flags, {}, 0);
ConcreteCompilerVariable* converted_iter_call = iter_call->makeConverted(emitter, iter_call->getBoxType());

// If the type analysis could determine the iter type is a valid pyston iter (has 'hasnext') we are finished.
Expand Down Expand Up @@ -657,11 +657,11 @@ CompilerVariable* UnknownType::call(IREmitter& emitter, const OpInfo& info, Conc
}

CompilerVariable* UnknownType::callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
BoxedString* attr, CallattrFlags flags, ArgPassSpec argspec,
BoxedString* attr, CallattrFlags flags,
const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) {
bool pass_keywords = (argspec.num_keywords != 0);
int npassed_args = argspec.totalPassed();
bool pass_keywords = (flags.argspec.num_keywords != 0);
int npassed_args = flags.argspec.totalPassed();

llvm::Value* func;
if (pass_keywords)
Expand All @@ -680,11 +680,8 @@ CompilerVariable* UnknownType::callattr(IREmitter& emitter, const OpInfo& info,
std::vector<llvm::Value*> other_args;
other_args.push_back(var->getValue());
other_args.push_back(embedRelocatablePtr(attr, g.llvm_boxedstring_type_ptr));
other_args.push_back(getConstantInt(flags.asInt(), g.i8));

llvm::Value* llvm_argspec = llvm::ConstantInt::get(g.i32, argspec.asInt(), false);
other_args.push_back(llvm_argspec);
return _call(emitter, info, func, (void*)pyston::callattr, other_args, argspec, args, keyword_names, UNKNOWN);
other_args.push_back(getConstantInt(flags.asInt(), g.i64));
return _call(emitter, info, func, (void*)pyston::callattr, other_args, flags.argspec, args, keyword_names, UNKNOWN);
}

ConcreteCompilerVariable* UnknownType::nonzero(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) {
Expand Down Expand Up @@ -917,10 +914,10 @@ class IntType : public ConcreteCompilerType {
}

CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr,
CallattrFlags flags, ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
CallattrFlags flags, const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_INT);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
Expand Down Expand Up @@ -1161,10 +1158,10 @@ class FloatType : public ConcreteCompilerType {
}

CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr,
CallattrFlags flags, ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
CallattrFlags flags, const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
Expand Down Expand Up @@ -1645,15 +1642,15 @@ class NormalObjectType : public ConcreteCompilerType {
}

CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr,
CallattrFlags flags, ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
CallattrFlags flags, const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override {
ConcreteCompilerVariable* called_constant
= tryCallattrConstant(emitter, info, var, attr, flags.cls_only, argspec, args, keyword_names);
= tryCallattrConstant(emitter, info, var, attr, flags.cls_only, flags.argspec, args, keyword_names);
if (called_constant)
return called_constant;

ConcreteCompilerVariable* converted = var->makeConverted(emitter, UNKNOWN);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
Expand Down Expand Up @@ -1902,10 +1899,10 @@ class StrConstantType : public ValuedCompilerType<BoxedString*> {
}

CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, BoxedString* attr, CallattrFlags flags,
ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, STR);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
Expand Down Expand Up @@ -2036,10 +2033,10 @@ class BoolType : public ConcreteCompilerType {
}

CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr,
CallattrFlags flags, ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
CallattrFlags flags, const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_BOOL);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
Expand Down Expand Up @@ -2216,10 +2213,10 @@ class TupleType : public ValuedCompilerType<const std::vector<CompilerVariable*>
}

CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, BoxedString* attr, CallattrFlags flags,
ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override {
return makeConverted(emitter, var, getConcreteType())
->callattr(emitter, info, attr, flags, argspec, args, keyword_names);
->callattr(emitter, info, attr, flags, args, keyword_names);
}

void serializeToFrame(VAR* var, std::vector<llvm::Value*>& stackmap_args) override {
Expand Down Expand Up @@ -2320,7 +2317,7 @@ class UndefType : public ConcreteCompilerType {
}

CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, BoxedString* attr, CallattrFlags flags,
ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override {
return undefVariable();
}
Expand Down
9 changes: 4 additions & 5 deletions src/codegen/compvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ template <class V> class _ValuedCompilerType : public CompilerType {
}

virtual CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, BoxedString* attr,
CallattrFlags flags, struct ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
CallattrFlags flags, const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) {
printf("callattr not defined for %s\n", debugName().c_str());
abort();
Expand Down Expand Up @@ -268,7 +267,7 @@ class CompilerVariable {
virtual void setattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, CompilerVariable* v) = 0;
virtual void delattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr) = 0;
virtual CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, CallattrFlags flags,
struct ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) = 0;
virtual CompilerVariable* call(IREmitter& emitter, const OpInfo& info, struct ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
Expand Down Expand Up @@ -348,9 +347,9 @@ template <class V> class ValuedCompilerVariable : public CompilerVariable {
}

CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, CallattrFlags flags,
struct ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override {
return type->callattr(emitter, info, this, attr, flags, argspec, args, keyword_names);
return type->callattr(emitter, info, this, attr, flags, args, keyword_names);
}
CompilerVariable* call(IREmitter& emitter, const OpInfo& info, struct ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args,
Expand Down
24 changes: 11 additions & 13 deletions src/codegen/irgen/irgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,8 @@ class IRGeneratorImpl : public IRGenerator {

CompilerVariable* rtn;
if (is_callattr) {
CallattrFlags flags = {.cls_only = callattr_clsonly, .null_on_nonexistent = false };
rtn = func->callattr(emitter, getOpInfoForNode(node, unw_info), attr.getBox(), flags, argspec, args,
keyword_names);
CallattrFlags flags = {.cls_only = callattr_clsonly, .null_on_nonexistent = false, .argspec = argspec };
rtn = func->callattr(emitter, getOpInfoForNode(node, unw_info), attr.getBox(), flags, args, keyword_names);
} else {
rtn = func->call(emitter, getOpInfoForNode(node, unw_info), argspec, args, keyword_names);
}
Expand Down Expand Up @@ -1138,9 +1137,9 @@ class IRGeneratorImpl : public IRGenerator {

for (int i = 0; i < node->elts.size(); i++) {
CompilerVariable* elt = elts[i];
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);
CallattrFlags flags = {.cls_only = true, .null_on_nonexistent = false, .argspec = ArgPassSpec(1) };
CompilerVariable* r
= rtn->callattr(emitter, getOpInfoForNode(node, unw_info), add_str, flags, { elt }, NULL);
r->decvref(emitter);
elt->decvref(emitter);
}
Expand Down Expand Up @@ -1907,9 +1906,9 @@ class IRGeneratorImpl : public IRGenerator {

curblock = ss_block;
emitter.getBuilder()->SetInsertPoint(ss_block);
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);
CallattrFlags flags = {.cls_only = false, .null_on_nonexistent = false, .argspec = ArgPassSpec(1) };
auto r = dest->callattr(emitter, getOpInfoForNode(node, unw_info), write_str, flags, { makeStr(space_str) },
NULL);
r->decvref(emitter);

emitter.getBuilder()->CreateBr(join_block);
Expand All @@ -1921,16 +1920,15 @@ class IRGeneratorImpl : public IRGenerator {
llvm::Value* v = emitter.createCall(unw_info, g.funcs.strOrUnicode, 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, flags, ArgPassSpec(1), { s },
NULL);
r = dest->callattr(emitter, getOpInfoForNode(node, unw_info), write_str, flags, { s }, NULL);
s->decvref(emitter);
r->decvref(emitter);
converted->decvref(emitter);
}

if (node->nl) {
CallattrFlags flags = {.cls_only = false, .null_on_nonexistent = false };
auto r = dest->callattr(emitter, getOpInfoForNode(node, unw_info), write_str, flags, ArgPassSpec(1),
CallattrFlags flags = {.cls_only = false, .null_on_nonexistent = false, .argspec = ArgPassSpec(1) };
auto r = dest->callattr(emitter, getOpInfoForNode(node, unw_info), write_str, flags,
{ makeStr(newline_str) }, NULL);
r->decvref(emitter);

Expand Down
14 changes: 7 additions & 7 deletions src/codegen/runtime_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,17 @@ void initGlobalFuncs(GlobalState& g) {
g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr->getPointerTo());

g.funcs.callattr = getFunc((void*)callattr, "callattr");
g.funcs.callattr0 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr,
g.llvm_boxedstring_type_ptr, g.i1, g.i32);
g.funcs.callattr0
= addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_boxedstring_type_ptr, g.i64);
g.funcs.callattr1 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr,
g.llvm_boxedstring_type_ptr, g.i1, g.i32, g.llvm_value_type_ptr);
g.llvm_boxedstring_type_ptr, g.i64, g.llvm_value_type_ptr);
g.funcs.callattr2 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr,
g.llvm_boxedstring_type_ptr, g.i1, g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr);
g.llvm_boxedstring_type_ptr, g.i64, g.llvm_value_type_ptr, g.llvm_value_type_ptr);
g.funcs.callattr3
= addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_boxedstring_type_ptr, g.i1,
g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr);
= addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_boxedstring_type_ptr, g.i64,
g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr);
g.funcs.callattrN = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr,
g.llvm_boxedstring_type_ptr, g.i1, g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr,
g.llvm_boxedstring_type_ptr, g.i64, g.llvm_value_type_ptr, g.llvm_value_type_ptr,
g.llvm_value_type_ptr, g.llvm_value_type_ptr->getPointerTo());

g.funcs.reoptCompiledFunc = addFunc((void*)reoptCompiledFunc, g.i8_ptr, g.i8_ptr);
Expand Down
4 changes: 3 additions & 1 deletion src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,11 @@ struct FrameInfo {
struct CallattrFlags {
bool cls_only : 1;
bool null_on_nonexistent : 1;
ArgPassSpec argspec;

char asInt() { return (cls_only << 0) + (null_on_nonexistent << 1); }
uint64_t asInt() { return (uint64_t(argspec.asInt()) << 32) | (cls_only << 0) | (null_on_nonexistent << 1); }
};
static_assert(sizeof(CallattrFlags) == sizeof(uint64_t), "");
}

namespace std {
Expand Down
Loading