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
bcd80646
Commit
bcd80646
authored
Sep 01, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move filename and name off of SourceInfo
parent
1b101760
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
122 additions
and
138 deletions
+122
-138
src/codegen/ast_interpreter.cpp
src/codegen/ast_interpreter.cpp
+2
-2
src/codegen/codegen.cpp
src/codegen/codegen.cpp
+1
-29
src/codegen/irgen.cpp
src/codegen/irgen.cpp
+5
-5
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+4
-31
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+6
-6
src/codegen/irgen/irgenerator.h
src/codegen/irgen/irgenerator.h
+1
-1
src/codegen/unwinding.cpp
src/codegen/unwinding.cpp
+2
-4
src/core/cfg.cpp
src/core/cfg.cpp
+16
-15
src/core/types.h
src/core/types.h
+1
-6
src/runtime/code.cpp
src/runtime/code.cpp
+69
-12
src/runtime/cxx_unwind.cpp
src/runtime/cxx_unwind.cpp
+1
-1
src/runtime/generator.cpp
src/runtime/generator.cpp
+1
-1
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+1
-9
src/runtime/types.cpp
src/runtime/types.cpp
+2
-7
src/runtime/types.h
src/runtime/types.h
+8
-7
src/runtime/util.cpp
src/runtime/util.cpp
+2
-2
No files found.
src/codegen/ast_interpreter.cpp
View file @
bcd80646
...
...
@@ -297,7 +297,7 @@ void ASTInterpreter::startJITing(CFGBlock* block, int exit_offset, llvm::DenseSe
code_block
=
code_blocks
[
code_blocks
.
size
()
-
1
].
get
();
if
(
!
code_block
||
code_block
->
shouldCreateNewBlock
())
{
code_blocks
.
push_back
(
llvm
::
make_unique
<
JitCodeBlock
>
(
getCode
(),
source_info
->
getName
()
->
s
()));
code_blocks
.
push_back
(
llvm
::
make_unique
<
JitCodeBlock
>
(
getCode
(),
getCode
()
->
name
->
s
()));
code_block
=
code_blocks
[
code_blocks
.
size
()
-
1
].
get
();
exit_offset
=
0
;
}
...
...
@@ -1002,7 +1002,7 @@ Value ASTInterpreter::visit_stmt(AST_stmt* node) {
#endif
if
(
0
)
{
printf
(
"%20s % 2d "
,
source_info
->
getName
()
->
c_str
(),
current_block
->
idx
);
printf
(
"%20s % 2d "
,
getCode
()
->
name
->
c_str
(),
current_block
->
idx
);
print_ast
(
node
);
printf
(
"
\n
"
);
}
...
...
src/codegen/codegen.cpp
View file @
bcd80646
...
...
@@ -36,27 +36,6 @@
namespace
pyston
{
BoxedCode
::
BoxedCode
(
int
num_args
,
bool
takes_varargs
,
bool
takes_kwargs
,
std
::
unique_ptr
<
SourceInfo
>
source
,
ParamNames
param_names
)
:
source
(
std
::
move
(
source
)),
param_names
(
std
::
move
(
param_names
)),
takes_varargs
(
takes_varargs
),
takes_kwargs
(
takes_kwargs
),
num_args
(
num_args
),
times_interpreted
(
0
),
internal_callable
(
NULL
,
NULL
)
{
}
BoxedCode
::
BoxedCode
(
int
num_args
,
bool
takes_varargs
,
bool
takes_kwargs
,
const
ParamNames
&
param_names
)
:
source
(
nullptr
),
param_names
(
param_names
),
takes_varargs
(
takes_varargs
),
takes_kwargs
(
takes_kwargs
),
num_args
(
num_args
),
times_interpreted
(
0
),
internal_callable
(
NULL
,
NULL
)
{
}
void
BoxedCode
::
addVersion
(
CompiledFunction
*
compiled
)
{
assert
(
compiled
);
assert
((
compiled
->
spec
!=
NULL
)
+
(
compiled
->
entry_descriptor
!=
NULL
)
==
1
);
...
...
@@ -79,15 +58,8 @@ void BoxedCode::addVersion(CompiledFunction* compiled) {
}
}
SourceInfo
::
SourceInfo
(
BoxedModule
*
m
,
ScopingResults
scoping
,
FutureFlags
future_flags
,
AST
*
ast
,
BoxedString
*
fn
)
SourceInfo
::
SourceInfo
(
BoxedModule
*
m
,
ScopingResults
scoping
,
FutureFlags
future_flags
,
AST
*
ast
)
:
parent_module
(
m
),
scoping
(
std
::
move
(
scoping
)),
ast
(
ast
),
cfg
(
NULL
),
future_flags
(
future_flags
)
{
assert
(
fn
);
// TODO: this is a very bad way of handling this:
incref
(
fn
);
late_constants
.
push_back
(
fn
);
this
->
fn
=
fn
;
switch
(
ast
->
type
)
{
case
AST_TYPE
:
:
ClassDef
:
...
...
src/codegen/irgen.cpp
View file @
bcd80646
...
...
@@ -988,14 +988,14 @@ static void computeBlockSetClosure(BlockSet& blocks) {
}
}
// returns a pointer to the function-info mdnode
static
llvm
::
MDNode
*
setupDebugInfo
(
SourceInfo
*
sourc
e
,
llvm
::
Function
*
f
,
std
::
string
origname
)
{
static
llvm
::
MDNode
*
setupDebugInfo
(
BoxedCode
*
cod
e
,
llvm
::
Function
*
f
,
std
::
string
origname
)
{
int
lineno
=
0
;
if
(
source
->
ast
)
lineno
=
source
->
ast
->
lineno
;
if
(
code
->
source
->
ast
)
lineno
=
code
->
source
->
ast
->
lineno
;
llvm
::
DIBuilder
builder
(
*
g
.
cur_module
);
BoxedString
*
fn
=
source
->
getFn
()
;
BoxedString
*
fn
=
code
->
filename
;
std
::
string
dir
=
""
;
std
::
string
producer
=
"pyston; git rev "
STRINGIFY
(
GITREV
);
...
...
@@ -1102,7 +1102,7 @@ std::pair<CompiledFunction*, llvm::Function*> doCompile(BoxedCode* code, SourceI
// g.func_registry.registerFunction(f, g.cur_module);
llvm
::
MDNode
*
dbg_funcinfo
=
setupDebugInfo
(
sourc
e
,
f
,
nameprefix
);
llvm
::
MDNode
*
dbg_funcinfo
=
setupDebugInfo
(
cod
e
,
f
,
nameprefix
);
irgen_us
+=
_t2
.
split
();
...
...
src/codegen/irgen/hooks.cpp
View file @
bcd80646
...
...
@@ -69,33 +69,6 @@ llvm::ArrayRef<AST_stmt*> SourceInfo::getBody() const {
};
}
BORROWED
(
BoxedString
*
)
SourceInfo
::
getFn
()
{
assert
(
fn
->
ob_refcnt
>=
1
);
return
fn
;
}
BORROWED
(
BoxedString
*
)
SourceInfo
::
getName
()
noexcept
{
assert
(
ast
);
static
BoxedString
*
lambda_name
=
getStaticString
(
"<lambda>"
);
static
BoxedString
*
module_name
=
getStaticString
(
"<module>"
);
switch
(
ast
->
type
)
{
case
AST_TYPE
:
:
ClassDef
:
return
ast_cast
<
AST_ClassDef
>
(
ast
)
->
name
.
getBox
();
case
AST_TYPE
:
:
FunctionDef
:
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
:
case
AST_TYPE
:
:
Suite
:
return
module_name
;
default:
RELEASE_ASSERT
(
0
,
"%d"
,
ast
->
type
);
}
}
Box
*
SourceInfo
::
getDocString
()
{
auto
body
=
getBody
();
if
(
body
.
size
()
>
0
&&
body
[
0
]
->
type
==
AST_TYPE
::
Expr
...
...
@@ -172,7 +145,7 @@ CompiledFunction* compileFunction(BoxedCode* code, FunctionSpecialization* spec,
SourceInfo
*
source
=
code
->
source
.
get
();
assert
(
source
);
BoxedString
*
name
=
source
->
getName
()
;
BoxedString
*
name
=
code
->
name
;
ASSERT
(
code
->
versions
.
size
()
<
20
,
"%s %u"
,
name
->
c_str
(),
code
->
versions
.
size
());
...
...
@@ -201,7 +174,7 @@ CompiledFunction* compileFunction(BoxedCode* code, FunctionSpecialization* spec,
RELEASE_ASSERT
((
int
)
effort
<
sizeof
(
colors
)
/
sizeof
(
colors
[
0
]),
""
);
if
(
spec
)
{
ss
<<
"
\033
["
<<
colors
[(
int
)
effort
]
<<
";1mJIT'ing "
<<
source
->
getFn
()
->
s
()
<<
":"
<<
name
->
s
()
ss
<<
"
\033
["
<<
colors
[(
int
)
effort
]
<<
";1mJIT'ing "
<<
code
->
filename
->
s
()
<<
":"
<<
name
->
s
()
<<
" with signature ("
;
for
(
int
i
=
0
;
i
<
spec
->
arg_types
.
size
();
i
++
)
{
if
(
i
>
0
)
...
...
@@ -212,7 +185,7 @@ CompiledFunction* compileFunction(BoxedCode* code, FunctionSpecialization* spec,
ss
<<
") -> "
;
ss
<<
spec
->
rtn_type
->
debugName
();
}
else
{
ss
<<
"
\033
["
<<
colors
[(
int
)
effort
]
<<
";1mDoing OSR-entry partial compile of "
<<
source
->
getFn
()
->
s
()
ss
<<
"
\033
["
<<
colors
[(
int
)
effort
]
<<
";1mDoing OSR-entry partial compile of "
<<
code
->
filename
->
s
()
<<
":"
<<
name
->
s
()
<<
", starting with backedge to block "
<<
entry_descriptor
->
backedge
->
target
->
idx
;
}
ss
<<
" at effort level "
<<
(
int
)
effort
<<
" with exception style "
...
...
@@ -243,7 +216,7 @@ CompiledFunction* compileFunction(BoxedCode* code, FunctionSpecialization* spec,
static
StatCounter
us_compiling
(
"us_compiling"
);
us_compiling
.
log
(
us
);
if
(
VERBOSITY
()
>=
1
&&
us
>
100000
)
{
printf
(
"Took %ldms to compile %s::%s (effort %d)!
\n
"
,
us
/
1000
,
source
->
getFn
()
->
c_str
(),
name
->
c_str
(),
printf
(
"Took %ldms to compile %s::%s (effort %d)!
\n
"
,
us
/
1000
,
code
->
filename
->
c_str
(),
name
->
c_str
(),
(
int
)
effort
);
}
...
...
src/codegen/irgen/irgenerator.cpp
View file @
bcd80646
...
...
@@ -213,7 +213,7 @@ template <typename Builder> static llvm::Value* getGlobalsGep(Builder& builder,
return
builder
.
CreateConstInBoundsGEP2_32
(
v
,
0
,
7
);
}
template
<
typename
Builder
>
static
llvm
::
Value
*
get
MD
Gep
(
Builder
&
builder
,
llvm
::
Value
*
v
)
{
template
<
typename
Builder
>
static
llvm
::
Value
*
get
Code
Gep
(
Builder
&
builder
,
llvm
::
Value
*
v
)
{
static_assert
(
offsetof
(
FrameInfo
,
code
)
==
72
+
16
,
""
);
return
builder
.
CreateConstInBoundsGEP2_32
(
v
,
0
,
9
);
}
...
...
@@ -330,8 +330,8 @@ void IRGenState::setupFrameInfoVar(llvm::Value* passed_closure, llvm::Value* pas
builder
.
CreateStore
(
vregs
,
getVRegsGep
(
builder
,
al
));
builder
.
CreateStore
(
getConstantInt
(
num_user_visible_vregs
,
g
.
i32
),
getNumVRegsGep
(
builder
,
al
));
builder
.
CreateStore
(
getRefcounts
()
->
setType
(
embedRelocatablePtr
(
get
MD
(),
g
.
llvm_code_type_ptr
),
RefType
::
BORROWED
),
get
MD
Gep
(
builder
,
al
));
getRefcounts
()
->
setType
(
embedRelocatablePtr
(
get
Code
(),
g
.
llvm_code_type_ptr
),
RefType
::
BORROWED
),
get
Code
Gep
(
builder
,
al
));
this
->
frame_info
=
al
;
this
->
globals
=
passed_globals
;
...
...
@@ -1709,8 +1709,8 @@ private:
// I think it's better to just not generate bad speculations:
if
(
rtn
->
canConvertTo
(
speculated_type
))
{
auto
source
=
irstate
->
getSourceInfo
();
printf
(
"On %s:%d, function %s:
\n
"
,
source
->
getFn
()
->
c_str
(),
source
->
getBody
()[
0
]
->
lineno
,
source
->
getName
()
->
c_str
());
printf
(
"On %s:%d, function %s:
\n
"
,
irstate
->
getCode
()
->
filename
->
c_str
(),
source
->
getBody
()[
0
]
->
lineno
,
irstate
->
getCode
()
->
name
->
c_str
());
irstate
->
getSourceInfo
()
->
cfg
->
print
();
}
RELEASE_ASSERT
(
!
rtn
->
canConvertTo
(
speculated_type
),
"%s %s"
,
rtn
->
getType
()
->
debugName
().
c_str
(),
...
...
@@ -2337,7 +2337,7 @@ private:
// Emitting the actual OSR:
emitter.getBuilder()->SetInsertPoint(onramp);
OSREntryDescriptor* entry = OSREntryDescriptor::create(irstate->get
MD
(), osr_key, irstate->getExceptionStyle());
OSREntryDescriptor* entry = OSREntryDescriptor::create(irstate->get
Code
(), osr_key, irstate->getExceptionStyle());
OSRExit* exit = new OSRExit(entry);
llvm::Value* partial_func = emitter.getBuilder()->CreateCall(g.funcs.compilePartialFunc,
embedRelocatablePtr(exit, g.i8->getPointerTo()));
...
...
src/codegen/irgen/irgenerator.h
View file @
bcd80646
...
...
@@ -91,7 +91,7 @@ public:
CFG
*
getCFG
()
{
return
getSourceInfo
()
->
cfg
;
}
CompiledFunction
*
getCurFunction
()
{
return
cf
;
}
BoxedCode
*
get
MD
()
{
return
code
;
}
BoxedCode
*
get
Code
()
{
return
code
;
}
ExceptionStyle
getExceptionStyle
()
{
return
cf
->
exception_style
;
}
...
...
src/codegen/unwinding.cpp
View file @
bcd80646
...
...
@@ -490,9 +490,7 @@ static const LineInfo lineInfoForFrameInfo(FrameInfo* frame_info) {
auto
*
code
=
frame_info
->
code
;
assert
(
code
);
auto
source
=
code
->
source
.
get
();
return
LineInfo
(
current_stmt
->
lineno
,
current_stmt
->
col_offset
,
source
->
getFn
(),
source
->
getName
());
return
LineInfo
(
current_stmt
->
lineno
,
current_stmt
->
col_offset
,
code
->
filename
,
code
->
name
);
}
// A class that converts a C stack trace to a Python stack trace.
...
...
@@ -1073,7 +1071,7 @@ std::string getCurrentPythonLine() {
auto
current_stmt
=
frame_info
->
stmt
;
stream
<<
source
->
getFn
()
->
c_str
()
<<
":"
<<
current_stmt
->
lineno
;
stream
<<
code
->
filename
->
c_str
()
<<
":"
<<
current_stmt
->
lineno
;
return
stream
.
str
();
}
return
"unknown:-1"
;
...
...
src/core/cfg.cpp
View file @
bcd80646
...
...
@@ -263,7 +263,7 @@ public:
void
runRecursively
(
AST
*
ast
,
AST_arguments
*
args
,
AST
*
orig_node
);
};
static
CFG
*
computeCFG
(
SourceInfo
*
source
,
const
ParamNames
&
param_names
,
ScopeInfo
*
scoping
,
static
CFG
*
computeCFG
(
BoxedString
*
fn
,
SourceInfo
*
source
,
const
ParamNames
&
param_names
,
ScopeInfo
*
scoping
,
ModuleCFGProcessor
*
cfgizer
);
// A class that crawls the AST of a single function and computes the CFG
...
...
@@ -343,6 +343,7 @@ private:
// ---------- Member fields ----------
private:
BoxedString
*
filename
;
SourceInfo
*
source
;
InternedStringPool
&
stringpool
;
ScopeInfo
*
scoping
;
...
...
@@ -360,12 +361,14 @@ private:
unsigned
int
next_var_index
=
0
;
friend
CFG
*
computeCFG
(
SourceInfo
*
source
,
const
ParamNames
&
param_names
,
ScopeInfo
*
,
ModuleCFGProcessor
*
);
friend
CFG
*
computeCFG
(
BoxedString
*
fn
,
SourceInfo
*
source
,
const
ParamNames
&
param_names
,
ScopeInfo
*
,
ModuleCFGProcessor
*
);
public:
CFGVisitor
(
SourceInfo
*
source
,
InternedStringPool
&
stringpool
,
ScopeInfo
*
scoping
,
AST_TYPE
::
AST_TYPE
root_type
,
FutureFlags
future_flags
,
CFG
*
cfg
,
ModuleCFGProcessor
*
cfgizer
)
:
source
(
source
),
CFGVisitor
(
BoxedString
*
filename
,
SourceInfo
*
source
,
InternedStringPool
&
stringpool
,
ScopeInfo
*
scoping
,
AST_TYPE
::
AST_TYPE
root_type
,
FutureFlags
future_flags
,
CFG
*
cfg
,
ModuleCFGProcessor
*
cfgizer
)
:
filename
(
filename
),
source
(
source
),
stringpool
(
stringpool
),
scoping
(
scoping
),
root_type
(
root_type
),
...
...
@@ -459,8 +462,7 @@ private:
}
}
raiseSyntaxError
(
"'continue' not properly in loop"
,
value
->
lineno
,
value
->
col_offset
,
source
->
getFn
()
->
s
(),
""
,
true
);
raiseSyntaxError
(
"'continue' not properly in loop"
,
value
->
lineno
,
value
->
col_offset
,
filename
->
s
(),
""
,
true
);
}
void
doBreak
(
AST
*
value
)
{
...
...
@@ -477,7 +479,7 @@ private:
}
}
raiseSyntaxError
(
"'break' outside loop"
,
value
->
lineno
,
value
->
col_offset
,
source
->
getFn
()
->
s
(),
""
,
true
);
raiseSyntaxError
(
"'break' outside loop"
,
value
->
lineno
,
value
->
col_offset
,
filename
->
s
(),
""
,
true
);
}
AST_expr
*
callNonzero
(
AST_expr
*
e
)
{
...
...
@@ -2959,7 +2961,7 @@ void VRegInfo::assignVRegs(CFG* cfg, const ParamNames& param_names) {
}
static
CFG
*
computeCFG
(
SourceInfo
*
source
,
const
ParamNames
&
param_names
,
ScopeInfo
*
scoping
,
static
CFG
*
computeCFG
(
BoxedString
*
filename
,
SourceInfo
*
source
,
const
ParamNames
&
param_names
,
ScopeInfo
*
scoping
,
ModuleCFGProcessor
*
cfgizer
)
{
STAT_TIMER
(
t0
,
"us_timer_computecfg"
,
0
);
...
...
@@ -2968,7 +2970,7 @@ static CFG* computeCFG(SourceInfo* source, const ParamNames& param_names, ScopeI
CFG
*
rtn
=
new
CFG
();
auto
&&
stringpool
=
cfgizer
->
stringpool
;
CFGVisitor
visitor
(
source
,
stringpool
,
scoping
,
source
->
ast
->
type
,
source
->
future_flags
,
rtn
,
cfgizer
);
CFGVisitor
visitor
(
filename
,
source
,
stringpool
,
scoping
,
source
->
ast
->
type
,
source
->
future_flags
,
rtn
,
cfgizer
);
bool
skip_first
=
false
;
...
...
@@ -3091,7 +3093,6 @@ static CFG* computeCFG(SourceInfo* source, const ParamNames& param_names, ScopeI
if
(
b
->
predecessors
.
size
()
==
0
)
{
if
(
b
!=
rtn
->
getStartingBlock
())
{
rtn
->
print
();
printf
(
"%s
\n
"
,
source
->
getName
()
->
c_str
());
}
ASSERT
(
b
==
rtn
->
getStartingBlock
(),
"%d"
,
b
->
idx
);
}
...
...
@@ -3290,19 +3291,19 @@ InternedStringPool& stringpoolForAST(AST* ast) {
void
ModuleCFGProcessor
::
runRecursively
(
AST
*
ast
,
AST_arguments
*
args
,
AST
*
orig_node
)
{
ScopeInfo
*
scope_info
=
scoping
.
getScopeInfoForNode
(
orig_node
);
std
::
unique_ptr
<
SourceInfo
>
si
(
new
SourceInfo
(
bm
,
ScopingResults
(
scope_info
,
scoping
.
areGlobalsFromModule
()),
future_flags
,
ast
,
fn
));
new
SourceInfo
(
bm
,
ScopingResults
(
scope_info
,
scoping
.
areGlobalsFromModule
()),
future_flags
,
ast
));
ParamNames
param_names
(
ast
,
stringpool
);
for
(
auto
e
:
param_names
.
allArgsAsName
())
fillScopingInfo
(
e
,
scope_info
);
si
->
cfg
=
computeCFG
(
si
.
get
(),
param_names
,
scope_info
,
this
);
si
->
cfg
=
computeCFG
(
fn
,
si
.
get
(),
param_names
,
scope_info
,
this
);
BoxedCode
*
code
;
if
(
args
)
code
=
new
BoxedCode
(
args
->
args
.
size
(),
args
->
vararg
,
args
->
kwarg
,
std
::
move
(
si
),
std
::
move
(
param_names
));
code
=
new
BoxedCode
(
args
->
args
.
size
(),
args
->
vararg
,
args
->
kwarg
,
std
::
move
(
si
),
std
::
move
(
param_names
)
,
fn
);
else
code
=
new
BoxedCode
(
0
,
false
,
false
,
std
::
move
(
si
),
std
::
move
(
param_names
));
code
=
new
BoxedCode
(
0
,
false
,
false
,
std
::
move
(
si
),
std
::
move
(
param_names
)
,
fn
);
// XXX very bad! Should properly track this:
constants
.
push_back
(
code
);
...
...
src/core/types.h
View file @
bcd80646
...
...
@@ -486,7 +486,6 @@ public:
// Data about a single textual function definition.
class
SourceInfo
{
private:
BoxedString
*
fn
;
// equivalent of code.co_filename
std
::
unique_ptr
<
LivenessAnalysis
>
liveness_info
;
public:
...
...
@@ -499,15 +498,11 @@ public:
LivenessAnalysis
*
getLiveness
();
// does not throw CXX or CAPI exceptions:
BORROWED
(
BoxedString
*
)
getName
()
noexcept
;
BORROWED
(
BoxedString
*
)
getFn
();
llvm
::
ArrayRef
<
AST_stmt
*>
getBody
()
const
;
Box
*
getDocString
();
SourceInfo
(
BoxedModule
*
m
,
ScopingResults
scoping
,
FutureFlags
future_flags
,
AST
*
ast
,
BoxedString
*
fn
);
SourceInfo
(
BoxedModule
*
m
,
ScopingResults
scoping
,
FutureFlags
future_flags
,
AST
*
ast
);
~
SourceInfo
();
};
...
...
src/runtime/code.cpp
View file @
bcd80646
...
...
@@ -26,28 +26,36 @@ extern "C" {
BoxedClass
*
code_cls
;
}
#if 0
BORROWED(Box*) BoxedCode::name(Box* b, void*) noexcept {
RELEASE_ASSERT(b->cls == code_cls, "");
BoxedCode* code = static_cast<BoxedCode*>(b);
if (code->_name)
return code->_name;
return
code
->
source
->
getName
()
;
return code->
name
;
}
#endif
Box
*
BoxedCode
::
co_name
(
Box
*
b
,
void
*
arg
)
noexcept
{
return
incref
(
name
(
b
,
arg
));
RELEASE_ASSERT
(
b
->
cls
==
code_cls
,
""
);
BoxedCode
*
code
=
static_cast
<
BoxedCode
*>
(
b
);
return
incref
(
code
->
name
);
}
#if 0
BORROWED(Box*) BoxedCode::filename(Box* b, void*) noexcept {
RELEASE_ASSERT(b->cls == code_cls, "");
BoxedCode* code = static_cast<BoxedCode*>(b);
if (code->_filename)
return code->_filename;
return
code
->
source
->
getFn
()
;
return code->
filename
;
}
#endif
Box
*
BoxedCode
::
co_filename
(
Box
*
b
,
void
*
arg
)
noexcept
{
return
incref
(
filename
(
b
,
arg
));
RELEASE_ASSERT
(
b
->
cls
==
code_cls
,
""
);
BoxedCode
*
code
=
static_cast
<
BoxedCode
*>
(
b
);
return
incref
(
code
->
filename
);
}
Box
*
BoxedCode
::
firstlineno
(
Box
*
b
,
void
*
)
noexcept
{
...
...
@@ -102,19 +110,67 @@ Box* BoxedCode::flags(Box* b, void*) noexcept {
void
BoxedCode
::
dealloc
(
Box
*
b
)
noexcept
{
BoxedCode
*
o
=
static_cast
<
BoxedCode
*>
(
b
);
Py_XDECREF
(
o
->
_
filename
);
Py_XDECREF
(
o
->
_
name
);
Py_XDECREF
(
o
->
filename
);
Py_XDECREF
(
o
->
name
);
o
->
source
.
~
decltype
(
o
->
source
)();
o
->
cls
->
tp_free
(
o
);
}
BORROWED
(
BoxedString
*
)
getASTName
(
AST
*
ast
)
noexcept
{
assert
(
ast
);
static
BoxedString
*
lambda_name
=
getStaticString
(
"<lambda>"
);
static
BoxedString
*
module_name
=
getStaticString
(
"<module>"
);
switch
(
ast
->
type
)
{
case
AST_TYPE
:
:
ClassDef
:
return
ast_cast
<
AST_ClassDef
>
(
ast
)
->
name
.
getBox
();
case
AST_TYPE
:
:
FunctionDef
:
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
:
case
AST_TYPE
:
:
Suite
:
return
module_name
;
default:
RELEASE_ASSERT
(
0
,
"%d"
,
ast
->
type
);
}
}
BoxedCode
::
BoxedCode
(
int
num_args
,
bool
takes_varargs
,
bool
takes_kwargs
,
std
::
unique_ptr
<
SourceInfo
>
source
,
ParamNames
param_names
,
BoxedString
*
filename
)
:
source
(
std
::
move
(
source
)),
filename
(
incref
(
filename
)),
name
(
incref
(
getASTName
(
this
->
source
->
ast
))),
param_names
(
std
::
move
(
param_names
)),
takes_varargs
(
takes_varargs
),
takes_kwargs
(
takes_kwargs
),
num_args
(
num_args
),
times_interpreted
(
0
),
internal_callable
(
NULL
,
NULL
)
{
}
BoxedCode
::
BoxedCode
(
int
num_args
,
bool
takes_varargs
,
bool
takes_kwargs
,
const
ParamNames
&
param_names
,
BoxedString
*
filename
)
:
source
(
nullptr
),
// This should probably be just an "incref"?
filename
(
xincref
(
filename
)),
name
(
boxString
(
"???"
)),
param_names
(
param_names
),
takes_varargs
(
takes_varargs
),
takes_kwargs
(
takes_kwargs
),
num_args
(
num_args
),
times_interpreted
(
0
),
internal_callable
(
NULL
,
NULL
)
{
}
// The dummy constructor for PyCode_New:
BoxedCode
::
BoxedCode
(
Box
*
filename
,
Box
*
name
,
int
firstline
)
:
_
filename
(
filename
),
_
name
(
name
),
BoxedCode
::
BoxedCode
(
Box
edString
*
filename
,
BoxedString
*
name
,
int
firstline
)
:
filename
(
filename
),
name
(
name
),
_firstline
(
firstline
),
param_names
(
ParamNames
::
empty
()),
takes_varargs
(
false
),
...
...
@@ -143,7 +199,8 @@ extern "C" PyCodeObject* PyCode_New(int argcount, int nlocals, int stacksize, in
RELEASE_ASSERT
(
PyString_Check
(
filename
),
""
);
RELEASE_ASSERT
(
PyString_Check
(
name
),
""
);
return
(
PyCodeObject
*
)
new
BoxedCode
(
filename
,
name
,
firstlineno
);
return
(
PyCodeObject
*
)
new
BoxedCode
(
static_cast
<
BoxedString
*>
(
filename
),
static_cast
<
BoxedString
*>
(
name
),
firstlineno
);
}
extern
"C"
PyCodeObject
*
PyCode_NewEmpty
(
const
char
*
filename
,
const
char
*
funcname
,
int
firstlineno
)
noexcept
{
...
...
@@ -198,12 +255,12 @@ extern "C" int PyCode_GetArgCount(PyCodeObject* op) noexcept {
extern
"C"
BORROWED
(
PyObject
*
)
PyCode_GetFilename
(
PyCodeObject
*
op
)
noexcept
{
RELEASE_ASSERT
(
PyCode_Check
((
Box
*
)
op
),
""
);
return
BoxedCode
::
filename
((
Box
*
)
op
,
NULL
)
;
return
reinterpret_cast
<
BoxedCode
*>
(
op
)
->
filename
;
}
extern
"C"
BORROWED
(
PyObject
*
)
PyCode_GetName
(
PyCodeObject
*
op
)
noexcept
{
RELEASE_ASSERT
(
PyCode_Check
((
Box
*
)
op
),
""
);
return
BoxedCode
::
name
((
Box
*
)
op
,
NULL
)
;
return
reinterpret_cast
<
BoxedCode
*>
(
op
)
->
name
;
}
extern
"C"
int
PyCode_HasFreeVars
(
PyCodeObject
*
_code
)
noexcept
{
...
...
src/runtime/cxx_unwind.cpp
View file @
bcd80646
...
...
@@ -361,7 +361,7 @@ static void print_frame(unw_cursor_t* cursor, const unw_proc_info_t* pip) {
if
(
frame_type
==
INTERPRETED
&&
cf
&&
cur_stmt
)
{
auto
source
=
cf
->
code_obj
->
source
.
get
();
// FIXME: dup'ed from lineInfoForFrame
LineInfo
line
(
cur_stmt
->
lineno
,
cur_stmt
->
col_offset
,
source
->
getFn
(),
source
->
getName
()
);
LineInfo
line
(
cur_stmt
->
lineno
,
cur_stmt
->
col_offset
,
cf
->
code_obj
->
filename
,
cf
->
code_obj
->
name
);
printf
(
" File
\"
%s
\"
, line %d, in %s
\n
"
,
line
.
file
->
c_str
(),
line
.
line
,
line
.
func
->
c_str
());
}
}
...
...
src/runtime/generator.cpp
View file @
bcd80646
...
...
@@ -531,7 +531,7 @@ Box* generator_name(Box* _self, void* context) noexcept {
assert
(
isSubclass
(
_self
->
cls
,
generator_cls
));
BoxedGenerator
*
self
=
static_cast
<
BoxedGenerator
*>
(
_self
);
return
incref
(
self
->
function
->
code
->
source
->
getName
()
);
return
incref
(
self
->
function
->
code
->
name
);
}
extern
"C"
int
PyGen_NeedsFinalizing
(
PyGenObject
*
gen
)
noexcept
{
...
...
src/runtime/objmodel.cpp
View file @
bcd80646
...
...
@@ -4011,15 +4011,7 @@ static CompiledFunction* pickVersion(BoxedCode* code, int num_output_args, Box*
}
static
llvm
::
StringRef
getFunctionName
(
BoxedCode
*
code
)
{
if
(
code
->
source
)
return
code
->
source
->
getName
()
->
s
();
else
if
(
code
->
versions
.
size
())
{
return
"<builtin function>"
;
// std::ostringstream oss;
// oss << "<function at " << code->versions[0]->code << ">";
// return oss.str();
}
return
"<unknown function>"
;
return
code
->
name
->
s
();
}
// A hacky little class that lets us save on some parameter size.
...
...
src/runtime/types.cpp
View file @
bcd80646
...
...
@@ -378,13 +378,8 @@ BoxedFunction::BoxedFunction(BoxedCode* code, llvm::ArrayRef<Box*> defaults, Box
bool
can_change_defaults
)
:
BoxedFunctionBase
(
code
,
defaults
,
closure
,
globals
,
can_change_defaults
)
{
// TODO eventually we want this to assert(f->source), I think, but there are still
// some builtin functions that are BoxedFunctions but really ought to be a type that
// we don't have yet.
if
(
code
->
source
)
{
assert
(
!
this
->
name
);
this
->
name
=
incref
(
static_cast
<
BoxedString
*>
(
code
->
source
->
getName
()));
}
assert
(
!
this
->
name
);
this
->
name
=
incref
(
code
->
name
);
}
BoxedBuiltinFunctionOrMethod
::
BoxedBuiltinFunctionOrMethod
(
BoxedCode
*
code
,
const
char
*
name
,
const
char
*
doc
)
...
...
src/runtime/types.h
View file @
bcd80646
...
...
@@ -1078,8 +1078,8 @@ class BoxedCode : public Box {
public:
std
::
unique_ptr
<
SourceInfo
>
source
;
// source can be NULL for functions defined in the C/C++ runtime
Box
*
_
filename
=
nullptr
;
Box
*
_
name
=
nullptr
;
Box
edString
*
filename
=
nullptr
;
Box
edString
*
name
=
nullptr
;
int
_firstline
;
const
ParamNames
param_names
;
...
...
@@ -1110,12 +1110,13 @@ public:
InternalCallable
internal_callable
;
BoxedCode
(
int
num_args
,
bool
takes_varargs
,
bool
takes_kwargs
,
std
::
unique_ptr
<
SourceInfo
>
source
,
ParamNames
param_names
);
BoxedCode
(
int
num_args
,
bool
takes_varargs
,
bool
takes_kwargs
,
const
ParamNames
&
param_names
=
ParamNames
::
empty
());
ParamNames
param_names
,
BoxedString
*
filename
);
BoxedCode
(
int
num_args
,
bool
takes_varargs
,
bool
takes_kwargs
,
const
ParamNames
&
param_names
=
ParamNames
::
empty
(),
BoxedString
*
filename
=
nullptr
);
~
BoxedCode
();
// The dummy constructor for PyCode_New:
BoxedCode
(
Box
*
filename
,
Box
*
name
,
int
firstline
);
BoxedCode
(
Box
edString
*
filename
,
BoxedString
*
name
,
int
firstline
);
DEFAULT_CLASS_SIMPLE
(
code_cls
,
false
);
...
...
@@ -1161,8 +1162,8 @@ public:
// These need to be static functions rather than methods because function
// pointers could point to them.
static
BORROWED
(
Box
*
)
name
(
Box
*
b
,
void
*
)
noexcept
;
static
BORROWED
(
Box
*
)
filename
(
Box
*
b
,
void
*
)
noexcept
;
//
static BORROWED(Box*) name(Box* b, void*) noexcept;
//
static BORROWED(Box*) filename(Box* b, void*) noexcept;
static
Box
*
co_name
(
Box
*
b
,
void
*
)
noexcept
;
static
Box
*
co_filename
(
Box
*
b
,
void
*
)
noexcept
;
static
Box
*
firstlineno
(
Box
*
b
,
void
*
)
noexcept
;
...
...
src/runtime/util.cpp
View file @
bcd80646
...
...
@@ -250,8 +250,8 @@ extern "C" void dumpEx(void* p, int levels) {
BoxedCode
*
code
=
f
->
code
;
if
(
code
->
source
)
{
printf
(
"User-defined function '%s'
\n
"
,
code
->
source
->
getName
()
->
c_str
());
printf
(
"Defined at %s:%d
\n
"
,
code
->
source
->
getFn
()
->
c_str
(),
code
->
source
->
ast
->
lineno
);
printf
(
"User-defined function '%s'
\n
"
,
code
->
name
->
c_str
());
printf
(
"Defined at %s:%d
\n
"
,
code
->
filename
->
c_str
(),
code
->
source
->
ast
->
lineno
);
if
(
code
->
source
->
cfg
&&
levels
>
0
)
{
code
->
source
->
cfg
->
print
();
...
...
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