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
6c38b210
Commit
6c38b210
authored
Aug 25, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'enumerate_generator' of
https://github.com/undingen/pyston
Conflicts: test/tests/builtins.py
parents
15f24443
5d8d680e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
36 deletions
+23
-36
minibenchmarks/spectral_norm.py
minibenchmarks/spectral_norm.py
+2
-12
src/core/types.h
src/core/types.h
+2
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+9
-24
src/runtime/types.cpp
src/runtime/types.cpp
+5
-0
test/tests/builtins.py
test/tests/builtins.py
+5
-0
No files found.
minibenchmarks/spectral_norm.py
View file @
6c38b210
...
...
@@ -11,16 +11,6 @@
from
math
import
sqrt
from
sys
import
argv
# pyston does not yet support enumerate
def
_enumerate
(
sequence
):
n
=
0
rtn
=
[]
for
elem
in
sequence
:
rtn
.
append
((
n
,
elem
))
n
+=
1
return
rtn
def
eval_A
(
i
,
j
):
ij
=
i
+
j
return
1.0
/
(
ij
*
(
ij
+
1
)
/
2
+
i
+
1
)
...
...
@@ -30,7 +20,7 @@ def eval_A_times_u(u):
local_eval_A
=
eval_A
return
[
sum
([
local_eval_A
(
i
,
j
)
*
u_j
for
j
,
u_j
in
_
enumerate
(
u
)
for
j
,
u_j
in
enumerate
(
u
)
]
)
for
i
in
range
(
len
(
u
))
...
...
@@ -41,7 +31,7 @@ def eval_At_times_u(u):
local_eval_A
=
eval_A
return
[
sum
([
local_eval_A
(
j
,
i
)
*
u_j
for
j
,
u_j
in
_
enumerate
(
u
)
for
j
,
u_j
in
enumerate
(
u
)
]
)
for
i
in
range
(
len
(
u
))
...
...
src/core/types.h
View file @
6c38b210
...
...
@@ -297,6 +297,8 @@ public:
Box
*
operator
*
()
const
{
return
value
;
}
Box
*
operator
*
()
{
return
value
;
}
void
gcHandler
(
GCVisitor
*
v
);
private:
Box
*
iter
;
Box
*
value
;
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
6c38b210
...
...
@@ -471,23 +471,20 @@ static BoxedClass* makeBuiltinException(BoxedClass* base, const char* name) {
BoxedClass
*
enumerate_cls
;
class
BoxedEnumerate
:
public
Box
{
private:
Box
*
iterator
;
Box
Iterator
iterator
,
iterator_end
;
int64_t
idx
;
public:
BoxedEnumerate
(
Box
*
iterator
,
int64_t
idx
)
:
Box
(
enumerate_cls
),
iterator
(
iterator
),
idx
(
idx
)
{}
BoxedEnumerate
(
BoxIterator
iterator_begin
,
BoxIterator
iterator_end
,
int64_t
idx
)
:
Box
(
enumerate_cls
),
iterator
(
iterator_begin
),
iterator_end
(
iterator_end
),
idx
(
idx
)
{}
static
Box
*
new_
(
Box
*
cls
,
Box
*
obj
,
Box
*
start
)
{
RELEASE_ASSERT
(
cls
==
enumerate_cls
,
""
);
RELEASE_ASSERT
(
start
->
cls
==
int_cls
,
""
);
int64_t
idx
=
static_cast
<
BoxedInt
*>
(
start
)
->
n
;
static
const
std
::
string
iter_name
(
"__iter__"
);
Box
*
iterator
=
callattrInternal
(
obj
,
&
iter_name
,
CLASS_ONLY
,
NULL
,
ArgPassSpec
(
0
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
!
iterator
)
raiseNotIterableError
(
getTypeName
(
iterator
)
->
c_str
());
return
new
BoxedEnumerate
(
iterator
,
idx
);
llvm
::
iterator_range
<
BoxIterator
>
range
=
obj
->
pyElements
();
return
new
BoxedEnumerate
(
range
.
begin
(),
range
.
end
(),
idx
);
}
static
Box
*
iter
(
Box
*
_self
)
{
...
...
@@ -497,35 +494,23 @@ public:
}
static
Box
*
next
(
Box
*
_self
)
{
static
const
std
::
string
next_name
(
"next"
);
assert
(
_self
->
cls
==
enumerate_cls
);
BoxedEnumerate
*
self
=
static_cast
<
BoxedEnumerate
*>
(
_self
);
Box
*
o
=
callattrInternal
(
self
->
iterator
,
&
next_name
,
CLASS_ONLY
,
NULL
,
ArgPassSpec
(
0
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
RELEASE_ASSERT
(
o
,
""
);
Box
*
r
=
new
BoxedTuple
({
boxInt
(
self
->
idx
),
o
});
self
->
idx
++
;
return
r
;
return
new
BoxedTuple
({
boxInt
(
self
->
idx
++
),
*
self
->
iterator
++
});
}
static
Box
*
hasnext
(
Box
*
_self
)
{
static
const
std
::
string
hasnext_name
(
"__hasnext__"
);
assert
(
_self
->
cls
==
enumerate_cls
);
BoxedEnumerate
*
self
=
static_cast
<
BoxedEnumerate
*>
(
_self
);
Box
*
r
=
callattrInternal
(
self
->
iterator
,
&
hasnext_name
,
CLASS_ONLY
,
NULL
,
ArgPassSpec
(
0
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
RELEASE_ASSERT
(
r
,
"%s"
,
getTypeName
(
self
->
iterator
)
->
c_str
());
return
r
;
return
boxBool
(
self
->
iterator
!=
self
->
iterator_end
);
}
static
void
gcHandler
(
GCVisitor
*
v
,
Box
*
b
)
{
boxGCHandler
(
v
,
b
);
BoxedEnumerate
*
it
=
(
BoxedEnumerate
*
)
b
;
v
->
visit
(
it
->
iterator
);
it
->
iterator
.
gcHandler
(
v
);
it
->
iterator_end
.
gcHandler
(
v
);
}
};
...
...
src/runtime/types.cpp
View file @
6c38b210
...
...
@@ -73,6 +73,11 @@ BoxIterator& BoxIterator::operator++() {
return
*
this
;
}
void
BoxIterator
::
gcHandler
(
GCVisitor
*
v
)
{
v
->
visitPotential
(
iter
);
v
->
visitPotential
(
value
);
}
llvm
::
iterator_range
<
BoxIterator
>
Box
::
pyElements
()
{
static
std
::
string
iter_str
(
"__iter__"
);
...
...
test/tests/builtins.py
View file @
6c38b210
...
...
@@ -46,3 +46,8 @@ try:
divmod
(
1
,
""
)
except
TypeError
,
e
:
print
e
def
G
():
yield
"A"
;
yield
"B"
;
yield
"C"
print
list
(
enumerate
(
G
()))
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