Commit 02ff4ed7 authored by Dong-hee Na's avatar Dong-hee Na Committed by Dylan Trotter

Implement Ellipsis type (#230)

parent 637b02f8
......@@ -27,6 +27,11 @@ var (
builtinStr = NewStr("__builtin__")
// ExceptionTypes contains all builtin exception types.
ExceptionTypes []*Type
// EllipsisType is the object representing the Python 'ellipsis' type
EllipsisType = newSimpleType("ellipsis", ObjectType)
// Ellipsis is the singleton ellipsis object representing the Python
// 'Ellipsis' object.
Ellipsis = &Object{typ: EllipsisType}
// NoneType is the object representing the Python 'NoneType' type.
NoneType = newSimpleType("NoneType", ObjectType)
// None is the singleton NoneType object representing the Python 'None'
......@@ -44,10 +49,19 @@ var (
UnboundLocal = newObject(unboundLocalType)
)
func ellipsisRepr(*Frame, *Object) (*Object, *BaseException) {
return NewStr("Ellipsis").ToObject(), nil
}
func noneRepr(*Frame, *Object) (*Object, *BaseException) {
return NewStr("None").ToObject(), nil
}
func initEllipsisType(map[string]*Object) {
EllipsisType.flags &= ^(typeFlagInstantiable | typeFlagBasetype)
EllipsisType.slots.Repr = &unaryOpSlot{ellipsisRepr}
}
func initNoneType(map[string]*Object) {
NoneType.flags &= ^(typeFlagInstantiable | typeFlagBasetype)
NoneType.slots.Repr = &unaryOpSlot{noneRepr}
......@@ -93,6 +107,7 @@ var builtinTypes = map[*Type]*builtinTypeInfo{
dictKeyIteratorType: {init: initDictKeyIteratorType},
dictValueIteratorType: {init: initDictValueIteratorType},
DictType: {init: initDictType, global: true},
EllipsisType: {init: initEllipsisType, global: true},
enumerateType: {init: initEnumerateType, global: true},
EnvironmentErrorType: {global: true},
ExceptionType: {global: true},
......@@ -628,6 +643,7 @@ func init() {
"cmp": newBuiltinFunction("cmp", builtinCmp).ToObject(),
"delattr": newBuiltinFunction("delattr", builtinDelAttr).ToObject(),
"dir": newBuiltinFunction("dir", builtinDir).ToObject(),
"Ellipsis": Ellipsis,
"False": False.ToObject(),
"getattr": newBuiltinFunction("getattr", builtinGetAttr).ToObject(),
"globals": newBuiltinFunction("globals", builtinGlobals).ToObject(),
......
......@@ -327,6 +327,13 @@ func TestBuiltinGlobals(t *testing.T) {
}
}
func TestEllipsisRepr(t *testing.T) {
cas := invokeTestCase{args: wrapArgs(Ellipsis), want: NewStr("Ellipsis").ToObject()}
if err := runInvokeMethodTestCase(EllipsisType, "__repr__", &cas); err != "" {
t.Error(err)
}
}
func TestNoneRepr(t *testing.T) {
cas := invokeTestCase{args: wrapArgs(None), want: NewStr("None").ToObject()}
if err := runInvokeMethodTestCase(NoneType, "__repr__", &cas); err != "" {
......
......@@ -72,7 +72,7 @@ except TypeError:
del tb
SliceType = slice
#EllipsisType = type(Ellipsis)
EllipsisType = type(Ellipsis)
#DictProxyType = type(TypeType.__dict__)
NotImplementedType = type(NotImplemented)
......
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