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
a9fe6120
Commit
a9fe6120
authored
Jan 20, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sys.exc_info which accesses the frame-local ExcInfo
Currently nothing sets that though.
parent
1e672eb3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
17 deletions
+60
-17
src/codegen/ast_interpreter.cpp
src/codegen/ast_interpreter.cpp
+9
-1
src/codegen/ast_interpreter.h
src/codegen/ast_interpreter.h
+1
-0
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+4
-2
src/codegen/unwinding.cpp
src/codegen/unwinding.cpp
+36
-8
src/codegen/unwinding.h
src/codegen/unwinding.h
+2
-3
src/core/types.h
src/core/types.h
+2
-0
src/runtime/builtin_modules/sys.cpp
src/runtime/builtin_modules/sys.cpp
+6
-3
No files found.
src/codegen/ast_interpreter.cpp
View file @
a9fe6120
...
...
@@ -127,6 +127,7 @@ private:
BoxedClosure
*
passed_closure
,
*
created_closure
;
BoxedGenerator
*
generator
;
unsigned
edgecount
;
FrameInfo
frame_info
;
public:
AST_stmt
*
getCurrentStatement
()
{
...
...
@@ -135,6 +136,7 @@ public:
}
CompiledFunction
*
getCF
()
{
return
compiled_func
;
}
FrameInfo
*
getFrameInfo
()
{
return
&
frame_info
;
}
const
SymMap
&
getSymbolTable
()
{
return
sym_table
;
}
void
gcVisit
(
GCVisitor
*
visitor
);
};
...
...
@@ -189,6 +191,12 @@ CompiledFunction* getCFForInterpretedFrame(void* frame_ptr) {
return
interpreter
->
getCF
();
}
FrameInfo
*
getFrameInfoForInterpretedFrame
(
void
*
frame_ptr
)
{
ASTInterpreter
*
interpreter
=
s_interpreterMap
[
frame_ptr
];
assert
(
interpreter
);
return
interpreter
->
getFrameInfo
();
}
BoxedDict
*
localsForInterpretedFrame
(
void
*
frame_ptr
,
bool
only_user_visible
)
{
ASTInterpreter
*
interpreter
=
s_interpreterMap
[
frame_ptr
];
assert
(
interpreter
);
...
...
@@ -225,7 +233,7 @@ void gatherInterpreterRoots(GCVisitor* visitor) {
ASTInterpreter
::
ASTInterpreter
(
CompiledFunction
*
compiled_function
)
:
compiled_func
(
compiled_function
),
source_info
(
compiled_function
->
clfunc
->
source
),
scope_info
(
0
),
next_block
(
0
),
current_block
(
0
),
current_inst
(
0
),
last_exception
(
NULL
,
NULL
,
NULL
),
passed_closure
(
0
),
created_closure
(
0
),
generator
(
0
),
edgecount
(
0
)
{
generator
(
0
),
edgecount
(
0
)
,
frame_info
(
ExcInfo
(
NULL
,
NULL
,
NULL
))
{
CLFunction
*
f
=
compiled_function
->
clfunc
;
if
(
!
source_info
->
cfg
)
...
...
src/codegen/ast_interpreter.h
View file @
a9fe6120
...
...
@@ -35,6 +35,7 @@ Box* astInterpretFrom(CompiledFunction* cf, AST_stmt* start_at, BoxedDict* local
AST_stmt
*
getCurrentStatementForInterpretedFrame
(
void
*
frame_ptr
);
CompiledFunction
*
getCFForInterpretedFrame
(
void
*
frame_ptr
);
FrameInfo
*
getFrameInfoForInterpretedFrame
(
void
*
frame_ptr
);
void
gatherInterpreterRoots
(
gc
::
GCVisitor
*
visitor
);
BoxedDict
*
localsForInterpretedFrame
(
void
*
frame_ptr
,
bool
only_user_visible
);
...
...
src/codegen/irgen/irgenerator.cpp
View file @
a9fe6120
...
...
@@ -85,8 +85,10 @@ llvm::Value* IRGenState::getFrameInfoVar() {
llvm
::
AllocaInst
*
al
=
builder
.
CreateAlloca
(
g
.
frame_info_type
,
NULL
,
"frame_info"
);
assert
(
al
->
isStaticAlloca
());
static_assert
(
offsetof
(
FrameInfo
,
exc_type
)
==
0
,
""
);
llvm
::
Value
*
exctype_gep
=
builder
.
CreateConstInBoundsGEP2_32
(
al
,
0
,
0
);
static_assert
(
offsetof
(
FrameInfo
,
exc
)
==
0
,
""
);
static_assert
(
offsetof
(
ExcInfo
,
type
)
==
0
,
""
);
llvm
::
Value
*
exctype_gep
=
builder
.
CreateConstInBoundsGEP2_32
(
builder
.
CreateConstInBoundsGEP2_32
(
al
,
0
,
0
),
0
,
0
);
builder
.
CreateStore
(
embedConstantPtr
(
NULL
,
g
.
llvm_value_type_ptr
),
exctype_gep
);
frame_info
=
al
;
...
...
src/codegen/unwinding.cpp
View file @
a9fe6120
...
...
@@ -281,6 +281,14 @@ public:
abort
();
}
FrameInfo
*
getFrameInfo
()
{
if
(
id
.
type
==
PythonFrameId
::
COMPILED
)
{
}
else
if
(
id
.
type
==
PythonFrameId
::
INTERPRETED
)
{
return
getFrameInfoForInterpretedFrame
((
void
*
)
id
.
bp
);
}
abort
();
}
const
PythonFrameId
&
getId
()
const
{
return
id
;
}
static
std
::
unique_ptr
<
PythonFrameIterator
>
end
()
{
return
std
::
unique_ptr
<
PythonFrameIterator
>
(
nullptr
);
}
...
...
@@ -450,15 +458,35 @@ const LineInfo* getMostRecentLineInfo() {
return
lineInfoForFrame
(
*
frame
);
}
FrameInfo
*
getTopFrameInfo
()
{
std
::
unique_ptr
<
PythonFrameIterator
>
frame
=
getTopPythonFrame
();
if
(
frame
.
get_id
().
type
==
PythonFrameId
::
COMPILED
)
{
abort
();
}
else
if
(
frame
.
get_id
().
type
==
PythonFrameId
::
INTERPRETED
)
{
abort
();
}
else
{
abort
();
ExcInfo
getFrameExcInfo
()
{
std
::
vector
<
ExcInfo
*>
to_update
;
ExcInfo
*
cur_exc
=
NULL
;
for
(
PythonFrameIterator
&
frame_iter
:
unwindPythonFrames
())
{
FrameInfo
*
frame_info
=
frame_iter
.
getFrameInfo
();
cur_exc
=
&
frame_info
->
exc
;
if
(
!
cur_exc
->
type
)
{
to_update
.
push_back
(
cur_exc
);
continue
;
}
break
;
}
assert
(
cur_exc
);
// Only way this could still be NULL is if there weren't any python frames
if
(
!
cur_exc
->
type
)
{
// No exceptions found:
*
cur_exc
=
ExcInfo
(
None
,
None
,
None
);
}
assert
(
cur_exc
->
value
);
assert
(
cur_exc
->
traceback
);
for
(
auto
*
ex
:
to_update
)
{
*
ex
=
*
cur_exc
;
}
return
*
cur_exc
;
}
CompiledFunction
*
getTopCompiledFunction
()
{
...
...
src/codegen/unwinding.h
View file @
a9fe6120
...
...
@@ -30,9 +30,8 @@ CompiledFunction* getCFForAddress(uint64_t addr);
class
BoxedDict
;
BoxedDict
*
getLocals
(
bool
only_user_visible
);
struct
FrameInfo
;
FrameInfo
*
getTopFrameInfo
();
// Fetches the frame-local excinfo object, calculating it if necessary (from previous frames):
ExcInfo
getFrameExcInfo
();
}
#endif
src/core/types.h
View file @
a9fe6120
...
...
@@ -483,6 +483,8 @@ struct FrameInfo {
// In Pyston, exc is the frame-local value of sys.exc_info.
// - This makes frame entering+leaving faster at the expense of slower exceptions.
ExcInfo
exc
;
FrameInfo
(
ExcInfo
exc
)
:
exc
(
exc
)
{}
};
}
...
...
src/runtime/builtin_modules/sys.cpp
View file @
a9fe6120
...
...
@@ -19,6 +19,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "codegen/unwinding.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/inline/boxing.h"
...
...
@@ -32,9 +33,11 @@ BoxedModule* sys_module;
BoxedDict
*
sys_modules_dict
;
Box
*
sysExcInfo
()
{
return
new
BoxedTuple
({
cur_thread_state
.
curexc_type
?
cur_thread_state
.
curexc_type
:
None
,
cur_thread_state
.
curexc_value
?
cur_thread_state
.
curexc_value
:
None
,
cur_thread_state
.
curexc_traceback
?
cur_thread_state
.
curexc_traceback
:
None
});
ExcInfo
exc
=
getFrameExcInfo
();
assert
(
exc
.
type
);
assert
(
exc
.
value
);
assert
(
exc
.
traceback
);
return
new
BoxedTuple
({
exc
.
type
,
exc
.
value
,
exc
.
traceback
});
}
static
Box
*
sysExit
(
Box
*
arg
)
{
...
...
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