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
2775f89f
Commit
2775f89f
authored
Oct 18, 2014
by
Travis Hance
Committed by
Travis Hance
Oct 29, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made property with get
parent
cd73ad20
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
2 deletions
+46
-2
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+1
-0
src/runtime/descr.cpp
src/runtime/descr.cpp
+13
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+10
-0
src/runtime/types.cpp
src/runtime/types.cpp
+2
-1
src/runtime/types.h
src/runtime/types.h
+12
-1
test/tests/property.py
test/tests/property.py
+8
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
2775f89f
...
...
@@ -826,5 +826,6 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"instancemethod"
,
instancemethod_cls
);
builtins_module
->
giveAttr
(
"complex"
,
complex_cls
);
builtins_module
->
giveAttr
(
"super"
,
super_cls
);
builtins_module
->
giveAttr
(
"property"
,
property_cls
);
}
}
src/runtime/descr.cpp
View file @
2775f89f
...
...
@@ -23,10 +23,23 @@ static Box* memberGet(BoxedMemberDescriptor* self, Box* inst, Box* owner) {
Py_FatalError
(
"unimplemented"
);
}
static
Box
*
propertyNew
(
Box
*
cls
,
Box
*
fget
,
Box
*
fset
,
Box
**
args
)
{
RELEASE_ASSERT
(
cls
==
property_cls
,
""
);
Box
*
fdel
=
args
[
0
];
Box
*
doc
=
args
[
1
];
return
new
BoxedProperty
(
fget
,
fset
,
fdel
,
doc
);
}
void
setupDescr
()
{
member_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"member"
));
member_cls
->
giveAttr
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
memberGet
,
UNKNOWN
,
3
)));
member_cls
->
freeze
();
property_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"property"
));
property_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
propertyNew
,
UNKNOWN
,
5
,
4
,
false
,
false
),
{
None
,
None
,
None
,
None
}));
property_cls
->
freeze
();
}
void
teardownDescr
()
{
...
...
src/runtime/objmodel.cpp
View file @
2775f89f
...
...
@@ -907,6 +907,16 @@ Box* dataDescriptorInstanceSpecialCases(GetattrRewriteArgs* rewrite_args, const
}
}
else
if
(
descr
->
cls
==
property_cls
)
{
rewrite_args
=
NULL
;
// TODO
BoxedProperty
*
prop
=
static_cast
<
BoxedProperty
*>
(
descr
);
if
(
prop
->
prop_get
==
NULL
||
prop
->
prop_get
==
None
)
{
raiseExcHelper
(
AttributeError
,
"unreadable attribute"
);
}
return
runtimeCallInternal1
(
prop
->
prop_get
,
NULL
,
ArgPassSpec
(
1
),
obj
);
}
return
NULL
;
}
...
...
src/runtime/types.cpp
View file @
2775f89f
...
...
@@ -291,7 +291,7 @@ extern "C" void closureGCHandler(GCVisitor* v, Box* b) {
extern
"C"
{
BoxedClass
*
object_cls
,
*
type_cls
,
*
none_cls
,
*
bool_cls
,
*
int_cls
,
*
float_cls
,
*
str_cls
,
*
function_cls
,
*
instancemethod_cls
,
*
list_cls
,
*
slice_cls
,
*
module_cls
,
*
dict_cls
,
*
tuple_cls
,
*
file_cls
,
*
member_cls
,
*
closure_cls
,
*
generator_cls
,
*
complex_cls
,
*
basestring_cls
,
*
unicode_cls
;
*
closure_cls
,
*
generator_cls
,
*
complex_cls
,
*
basestring_cls
,
*
unicode_cls
,
*
property_cls
;
BoxedTuple
*
EmptyTuple
;
...
...
@@ -700,6 +700,7 @@ void setupRuntime() {
member_cls
=
new
BoxedClass
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
BoxedMemberDescriptor
),
false
);
closure_cls
=
new
BoxedClass
(
type_cls
,
object_cls
,
&
closureGCHandler
,
offsetof
(
BoxedClosure
,
attrs
),
sizeof
(
BoxedClosure
),
false
);
property_cls
=
new
BoxedClass
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
BoxedProperty
),
false
);
attrwrapper_cls
=
new
BoxedClass
(
type_cls
,
object_cls
,
&
AttrWrapper
::
gcHandler
,
0
,
sizeof
(
AttrWrapper
),
false
);
STR
=
typeFromClass
(
str_cls
);
...
...
src/runtime/types.h
View file @
2775f89f
...
...
@@ -80,7 +80,7 @@ Box* getSysStdout();
extern
"C"
{
extern
BoxedClass
*
object_cls
,
*
type_cls
,
*
bool_cls
,
*
int_cls
,
*
long_cls
,
*
float_cls
,
*
str_cls
,
*
function_cls
,
*
none_cls
,
*
instancemethod_cls
,
*
list_cls
,
*
slice_cls
,
*
module_cls
,
*
dict_cls
,
*
tuple_cls
,
*
file_cls
,
*
xrange_cls
,
*
member_cls
,
*
method_cls
,
*
closure_cls
,
*
generator_cls
,
*
complex_cls
,
*
basestring_cls
,
*
unicode_cls
;
*
member_cls
,
*
method_cls
,
*
closure_cls
,
*
generator_cls
,
*
complex_cls
,
*
basestring_cls
,
*
unicode_cls
,
*
property_cls
;
}
extern
"C"
{
extern
Box
*
None
,
*
NotImplemented
,
*
True
,
*
False
;
}
extern
"C"
{
...
...
@@ -390,6 +390,17 @@ public:
:
Box
(
member_cls
),
type
((
MemberType
)
member
->
type
),
offset
(
member
->
offset
)
{}
};
class
BoxedProperty
:
public
Box
{
public:
Box
*
prop_get
;
Box
*
prop_set
;
Box
*
prop_del
;
Box
*
prop_doc
;
BoxedProperty
(
Box
*
get
,
Box
*
set
,
Box
*
del
,
Box
*
doc
)
:
Box
(
property_cls
),
prop_get
(
get
),
prop_set
(
set
),
prop_del
(
del
),
prop_doc
(
doc
)
{}
};
// TODO is there any particular reason to make this a Box, ie a python-level object?
class
BoxedClosure
:
public
Box
{
public:
...
...
test/tests/property.py
0 → 100644
View file @
2775f89f
class
C
(
object
):
def
fget
(
self
):
return
5
x
=
property
(
fget
)
c
=
C
()
print
c
.
x
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