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
36f59af3
Commit
36f59af3
authored
Apr 25, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement set iterator
parent
6922f0e7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
6 deletions
+63
-6
src/codegen/parser.cpp
src/codegen/parser.cpp
+0
-1
src/runtime/list.cpp
src/runtime/list.cpp
+11
-0
src/runtime/set.cpp
src/runtime/set.cpp
+52
-1
test/tests/set.py
test/tests/set.py
+0
-4
No files found.
src/codegen/parser.cpp
View file @
36f59af3
...
...
@@ -761,7 +761,6 @@ static void _reparse(const char* fn, const std::string &cache_fn) {
llvm
::
sys
::
path
::
append
(
parse_ast_fn
,
"codegen/parse_ast.py"
);
std
::
string
cmdline
=
std
::
string
(
"python -S "
)
+
parse_ast_fn
.
str
().
str
()
+
" "
+
fn
;
printf
(
"%s
\n
"
,
cmdline
.
c_str
());
FILE
*
parser
=
popen
(
cmdline
.
c_str
(),
"r"
);
FILE
*
cache_fp
=
fopen
(
cache_fn
.
c_str
(),
"w"
);
assert
(
cache_fp
);
...
...
src/runtime/list.cpp
View file @
36f59af3
...
...
@@ -14,6 +14,7 @@
#include <cstring>
#include <sstream>
#include <algorithm>
#include "core/common.h"
#include "core/stats.h"
...
...
@@ -267,6 +268,14 @@ Box* listAdd(BoxedList* self, Box* _rhs) {
return
rtn
;
}
Box
*
listSort1
(
BoxedList
*
self
)
{
assert
(
self
->
cls
==
list_cls
);
std
::
sort
<
Box
**
,
PyLt
>
(
self
->
elts
->
elts
,
self
->
elts
->
elts
+
self
->
size
,
PyLt
());
return
None
;
}
BoxedClass
*
list_iterator_cls
=
NULL
;
extern
"C"
void
listIteratorGCHandler
(
GCVisitor
*
v
,
void
*
p
)
{
boxGCHandler
(
v
,
p
);
...
...
@@ -337,6 +346,8 @@ void setupList() {
list_cls
->
giveAttr
(
"__iadd__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listIAdd
,
NULL
,
2
,
false
)));
list_cls
->
giveAttr
(
"__add__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listAdd
,
NULL
,
2
,
false
)));
list_cls
->
giveAttr
(
"sort"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listSort1
,
NULL
,
1
,
false
)));
CLFunction
*
new_
=
boxRTFunction
((
void
*
)
listNew1
,
NULL
,
1
,
false
);
addRTFunction
(
new_
,
(
void
*
)
listNew2
,
NULL
,
2
,
false
);
list_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
new_
));
...
...
src/runtime/set.cpp
View file @
36f59af3
...
...
@@ -22,8 +22,42 @@
namespace
pyston
{
BoxedClass
*
set_cls
;
BoxedClass
*
set_cls
,
*
set_iterator_cls
;
const
ObjectFlavor
set_flavor
(
&
boxGCHandler
,
NULL
);
const
ObjectFlavor
set_iterator_flavor
(
&
boxGCHandler
,
NULL
);
namespace
set
{
class
BoxedSetIterator
:
public
Box
{
private:
BoxedSet
*
s
;
decltype
(
BoxedSet
::
s
)
::
iterator
it
;
public:
BoxedSetIterator
(
BoxedSet
*
s
)
:
Box
(
&
set_iterator_flavor
,
set_iterator_cls
),
s
(
s
),
it
(
s
->
s
.
begin
())
{
}
bool
hasNext
()
{
return
it
!=
s
->
s
.
end
();
}
Box
*
next
()
{
Box
*
rtn
=
*
it
;
++
it
;
return
rtn
;
}
};
Box
*
setiteratorHasnext
(
BoxedSetIterator
*
self
)
{
assert
(
self
->
cls
==
set_iterator_cls
);
return
boxBool
(
self
->
hasNext
());
}
Box
*
setiteratorNext
(
BoxedSetIterator
*
self
)
{
assert
(
self
->
cls
==
set_iterator_cls
);
return
self
->
next
();
}
Box
*
setAdd2
(
Box
*
_self
,
Box
*
b
)
{
assert
(
_self
->
cls
==
set_cls
);
...
...
@@ -142,9 +176,24 @@ Box* setXorSet(BoxedSet *lhs, BoxedSet *rhs) {
return
rtn
;
}
Box
*
setIter
(
BoxedSet
*
self
)
{
assert
(
self
->
cls
==
set_cls
);
return
new
BoxedSetIterator
(
self
);
}
}
// namespace set
using
namespace
pyston
::
set
;
void
setupSet
()
{
set_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"set"
));
set_iterator_cls
=
new
BoxedClass
(
false
,
NULL
);
set_iterator_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"setiterator"
));
set_iterator_cls
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setiteratorHasnext
,
BOXED_BOOL
,
1
,
false
)));
set_iterator_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setiteratorNext
,
UNKNOWN
,
1
,
false
)));
set_iterator_cls
->
freeze
();
CLFunction
*
new_
=
boxRTFunction
((
void
*
)
setNew1
,
SET
,
1
,
false
);
addRTFunction
(
new_
,
(
void
*
)
setNew2
,
SET
,
2
,
false
);
set_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
new_
));
...
...
@@ -173,6 +222,8 @@ void setupSet() {
addRTFunction
(
and_
,
(
void
*
)
setAndSet
,
SET
,
v_ss
,
false
);
set_cls
->
giveAttr
(
"__and__"
,
new
BoxedFunction
(
and_
));
set_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setIter
,
typeFromClass
(
set_iterator_cls
),
1
,
false
)));
set_cls
->
freeze
();
}
...
...
test/tests/set.py
View file @
36f59af3
...
...
@@ -15,7 +15,3 @@ print sorted(s2 - s1)
print
sorted
(
s1
^
s2
)
print
sorted
(
s1
&
s2
)
print
sorted
(
s1
|
s2
)
s3
=
s1
s1
-=
s2
print
sorted
(
s1
),
sorted
(
s2
),
sorted
(
s3
)
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