Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
02ff4ed7
Commit
02ff4ed7
authored
Feb 02, 2017
by
Dong-hee Na
Committed by
Dylan Trotter
Feb 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Ellipsis type (#230)
parent
637b02f8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
1 deletion
+24
-1
runtime/builtin_types.go
runtime/builtin_types.go
+16
-0
runtime/builtin_types_test.go
runtime/builtin_types_test.go
+7
-0
third_party/stdlib/types.py
third_party/stdlib/types.py
+1
-1
No files found.
runtime/builtin_types.go
View file @
02ff4ed7
...
@@ -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
(),
...
...
runtime/builtin_types_test.go
View file @
02ff4ed7
...
@@ -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
!=
""
{
...
...
third_party/stdlib/types.py
View file @
02ff4ed7
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment