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
4c5996eb
Commit
4c5996eb
authored
Jun 29, 2014
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lmabda: execute review comments
parent
87ab64e6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
66 deletions
+53
-66
src/analysis/function_analysis.cpp
src/analysis/function_analysis.cpp
+5
-1
src/analysis/scoping_analysis.cpp
src/analysis/scoping_analysis.cpp
+24
-20
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+0
-31
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+5
-6
src/core/cfg.cpp
src/core/cfg.cpp
+11
-5
src/core/types.h
src/core/types.h
+2
-1
test/tests/lambda.py
test/tests/lambda.py
+6
-2
No files found.
src/analysis/function_analysis.cpp
View file @
4c5996eb
...
...
@@ -67,7 +67,11 @@ public:
return
true
;
}
bool
visit_lambda
(
AST_Lambda
*
node
)
{
return
true
;
}
bool
visit_lambda
(
AST_Lambda
*
node
)
{
for
(
auto
*
d
:
node
->
args
->
defaults
)
d
->
accept
(
this
);
return
true
;
}
bool
visit_name
(
AST_Name
*
node
)
{
if
(
node
->
ctx_type
==
AST_TYPE
::
Load
)
...
...
src/analysis/scoping_analysis.cpp
View file @
4c5996eb
...
...
@@ -235,15 +235,21 @@ public:
}
virtual
bool
visit_lambda
(
AST_Lambda
*
node
)
{
assert
(
node
==
orig_node
);
for
(
AST_expr
*
e
:
node
->
args
->
args
)
e
->
accept
(
this
);
if
(
node
->
args
->
vararg
.
size
())
doWrite
(
node
->
args
->
vararg
);
if
(
node
->
args
->
kwarg
.
size
())
doWrite
(
node
->
args
->
kwarg
);
node
->
body
->
accept
(
this
);
if
(
node
==
orig_node
)
{
for
(
AST_expr
*
e
:
node
->
args
->
args
)
e
->
accept
(
this
);
if
(
node
->
args
->
vararg
.
size
())
doWrite
(
node
->
args
->
vararg
);
if
(
node
->
args
->
kwarg
.
size
())
doWrite
(
node
->
args
->
kwarg
);
node
->
body
->
accept
(
this
);
}
else
{
for
(
auto
*
e
:
node
->
args
->
defaults
)
e
->
accept
(
this
);
(
*
map
)[
node
]
=
new
ScopingAnalysis
::
ScopeNameUsage
(
node
,
cur
);
collect
(
node
,
map
);
}
return
true
;
}
...
...
@@ -293,15 +299,13 @@ static std::vector<ScopingAnalysis::ScopeNameUsage*> sortNameUsages(ScopingAnaly
}
void
ScopingAnalysis
::
processNameUsages
(
ScopingAnalysis
::
NameUsageMap
*
usages
)
{
typedef
ScopeNameUsage
::
StrSet
StrSet
;
// Resolve name lookups:
for
(
const
auto
&
p
:
*
usages
)
{
ScopeNameUsage
*
usage
=
p
.
second
;
for
(
StrSet
::
iterator
it2
=
usage
->
read
.
begin
(),
end2
=
usage
->
read
.
end
();
it2
!=
end2
;
++
it2
)
{
if
(
usage
->
forced_globals
.
count
(
*
it2
))
for
(
const
auto
&
name
:
usage
->
read
)
{
if
(
usage
->
forced_globals
.
count
(
name
))
continue
;
if
(
usage
->
written
.
count
(
*
it2
))
if
(
usage
->
written
.
count
(
name
))
continue
;
std
::
vector
<
ScopeNameUsage
*>
intermediate_parents
;
...
...
@@ -310,15 +314,15 @@ void ScopingAnalysis::processNameUsages(ScopingAnalysis::NameUsageMap* usages) {
while
(
parent
)
{
if
(
parent
->
node
->
type
==
AST_TYPE
::
ClassDef
)
{
parent
=
parent
->
parent
;
}
else
if
(
parent
->
forced_globals
.
count
(
*
it2
))
{
}
else
if
(
parent
->
forced_globals
.
count
(
name
))
{
break
;
}
else
if
(
parent
->
written
.
count
(
*
it2
))
{
usage
->
got_from_closure
.
insert
(
*
it2
);
parent
->
referenced_from_nested
.
insert
(
*
it2
);
}
else
if
(
parent
->
written
.
count
(
name
))
{
usage
->
got_from_closure
.
insert
(
name
);
parent
->
referenced_from_nested
.
insert
(
name
);
for
(
ScopeNameUsage
*
iparent
:
intermediate_parents
)
{
iparent
->
referenced_from_nested
.
insert
(
*
it2
);
iparent
->
got_from_closure
.
insert
(
*
it2
);
iparent
->
referenced_from_nested
.
insert
(
name
);
iparent
->
got_from_closure
.
insert
(
name
);
}
break
;
...
...
src/codegen/irgen/hooks.cpp
View file @
4c5996eb
...
...
@@ -75,37 +75,6 @@ const std::string SourceInfo::getName() {
}
}
/*
const std::vector<AST_expr*>& SourceInfo::getArgNames() {
static std::vector<AST_expr*> empty;
AST_arguments* args = getArgsAST();
if (args == NULL)
return empty;
return args->args;
}
const std::vector<AST_expr*>* CLFunction::getArgNames() {
if (!source)
return NULL;
return &source->getArgNames();
//////////////
const std::vector<AST_stmt*>& SourceInfo::getBody() {
assert(ast);
switch (ast->type) {
case AST_TYPE::FunctionDef:
return ast_cast<AST_FunctionDef>(ast)->body;
case AST_TYPE::Module:
return ast_cast<AST_Module>(ast)->body;
default:
RELEASE_ASSERT(0, "%d", ast->type);
}
}
*/
EffortLevel
::
EffortLevel
initialEffort
()
{
if
(
FORCE_OPTIMIZE
)
return
EffortLevel
::
MAXIMAL
;
...
...
src/codegen/irgen/irgenerator.cpp
View file @
4c5996eb
...
...
@@ -1497,16 +1497,15 @@ private:
CLFunction
*&
cl
=
made
[
node
];
if
(
cl
==
NULL
)
{
SourceInfo
*
si
=
new
SourceInfo
(
irstate
->
getSourceInfo
()
->
parent_module
,
irstate
->
getSourceInfo
()
->
scoping
,
node
,
body
);
cl
=
new
CLFunction
(
args
->
args
.
size
(),
args
->
defaults
.
size
(),
args
->
vararg
.
size
(),
args
->
kwarg
.
size
(),
si
);
SourceInfo
*
si
=
new
SourceInfo
(
irstate
->
getSourceInfo
()
->
parent_module
,
irstate
->
getSourceInfo
()
->
scoping
,
node
,
body
);
cl
=
new
CLFunction
(
args
->
args
.
size
(),
args
->
defaults
.
size
(),
args
->
vararg
.
size
(),
args
->
kwarg
.
size
(),
si
);
}
return
cl
;
}
CompilerVariable
*
createFunction
(
AST
*
node
,
ExcInfo
exc_info
,
AST_arguments
*
args
,
const
std
::
vector
<
AST_stmt
*>&
body
)
{
CompilerVariable
*
createFunction
(
AST
*
node
,
ExcInfo
exc_info
,
AST_arguments
*
args
,
const
std
::
vector
<
AST_stmt
*>&
body
)
{
CLFunction
*
cl
=
this
->
_wrapFunction
(
node
,
args
,
body
);
std
::
vector
<
ConcreteCompilerVariable
*>
defaults
;
...
...
src/core/cfg.cpp
View file @
4c5996eb
...
...
@@ -619,15 +619,21 @@ private:
}
AST_expr
*
remapLambda
(
AST_Lambda
*
node
)
{
if
(
node
->
args
->
defaults
.
empty
())
{
return
node
;
}
AST_Lambda
*
rtn
=
new
AST_Lambda
();
rtn
->
lineno
=
node
->
lineno
;
rtn
->
col_offset
=
node
->
col_offset
;
rtn
->
args
=
node
->
args
;
// remap default arguments
rtn
->
args
->
defaults
.
clear
();
for
(
auto
&
e
:
node
->
args
->
defaults
)
rtn
->
args
->
defaults
.
push_back
(
remapExpr
(
e
));
rtn
->
args
=
new
AST_arguments
();
rtn
->
args
->
args
=
node
->
args
->
args
;
rtn
->
args
->
vararg
=
node
->
args
->
vararg
;
rtn
->
args
->
kwarg
=
node
->
args
->
kwarg
;
for
(
auto
d
:
node
->
args
->
defaults
)
{
rtn
->
args
->
defaults
.
push_back
(
remapExpr
(
d
));
}
rtn
->
body
=
node
->
body
;
return
rtn
;
...
...
src/core/types.h
View file @
4c5996eb
...
...
@@ -223,7 +223,8 @@ public:
const
std
::
string
getName
();
SourceInfo
(
BoxedModule
*
m
,
ScopingAnalysis
*
scoping
,
AST
*
ast
,
const
std
::
vector
<
AST_stmt
*>&
body
)
:
parent_module
(
m
),
scoping
(
scoping
),
ast
(
ast
),
cfg
(
NULL
),
liveness
(
NULL
),
phis
(
NULL
),
arg_names
(
ast
),
body
(
body
)
{}
:
parent_module
(
m
),
scoping
(
scoping
),
ast
(
ast
),
cfg
(
NULL
),
liveness
(
NULL
),
phis
(
NULL
),
arg_names
(
ast
),
body
(
body
)
{}
};
typedef
std
::
vector
<
CompiledFunction
*>
FunctionList
;
...
...
test/tests/lambda.py
View file @
4c5996eb
s
=
lambda
x
:
x
**
2
print
s
(
8
),
s
(
100
)
s
=
lambda
x
=
5
:
x
**
2
print
s
(
8
),
s
(
100
)
,
s
()
for
i
in
range
(
10
):
print
(
lambda
x
,
y
:
x
<
y
)(
i
,
5
)
t
=
lambda
s
:
" "
.
join
(
s
.
split
())
print
t
(
"test
\
t
str
\
n
i
\
n
ng"
)
def
T
(
y
):
return
(
lambda
x
:
x
<
y
)
print
T
(
10
)(
1
),
T
(
10
)(
20
)
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