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
17b548d9
Commit
17b548d9
authored
Oct 04, 2016
by
Marius Wachtler
Committed by
Boxiang Sun
Oct 20, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BST: use constant table for the interned strings
parent
53a1a557
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
174 additions
and
132 deletions
+174
-132
src/analysis/type_analysis.cpp
src/analysis/type_analysis.cpp
+11
-7
src/codegen/ast_interpreter.cpp
src/codegen/ast_interpreter.cpp
+30
-27
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+32
-26
src/core/bst.cpp
src/core/bst.cpp
+11
-11
src/core/bst.h
src/core/bst.h
+11
-11
src/core/cfg.cpp
src/core/cfg.cpp
+65
-50
src/core/stringpool.h
src/core/stringpool.h
+8
-0
src/runtime/types.h
src/runtime/types.h
+6
-0
No files found.
src/analysis/type_analysis.cpp
View file @
17b548d9
...
...
@@ -279,10 +279,11 @@ private:
void
visit_callattr
(
BST_CallAttr
*
node
)
override
{
CompilerType
*
t
=
getType
(
node
->
vreg_value
);
CompilerType
*
func
=
t
->
getattrType
(
node
->
attr
,
false
);
InternedString
attr
=
getCodeConstants
().
getInternedString
(
node
->
index_attr
);
CompilerType
*
func
=
t
->
getattrType
(
attr
,
false
);
if
(
VERBOSITY
()
>=
2
&&
func
==
UNDEF
)
{
printf
(
"Think %s.%s is undefined, at %d
\n
"
,
t
->
debugName
().
c_str
(),
node
->
attr
.
c_str
(),
node
->
lineno
);
printf
(
"Think %s.%s is undefined, at %d
\n
"
,
t
->
debugName
().
c_str
(),
attr
.
c_str
(),
node
->
lineno
);
print_bst
(
node
,
code_constants
);
printf
(
"
\n
"
);
}
...
...
@@ -292,10 +293,11 @@ private:
void
visit_callclsattr
(
BST_CallClsAttr
*
node
)
override
{
CompilerType
*
t
=
getType
(
node
->
vreg_value
);
CompilerType
*
func
=
t
->
getattrType
(
node
->
attr
,
true
);
InternedString
attr
=
getCodeConstants
().
getInternedString
(
node
->
index_attr
);
CompilerType
*
func
=
t
->
getattrType
(
attr
,
true
);
if
(
VERBOSITY
()
>=
2
&&
func
==
UNDEF
)
{
printf
(
"Think %s.%s is undefined, at %d
\n
"
,
t
->
debugName
().
c_str
(),
node
->
attr
.
c_str
(),
node
->
lineno
);
printf
(
"Think %s.%s is undefined, at %d
\n
"
,
t
->
debugName
().
c_str
(),
attr
.
c_str
(),
node
->
lineno
);
print_bst
(
node
,
code_constants
);
printf
(
"
\n
"
);
}
...
...
@@ -379,7 +381,8 @@ private:
auto
name_scope
=
node
->
lookup_type
;
if
(
name_scope
==
ScopeInfo
::
VarScopeType
::
GLOBAL
)
{
if
(
node
->
id
.
s
()
==
"None"
)
InternedString
id
=
getCodeConstants
().
getInternedString
(
node
->
index_id
);
if
(
id
.
s
()
==
"None"
)
t
=
NONE
;
}
else
if
(
name_scope
==
ScopeInfo
::
VarScopeType
::
FAST
||
name_scope
==
ScopeInfo
::
VarScopeType
::
CLOSURE
)
t
=
getType
(
node
->
vreg
);
...
...
@@ -389,7 +392,8 @@ private:
void
visit_loadattr
(
BST_LoadAttr
*
node
)
override
{
CompilerType
*
t
=
getType
(
node
->
vreg_value
);
CompilerType
*
rtn
=
t
->
getattrType
(
node
->
attr
,
node
->
clsonly
);
InternedString
attr
=
getCodeConstants
().
getInternedString
(
node
->
index_attr
);
CompilerType
*
rtn
=
t
->
getattrType
(
attr
,
node
->
clsonly
);
if
(
speculation
!=
TypeAnalysis
::
NONE
)
{
BoxedClass
*
speculated_class
=
predictClassFor
(
node
);
...
...
@@ -397,7 +401,7 @@ private:
}
if
(
VERBOSITY
()
>=
2
&&
rtn
==
UNDEF
)
{
printf
(
"Think %s.%s is undefined, at %d
\n
"
,
t
->
debugName
().
c_str
(),
node
->
attr
.
c_str
(),
node
->
lineno
);
printf
(
"Think %s.%s is undefined, at %d
\n
"
,
t
->
debugName
().
c_str
(),
attr
.
c_str
(),
node
->
lineno
);
print_bst
(
node
,
code_constants
);
printf
(
"
\n
"
);
}
...
...
src/codegen/ast_interpreter.cpp
View file @
17b548d9
...
...
@@ -1263,7 +1263,8 @@ Value ASTInterpreter::visit_makeClass(BST_MakeClass* mkclass) {
ArgPassSpec
(
0
),
0
,
0
,
0
,
0
,
0
);
AUTO_DECREF
(
attrDict
);
Box
*
classobj
=
createUserClass
(
node
->
name
.
getBox
(),
bases_tuple
,
attrDict
);
InternedString
name
=
getCodeConstants
().
getInternedString
(
node
->
index_name
);
Box
*
classobj
=
createUserClass
(
name
.
getBox
(),
bases_tuple
,
attrDict
);
for
(
int
i
=
decorators
.
size
()
-
1
;
i
>=
0
;
i
--
)
{
classobj
=
runtimeCall
(
autoDecref
(
decorators
[
i
]),
ArgPassSpec
(
1
),
autoDecref
(
classobj
),
0
,
0
,
0
,
0
);
...
...
@@ -1311,7 +1312,7 @@ void ASTInterpreter::visit_assert(BST_Assert* node) {
void
ASTInterpreter
::
visit_deleteattr
(
BST_DeleteAttr
*
node
)
{
Value
target
=
getVReg
(
node
->
vreg_value
);
AUTO_DECREF
(
target
.
o
);
BoxedString
*
str
=
node
->
attr
.
getBox
();
BoxedString
*
str
=
getCodeConstants
().
getInternedString
(
node
->
index_attr
)
.
getBox
();
if
(
jit
)
jit
->
emitDelAttr
(
target
,
str
);
delattr
(
target
.
o
,
str
);
...
...
@@ -1344,27 +1345,28 @@ void ASTInterpreter::visit_deletename(BST_DeleteName* target) {
assert
(
target
->
lookup_type
!=
ScopeInfo
::
VarScopeType
::
UNKNOWN
);
ScopeInfo
::
VarScopeType
vst
=
target
->
lookup_type
;
InternedString
id
=
getCodeConstants
().
getInternedString
(
target
->
index_id
);
if
(
vst
==
ScopeInfo
::
VarScopeType
::
GLOBAL
)
{
if
(
jit
)
jit
->
emitDelGlobal
(
target
->
id
.
getBox
());
delGlobal
(
frame_info
.
globals
,
target
->
id
.
getBox
());
jit
->
emitDelGlobal
(
id
.
getBox
());
delGlobal
(
frame_info
.
globals
,
id
.
getBox
());
}
else
if
(
vst
==
ScopeInfo
::
VarScopeType
::
NAME
)
{
if
(
jit
)
jit
->
emitDelName
(
target
->
id
);
ASTInterpreterJitInterface
::
delNameHelper
(
this
,
target
->
id
);
jit
->
emitDelName
(
id
);
ASTInterpreterJitInterface
::
delNameHelper
(
this
,
id
);
}
else
{
assert
(
vst
==
ScopeInfo
::
VarScopeType
::
FAST
);
assert
(
getVRegInfo
().
getVReg
(
target
->
id
)
==
target
->
vreg
);
assert
(
getVRegInfo
().
getVReg
(
id
)
==
target
->
vreg
);
if
(
target
->
id
.
s
()[
0
]
==
'#'
)
{
if
(
id
.
s
()[
0
]
==
'#'
)
{
assert
(
vregs
[
target
->
vreg
]
!=
NULL
);
if
(
jit
)
jit
->
emitKillTemporary
(
target
->
vreg
);
}
else
{
abortJITing
();
if
(
vregs
[
target
->
vreg
]
==
0
)
{
assertNameDefined
(
0
,
target
->
id
.
c_str
(),
NameError
,
true
/* local_var_msg */
);
assertNameDefined
(
0
,
id
.
c_str
(),
NameError
,
true
/* local_var_msg */
);
return
;
}
}
...
...
@@ -1428,14 +1430,14 @@ Value ASTInterpreter::visit_call(BST_Call* node) {
callattr_clsonly
=
false
;
auto
*
attr_ast
=
bst_cast
<
BST_CallAttr
>
(
node
);
func
=
getVReg
(
attr_ast
->
vreg_value
);
attr
=
attr_ast
->
attr
;
attr
=
getCodeConstants
().
getInternedString
(
attr_ast
->
index_attr
)
;
vreg_elts
=
bst_cast
<
BST_CallAttr
>
(
node
)
->
elts
;
}
else
if
(
node
->
type
==
BST_TYPE
::
CallClsAttr
)
{
is_callattr
=
true
;
callattr_clsonly
=
true
;
auto
*
attr_ast
=
bst_cast
<
BST_CallClsAttr
>
(
node
);
func
=
getVReg
(
attr_ast
->
vreg_value
);
attr
=
attr_ast
->
attr
;
attr
=
getCodeConstants
().
getInternedString
(
attr_ast
->
index_attr
)
;
vreg_elts
=
bst_cast
<
BST_CallClsAttr
>
(
node
)
->
elts
;
}
else
{
auto
*
attr_ast
=
bst_cast
<
BST_CallFunc
>
(
node
);
...
...
@@ -1577,14 +1579,14 @@ Value ASTInterpreter::getVReg(int vreg, bool is_kill) {
Value
ASTInterpreter
::
visit_loadname
(
BST_LoadName
*
node
)
{
assert
(
node
->
lookup_type
!=
ScopeInfo
::
VarScopeType
::
UNKNOWN
);
InternedString
id
=
getCodeConstants
().
getInternedString
(
node
->
index_id
);
switch
(
node
->
lookup_type
)
{
case
ScopeInfo
:
:
VarScopeType
::
GLOBAL
:
{
Value
v
;
if
(
jit
)
v
.
var
=
jit
->
emitGetGlobal
(
node
->
id
.
getBox
());
v
.
var
=
jit
->
emitGetGlobal
(
id
.
getBox
());
v
.
o
=
getGlobal
(
frame_info
.
globals
,
node
->
id
.
getBox
());
v
.
o
=
getGlobal
(
frame_info
.
globals
,
id
.
getBox
());
return
v
;
}
case
ScopeInfo
:
:
VarScopeType
::
DEREF
:
{
...
...
@@ -1601,13 +1603,13 @@ Value ASTInterpreter::visit_loadname(BST_LoadName* node) {
}
if
(
is_live
)
v
.
var
=
jit
->
emitGetLocal
(
node
->
id
,
node
->
vreg
);
v
.
var
=
jit
->
emitGetLocal
(
id
,
node
->
vreg
);
else
v
.
var
=
jit
->
emitGetBlockLocal
(
node
->
id
,
node
->
vreg
);
v
.
var
=
jit
->
emitGetBlockLocal
(
id
,
node
->
vreg
);
}
assert
(
node
->
vreg
>=
0
);
assert
(
getVRegInfo
().
getVReg
(
node
->
id
)
==
node
->
vreg
);
assert
(
getVRegInfo
().
getVReg
(
id
)
==
node
->
vreg
);
frame_info
.
num_vregs
=
std
::
max
(
frame_info
.
num_vregs
,
node
->
vreg
+
1
);
Box
*
val
=
vregs
[
node
->
vreg
];
...
...
@@ -1617,14 +1619,14 @@ Value ASTInterpreter::visit_loadname(BST_LoadName* node) {
return
v
;
}
assertNameDefined
(
0
,
node
->
id
.
c_str
(),
UnboundLocalError
,
true
);
assertNameDefined
(
0
,
id
.
c_str
(),
UnboundLocalError
,
true
);
RELEASE_ASSERT
(
0
,
"should be unreachable"
);
}
case
ScopeInfo
:
:
VarScopeType
::
NAME
:
{
Value
v
;
if
(
jit
)
v
.
var
=
jit
->
emitGetBoxedLocal
(
node
->
id
.
getBox
());
v
.
o
=
boxedLocalsGet
(
frame_info
.
boxedLocals
,
node
->
id
.
getBox
(),
frame_info
.
globals
);
v
.
var
=
jit
->
emitGetBoxedLocal
(
id
.
getBox
());
v
.
o
=
boxedLocalsGet
(
frame_info
.
boxedLocals
,
id
.
getBox
(),
frame_info
.
globals
);
return
v
;
}
default:
...
...
@@ -1636,7 +1638,7 @@ Value ASTInterpreter::visit_loadattr(BST_LoadAttr* node) {
Value
v
=
getVReg
(
node
->
vreg_value
);
AUTO_DECREF
(
v
.
o
);
BoxedString
*
attr
=
node
->
attr
.
getBox
();
BoxedString
*
attr
=
getCodeConstants
().
getInternedString
(
node
->
index_attr
)
.
getBox
();
Value
r
;
if
(
node
->
clsonly
)
r
=
Value
(
getclsattr
(
v
.
o
,
attr
),
jit
?
jit
->
emitGetClsAttr
(
v
,
attr
)
:
NULL
);
...
...
@@ -1680,7 +1682,7 @@ void ASTInterpreter::visit_storename(BST_StoreName* node) {
assert
(
node
->
lookup_type
!=
ScopeInfo
::
VarScopeType
::
UNKNOWN
);
InternedString
name
=
node
->
id
;
InternedString
name
=
getCodeConstants
().
getInternedString
(
node
->
index_id
)
;
ScopeInfo
::
VarScopeType
vst
=
node
->
lookup_type
;
if
(
vst
==
ScopeInfo
::
VarScopeType
::
GLOBAL
)
{
if
(
jit
)
...
...
@@ -1711,7 +1713,7 @@ void ASTInterpreter::visit_storename(BST_StoreName* node) {
if
(
closure
)
{
ASTInterpreterJitInterface
::
setLocalClosureHelper
(
this
,
node
->
vreg
,
node
->
closure_offset
,
value
.
o
);
}
else
{
assert
(
getVRegInfo
().
getVReg
(
n
ode
->
id
)
==
node
->
vreg
);
assert
(
getVRegInfo
().
getVReg
(
n
ame
)
==
node
->
vreg
);
frame_info
.
num_vregs
=
std
::
max
(
frame_info
.
num_vregs
,
node
->
vreg
+
1
);
Box
*
prev
=
vregs
[
node
->
vreg
];
vregs
[
node
->
vreg
]
=
value
.
o
;
...
...
@@ -1724,11 +1726,12 @@ void ASTInterpreter::visit_storename(BST_StoreName* node) {
void
ASTInterpreter
::
visit_storeattr
(
BST_StoreAttr
*
node
)
{
Value
value
=
getVReg
(
node
->
vreg_value
);
Value
o
=
getVReg
(
node
->
vreg_target
);
InternedString
attr
=
getCodeConstants
().
getInternedString
(
node
->
index_attr
);
if
(
jit
)
{
jit
->
emitSetAttr
(
node
,
o
,
node
->
attr
.
getBox
(),
value
);
jit
->
emitSetAttr
(
node
,
o
,
attr
.
getBox
(),
value
);
}
AUTO_DECREF
(
o
.
o
);
pyston
::
setattr
(
o
.
o
,
node
->
attr
.
getBox
(),
value
.
o
);
pyston
::
setattr
(
o
.
o
,
attr
.
getBox
(),
value
.
o
);
}
void
ASTInterpreter
::
visit_storesub
(
BST_StoreSub
*
node
)
{
...
...
@@ -1860,8 +1863,8 @@ Box* ASTInterpreterJitInterface::derefHelper(void* _interpreter, BST_LoadName* n
}
Box
*
val
=
closure
->
elts
[
deref_info
.
offset
];
if
(
val
==
NULL
)
{
raiseExcHelper
(
NameError
,
"free variable '%s' referenced before assignment in enclosing scope"
,
node
->
id
.
c_str
());
InternedString
id
=
interpreter
->
getCodeConstants
().
getInternedString
(
node
->
index_id
);
raiseExcHelper
(
NameError
,
"free variable '%s' referenced before assignment in enclosing scope"
,
id
.
c_str
());
}
Py_INCREF
(
val
);
return
val
;
...
...
src/codegen/irgen/irgenerator.cpp
View file @
17b548d9
...
...
@@ -1104,14 +1104,14 @@ private:
auto
*
attr_ast
=
bst_cast
<
BST_CallAttr
>
(
node
);
vreg_elts
=
bst_cast
<
BST_CallAttr
>
(
node
)
->
elts
;
func
=
evalVReg
(
attr_ast
->
vreg_value
);
attr
=
attr_ast
->
attr
;
attr
=
irstate
->
getCodeConstants
().
getInternedString
(
attr_ast
->
index_attr
)
;
}
else
if
(
node
->
type
==
BST_TYPE
::
CallClsAttr
)
{
is_callattr
=
true
;
callattr_clsonly
=
true
;
auto
*
attr_ast
=
bst_cast
<
BST_CallClsAttr
>
(
node
);
vreg_elts
=
bst_cast
<
BST_CallClsAttr
>
(
node
)
->
elts
;
func
=
evalVReg
(
attr_ast
->
vreg_value
);
attr
=
attr_ast
->
attr
;
attr
=
irstate
->
getCodeConstants
().
getInternedString
(
attr_ast
->
index_attr
)
;
}
else
{
is_callattr
=
false
;
auto
*
attr_ast
=
bst_cast
<
BST_CallFunc
>
(
node
);
...
...
@@ -1199,7 +1199,8 @@ private:
}
ConcreteCompilerVariable
*
_getGlobal
(
BST_LoadName
*
node
,
const
UnwindInfo
&
unw_info
)
{
if
(
node
->
id
.
s
()
==
"None"
)
InternedString
id
=
irstate
->
getCodeConstants
().
getInternedString
(
node
->
index_id
);
if
(
id
.
s
()
==
"None"
)
return
emitter
.
getNone
();
bool
do_patchpoint
=
ENABLE_ICGETGLOBALS
;
...
...
@@ -1208,8 +1209,8 @@ private:
std
::
vector
<
llvm
::
Value
*>
llvm_args
;
llvm_args
.
push_back
(
irstate
->
getGlobals
());
llvm_args
.
push_back
(
emitter
.
setType
(
embedRelocatablePtr
(
node
->
id
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
),
RefType
::
BORROWED
));
llvm_args
.
push_back
(
emitter
.
setType
(
embedRelocatablePtr
(
id
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
),
RefType
::
BORROWED
));
llvm
::
Instruction
*
uncasted
=
emitter
.
createIC
(
std
::
move
(
pp
),
(
void
*
)
pyston
::
getGlobal
,
llvm_args
,
unw_info
);
...
...
@@ -1219,8 +1220,7 @@ private:
}
else
{
llvm
::
Value
*
r
=
emitter
.
createCall2
(
unw_info
,
g
.
funcs
.
getGlobal
,
irstate
->
getGlobals
(),
emitter
.
setType
(
embedRelocatablePtr
(
node
->
id
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
),
RefType
::
BORROWED
));
emitter
.
setType
(
embedRelocatablePtr
(
id
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
),
RefType
::
BORROWED
));
emitter
.
setType
(
r
,
RefType
::
OWNED
);
return
new
ConcreteCompilerVariable
(
UNKNOWN
,
r
);
}
...
...
@@ -1264,6 +1264,7 @@ private:
CompilerVariable
*
evalLoadName
(
BST_LoadName
*
node
,
const
UnwindInfo
&
unw_info
)
{
InternedString
id
=
irstate
->
getCodeConstants
().
getInternedString
(
node
->
index_id
);
// LoadName is never a kill
auto
&&
scope_info
=
irstate
->
getScopeInfo
();
...
...
@@ -1312,7 +1313,7 @@ private:
emitter
.
getBuilder
()
->
SetInsertPoint
(
curblock
);
llvm
::
CallSite
call
=
emitter
.
createCall
(
unw_info
,
g
.
funcs
.
assertFailDerefNameDefined
,
embedRelocatablePtr
(
node
->
id
.
c_str
(),
g
.
i8_ptr
));
embedRelocatablePtr
(
id
.
c_str
(),
g
.
i8_ptr
));
call
.
setDoesNotReturn
();
emitter
.
getBuilder
()
->
CreateUnreachable
();
...
...
@@ -1323,7 +1324,7 @@ private:
return
new
ConcreteCompilerVariable
(
UNKNOWN
,
lookupResult
);
}
else
if
(
vst
==
ScopeInfo
::
VarScopeType
::
NAME
)
{
llvm
::
Value
*
boxedLocals
=
irstate
->
getBoxedLocalsVar
();
llvm
::
Value
*
attr
=
embedRelocatablePtr
(
node
->
id
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
);
llvm
::
Value
*
attr
=
embedRelocatablePtr
(
id
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
);
emitter
.
setType
(
attr
,
RefType
::
BORROWED
);
llvm
::
Value
*
module
=
irstate
->
getGlobals
();
llvm
::
Value
*
r
=
emitter
.
createCall3
(
unw_info
,
g
.
funcs
.
boxedLocalsGet
,
boxedLocals
,
attr
,
module
);
...
...
@@ -1337,7 +1338,7 @@ private:
// state = DEAD;
llvm
::
CallSite
call
=
emitter
.
createCall
(
unw_info
,
g
.
funcs
.
assertNameDefined
,
{
getConstantInt
(
0
,
g
.
i1
),
embedRelocatablePtr
(
node
->
id
.
c_str
(),
g
.
i8_ptr
),
{
getConstantInt
(
0
,
g
.
i1
),
embedRelocatablePtr
(
id
.
c_str
(),
g
.
i8_ptr
),
emitter
.
setType
(
embedRelocatablePtr
(
UnboundLocalError
,
g
.
llvm_class_type_ptr
),
RefType
::
BORROWED
),
getConstantInt
(
true
,
g
.
i1
)
});
call
.
setDoesNotReturn
();
...
...
@@ -1349,7 +1350,7 @@ private:
if
(
is_defined_var
)
{
emitter
.
createCall
(
unw_info
,
g
.
funcs
.
assertNameDefined
,
{
i1FromLLVMBool
(
emitter
,
is_defined_var
),
embedRelocatablePtr
(
node
->
id
.
c_str
(),
g
.
i8_ptr
),
{
i1FromLLVMBool
(
emitter
,
is_defined_var
),
embedRelocatablePtr
(
id
.
c_str
(),
g
.
i8_ptr
),
emitter
.
setType
(
embedRelocatablePtr
(
UnboundLocalError
,
g
.
llvm_class_type_ptr
),
RefType
::
BORROWED
),
getConstantInt
(
true
,
g
.
i1
)
});
...
...
@@ -1412,8 +1413,8 @@ private:
CompilerVariable
*
evalLoadAttr
(
BST_LoadAttr
*
node
,
const
UnwindInfo
&
unw_info
)
{
CompilerVariable
*
value
=
evalVReg
(
node
->
vreg_value
);
CompilerVariable
*
rtn
=
value
->
getattr
(
emitter
,
getOpInfoForNode
(
node
,
unw_info
),
node
->
attr
.
getBox
(),
node
->
clsonly
);
InternedString
attr
=
irstate
->
getCodeConstants
().
getInternedString
(
node
->
index_attr
);
CompilerVariable
*
rtn
=
value
->
getattr
(
emitter
,
getOpInfoForNode
(
node
,
unw_info
),
attr
.
getBox
(),
node
->
clsonly
);
return
rtn
;
}
...
...
@@ -1526,9 +1527,10 @@ private:
ConcreteCompilerVariable
*
converted_attr_dict
=
attr_dict
->
makeConverted
(
emitter
,
attr_dict
->
getBoxType
());
InternedString
name
=
irstate
->
getCodeConstants
().
getInternedString
(
node
->
index_name
);
llvm
::
Value
*
classobj
=
emitter
.
createCall3
(
unw_info
,
g
.
funcs
.
createUserClass
,
emitter
.
setType
(
embedRelocatablePtr
(
n
ode
->
n
ame
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
),
RefType
::
BORROWED
),
emitter
.
setType
(
embedRelocatablePtr
(
name
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
),
RefType
::
BORROWED
),
bases_tuple
->
getValue
(),
converted_attr_dict
->
getValue
());
emitter
.
setType
(
classobj
,
RefType
::
OWNED
);
...
...
@@ -1764,17 +1766,17 @@ private:
}
void
doStoreName
(
BST_StoreName
*
node
,
const
UnwindInfo
&
unw_info
)
{
InternedString
name
=
irstate
->
getCodeConstants
().
getInternedString
(
node
->
index_id
);
CompilerVariable
*
val
=
evalVReg
(
node
->
vreg_value
);
assert
(
n
ode
->
id
.
s
()
!=
"None"
);
assert
(
n
ode
->
id
.
s
()
!=
FRAME_INFO_PTR_NAME
);
assert
(
n
ame
.
s
()
!=
"None"
);
assert
(
n
ame
.
s
()
!=
FRAME_INFO_PTR_NAME
);
assert
(
val
->
getType
()
->
isUsable
());
auto
vst
=
node
->
lookup_type
;
assert
(
vst
!=
ScopeInfo
::
VarScopeType
::
UNKNOWN
);
assert
(
vst
!=
ScopeInfo
::
VarScopeType
::
DEREF
);
auto
name
=
node
->
id
;
auto
vreg
=
node
->
vreg
;
if
(
vst
==
ScopeInfo
::
VarScopeType
::
GLOBAL
)
{
...
...
@@ -1831,7 +1833,8 @@ private:
void
doStoreAttr
(
BST_StoreAttr
*
target
,
const
UnwindInfo
&
unw_info
)
{
CompilerVariable
*
val
=
evalVReg
(
target
->
vreg_value
);
CompilerVariable
*
t
=
evalVReg
(
target
->
vreg_target
);
t
->
setattr
(
emitter
,
getEmptyOpInfo
(
unw_info
),
target
->
attr
.
getBox
(),
val
);
InternedString
attr
=
irstate
->
getCodeConstants
().
getInternedString
(
target
->
index_attr
);
t
->
setattr
(
emitter
,
getEmptyOpInfo
(
unw_info
),
attr
.
getBox
(),
val
);
}
void
_assignSlice
(
llvm
::
Value
*
target
,
llvm
::
Value
*
value
,
const
UnboxedSlice
&
slice_val
,
...
...
@@ -1998,13 +2001,16 @@ private:
}
void
_doDelAttr
(
BST_DeleteAttr
*
node
,
const
UnwindInfo
&
unw_info
)
{
InternedString
attr
=
irstate
->
getCodeConstants
().
getInternedString
(
node
->
index_attr
);
CompilerVariable
*
value
=
evalVReg
(
node
->
vreg_value
);
value
->
delattr
(
emitter
,
getEmptyOpInfo
(
unw_info
),
node
->
attr
.
getBox
());
value
->
delattr
(
emitter
,
getEmptyOpInfo
(
unw_info
),
attr
.
getBox
());
}
void
_doDelName
(
BST_DeleteName
*
target
,
const
UnwindInfo
&
unw_info
)
{
InternedString
id
=
irstate
->
getCodeConstants
().
getInternedString
(
target
->
index_id
);
// Hack: we don't have a bytecode for temporary-kills:
if
(
target
->
id
.
s
()[
0
]
==
'#'
)
{
if
(
id
.
s
()[
0
]
==
'#'
)
{
// The refcounter will automatically delete this object.
return
;
}
...
...
@@ -2013,15 +2019,15 @@ private:
assert
(
vst
!=
ScopeInfo
::
VarScopeType
::
UNKNOWN
);
if
(
vst
==
ScopeInfo
::
VarScopeType
::
GLOBAL
)
{
// Can't use delattr since the errors are different:
emitter
.
createCall2
(
unw_info
,
g
.
funcs
.
delGlobal
,
irstate
->
getGlobals
(),
emitter
.
setType
(
embedRelocatablePtr
(
target
->
id
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
),
RefType
::
BORROWED
));
emitter
.
createCall2
(
unw_info
,
g
.
funcs
.
delGlobal
,
irstate
->
getGlobals
(
),
emitter
.
setType
(
embedRelocatablePtr
(
id
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
),
RefType
::
BORROWED
));
return
;
}
if
(
vst
==
ScopeInfo
::
VarScopeType
::
NAME
)
{
llvm
::
Value
*
boxedLocals
=
irstate
->
getBoxedLocalsVar
();
llvm
::
Value
*
attr
=
embedRelocatablePtr
(
target
->
id
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
);
llvm
::
Value
*
attr
=
embedRelocatablePtr
(
id
.
getBox
(),
g
.
llvm_boxedstring_type_ptr
);
emitter
.
setType
(
attr
,
RefType
::
BORROWED
);
emitter
.
createCall2
(
unw_info
,
g
.
funcs
.
boxedLocalsDel
,
boxedLocals
,
attr
);
return
;
...
...
@@ -2041,7 +2047,7 @@ private:
if
(
!
symbol_table
[
target
->
vreg
])
{
llvm
::
CallSite
call
=
emitter
.
createCall
(
unw_info
,
g
.
funcs
.
assertNameDefined
,
{
getConstantInt
(
0
,
g
.
i1
),
embedConstantPtr
(
target
->
id
.
c_str
(),
g
.
i8_ptr
),
{
getConstantInt
(
0
,
g
.
i1
),
embedConstantPtr
(
id
.
c_str
(),
g
.
i8_ptr
),
emitter
.
setType
(
embedRelocatablePtr
(
NameError
,
g
.
llvm_class_type_ptr
),
RefType
::
BORROWED
),
getConstantInt
(
true
/*local_error_msg*/
,
g
.
i1
)
});
call
.
setDoesNotReturn
();
...
...
@@ -2051,7 +2057,7 @@ private:
if
(
is_defined_var
)
{
emitter
.
createCall
(
unw_info
,
g
.
funcs
.
assertNameDefined
,
{
i1FromLLVMBool
(
emitter
,
is_defined_var
),
embedConstantPtr
(
target
->
id
.
c_str
(),
g
.
i8_ptr
),
{
i1FromLLVMBool
(
emitter
,
is_defined_var
),
embedConstantPtr
(
id
.
c_str
(),
g
.
i8_ptr
),
emitter
.
setType
(
embedRelocatablePtr
(
NameError
,
g
.
llvm_class_type_ptr
),
RefType
::
BORROWED
),
getConstantInt
(
true
/*local_error_msg*/
,
g
.
i1
)
});
popDefinedVar
(
target
->
vreg
);
...
...
src/core/bst.cpp
View file @
17b548d9
...
...
@@ -837,7 +837,7 @@ bool PrintVisitor::visit_callattr(BST_CallAttr* node) {
visit_vreg
(
&
node
->
vreg_dst
,
true
);
visit_vreg
(
&
node
->
vreg_value
);
stream
<<
"."
;
stream
<<
node
->
attr
.
s
();
stream
<<
code_constants
.
getInternedString
(
node
->
index_attr
)
.
s
();
stream
<<
"("
;
bool
prevarg
=
false
;
...
...
@@ -867,7 +867,7 @@ bool PrintVisitor::visit_callclsattr(BST_CallClsAttr* node) {
visit_vreg
(
&
node
->
vreg_dst
,
true
);
visit_vreg
(
&
node
->
vreg_value
);
stream
<<
":"
;
stream
<<
node
->
attr
.
s
();
stream
<<
code_constants
.
getInternedString
(
node
->
index_attr
)
.
s
();
stream
<<
"("
;
bool
prevarg
=
false
;
...
...
@@ -909,7 +909,7 @@ bool PrintVisitor::visit_classdef(BST_ClassDef* node) {
stream
<<
"
\n
"
;
printIndent
();
}
stream
<<
"class "
<<
node
->
name
.
s
()
<<
"("
;
stream
<<
"class "
<<
code_constants
.
getInternedString
(
node
->
index_name
)
.
s
()
<<
"("
;
visit_vreg
(
&
node
->
vreg_bases_tuple
);
stream
<<
")"
;
...
...
@@ -954,7 +954,7 @@ bool PrintVisitor::visit_deleteattr(BST_DeleteAttr* node) {
stream
<<
"del "
;
visit_vreg
(
&
node
->
vreg_value
);
stream
<<
'.'
;
stream
<<
node
->
attr
.
s
();
stream
<<
code_constants
.
getInternedString
(
node
->
index_attr
)
.
s
();
return
true
;
}
bool
PrintVisitor
::
visit_deletename
(
BST_DeleteName
*
node
)
{
...
...
@@ -963,7 +963,7 @@ bool PrintVisitor::visit_deletename(BST_DeleteName* node) {
visit_vreg
(
&
node
->
vreg
);
stream
<<
" "
;
}
stream
<<
node
->
id
.
s
();
stream
<<
code_constants
.
getInternedString
(
node
->
index_id
)
.
s
();
return
true
;
}
...
...
@@ -999,8 +999,8 @@ bool PrintVisitor::visit_functiondef(BST_FunctionDef* node) {
}
stream
<<
"def "
;
if
(
node
->
name
!=
InternedString
()
)
stream
<<
node
->
name
.
s
();
if
(
node
->
index_name
!=
VREG_UNDEFINED
)
stream
<<
code_constants
.
getInternedString
(
node
->
index_name
)
.
s
();
else
stream
<<
"<lambda>"
;
stream
<<
"("
;
...
...
@@ -1226,14 +1226,14 @@ bool PrintVisitor::visit_loadname(BST_LoadName* node) {
visit_vreg
(
&
node
->
vreg
);
stream
<<
" "
;
}
stream
<<
node
->
id
.
s
();
stream
<<
code_constants
.
getInternedString
(
node
->
index_id
)
.
s
();
return
true
;
}
bool
PrintVisitor
::
visit_loadattr
(
BST_LoadAttr
*
node
)
{
visit_vreg
(
&
node
->
vreg_dst
,
true
);
visit_vreg
(
&
node
->
vreg_value
);
stream
<<
(
node
->
clsonly
?
':'
:
'.'
)
<<
node
->
attr
.
s
();
stream
<<
(
node
->
clsonly
?
':'
:
'.'
)
<<
code_constants
.
getInternedString
(
node
->
index_attr
)
.
s
();
return
true
;
}
...
...
@@ -1265,7 +1265,7 @@ bool PrintVisitor::visit_storename(BST_StoreName* node) {
visit_vreg
(
&
node
->
vreg
);
stream
<<
" "
;
}
stream
<<
node
->
id
.
s
();
stream
<<
code_constants
.
getInternedString
(
node
->
index_id
)
.
s
();
stream
<<
" = "
;
visit_vreg
(
&
node
->
vreg_value
);
return
true
;
...
...
@@ -1273,7 +1273,7 @@ bool PrintVisitor::visit_storename(BST_StoreName* node) {
bool
PrintVisitor
::
visit_storeattr
(
BST_StoreAttr
*
node
)
{
visit_vreg
(
&
node
->
vreg_target
);
stream
<<
"."
<<
node
->
attr
.
s
()
<<
" = "
;
stream
<<
"."
<<
code_constants
.
getInternedString
(
node
->
index_attr
)
.
s
()
<<
" = "
;
visit_vreg
(
&
node
->
vreg_value
);
return
true
;
}
...
...
src/core/bst.h
View file @
17b548d9
...
...
@@ -258,7 +258,7 @@ class BST_StoreName : public BST_stmt {
public:
int
vreg_value
=
VREG_UNDEFINED
;
InternedString
id
;
int
index_id
=
VREG_UNDEFINED
;
ScopeInfo
::
VarScopeType
lookup_type
;
int
vreg
=
VREG_UNDEFINED
;
...
...
@@ -272,7 +272,7 @@ public:
class
BST_StoreAttr
:
public
BST_stmt
{
public:
InternedString
attr
;
int
index_attr
=
VREG_UNDEFINED
;
int
vreg_target
=
VREG_UNDEFINED
;
int
vreg_value
=
VREG_UNDEFINED
;
...
...
@@ -299,7 +299,7 @@ public:
class
BST_LoadName
:
public
BST_stmt_with_dest
{
public:
InternedString
id
;
int
index_id
=
VREG_UNDEFINED
;
ScopeInfo
::
VarScopeType
lookup_type
;
// LoadName does not kill this vreg
int
vreg
=
VREG_UNDEFINED
;
...
...
@@ -314,7 +314,7 @@ public:
class
BST_LoadAttr
:
public
BST_stmt_with_dest
{
public:
InternedString
attr
;
int
index_attr
=
VREG_UNDEFINED
;
int
vreg_value
=
VREG_UNDEFINED
;
bool
clsonly
=
false
;
...
...
@@ -376,7 +376,7 @@ public:
class
BST_CallAttr
:
public
BST_Call
{
public:
int
vreg_value
=
VREG_UNDEFINED
;
InternedString
attr
;
int
index_attr
=
VREG_UNDEFINED
;
int
elts
[
1
];
BSTVARVREGS2CALL
(
CallAttr
,
num_args
,
num_keywords
,
elts
)
...
...
@@ -385,7 +385,7 @@ public:
class
BST_CallClsAttr
:
public
BST_Call
{
public:
int
vreg_value
=
VREG_UNDEFINED
;
InternedString
attr
;
int
index_attr
=
VREG_UNDEFINED
;
int
elts
[
1
];
BSTVARVREGS2CALL
(
CallClsAttr
,
num_args
,
num_keywords
,
elts
)
...
...
@@ -403,8 +403,8 @@ public:
class
BST_ClassDef
:
public
BST_stmt
{
public:
InternedString
name
;
int
vreg_bases_tuple
;
int
index_name
=
VREG_UNDEFINED
;
int
vreg_bases_tuple
=
VREG_UNDEFINED
;
const
int
num_decorator
;
int
decorator
[
1
];
...
...
@@ -419,14 +419,14 @@ public:
class
BST_DeleteAttr
:
public
BST_stmt
{
public:
int
vreg_value
=
VREG_UNDEFINED
;
InternedString
attr
;
int
index_attr
=
VREG_UNDEFINED
;
BSTFIXEDVREGS
(
DeleteAttr
,
BST_stmt
)
};
class
BST_DeleteName
:
public
BST_stmt
{
public:
InternedString
id
;
int
index_id
=
VREG_UNDEFINED
;
ScopeInfo
::
VarScopeType
lookup_type
;
int
vreg
=
VREG_UNDEFINED
;
...
...
@@ -466,7 +466,7 @@ public:
class
BST_FunctionDef
:
public
BST_stmt
{
public:
InternedString
name
;
// if the name is not set this is a lambda
int
index_name
=
VREG_UNDEFINED
;
// if the name is not set this is a lambda
const
int
num_decorator
;
const
int
num_defaults
;
...
...
src/core/cfg.cpp
View file @
17b548d9
...
...
@@ -38,18 +38,18 @@
namespace
pyston
{
template
<
typename
Node
>
void
fillScopingInfo
(
Node
*
node
,
ScopeInfo
*
scope_info
)
{
node
->
lookup_type
=
scope_info
->
getScopeTypeOfName
(
node
->
id
);
template
<
typename
Node
>
void
fillScopingInfo
(
Node
*
node
,
InternedString
id
,
ScopeInfo
*
scope_info
)
{
node
->
lookup_type
=
scope_info
->
getScopeTypeOfName
(
id
);
if
(
node
->
lookup_type
==
ScopeInfo
::
VarScopeType
::
CLOSURE
)
node
->
closure_offset
=
scope_info
->
getClosureOffset
(
node
->
id
);
node
->
closure_offset
=
scope_info
->
getClosureOffset
(
id
);
else
if
(
node
->
lookup_type
==
ScopeInfo
::
VarScopeType
::
DEREF
)
node
->
deref_info
=
scope_info
->
getDerefInfo
(
node
->
id
);
node
->
deref_info
=
scope_info
->
getDerefInfo
(
id
);
assert
(
node
->
lookup_type
!=
ScopeInfo
::
VarScopeType
::
UNKNOWN
);
}
template
<
>
void
fillScopingInfo
<
BST_Name
>
(
BST_Name
*
node
,
ScopeInfo
*
scope_info
)
{
void
fillScopingInfo
(
BST_Name
*
node
,
ScopeInfo
*
scope_info
)
{
node
->
lookup_type
=
scope_info
->
getScopeTypeOfName
(
node
->
id
);
if
(
node
->
lookup_type
==
ScopeInfo
::
VarScopeType
::
CLOSURE
)
...
...
@@ -504,6 +504,15 @@ private:
return
name
;
}
int
remapInternedString
(
InternedString
id
)
{
auto
it
=
interned_string_constants
.
find
(
id
);
if
(
it
!=
interned_string_constants
.
end
())
return
it
->
second
;
int
index
=
code_constants
.
addInternedString
(
id
);
interned_string_constants
[
id
]
=
index
;
return
index
;
}
TmpValue
remapName
(
AST_Name
*
name
)
{
if
(
!
name
)
return
TmpValue
();
...
...
@@ -514,9 +523,9 @@ private:
auto
rtn
=
new
BST_LoadName
;
rtn
->
lineno
=
name
->
lineno
;
rtn
->
i
d
=
name
->
id
;
rtn
->
i
ndex_id
=
remapInternedString
(
name
->
id
)
;
rtn
->
lookup_type
=
name
->
lookup_type
;
fillScopingInfo
(
rtn
,
scoping
);
fillScopingInfo
(
rtn
,
name
->
id
,
scoping
);
return
pushBackCreateDst
(
rtn
);
}
...
...
@@ -808,7 +817,7 @@ private:
BST_LoadAttr
*
rtn
=
new
BST_LoadAttr
();
rtn
->
clsonly
=
clsonly
;
unmapExpr
(
base
,
&
rtn
->
vreg_value
);
rtn
->
attr
=
attr
;
rtn
->
index_attr
=
remapInternedString
(
attr
)
;
rtn
->
lineno
=
base
.
lineno
;
return
pushBackCreateDst
(
rtn
);
}
...
...
@@ -850,7 +859,7 @@ private:
BST_Call
*
rtn
=
NULL
;
if
(
!
is_cls
)
{
BST_CallAttr
*
call
=
BST_CallAttr
::
create
(
args
.
size
(),
0
/* num keywords */
);
call
->
attr
=
attr
;
call
->
index_attr
=
remapInternedString
(
attr
)
;
unmapExpr
(
target
,
&
call
->
vreg_value
);
for
(
int
i
=
0
;
i
<
args
.
size
();
++
i
)
{
unmapExpr
(
args
[
i
],
&
call
->
elts
[
i
]);
...
...
@@ -858,7 +867,7 @@ private:
rtn
=
call
;
}
else
{
BST_CallClsAttr
*
call
=
BST_CallClsAttr
::
create
(
args
.
size
(),
0
/* num keywords */
);
call
->
attr
=
attr
;
call
->
index_attr
=
remapInternedString
(
attr
)
;
unmapExpr
(
target
,
&
call
->
vreg_value
);
for
(
int
i
=
0
;
i
<
args
.
size
();
++
i
)
{
unmapExpr
(
args
[
i
],
&
call
->
elts
[
i
]);
...
...
@@ -882,8 +891,8 @@ private:
BST_StoreName
*
assign
=
new
BST_StoreName
();
unmapExpr
(
val
,
&
assign
->
vreg_value
);
assign
->
lineno
=
val
.
lineno
;
assign
->
i
d
=
ast_cast
<
AST_Name
>
(
target
)
->
id
;
fillScopingInfo
(
assign
,
scoping
);
assign
->
i
ndex_id
=
remapInternedString
(
ast_cast
<
AST_Name
>
(
target
)
->
id
)
;
fillScopingInfo
(
assign
,
ast_cast
<
AST_Name
>
(
target
)
->
id
,
scoping
);
push_back
(
assign
);
}
else
if
(
target
->
type
==
AST_TYPE
::
Subscript
)
{
AST_Subscript
*
s
=
ast_cast
<
AST_Subscript
>
(
target
);
...
...
@@ -912,7 +921,7 @@ private:
BST_StoreAttr
*
a_target
=
new
BST_StoreAttr
();
unmapExpr
(
val
,
&
a_target
->
vreg_value
);
unmapExpr
(
remapExpr
(
a
->
value
),
&
a_target
->
vreg_target
);
a_target
->
attr
=
scoping
->
mangleName
(
a
->
attr
);
a_target
->
index_attr
=
remapInternedString
(
scoping
->
mangleName
(
a
->
attr
)
);
a_target
->
lineno
=
a
->
lineno
;
push_back
(
a_target
);
}
else
if
(
target
->
type
==
AST_TYPE
::
Tuple
||
target
->
type
==
AST_TYPE
::
List
)
{
...
...
@@ -963,8 +972,8 @@ private:
auto
*
assign
=
new
BST_StoreName
();
unmapExpr
(
val
,
&
assign
->
vreg_value
);
assign
->
lineno
=
val
.
lineno
;
assign
->
i
d
=
id
;
fillScopingInfo
(
assign
,
scoping
);
assign
->
i
ndex_id
=
remapInternedString
(
id
)
;
fillScopingInfo
(
assign
,
id
,
scoping
);
push_back
(
assign
);
}
...
...
@@ -989,7 +998,7 @@ private:
TmpValue
remapAttribute
(
AST_Attribute
*
node
)
{
BST_LoadAttr
*
rtn
=
new
BST_LoadAttr
();
rtn
->
lineno
=
node
->
lineno
;
rtn
->
attr
=
scoping
->
mangleName
(
node
->
attr
);
rtn
->
index_attr
=
remapInternedString
(
scoping
->
mangleName
(
node
->
attr
)
);
unmapExpr
(
remapExpr
(
node
->
value
),
&
rtn
->
vreg_value
);
return
pushBackCreateDst
(
rtn
);
}
...
...
@@ -1077,7 +1086,7 @@ private:
if
(
node
->
func
->
type
==
AST_TYPE
::
Attribute
)
{
BST_CallAttr
*
rtn
=
BST_CallAttr
::
create
(
node
->
args
.
size
(),
node
->
keywords
.
size
());
auto
*
attr
=
ast_cast
<
AST_Attribute
>
(
node
->
func
);
rtn
->
attr
=
scoping
->
mangleName
(
attr
->
attr
);
rtn
->
index_attr
=
remapInternedString
(
scoping
->
mangleName
(
attr
->
attr
)
);
unmapExpr
(
remapExpr
(
attr
->
value
),
&
rtn
->
vreg_value
);
for
(
int
i
=
0
;
i
<
node
->
args
.
size
();
++
i
)
{
unmapExpr
(
remapExpr
(
node
->
args
[
i
]),
&
rtn
->
elts
[
i
]);
...
...
@@ -1089,7 +1098,7 @@ private:
}
else
if
(
node
->
func
->
type
==
AST_TYPE
::
ClsAttribute
)
{
BST_CallClsAttr
*
rtn
=
BST_CallClsAttr
::
create
(
node
->
args
.
size
(),
node
->
keywords
.
size
());
auto
*
attr
=
ast_cast
<
AST_ClsAttribute
>
(
node
->
func
);
rtn
->
attr
=
scoping
->
mangleName
(
attr
->
attr
);
rtn
->
index_attr
=
remapInternedString
(
scoping
->
mangleName
(
attr
->
attr
)
);
unmapExpr
(
remapExpr
(
attr
->
value
),
&
rtn
->
vreg_value
);
for
(
int
i
=
0
;
i
<
node
->
args
.
size
();
++
i
)
{
unmapExpr
(
remapExpr
(
node
->
args
[
i
]),
&
rtn
->
elts
[
i
]);
...
...
@@ -1129,7 +1138,7 @@ private:
BST_LoadAttr
*
rtn
=
new
BST_LoadAttr
();
rtn
->
clsonly
=
true
;
rtn
->
lineno
=
node
->
lineno
;
rtn
->
attr
=
scoping
->
mangleName
(
node
->
attr
);
rtn
->
index_attr
=
remapInternedString
(
scoping
->
mangleName
(
node
->
attr
)
);
unmapExpr
(
remapExpr
(
node
->
value
),
&
rtn
->
vreg_value
);
return
pushBackCreateDst
(
rtn
);
}
...
...
@@ -1709,7 +1718,7 @@ public:
};
if
(
type
==
BST_TYPE
::
StoreName
)
{
if
(
bst_cast
<
BST_StoreName
>
(
node
)
->
id
.
s
()[
0
]
!=
'#'
)
{
if
(
code_constants
.
getInternedString
(
bst_cast
<
BST_StoreName
>
(
node
)
->
index_id
)
.
s
()[
0
]
!=
'#'
)
{
curblock
->
push_back
(
node
);
return
;
}
...
...
@@ -1718,7 +1727,7 @@ public:
// Deleting temporary names is safe, since we only use it to represent kills.
if
(
node
->
type
==
BST_TYPE
::
DeleteName
)
{
BST_DeleteName
*
del
=
bst_cast
<
BST_DeleteName
>
(
node
);
if
(
del
->
id
.
s
()[
0
]
==
'#'
)
{
if
(
code_constants
.
getInternedString
(
del
->
index_id
)
.
s
()[
0
]
==
'#'
)
{
curblock
->
push_back
(
node
);
return
;
}
...
...
@@ -1777,17 +1786,17 @@ public:
void
pushStoreName
(
InternedString
name
,
TmpValue
value
)
{
BST_StoreName
*
store
=
new
BST_StoreName
();
store
->
i
d
=
name
;
store
->
i
ndex_id
=
remapInternedString
(
name
)
;
unmapExpr
(
value
,
&
store
->
vreg_value
);
store
->
lineno
=
value
.
lineno
;
fillScopingInfo
(
store
,
scoping
);
fillScopingInfo
(
store
,
name
,
scoping
);
push_back
(
store
);
}
bool
visit_classdef
(
AST_ClassDef
*
node
)
override
{
auto
def
=
BST_ClassDef
::
create
(
node
->
decorator_list
.
size
());
def
->
lineno
=
node
->
lineno
;
def
->
name
=
node
->
name
;
def
->
index_name
=
remapInternedString
(
node
->
name
)
;
// Decorators are evaluated before bases:
for
(
int
i
=
0
;
i
<
node
->
decorator_list
.
size
();
++
i
)
{
...
...
@@ -1804,7 +1813,7 @@ public:
auto
*
code
=
cfgizer
->
runRecursively
(
node
->
body
,
node
->
name
.
getBox
(),
node
->
lineno
,
NULL
,
node
);
auto
mkclass
=
new
BST_MakeClass
(
def
,
code_constants
.
addFuncOrClass
(
def
,
code
));
auto
tmp
=
pushBackCreateDst
(
mkclass
);
pushAssign
(
TmpValue
(
scoping
->
mangleName
(
def
->
name
),
node
->
lineno
),
tmp
);
pushAssign
(
TmpValue
(
scoping
->
mangleName
(
node
->
name
),
node
->
lineno
),
tmp
);
return
true
;
}
...
...
@@ -1812,7 +1821,7 @@ public:
bool
visit_functiondef
(
AST_FunctionDef
*
node
)
override
{
auto
def
=
BST_FunctionDef
::
create
(
node
->
decorator_list
.
size
(),
node
->
args
->
defaults
.
size
());
def
->
lineno
=
node
->
lineno
;
def
->
name
=
node
->
name
;
def
->
index_name
=
remapInternedString
(
node
->
name
)
;
// Decorators are evaluated before the defaults, so this *must* go before remapArguments().
// TODO(rntz): do we have a test for this
...
...
@@ -1826,7 +1835,7 @@ public:
auto
*
code
=
cfgizer
->
runRecursively
(
node
->
body
,
node
->
name
.
getBox
(),
node
->
lineno
,
node
->
args
,
node
);
auto
mkfunc
=
new
BST_MakeFunction
(
def
,
code_constants
.
addFuncOrClass
(
def
,
code
));
auto
tmp
=
pushBackCreateDst
(
mkfunc
);
pushAssign
(
TmpValue
(
scoping
->
mangleName
(
def
->
name
),
node
->
lineno
),
tmp
);
pushAssign
(
TmpValue
(
scoping
->
mangleName
(
node
->
name
),
node
->
lineno
),
tmp
);
return
true
;
}
...
...
@@ -1885,7 +1894,8 @@ public:
auto
*
store
=
new
BST_LoadAttr
;
store
->
lineno
=
import
->
lineno
;
store
->
attr
=
scoping
->
mangleName
(
internString
(
a
->
name
.
s
().
substr
(
l
,
r
-
l
)));
store
->
index_attr
=
remapInternedString
(
scoping
->
mangleName
(
internString
(
a
->
name
.
s
().
substr
(
l
,
r
-
l
))));
unmapExpr
(
tmpname
,
&
store
->
vreg_value
);
unmapExpr
(
tmpname
,
&
store
->
vreg_dst
);
push_back
(
store
);
...
...
@@ -2095,7 +2105,7 @@ public:
BST_LoadAttr
*
a_lhs
=
new
BST_LoadAttr
();
unmapExpr
(
_dup
(
value_remapped
),
&
a_lhs
->
vreg_value
);
a_lhs
->
attr
=
scoping
->
mangleName
(
a
->
attr
);
a_lhs
->
index_attr
=
remapInternedString
(
scoping
->
mangleName
(
a
->
attr
)
);
a_lhs
->
lineno
=
a
->
lineno
;
TmpValue
name_lhs
=
pushBackCreateDst
(
a_lhs
);
...
...
@@ -2109,7 +2119,7 @@ public:
BST_StoreAttr
*
a_target
=
new
BST_StoreAttr
();
unmapExpr
(
node_name
,
&
a_target
->
vreg_value
);
unmapExpr
(
value_remapped
,
&
a_target
->
vreg_target
);
a_target
->
attr
=
a_lhs
->
attr
;
a_target
->
index_attr
=
a_lhs
->
index_
attr
;
a_target
->
lineno
=
a
->
lineno
;
push_back
(
a_target
);
...
...
@@ -2156,7 +2166,7 @@ public:
auto
*
del
=
new
BST_DeleteAttr
;
del
->
lineno
=
node
->
lineno
;
unmapExpr
(
remapExpr
(
astattr
->
value
),
&
del
->
vreg_value
);
del
->
attr
=
scoping
->
mangleName
(
astattr
->
attr
);
del
->
index_attr
=
remapInternedString
(
scoping
->
mangleName
(
astattr
->
attr
)
);
push_back
(
del
);
break
;
}
...
...
@@ -2164,8 +2174,8 @@ public:
AST_Name
*
s
=
static_cast
<
AST_Name
*>
(
t
);
auto
*
del
=
new
BST_DeleteName
;
del
->
lineno
=
node
->
lineno
;
del
->
i
d
=
s
->
id
;
fillScopingInfo
(
del
,
scoping
);
del
->
i
ndex_id
=
remapInternedString
(
s
->
id
)
;
fillScopingInfo
(
del
,
s
->
id
,
s
coping
);
push_back
(
del
);
break
;
}
...
...
@@ -2398,9 +2408,9 @@ public:
BST_stmt
*
makeKill
(
InternedString
name
)
{
// There might be a better way to represent this, maybe with a dedicated AST_Kill bytecode?
auto
del
=
new
BST_DeleteName
();
del
->
i
d
=
name
;
del
->
i
ndex_id
=
remapInternedString
(
name
)
;
del
->
lineno
=
0
;
fillScopingInfo
(
del
,
scoping
);
fillScopingInfo
(
del
,
name
,
scoping
);
return
del
;
}
...
...
@@ -2959,44 +2969,48 @@ public:
return
sym_blocks_map
[
id
].
size
()
==
1
;
}
template
<
typename
T
>
bool
visit_nameHelper
(
T
*
node
)
{
template
<
typename
T
>
bool
visit_nameHelper
(
T
*
node
,
InternedString
id
)
{
if
(
node
->
vreg
!=
VREG_UNDEFINED
)
return
true
;
ASSERT
(
node
->
lookup_type
!=
ScopeInfo
::
VarScopeType
::
UNKNOWN
,
"%s"
,
node
->
id
.
c_str
());
ASSERT
(
node
->
lookup_type
!=
ScopeInfo
::
VarScopeType
::
UNKNOWN
,
"%s"
,
id
.
c_str
());
if
(
node
->
lookup_type
!=
ScopeInfo
::
VarScopeType
::
FAST
&&
node
->
lookup_type
!=
ScopeInfo
::
VarScopeType
::
CLOSURE
)
return
true
;
if
(
step
==
TrackBlockUsage
)
{
sym_blocks_map
[
node
->
id
].
insert
(
current_block
);
sym_blocks_map
[
id
].
insert
(
current_block
);
return
true
;
}
else
if
(
step
==
UserVisible
)
{
if
(
node
->
id
.
isCompilerCreatedName
())
if
(
id
.
isCompilerCreatedName
())
return
true
;
}
else
{
bool
is_block_local
=
node
->
lookup_type
==
ScopeInfo
::
VarScopeType
::
FAST
&&
isNameUsedInSingleBlock
(
node
->
id
);
bool
is_block_local
=
node
->
lookup_type
==
ScopeInfo
::
VarScopeType
::
FAST
&&
isNameUsedInSingleBlock
(
id
);
if
(
step
==
CrossBlock
&&
is_block_local
)
return
true
;
if
(
step
==
SingleBlockUse
&&
!
is_block_local
)
return
true
;
}
node
->
vreg
=
assignVReg
(
node
->
id
);
node
->
vreg
=
assignVReg
(
id
);
return
true
;
}
bool
visit_loadname
(
BST_LoadName
*
node
)
override
{
visit_vreg
(
&
node
->
vreg_dst
,
true
);
return
visit_nameHelper
(
node
);
InternedString
id
=
code_constants
.
getInternedString
(
node
->
index_id
);
return
visit_nameHelper
(
node
,
id
);
}
bool
visit_storename
(
BST_StoreName
*
node
)
override
{
visit_vreg
(
&
node
->
vreg_value
);
return
visit_nameHelper
(
node
);
InternedString
id
=
code_constants
.
getInternedString
(
node
->
index_id
);
return
visit_nameHelper
(
node
,
id
);
}
bool
visit_deletename
(
BST_DeleteName
*
node
)
override
{
return
visit_nameHelper
(
node
);
}
bool
visit_deletename
(
BST_DeleteName
*
node
)
override
{
InternedString
id
=
code_constants
.
getInternedString
(
node
->
index_id
);
return
visit_nameHelper
(
node
,
id
);
}
int
assignVReg
(
InternedString
id
)
{
assert
(
id
.
s
().
size
());
...
...
@@ -3035,7 +3049,7 @@ void VRegInfo::assignVRegs(const CodeConstants& code_constants, CFG* cfg, const
if
(
b
==
cfg
->
getStartingBlock
())
{
for
(
auto
*
name
:
param_names
.
allArgsAsName
())
{
visitor
.
visit_nameHelper
(
name
);
visitor
.
visit_nameHelper
(
name
,
name
->
id
);
}
}
...
...
@@ -3084,11 +3098,12 @@ static std::pair<CFG*, CodeConstants> computeCFG(llvm::ArrayRef<AST_stmt*> body,
bool
skip_first
=
false
;
if
(
ast_type
==
AST_TYPE
::
ClassDef
)
{
InternedString
id
=
stringpool
.
get
(
"__name__"
);
// A classdef always starts with "__module__ = __name__"
auto
module_name_value
=
new
BST_LoadName
;
module_name_value
->
lineno
=
lineno
;
module_name_value
->
i
d
=
stringpool
.
get
(
"__name__"
);
fillScopingInfo
(
module_name_value
,
scoping
);
module_name_value
->
i
ndex_id
=
visitor
.
remapInternedString
(
id
);
fillScopingInfo
(
module_name_value
,
id
,
scoping
);
TmpValue
module_name
=
visitor
.
pushBackCreateDst
(
module_name_value
);
visitor
.
pushStoreName
(
stringpool
.
get
(
"__module__"
),
module_name
);
...
...
@@ -3118,9 +3133,9 @@ static std::pair<CFG*, CodeConstants> computeCFG(llvm::ArrayRef<AST_stmt*> body,
assert
(
scoping
->
getScopeTypeOfName
(
arg_name
)
==
ScopeInfo
::
VarScopeType
::
FAST
);
auto
load
=
new
BST_LoadName
();
load
->
i
d
=
stringpool
.
get
(
"."
+
std
::
to_string
(
counter
)
);
load
->
i
ndex_id
=
visitor
.
remapInternedString
(
arg_name
);
load
->
lineno
=
arg_expr
->
lineno
;
fillScopingInfo
(
load
,
scoping
);
fillScopingInfo
(
load
,
arg_name
,
scoping
);
TmpValue
val
=
visitor
.
pushBackCreateDst
(
load
);
visitor
.
pushAssign
(
arg_expr
,
val
);
...
...
src/core/stringpool.h
View file @
17b548d9
...
...
@@ -86,6 +86,14 @@ public:
bool
isCompilerCreatedName
()
const
;
static
InternedString
unsafe
(
BoxedString
*
str
)
{
#ifndef NDEBUG
return
InternedString
(
str
,
NULL
);
#else
return
InternedString
(
str
);
#endif
}
friend
class
InternedStringPool
;
friend
struct
std
::
hash
<
InternedString
>
;
friend
struct
std
::
less
<
InternedString
>
;
...
...
src/runtime/types.h
View file @
17b548d9
...
...
@@ -1099,12 +1099,15 @@ public:
BORROWED
(
Box
*
)
getConstant
(
int
vreg
)
const
{
return
constants
[
-
(
vreg
+
1
)];
}
InternedString
getInternedString
(
int
vreg
)
const
{
return
InternedString
::
unsafe
((
BoxedString
*
)
getConstant
(
vreg
));
}
// returns the vreg num for the constant (which is a negative number)
int
createVRegEntryForConstant
(
Box
*
o
)
{
constants
.
push_back
(
o
);
return
-
constants
.
size
();
}
void
addOwnedRef
(
Box
*
o
)
const
{
owned_refs
.
emplace_back
(
o
);
}
BORROWED
(
BoxedInt
*
)
getIntConstant
(
int64_t
n
)
const
;
...
...
@@ -1113,6 +1116,9 @@ public:
std
::
pair
<
BST_stmt
*
,
BORROWED
(
BoxedCode
*
)
>
getFuncOrClass
(
int
constant
)
const
{
return
funcs_and_classes
[
constant
];
}
int
addInternedString
(
InternedString
s
)
{
return
createVRegEntryForConstant
(
s
.
getBox
());
}
int
addFuncOrClass
(
BST_stmt
*
stmt
,
STOLEN
(
BoxedCode
*
)
code
)
{
funcs_and_classes
.
emplace_back
(
stmt
,
code
);
return
funcs_and_classes
.
size
()
-
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