Commit 4b51f74e authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #389 from undingen/virtualenv_fixes6

Fix a threading.local() and a unicode type analysis bug and add support for round(f, 0)
parents 075620c7 c1c3b9fd
......@@ -452,7 +452,13 @@ private:
void* visit_slice(AST_Slice* node) override { return SLICE; }
void* visit_str(AST_Str* node) override { return STR; }
void* visit_str(AST_Str* node) override {
if (node->str_type == AST_Str::STR)
return STR;
else if (node->str_type == AST_Str::UNICODE)
return typeFromClass(unicode_cls);
RELEASE_ASSERT(0, "Unknown string type %d", (int)node->str_type);
}
void* visit_subscript(AST_Subscript* node) override {
CompilerType* val = getType(node->value);
......
......@@ -119,6 +119,8 @@ public:
v->visit(pub_state->curexc_value);
if (pub_state->curexc_traceback)
v->visit(pub_state->curexc_traceback);
if (pub_state->dict)
v->visit(pub_state->dict);
for (auto& stack_info : previous_stacks) {
v->visit(stack_info.next_generator);
......
......@@ -998,6 +998,22 @@ Box* input(Box* prompt) {
Py_FatalError("unimplemented");
}
Box* builtinRound(Box* _number, Box* _ndigits) {
if (!isSubclass(_number->cls, float_cls))
raiseExcHelper(TypeError, "a float is required");
BoxedFloat* number = (BoxedFloat*)_number;
if (isSubclass(_ndigits->cls, int_cls)) {
BoxedInt* ndigits = (BoxedInt*)_ndigits;
if (ndigits->n == 0)
return boxFloat(round(number->d));
}
Py_FatalError("unimplemented");
}
Box* builtinCmp(Box* lhs, Box* rhs) {
Py_FatalError("unimplemented");
}
......@@ -1129,6 +1145,10 @@ void setupBuiltins() {
{ NULL, NULL });
builtins_module->giveAttr("range", range_obj);
auto* round_obj = new BoxedBuiltinFunctionOrMethod(
boxRTFunction((void*)builtinRound, BOXED_FLOAT, 2, 1, false, false), "round", { boxInt(0) });
builtins_module->giveAttr("round", round_obj);
setupXrange();
builtins_module->giveAttr("xrange", xrange_cls);
......
......@@ -103,6 +103,8 @@ print callable(lambda: 1)
print range(5L, 7L)
print round(-1.1), round(-1.9)
print round(0.5), round(-0.5)
print list(iter(xrange(100).__iter__().next, 20))
......
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