Commit 78c12dde authored by Vinzenz Feenstra's avatar Vinzenz Feenstra

Added implementation of 'dir'

Signed-off-by: default avatarVinzenz Feenstra <evilissimo@gmail.com>
parent 5e418340
......@@ -25,7 +25,7 @@
#include "runtime/set.h"
#include "runtime/types.h"
#include "runtime/util.h"
#include "runtime/list.h"
namespace pyston {
extern "C" Box* trap() {
......@@ -34,6 +34,17 @@ extern "C" Box* trap() {
return None;
}
extern "C" Box * dir(Box* x) {
BoxedList * result = new BoxedList();
if(x->cls->hasattrs) {
HCBox * hcb = static_cast<HCBox*>(x);
for(auto const & kv : hcb->hcls->attr_offsets) {
listAppend(result, boxString(kv.first));
}
}
return result;
}
extern "C" Box* abs_(Box* x) {
if (x->cls == int_cls) {
i64 n = static_cast<BoxedInt*>(x)->n;
......@@ -507,6 +518,7 @@ void setupBuiltins() {
builtins_module->giveAttr("map", new BoxedFunction(boxRTFunction((void*)map2, LIST, 2, false)));
builtins_module->giveAttr("zip", new BoxedFunction(boxRTFunction((void*)zip2, LIST, 2, false)));
builtins_module->giveAttr("dir", new BoxedFunction(boxRTFunction((void*)dir, LIST, 1, false)));
builtins_module->giveAttr("object", object_cls);
builtins_module->giveAttr("str", str_cls);
builtins_module->giveAttr("int", int_cls);
......
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