Commit 88fd6101 authored by Marius Wachtler's avatar Marius Wachtler

return correct type for unary float ops

parent 646f321a
......@@ -225,7 +225,7 @@ private:
return rtn;
}
bool hasFixedBinops(CompilerType* type) {
bool hasFixedOps(CompilerType* type) {
// This is non-exhaustive:
return type == STR || type == INT || type == FLOAT || type == LIST || type == DICT;
}
......@@ -233,7 +233,7 @@ private:
void* visit_augbinop(AST_AugBinOp* node) override {
CompilerType* left = getType(node->left);
CompilerType* right = getType(node->right);
if (!hasFixedBinops(left) || !hasFixedBinops(right))
if (!hasFixedOps(left) || !hasFixedOps(right))
return UNKNOWN;
// TODO this isn't the exact behavior
......@@ -262,7 +262,7 @@ private:
void* visit_binop(AST_BinOp* node) override {
CompilerType* left = getType(node->left);
CompilerType* right = getType(node->right);
if (!hasFixedBinops(left) || !hasFixedBinops(right))
if (!hasFixedOps(left) || !hasFixedOps(right))
return UNKNOWN;
// TODO this isn't the exact behavior
......@@ -508,12 +508,20 @@ private:
void* visit_unaryop(AST_UnaryOp* node) override {
CompilerType* operand = getType(node->operand);
if (!hasFixedOps(operand))
return UNKNOWN;
// TODO this isn't the exact behavior
BoxedString* name = getOpName(node->op_type);
CompilerType* attr_type = operand->getattrType(name, true);
if (attr_type == UNDEF)
attr_type = UNKNOWN;
std::vector<CompilerType*> arg_types;
return attr_type->callType(ArgPassSpec(0), arg_types, NULL);
CompilerType* rtn_type = attr_type->callType(ArgPassSpec(0), arg_types, NULL);
rtn_type = unboxedType(rtn_type->getConcreteType());
return rtn_type;
}
void* visit_yield(AST_Yield*) override { return UNKNOWN; }
......
......@@ -1294,6 +1294,14 @@ public:
return boolFromI1(emitter, cmp);
}
ConcreteCompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
AST_TYPE::AST_TYPE op_type) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
auto rtn = converted->unaryop(emitter, info, op_type);
converted->decvref(emitter);
return rtn;
}
CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, VAR* var, CompilerVariable* slice) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
CompilerVariable* rtn = converted->getitem(emitter, info, slice);
......@@ -1885,6 +1893,15 @@ public:
ConcreteCompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
AST_TYPE::AST_TYPE op_type) override {
BoxedString* attr = getOpName(op_type);
bool no_attribute = false;
ConcreteCompilerVariable* called_constant
= tryCallattrConstant(emitter, info, var, attr, true, ArgPassSpec(0, 0, 0, 0), {}, NULL, &no_attribute);
if (called_constant && !no_attribute)
return called_constant;
return UNKNOWN->unaryop(emitter, info, var, op_type);
}
......
......@@ -108,3 +108,6 @@ for lhs in all_args:
import sys
print sys.float_info
if 1:
x = -2.0
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