Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
1de75ab7
Commit
1de75ab7
authored
Aug 25, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dict_init' of
https://github.com/chrisrammy/pyston
Conflicts: test/tests/dict.py
parents
a1227e08
19b53e51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
10 deletions
+18
-10
src/runtime/dict.cpp
src/runtime/dict.cpp
+13
-10
test/tests/dict.py
test/tests/dict.py
+5
-0
No files found.
src/runtime/dict.cpp
View file @
1de75ab7
...
...
@@ -207,9 +207,12 @@ extern "C" Box* dictNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
RELEASE_ASSERT
(
cls
==
dict_cls
,
""
);
return
new
BoxedDict
();
}
extern
"C"
Box
*
dictInit
(
BoxedDict
*
self
,
BoxedTuple
*
args
,
BoxedDict
*
kwargs
)
{
int
args_sz
=
args
->
elts
.
size
();
int
kwargs_sz
=
kwargs
->
d
.
size
();
BoxedDict
*
r
=
new
BoxedDict
();
// CPython accepts a single positional and keyword arguments, in any combination
if
(
args_sz
>
1
)
...
...
@@ -218,11 +221,9 @@ extern "C" Box* dictNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
// handle positional argument first as iterable
if
(
args_sz
==
1
)
{
int
idx
=
0
;
// raises if not iterable
llvm
::
iterator_range
<
BoxIterator
>
range
=
args
->
elts
[
0
]
->
pyElements
();
for
(
BoxIterator
it1
=
range
.
begin
();
it1
!=
range
.
end
();
++
it1
,
idx
++
)
{
Box
*
element
=
*
it1
;
// raises if not iterable
for
(
const
auto
&
element
:
args
->
elts
[
0
]
->
pyElements
())
{
// should this check subclasses? anyway to check if something is iterable...
if
(
element
->
cls
==
list_cls
)
{
...
...
@@ -231,16 +232,18 @@ extern "C" Box* dictNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
raiseExcHelper
(
ValueError
,
"dictionary update sequence element #%d has length %d; 2 is required"
,
idx
,
list
->
size
);
r
->
d
[
list
->
elts
->
elts
[
0
]]
=
list
->
elts
->
elts
[
1
];
self
->
d
[
list
->
elts
->
elts
[
0
]]
=
list
->
elts
->
elts
[
1
];
}
else
if
(
element
->
cls
==
tuple_cls
)
{
BoxedTuple
*
tuple
=
static_cast
<
BoxedTuple
*>
(
element
);
if
(
tuple
->
elts
.
size
()
!=
2
)
raiseExcHelper
(
ValueError
,
"dictionary update sequence element #%d has length %d; 2 is required"
,
idx
,
tuple
->
elts
.
size
());
r
->
d
[
tuple
->
elts
[
0
]]
=
tuple
->
elts
[
1
];
self
->
d
[
tuple
->
elts
[
0
]]
=
tuple
->
elts
[
1
];
}
else
raiseExcHelper
(
TypeError
,
"cannot convert dictionary update sequence element #%d to a sequence"
,
idx
);
idx
++
;
}
}
...
...
@@ -248,9 +251,9 @@ extern "C" Box* dictNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
assert
(
kwargs
->
cls
==
dict_cls
);
for
(
const
auto
&
p
:
kwargs
->
d
)
r
->
d
[
p
.
first
]
=
p
.
second
;
self
->
d
[
p
.
first
]
=
p
.
second
;
return
r
;
return
None
;
}
BoxedClass
*
dict_iterator_cls
=
NULL
;
...
...
@@ -267,7 +270,7 @@ void setupDict() {
dict_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"dict"
));
dict_cls
->
giveAttr
(
"__len__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictLen
,
BOXED_INT
,
1
)));
dict_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictNew
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
// dict_cls->giveAttr("__init__", new BoxedFunction(boxRTFunction((void*)dictInit, NULL, 1
)));
dict_cls
->
giveAttr
(
"__init__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictInit
,
NONE
,
1
,
0
,
true
,
true
)));
dict_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictRepr
,
STR
,
1
)));
dict_cls
->
giveAttr
(
"__str__"
,
dict_cls
->
getattr
(
"__repr__"
));
...
...
test/tests/dict.py
View file @
1de75ab7
...
...
@@ -109,3 +109,8 @@ d2[1].append(1)
print
d2
,
d
d2
[
1
]
=
1
print
d2
,
d
# __init__
d
=
{}
print
d
.
__init__
(((
'a'
,
1
),
(
'b'
,
2
)),
b
=
3
)
print
sorted
(
d
.
items
())
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