Commit 1a01b710 authored by Dong-hee Na's avatar Dong-hee Na

Ellipsis implementation

parent ac69cfef
......@@ -196,6 +196,8 @@ private:
}
}
void* visit_ellipsis(AST_Ellipsis* node) override { return ELLIPSIS; }
void* visit_attribute(AST_Attribute* node) override {
CompilerType* t = getType(node->value);
CompilerType* rtn = t->getattrType(node->attr, false);
......
......@@ -99,6 +99,7 @@ private:
Value visit_attribute(AST_Attribute* node);
Value visit_dict(AST_Dict* node);
Value visit_ellipsis(AST_Ellipsis* node);
Value visit_expr(AST_expr* node);
Value visit_expr(AST_Expr* node);
Value visit_extslice(AST_ExtSlice* node);
......@@ -549,7 +550,7 @@ Value ASTInterpreter::visit_slice(AST_slice* node) {
case AST_TYPE::ExtSlice:
return visit_extslice(static_cast<AST_ExtSlice*>(node));
case AST_TYPE::Ellipsis:
RELEASE_ASSERT(0, "not implemented");
return visit_ellipsis(static_cast<AST_Ellipsis*>(node));
break;
case AST_TYPE::Index:
return visit_index(static_cast<AST_Index*>(node));
......@@ -561,6 +562,10 @@ Value ASTInterpreter::visit_slice(AST_slice* node) {
return Value();
}
Value ASTInterpreter::visit_ellipsis(AST_Ellipsis* node) {
return Value(Ellipsis, jit ? jit->imm(Ellipsis) : NULL);
}
Value ASTInterpreter::visit_slice(AST_Slice* node) {
Value lower = node->lower ? visit_expr(node->lower) : getNone();
Value upper = node->upper ? visit_expr(node->upper) : getNone();
......
......@@ -1966,7 +1966,7 @@ public:
}
};
std::unordered_map<BoxedClass*, NormalObjectType*> NormalObjectType::made;
ConcreteCompilerType* STR, *BOXED_INT, *BOXED_FLOAT, *BOXED_BOOL, *NONE;
ConcreteCompilerType* STR, *BOXED_INT, *BOXED_FLOAT, *BOXED_BOOL, *NONE, *ELLIPSIS;
class ClosureType : public ConcreteCompilerType {
public:
......
......@@ -1073,6 +1073,11 @@ private:
return rtn;
}
ConcreteCompilerVariable* getEllipsis() {
llvm::Constant* ellipsis = embedRelocatablePtr(Ellipsis, g.llvm_value_type_ptr, "cEllipsis");
auto ellipsis_cls = Ellipsis->cls;
return new ConcreteCompilerVariable(typeFromClass(ellipsis_cls), ellipsis, false);
}
ConcreteCompilerVariable* getNone() {
llvm::Constant* none = embedRelocatablePtr(None, g.llvm_value_type_ptr, "cNone");
return new ConcreteCompilerVariable(typeFromClass(none_cls), none, false);
......@@ -1591,6 +1596,9 @@ private:
case AST_TYPE::ExtSlice:
rtn = evalExtSlice(ast_cast<AST_ExtSlice>(node), unw_info);
break;
case AST_TYPE::Ellipsis:
rtn = getEllipsis();
break;
case AST_TYPE::Index:
rtn = evalIndex(ast_cast<AST_Index>(node), unw_info);
break;
......
......@@ -88,7 +88,7 @@ template <class V> class ValuedCompilerType;
typedef ValuedCompilerType<llvm::Value*> ConcreteCompilerType;
ConcreteCompilerType* typeFromClass(BoxedClass*);
extern ConcreteCompilerType* INT, *BOXED_INT, *LONG, *FLOAT, *BOXED_FLOAT, *UNKNOWN, *BOOL, *STR, *NONE, *LIST, *SLICE,
extern ConcreteCompilerType* INT, *BOXED_INT, *LONG, *FLOAT, *BOXED_FLOAT, *UNKNOWN, *BOOL, *STR, *NONE, *LIST, *SLICE,*ELLIPSIS,
*MODULE, *DICT, *BOOL, *BOXED_BOOL, *BOXED_TUPLE, *SET, *FROZENSET, *CLOSURE, *GENERATOR, *BOXED_COMPLEX,
*FRAME_INFO;
extern CompilerType* UNDEF;
......
......@@ -1250,6 +1250,9 @@ extern "C" PyObject* PyEval_GetBuiltins(void) noexcept {
return builtins_module;
}
Box* ellipsisRepr(Box* self) {
return boxString("Ellipsis");
}
Box* divmod(Box* lhs, Box* rhs) {
return binopInternal(lhs, rhs, AST_TYPE::DivMod, false, NULL);
}
......@@ -1529,6 +1532,7 @@ void setupBuiltins() {
"the `nil' object; Ellipsis represents `...' in slices.");
BoxedClass* ellipsis_cls = BoxedClass::create(type_cls, object_cls, NULL, 0, 0, sizeof(Box), false, "ellipsis");
ellipsis_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)ellipsisRepr, STR, 1)));
Ellipsis = new (ellipsis_cls) Box();
assert(Ellipsis->cls);
gc::registerPermanentRoot(Ellipsis);
......
......@@ -128,7 +128,7 @@ extern BoxedClass* object_cls, *type_cls, *bool_cls, *int_cls, *long_cls, *float
extern std::vector<BoxedClass*> exception_types;
extern "C" {
extern Box* None, *NotImplemented, *True, *False;
extern Box* None, *NotImplemented, *True, *False, *Ellipsis;
}
extern "C" {
extern Box* repr_obj, *len_obj, *hash_obj, *range_obj, *abs_obj, *min_obj, *max_obj, *open_obj, *id_obj, *chr_obj,
......
print type(Ellipsis)
print type(Ellipsis).__base__
class TestEllipsis(object):
def __getitem__(self, item):
if item is Ellipsis:
return "Ellipsis"
else:
return "return %r items" % item
print Ellipsis
v = Ellipsis
print v
print type(v)
x = TestEllipsis()
print x[2]
print x[...]
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