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
b905e1e0
Commit
b905e1e0
authored
Mar 20, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make more use of the new slots
parent
23fe2a16
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
10 deletions
+54
-10
src/core/cfg.cpp
src/core/cfg.cpp
+4
-5
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+20
-0
src/runtime/iterobject.cpp
src/runtime/iterobject.cpp
+24
-3
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+4
-2
src/runtime/str.cpp
src/runtime/str.cpp
+1
-0
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+1
-0
No files found.
src/core/cfg.cpp
View file @
b905e1e0
...
...
@@ -249,9 +249,6 @@ private:
InternedString
iter_name
=
nodeName
(
node
,
"lc_iter"
,
i
);
pushAssign
(
iter_name
,
iter_call
);
// TODO bad to save these like this?
AST_expr
*
hasnext_attr
=
makeLoadAttribute
(
makeName
(
iter_name
,
AST_TYPE
::
Load
,
node
->
lineno
),
internString
(
"__hasnext__"
),
true
);
AST_expr
*
next_attr
=
makeLoadAttribute
(
makeName
(
iter_name
,
AST_TYPE
::
Load
,
node
->
lineno
),
internString
(
"next"
),
true
);
...
...
@@ -267,7 +264,9 @@ private:
push_back
(
j
);
curblock
=
test_block
;
AST_expr
*
test_call
=
callNonzero
(
remapExpr
(
makeCall
(
hasnext_attr
)));
AST_LangPrimitive
*
test_call
=
new
AST_LangPrimitive
(
AST_LangPrimitive
::
HASNEXT
);
test_call
->
args
.
push_back
(
makeName
(
iter_name
,
AST_TYPE
::
Load
,
node
->
lineno
));
AST_expr
*
test
=
remapExpr
(
test_call
);
CFGBlock
*
body_block
=
cfg
->
addBlock
();
body_block
->
info
=
"comprehension_body"
;
...
...
@@ -279,7 +278,7 @@ private:
AST_Branch
*
br
=
new
AST_Branch
();
br
->
col_offset
=
node
->
col_offset
;
br
->
lineno
=
node
->
lineno
;
br
->
test
=
test
_call
;
br
->
test
=
test
;
br
->
iftrue
=
body_block
;
br
->
iffalse
=
exit_block
;
curblock
->
connectTo
(
body_block
);
...
...
src/runtime/classobj.cpp
View file @
b905e1e0
...
...
@@ -166,6 +166,15 @@ static Box* classobjGetattribute(Box* _cls, Box* _attr) {
return
r
;
}
static
Box
*
classobj_getattro
(
Box
*
cls
,
Box
*
attr
)
noexcept
{
try
{
return
classobjGetattribute
(
cls
,
attr
);
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
NULL
;
}
}
Box
*
classobjStr
(
Box
*
_obj
)
{
if
(
!
isSubclass
(
_obj
->
cls
,
classobj_cls
))
{
raiseExcHelper
(
TypeError
,
"descriptor '__str__' requires a 'classobj' object but received an '%s'"
,
...
...
@@ -225,6 +234,15 @@ Box* instanceGetattribute(Box* _inst, Box* _attr) {
return
_instanceGetattribute
(
_inst
,
_attr
,
true
);
}
static
Box
*
instance_getattro
(
Box
*
cls
,
Box
*
attr
)
noexcept
{
try
{
return
instanceGetattribute
(
cls
,
attr
);
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
NULL
;
}
}
Box
*
instanceSetattr
(
Box
*
_inst
,
Box
*
_attr
,
Box
*
value
)
{
RELEASE_ASSERT
(
_inst
->
cls
==
instance_cls
,
""
);
BoxedInstance
*
inst
=
static_cast
<
BoxedInstance
*>
(
_inst
);
...
...
@@ -418,6 +436,7 @@ void setupClassobj() {
classobj_cls
->
giveAttr
(
"__dict__"
,
dict_descr
);
classobj_cls
->
freeze
();
classobj_cls
->
tp_getattro
=
classobj_getattro
;
instance_cls
->
giveAttr
(
"__getattribute__"
,
...
...
@@ -434,5 +453,6 @@ void setupClassobj() {
instance_cls
->
giveAttr
(
"__hash__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceHash
,
UNKNOWN
,
1
)));
instance_cls
->
freeze
();
instance_cls
->
tp_getattro
=
instance_getattro
;
}
}
src/runtime/iterobject.cpp
View file @
b905e1e0
...
...
@@ -39,6 +39,21 @@ Box* seqiterIter(Box* s) {
return
s
;
}
bool
seqiterHasnextUnboxed
(
Box
*
s
)
{
RELEASE_ASSERT
(
s
->
cls
==
seqiter_cls
||
s
->
cls
==
seqreviter_cls
,
""
);
BoxedSeqIter
*
self
=
static_cast
<
BoxedSeqIter
*>
(
s
);
Box
*
next
;
try
{
next
=
getitem
(
self
->
b
,
boxInt
(
self
->
idx
));
}
catch
(
ExcInfo
e
)
{
return
false
;
}
self
->
idx
++
;
self
->
next
=
next
;
return
true
;
}
Box
*
seqiterHasnext
(
Box
*
s
)
{
RELEASE_ASSERT
(
s
->
cls
==
seqiter_cls
||
s
->
cls
==
seqreviter_cls
,
""
);
BoxedSeqIter
*
self
=
static_cast
<
BoxedSeqIter
*>
(
s
);
...
...
@@ -107,7 +122,7 @@ static void iterwrapperGCVisit(GCVisitor* v, Box* b) {
v
->
visit
(
iw
->
next
);
}
Box
*
iterwrapperHasnext
(
Box
*
s
)
{
bool
iterwrapperHasnextUnboxed
(
Box
*
s
)
{
RELEASE_ASSERT
(
s
->
cls
==
iterwrapper_cls
,
""
);
BoxedIterWrapper
*
self
=
static_cast
<
BoxedIterWrapper
*>
(
s
);
...
...
@@ -119,12 +134,16 @@ Box* iterwrapperHasnext(Box* s) {
}
catch
(
ExcInfo
e
)
{
if
(
e
.
matches
(
StopIteration
))
{
self
->
next
=
NULL
;
return
F
alse
;
return
f
alse
;
}
throw
e
;
}
self
->
next
=
next
;
return
True
;
return
true
;
}
Box
*
iterwrapperHasnext
(
Box
*
s
)
{
return
boxBool
(
iterwrapperHasnextUnboxed
(
s
));
}
Box
*
iterwrapperNext
(
Box
*
s
)
{
...
...
@@ -155,6 +174,7 @@ void setupIter() {
seqiter_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
seqiterIter
,
UNKNOWN
,
1
)));
seqiter_cls
->
freeze
();
seqiter_cls
->
tpp_hasnext
=
seqiterHasnextUnboxed
;
seqreviter_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"reversed"
);
...
...
@@ -172,5 +192,6 @@ void setupIter() {
new
BoxedFunction
(
boxRTFunction
((
void
*
)
iterwrapperHasnext
,
BOXED_BOOL
,
1
)));
iterwrapper_cls
->
freeze
();
iterwrapper_cls
->
tpp_hasnext
=
iterwrapperHasnextUnboxed
;
}
}
src/runtime/objmodel.cpp
View file @
b905e1e0
...
...
@@ -3676,14 +3676,16 @@ extern "C" Box* createBoxedIterWrapperIfNeeded(Box* o) {
}
}
if
(
typeLookup
(
o
->
cls
,
hasnext_str
,
NULL
)
==
NULL
)
// assert((typeLookup(o->cls, hasnext_str, NULL) == NULL) == (o->cls->tpp_hasnext == object_cls->tpp_hasnext));
if
(
o
->
cls
->
tpp_hasnext
==
object_cls
->
tpp_hasnext
)
return
new
BoxedIterWrapper
(
o
);
return
o
;
}
extern
"C"
Box
*
getPystonIter
(
Box
*
o
)
{
Box
*
r
=
getiter
(
o
);
if
(
typeLookup
(
r
->
cls
,
hasnext_str
,
NULL
)
==
NULL
)
// assert((typeLookup(r->cls, hasnext_str, NULL) == NULL) == (r->cls->tpp_hasnext == object_cls->tpp_hasnext));
if
(
r
->
cls
->
tpp_hasnext
==
object_cls
->
tpp_hasnext
)
return
new
BoxedIterWrapper
(
r
);
return
r
;
}
...
...
src/runtime/str.cpp
View file @
b905e1e0
...
...
@@ -2419,6 +2419,7 @@ void setupStr() {
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedStringIterator
::
hasnext
,
BOXED_BOOL
,
1
)));
str_iterator_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedStringIterator
::
next
,
STR
,
1
)));
str_iterator_cls
->
freeze
();
str_iterator_cls
->
tpp_hasnext
=
(
BoxedClass
::
pyston_inquiry
)
BoxedStringIterator
::
hasnextUnboxed
;
str_cls
->
tp_as_buffer
=
&
string_as_buffer
;
...
...
src/runtime/tuple.cpp
View file @
b905e1e0
...
...
@@ -428,6 +428,7 @@ void setupTuple() {
tuple_iterator_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleiterNext
,
UNKNOWN
,
1
)));
tuple_iterator_cls
->
freeze
();
tuple_iterator_cls
->
tpp_hasnext
=
tupleiterHasnextUnboxed
;
}
void
teardownTuple
()
{
...
...
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