Commit 64faf815 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge commit 'd9896' into refcounting

parents 287a69e4 d98960b4
...@@ -423,16 +423,14 @@ public: ...@@ -423,16 +423,14 @@ public:
} }
// Sort in order of `num_parents_from_passed_closure` // Sort in order of `num_parents_from_passed_closure`
std::sort(allDerefVarsAndInfo.begin(), allDerefVarsAndInfo.end(), derefComparator); std::sort(
allDerefVarsAndInfo.begin(), allDerefVarsAndInfo.end(),
[](const std::pair<InternedString, DerefInfo>& p1, const std::pair<InternedString, DerefInfo>& p2) {
return p1.second.num_parents_from_passed_closure < p2.second.num_parents_from_passed_closure;
});
} }
return allDerefVarsAndInfo; return allDerefVarsAndInfo;
} }
private:
static bool derefComparator(const std::pair<InternedString, DerefInfo>& p1,
const std::pair<InternedString, DerefInfo>& p2) {
return p1.second.num_parents_from_passed_closure < p2.second.num_parents_from_passed_closure;
};
}; };
static void raiseGlobalAndLocalException(InternedString name, AST* node) { static void raiseGlobalAndLocalException(InternedString name, AST* node) {
......
...@@ -566,8 +566,31 @@ extern "C" int PyObject_HasAttrString(PyObject* v, const char* name) noexcept { ...@@ -566,8 +566,31 @@ extern "C" int PyObject_HasAttrString(PyObject* v, const char* name) noexcept {
// I'm not sure how we can support this one: // I'm not sure how we can support this one:
extern "C" PyObject** _PyObject_GetDictPtr(PyObject* obj) noexcept { extern "C" PyObject** _PyObject_GetDictPtr(PyObject* obj) noexcept {
fatalOrError(PyExc_NotImplementedError, "unimplemented"); Py_ssize_t dictoffset;
PyTypeObject* tp = Py_TYPE(obj);
if (!tp->instancesHaveHCAttrs()) {
dictoffset = tp->tp_dictoffset;
if (dictoffset == 0)
return NULL;
if (dictoffset < 0) {
Py_ssize_t tsize;
size_t size;
tsize = ((PyVarObject*)obj)->ob_size;
if (tsize < 0)
tsize = -tsize;
size = _PyObject_VAR_SIZE(tp, tsize);
dictoffset += (long)size;
assert(dictoffset > 0);
assert(dictoffset % SIZEOF_VOID_P == 0);
}
return (PyObject**)((char*)obj + dictoffset);
} else {
fatalOrError(PyExc_NotImplementedError, "unimplemented for hcattrs");
return nullptr; return nullptr;
}
} }
/* These methods are used to control infinite recursion in repr, str, print, /* These methods are used to control infinite recursion in repr, str, print,
......
...@@ -139,7 +139,7 @@ public: ...@@ -139,7 +139,7 @@ public:
AST_TYPE::AST_TYPE convert(boolop_ty op) { AST_TYPE::AST_TYPE convert(boolop_ty op) {
switch (op) { switch (op) {
CASE(Add); CASE(And);
CASE(Or); CASE(Or);
} }
// GCC wants this: // GCC wants this:
......
...@@ -1106,11 +1106,11 @@ AST_Module* parse_file(const char* fn, FutureFlags inherited_flags) { ...@@ -1106,11 +1106,11 @@ AST_Module* parse_file(const char* fn, FutureFlags inherited_flags) {
const char* getMagic() { const char* getMagic() {
if (ENABLE_CPYTHON_PARSER) if (ENABLE_CPYTHON_PARSER)
return "a\nCO"; return "a\nCP";
else if (ENABLE_PYPA_PARSER) else if (ENABLE_PYPA_PARSER)
return "a\ncO"; return "a\ncP";
else else
return "a\nco"; return "a\ncp";
} }
#define MAGIC_STRING_LENGTH 4 #define MAGIC_STRING_LENGTH 4
......
...@@ -1560,6 +1560,9 @@ bool PrintVisitor::visit_langprimitive(AST_LangPrimitive* node) { ...@@ -1560,6 +1560,9 @@ bool PrintVisitor::visit_langprimitive(AST_LangPrimitive* node) {
case AST_LangPrimitive::HASNEXT: case AST_LangPrimitive::HASNEXT:
stream << "HASNEXT"; stream << "HASNEXT";
break; break;
case AST_LangPrimitive::PRINT_EXPR:
stream << "PRINT_EXPR";
break;
default: default:
RELEASE_ASSERT(0, "%d", node->opcode); RELEASE_ASSERT(0, "%d", node->opcode);
} }
......
...@@ -746,9 +746,11 @@ private: ...@@ -746,9 +746,11 @@ private:
if (node->op_type == AST_TYPE::Or) { if (node->op_type == AST_TYPE::Or) {
br->iftrue = crit_break_block; br->iftrue = crit_break_block;
br->iffalse = next_block; br->iffalse = next_block;
} else { } else if (node->op_type == AST_TYPE::And) {
br->iffalse = crit_break_block; br->iffalse = crit_break_block;
br->iftrue = next_block; br->iftrue = next_block;
} else {
RELEASE_ASSERT(0, "");
} }
curblock = crit_break_block; curblock = crit_break_block;
......
...@@ -1635,7 +1635,7 @@ void setupFloat() { ...@@ -1635,7 +1635,7 @@ void setupFloat() {
_addFunc("__rdiv__", BOXED_FLOAT, (void*)floatRDivFloat, (void*)floatRDivInt, (void*)floatRDiv); _addFunc("__rdiv__", BOXED_FLOAT, (void*)floatRDivFloat, (void*)floatRDivInt, (void*)floatRDiv);
_addFunc("__floordiv__", BOXED_FLOAT, (void*)floatFloorDivFloat, (void*)floatFloorDivInt, (void*)floatFloorDiv); _addFunc("__floordiv__", BOXED_FLOAT, (void*)floatFloorDivFloat, (void*)floatFloorDivInt, (void*)floatFloorDiv);
float_cls->giveAttr("__rfloordiv__", float_cls->giveAttr("__rfloordiv__",
new BoxedFunction(FunctionMetadata::create((void*)floatRFloorDiv, BOXED_FLOAT, 2))); new BoxedFunction(FunctionMetadata::create((void*)floatRFloorDiv, UNKNOWN, 2)));
_addFunc("__truediv__", BOXED_FLOAT, (void*)floatDivFloat, (void*)floatDivInt, (void*)floatTruediv); _addFunc("__truediv__", BOXED_FLOAT, (void*)floatDivFloat, (void*)floatDivInt, (void*)floatTruediv);
float_cls->giveAttr("__rtruediv__", new BoxedFunction(FunctionMetadata::create((void*)floatRTruediv, UNKNOWN, 2))); float_cls->giveAttr("__rtruediv__", new BoxedFunction(FunctionMetadata::create((void*)floatRTruediv, UNKNOWN, 2)));
......
...@@ -2,6 +2,16 @@ ...@@ -2,6 +2,16 @@
# Doesn't test much of the functionality, but even importing the module is tough: # Doesn't test much of the functionality, but even importing the module is tough:
import datetime import datetime
def typeErrorTest(val):
try:
x = datetime.timedelta(43)
x // val
except TypeError as e:
return True
return False
print repr(datetime.time()) print repr(datetime.time())
print datetime.datetime.__base__ print datetime.datetime.__base__
print repr(datetime.datetime(1, 2, 3)) print repr(datetime.datetime(1, 2, 3))
...@@ -11,3 +21,8 @@ print str(datetime.timedelta(0)) ...@@ -11,3 +21,8 @@ print str(datetime.timedelta(0))
datetime.datetime.now().now() datetime.datetime.now().now()
print datetime.datetime(1924, 2, 3).strftime("%B %d, %Y - %X") print datetime.datetime(1924, 2, 3).strftime("%B %d, %Y - %X")
a = 3
b = 3.4
assert not typeErrorTest(a)
assert typeErrorTest(b)
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