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
4b096d98
Commit
4b096d98
authored
Aug 11, 2016
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cfg: convert lambdas to function defs
parent
232557a4
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
29 additions
and
47 deletions
+29
-47
src/analysis/function_analysis.cpp
src/analysis/function_analysis.cpp
+0
-6
src/analysis/type_analysis.cpp
src/analysis/type_analysis.cpp
+0
-2
src/codegen/ast_interpreter.cpp
src/codegen/ast_interpreter.cpp
+0
-12
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+2
-2
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+0
-15
src/core/ast.cpp
src/core/ast.cpp
+6
-1
src/core/ast.h
src/core/ast.h
+1
-1
src/core/cfg.cpp
src/core/cfg.cpp
+19
-8
src/core/stringpool.h
src/core/stringpool.h
+1
-0
No files found.
src/analysis/function_analysis.cpp
View file @
4b096d98
...
...
@@ -98,12 +98,6 @@ public:
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
->
vreg
==
-
1
)
return
true
;
...
...
src/analysis/type_analysis.cpp
View file @
4b096d98
...
...
@@ -391,8 +391,6 @@ private:
void
*
visit_index
(
AST_Index
*
node
)
override
{
return
getType
(
node
->
value
);
}
void
*
visit_lambda
(
AST_Lambda
*
node
)
override
{
return
typeFromClass
(
function_cls
);
}
void
*
visit_langprimitive
(
AST_LangPrimitive
*
node
)
override
{
switch
(
node
->
opcode
)
{
case
AST_LangPrimitive
:
:
CHECK_EXC_MATCH
:
...
...
src/codegen/ast_interpreter.cpp
View file @
4b096d98
...
...
@@ -103,7 +103,6 @@ private:
Value
visit_expr
(
AST_Expr
*
node
);
Value
visit_extslice
(
AST_ExtSlice
*
node
);
Value
visit_index
(
AST_Index
*
node
);
Value
visit_lambda
(
AST_Lambda
*
node
);
Value
visit_list
(
AST_List
*
node
);
Value
visit_name
(
AST_Name
*
node
);
Value
visit_num
(
AST_Num
*
node
);
...
...
@@ -1481,8 +1480,6 @@ Value ASTInterpreter::visit_expr(AST_expr* node) {
return
visit_compare
((
AST_Compare
*
)
node
);
case
AST_TYPE
:
:
Dict
:
return
visit_dict
((
AST_Dict
*
)
node
);
case
AST_TYPE
:
:
Lambda
:
return
visit_lambda
((
AST_Lambda
*
)
node
);
case
AST_TYPE
:
:
List
:
return
visit_list
((
AST_List
*
)
node
);
case
AST_TYPE
:
:
Name
:
...
...
@@ -1640,15 +1637,6 @@ Value ASTInterpreter::visit_repr(AST_Repr* node) {
return
Value
(
repr
(
v
.
o
),
jit
?
jit
->
emitRepr
(
v
)
:
NULL
);
}
Value
ASTInterpreter
::
visit_lambda
(
AST_Lambda
*
node
)
{
AST_Return
*
expr
=
new
AST_Return
();
expr
->
value
=
node
->
body
;
expr
->
lineno
=
node
->
body
->
lineno
;
std
::
vector
<
AST_stmt
*>
body
=
{
expr
};
return
createFunction
(
node
,
node
->
args
,
body
);
}
Value
ASTInterpreter
::
visit_dict
(
AST_Dict
*
node
)
{
RELEASE_ASSERT
(
node
->
keys
.
size
()
==
node
->
values
.
size
(),
"not implemented"
);
...
...
src/codegen/irgen/hooks.cpp
View file @
4b096d98
...
...
@@ -122,8 +122,8 @@ BORROWED(BoxedString*) SourceInfo::getName() noexcept {
case
AST_TYPE
:
:
ClassDef
:
return
ast_cast
<
AST_ClassDef
>
(
ast
)
->
name
.
getBox
();
case
AST_TYPE
:
:
FunctionDef
:
return
ast_cast
<
AST_FunctionDef
>
(
ast
)
->
name
.
getBox
();
case
AST_TYPE
:
:
Lambda
:
if
(
ast_cast
<
AST_FunctionDef
>
(
ast
)
->
name
!=
InternedString
())
return
ast_cast
<
AST_FunctionDef
>
(
ast
)
->
name
.
getBox
();
return
lambda_name
;
case
AST_TYPE
:
:
Module
:
case
AST_TYPE
:
:
Expression
:
...
...
src/codegen/irgen/irgenerator.cpp
View file @
4b096d98
...
...
@@ -1281,18 +1281,6 @@ private:
CompilerVariable
*
evalIndex
(
AST_Index
*
node
,
const
UnwindInfo
&
unw_info
)
{
return
evalExpr
(
node
->
value
,
unw_info
);
}
CompilerVariable
*
evalLambda
(
AST_Lambda
*
node
,
const
UnwindInfo
&
unw_info
)
{
AST_Return
*
expr
=
new
AST_Return
();
expr
->
value
=
node
->
body
;
expr
->
lineno
=
node
->
body
->
lineno
;
std
::
vector
<
AST_stmt
*>
body
=
{
expr
};
CompilerVariable
*
func
=
_createFunction
(
node
,
unw_info
,
node
->
args
,
body
);
ConcreteCompilerVariable
*
converted
=
func
->
makeConverted
(
emitter
,
func
->
getBoxType
());
return
converted
;
}
CompilerVariable
*
evalList
(
AST_List
*
node
,
const
UnwindInfo
&
unw_info
)
{
std
::
vector
<
CompilerVariable
*>
elts
;
...
...
@@ -1844,9 +1832,6 @@ private:
case
AST_TYPE
:
:
Dict
:
rtn
=
evalDict
(
ast_cast
<
AST_Dict
>
(
node
),
unw_info
);
break
;
case
AST_TYPE
:
:
Lambda
:
rtn
=
evalLambda
(
ast_cast
<
AST_Lambda
>
(
node
),
unw_info
);
break
;
case
AST_TYPE
:
:
List
:
rtn
=
evalList
(
ast_cast
<
AST_List
>
(
node
),
unw_info
);
break
;
...
...
src/core/ast.cpp
View file @
4b096d98
...
...
@@ -1405,7 +1405,12 @@ bool PrintVisitor::visit_functiondef(AST_FunctionDef* node) {
printIndent
();
}
stream
<<
"def "
<<
node
->
name
.
s
()
<<
"("
;
stream
<<
"def "
;
if
(
node
->
name
!=
InternedString
())
stream
<<
node
->
name
.
s
();
else
stream
<<
"<lambda>"
;
stream
<<
"("
;
node
->
args
->
accept
(
this
);
stream
<<
")"
;
...
...
src/core/ast.h
View file @
4b096d98
...
...
@@ -542,7 +542,7 @@ class AST_FunctionDef : public AST_stmt {
public:
std
::
vector
<
AST_stmt
*>
body
;
std
::
vector
<
AST_expr
*>
decorator_list
;
InternedString
name
;
InternedString
name
;
// if the name is not set this is a lambda
AST_arguments
*
args
;
virtual
void
accept
(
ASTVisitor
*
v
);
...
...
src/core/cfg.cpp
View file @
4b096d98
...
...
@@ -1199,14 +1199,25 @@ private:
}
AST_expr
*
remapLambda
(
AST_Lambda
*
node
)
{
auto
rtn
=
new
AST_Lambda
();
rtn
->
body
=
node
->
body
;
// don't remap now; will be CFG'ed later
rtn
->
args
=
remapArguments
(
node
->
args
);
rtn
->
lineno
=
node
->
lineno
;
rtn
->
col_offset
=
node
->
col_offset
;
// lambdas create scope, need to register as replacement
scoping_analysis
->
registerScopeReplacement
(
node
,
rtn
);
return
rtn
;
// we convert lambdas into normal functions (but don't give it a name)
auto
def
=
new
AST_FunctionDef
();
def
->
lineno
=
node
->
lineno
;
def
->
col_offset
=
node
->
col_offset
;
auto
stmt
=
new
AST_Return
;
stmt
->
lineno
=
node
->
lineno
;
stmt
->
col_offset
=
node
->
col_offset
;
stmt
->
value
=
node
->
body
;
// don't remap now; will be CFG'ed later
def
->
body
=
{
stmt
};
def
->
args
=
remapArguments
(
node
->
args
);
scoping_analysis
->
registerScopeReplacement
(
node
,
def
);
auto
tmp
=
nodeName
();
pushAssign
(
tmp
,
new
AST_MakeFunction
(
def
));
return
makeLoad
(
tmp
,
def
,
/* is_kill */
false
);
}
AST_expr
*
remapLangPrimitive
(
AST_LangPrimitive
*
node
)
{
...
...
src/core/stringpool.h
View file @
4b096d98
...
...
@@ -75,6 +75,7 @@ public:
// assert(this->pool == rhs.pool || this->pool == invalidPool() || rhs.pool == invalidPool());
return
this
->
_str
==
rhs
.
_str
;
}
bool
operator
!=
(
InternedString
rhs
)
const
{
return
!
(
*
this
==
rhs
);
}
// This function compares the actual string contents
bool
operator
<
(
InternedString
rhs
)
const
{
return
this
->
s
().
compare
(
rhs
.
s
())
==
-
1
;
}
...
...
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