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
5341455f
Commit
5341455f
authored
May 20, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some minor improvements
parent
79b7ab49
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
27 deletions
+81
-27
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+20
-27
test/tests/descriptor_ics.py
test/tests/descriptor_ics.py
+37
-0
test/tests/dunder_descriptors.py
test/tests/dunder_descriptors.py
+24
-0
No files found.
src/runtime/objmodel.cpp
View file @
5341455f
...
@@ -1731,17 +1731,16 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
...
@@ -1731,17 +1731,16 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
}
}
// TODO patch these cases
// TODO patch these cases
if
(
rewrite_args
)
{
assert
(
rewrite_args
->
out_success
==
false
);
rewrite_args
=
NULL
;
}
std
::
string
rop_name
=
getReverseOpName
(
op_type
);
std
::
string
rop_name
=
getReverseOpName
(
op_type
);
Box
*
rattr_func
=
getattr_internal
(
rhs
->
cls
,
rop_name
,
false
,
false
,
NULL
,
NULL
);
Box
*
rrtn
=
callattrInternal1
(
rhs
,
&
rop_name
,
CLASS_ONLY
,
NULL
,
1
,
lhs
);
if
(
rattr_func
)
{
if
(
rrtn
!=
NULL
&&
rrtn
!=
NotImplemented
)
Box
*
rtn
=
runtimeCall2
(
rattr_func
,
2
,
rhs
,
lhs
);
return
rrtn
;
if
(
rtn
!=
NotImplemented
)
{
return
rtn
;
}
}
else
{
// printf("rfunc doesn't exist\n");
}
llvm
::
StringRef
op_sym
=
getOpSymbol
(
op_type
);
llvm
::
StringRef
op_sym
=
getOpSymbol
(
op_type
);
const
char
*
op_sym_suffix
=
""
;
const
char
*
op_sym_suffix
=
""
;
...
@@ -1762,7 +1761,7 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
...
@@ -1762,7 +1761,7 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
fprintf
(
stderr
,
"%s has %s, but returned NotImplemented
\n
"
,
getTypeName
(
lhs
)
->
c_str
(),
op_name
.
c_str
());
fprintf
(
stderr
,
"%s has %s, but returned NotImplemented
\n
"
,
getTypeName
(
lhs
)
->
c_str
(),
op_name
.
c_str
());
else
else
fprintf
(
stderr
,
"%s does not have %s
\n
"
,
getTypeName
(
lhs
)
->
c_str
(),
op_name
.
c_str
());
fprintf
(
stderr
,
"%s does not have %s
\n
"
,
getTypeName
(
lhs
)
->
c_str
(),
op_name
.
c_str
());
if
(
r
attr_func
)
if
(
r
rtn
)
fprintf
(
stderr
,
"%s has %s, but returned NotImplemented
\n
"
,
getTypeName
(
rhs
)
->
c_str
(),
rop_name
.
c_str
());
fprintf
(
stderr
,
"%s has %s, but returned NotImplemented
\n
"
,
getTypeName
(
rhs
)
->
c_str
(),
rop_name
.
c_str
());
else
else
fprintf
(
stderr
,
"%s does not have %s
\n
"
,
getTypeName
(
rhs
)
->
c_str
(),
rop_name
.
c_str
());
fprintf
(
stderr
,
"%s does not have %s
\n
"
,
getTypeName
(
rhs
)
->
c_str
(),
rop_name
.
c_str
());
...
@@ -1877,7 +1876,7 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
...
@@ -1877,7 +1876,7 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
ASSERT
(
isUserDefined
(
rhs
->
cls
),
"%s should probably have a __contains__"
,
getTypeName
(
rhs
)
->
c_str
());
ASSERT
(
isUserDefined
(
rhs
->
cls
),
"%s should probably have a __contains__"
,
getTypeName
(
rhs
)
->
c_str
());
RELEASE_ASSERT
(
iter
==
NULL
,
"need to try iterating"
);
RELEASE_ASSERT
(
iter
==
NULL
,
"need to try iterating"
);
Box
*
getitem
=
getattr_internal
(
rhs
,
"__getitem__"
,
false
,
false
,
NULL
,
NULL
);
Box
*
getitem
=
typeLookup
(
rhs
->
cls
,
"__getitem__"
,
NULL
,
NULL
);
if
(
getitem
)
if
(
getitem
)
ASSERT
(
isUserDefined
(
rhs
->
cls
),
"%s should probably have a __contains__"
,
getTypeName
(
rhs
)
->
c_str
());
ASSERT
(
isUserDefined
(
rhs
->
cls
),
"%s should probably have a __contains__"
,
getTypeName
(
rhs
)
->
c_str
());
RELEASE_ASSERT
(
getitem
==
NULL
,
"need to try old iteration protocol"
);
RELEASE_ASSERT
(
getitem
==
NULL
,
"need to try old iteration protocol"
);
...
@@ -1930,24 +1929,18 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
...
@@ -1930,24 +1929,18 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
}
else
{
}
else
{
}
}
std
::
string
rop_name
=
getReverseOpName
(
op_type
);
Box
*
rattr_func
=
getattr_internal
(
rhs
->
cls
,
rop_name
,
false
,
false
,
NULL
,
NULL
);
// TODO patch these cases
if
(
rattr_func
)
{
if
(
rewrite_args
)
{
Box
*
rtn
=
runtimeCall2
(
rattr_func
,
2
,
rhs
,
lhs
);
assert
(
rewrite_args
->
out_success
==
false
);
if
(
rtn
!=
NotImplemented
)
{
rewrite_args
=
NULL
;
////printf("rfunc returned NotImplemented\n");
////bool can_patchpoint = lhs->cls->is_constant && (lattr_func == NULL || (lattr;
// bool can_patchpoint = !isUserDefined(lhs->cls) && lhs->cls->is_constant;
// if (can_patchpoint && rhs->cls->is_constant && rattr_func->cls == function_cls) {
// void* rtn_addr = __builtin_extract_return_addr(__builtin_return_address(0));
//_repatchBinExp(rtn_addr, true, lhs, rhs, rattr_func);
//}
return
rtn
;
}
}
else
{
// printf("rfunc doesn't exist\n");
}
}
std
::
string
rop_name
=
getReverseOpName
(
op_type
);
Box
*
rrtn
=
callattrInternal1
(
rhs
,
&
rop_name
,
CLASS_ONLY
,
NULL
,
1
,
lhs
);
if
(
rrtn
!=
NULL
&&
rrtn
!=
NotImplemented
)
return
rrtn
;
if
(
op_type
==
AST_TYPE
::
Eq
)
if
(
op_type
==
AST_TYPE
::
Eq
)
return
boxBool
(
lhs
==
rhs
);
return
boxBool
(
lhs
==
rhs
);
...
...
test/tests/descriptor_ics.py
0 → 100644
View file @
5341455f
# expected: fail
# - descriptors not implemented yet
# Make sure that we guard in a getattr IC to make sure that
# we don't subsequently get an object with a __get__ defined.
class
D
(
object
):
pass
class
C
(
object
):
d
=
D
()
c
=
C
()
def
print_d
(
c
):
print
c
.
d
print_d
(
c
)
def
get
(
self
,
obj
,
cls
):
print
self
,
obj
,
cls
return
1
D
.
__get__
=
get
print_d
(
c
)
# And also the other way around:
del
D
.
__get__
print_d
(
c
)
class
E
(
object
):
def
__get__
(
self
,
obj
,
cls
):
print
"E.__get__"
return
2
C
.
d
=
E
()
# Or if we switch out the object entirely:
print_d
(
c
)
test/tests/dunder_descriptors.py
0 → 100644
View file @
5341455f
# expected: fail
# - descriptors
# Descriptors get processed when fetched as part of a dunder lookup
class
D
(
object
):
def
__get__
(
self
,
obj
,
cls
):
print
"__get__()"
,
obj
is
None
def
desc
():
print
"desc()"
return
1
return
desc
def
__call__
(
self
):
print
"D.call"
return
2
class
C
(
object
):
__hash__
=
D
()
c
=
C
()
print
C
.
__hash__
()
print
c
.
__hash__
()
print
hash
(
c
)
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