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