Commit 280146ff authored by Chris Toshok's avatar Chris Toshok

move getreversed from objmodel.cpp to builtin_module/builtins.cpp

parent b131d40c
......@@ -32,6 +32,7 @@
#include "runtime/ics.h"
#include "runtime/import.h"
#include "runtime/inline/xrange.h"
#include "runtime/iterobject.h"
#include "runtime/list.h"
#include "runtime/long.h"
#include "runtime/objmodel.h"
......@@ -830,6 +831,23 @@ Box* print(BoxedTuple* args, BoxedDict* kwargs) {
return None;
}
Box* getreversed(Box* o) {
static const std::string reversed_str("__reversed__");
static const std::string getitem_str("__getitem__");
// TODO add rewriting to this? probably want to try to avoid this path though
Box* r = callattr(o, &reversed_str, CallattrFlags({.cls_only = true, .null_on_nonexistent = true }), ArgPassSpec(0),
NULL, NULL, NULL, NULL, NULL);
if (r)
return r;
if (!typeLookup(o->cls, getitem_str, NULL)) {
raiseExcHelper(TypeError, "'%s' object is not iterable", getTypeName(o));
}
int64_t len = unboxedLen(o); // this will throw an exception if __len__ isn't there
return new (seqreviter_cls) BoxedSeqIter(o, len - 1);
}
Box* pydump(void* p) {
dump(p);
return None;
......
......@@ -77,7 +77,6 @@ static const std::string get_str("__get__");
static const std::string hasnext_str("__hasnext__");
static const std::string init_str("__init__");
static const std::string iter_str("__iter__");
static const std::string reversed_str("__reversed__");
static const std::string new_str("__new__");
static const std::string none_str("None");
static const std::string repr_str("__repr__");
......@@ -3444,20 +3443,6 @@ Box* getiter(Box* o) {
raiseExcHelper(TypeError, "'%s' object is not iterable", getTypeName(o));
}
Box* getreversed(Box* o) {
// TODO add rewriting to this? probably want to try to avoid this path though
Box* r = callattrInternal0(o, &reversed_str, LookupScope::CLASS_ONLY, NULL, ArgPassSpec(0));
if (r)
return r;
if (!typeLookup(o->cls, getitem_str, NULL)) {
raiseExcHelper(TypeError, "'%s' object is not iterable", getTypeName(o));
}
int64_t len = unboxedLen(o); // this will throw an exception if __len__ isn't there
return new (seqreviter_cls) BoxedSeqIter(o, len - 1);
}
llvm::iterator_range<BoxIterator> Box::pyElements() {
// TODO: this should probably call getPystonIter
Box* iter = getiter(this);
......
......@@ -89,7 +89,6 @@ extern "C" bool isSubclass(BoxedClass* child, BoxedClass* parent);
extern "C" BoxedClosure* createClosure(BoxedClosure* parent_closure);
Box* getiter(Box* o);
Box* getreversed(Box* o);
extern "C" Box* getPystonIter(Box* o);
extern "C" void dump(void* p);
......
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