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
59e195aa
Commit
59e195aa
authored
Aug 25, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #135 from tjhance/module_desc
made __module__ a member descriptor for functions
parents
96e54f92
567d507c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
4 deletions
+15
-4
src/runtime/types.cpp
src/runtime/types.cpp
+10
-4
src/runtime/types.h
src/runtime/types.h
+3
-0
test/tests/68.py
test/tests/68.py
+2
-0
No files found.
src/runtime/types.cpp
View file @
59e195aa
...
...
@@ -89,6 +89,8 @@ llvm::iterator_range<BoxIterator> Box::pyElements() {
raiseExcHelper
(
TypeError
,
"'%s' object is not iterable"
,
getTypeName
(
this
)
->
c_str
());
}
std
::
string
builtinStr
(
"__builtin__"
);
extern
"C"
BoxedFunction
::
BoxedFunction
(
CLFunction
*
f
)
:
Box
(
function_cls
),
f
(
f
),
closure
(
NULL
),
isGenerator
(
false
),
ndefaults
(
0
),
defaults
(
NULL
)
{
if
(
f
->
source
)
{
...
...
@@ -96,8 +98,9 @@ extern "C" BoxedFunction::BoxedFunction(CLFunction* f)
// this->giveAttr("__name__", boxString(&f->source->ast->name));
this
->
giveAttr
(
"__name__"
,
boxString
(
f
->
source
->
getName
()));
Box
*
modname
=
f
->
source
->
parent_module
->
getattr
(
"__name__"
,
NULL
);
this
->
giveAttr
(
"__module__"
,
modname
);
this
->
modname
=
f
->
source
->
parent_module
->
getattr
(
"__name__"
,
NULL
);
}
else
{
this
->
modname
=
boxStringPtr
(
&
builtinStr
);
}
this
->
giveAttr
(
"__doc__"
,
None
);
...
...
@@ -121,8 +124,9 @@ extern "C" BoxedFunction::BoxedFunction(CLFunction* f, std::initializer_list<Box
// this->giveAttr("__name__", boxString(&f->source->ast->name));
this
->
giveAttr
(
"__name__"
,
boxString
(
f
->
source
->
getName
()));
Box
*
modname
=
f
->
source
->
parent_module
->
getattr
(
"__name__"
,
NULL
);
this
->
giveAttr
(
"__module__"
,
modname
);
this
->
modname
=
f
->
source
->
parent_module
->
getattr
(
"__name__"
,
NULL
);
}
else
{
this
->
modname
=
boxStringPtr
(
&
builtinStr
);
}
this
->
giveAttr
(
"__doc__"
,
None
);
...
...
@@ -748,6 +752,8 @@ void setupRuntime() {
function_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"function"
));
function_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
functionRepr
,
STR
,
1
)));
function_cls
->
giveAttr
(
"__str__"
,
function_cls
->
getattr
(
"__repr__"
));
function_cls
->
giveAttr
(
"__module__"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedFunction
,
modname
)));
function_cls
->
freeze
();
instancemethod_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"instancemethod"
));
...
...
src/runtime/types.h
View file @
59e195aa
...
...
@@ -299,6 +299,9 @@ public:
int
ndefaults
;
GCdArray
*
defaults
;
// Accessed via member descriptor
Box
*
modname
;
// __module__
BoxedFunction
(
CLFunction
*
f
);
BoxedFunction
(
CLFunction
*
f
,
std
::
initializer_list
<
Box
*>
defaults
,
BoxedClosure
*
closure
=
NULL
,
bool
isGenerator
=
false
);
...
...
test/tests/68.py
View file @
59e195aa
...
...
@@ -3,3 +3,5 @@ def f():
print
f
.
__name__
print
f
.
__module__
print
sum
.
__module__
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