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
acbc8021
Commit
acbc8021
authored
Jul 23, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some basic support for the two-arg raise statement
parent
2cff7121
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
23 deletions
+61
-23
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+10
-11
src/codegen/runtime_hooks.cpp
src/codegen/runtime_hooks.cpp
+1
-2
src/codegen/runtime_hooks.h
src/codegen/runtime_hooks.h
+1
-1
src/runtime/inline/link_forcer.cpp
src/runtime/inline/link_forcer.cpp
+1
-1
src/runtime/objmodel.h
src/runtime/objmodel.h
+1
-2
src/runtime/stacktrace.cpp
src/runtime/stacktrace.cpp
+15
-6
test/tests/exceptions.py
test/tests/exceptions.py
+16
-0
test/tests/exceptions_basic.py
test/tests/exceptions_basic.py
+16
-0
No files found.
src/codegen/irgen/irgenerator.cpp
View file @
acbc8021
...
...
@@ -1801,20 +1801,19 @@ private:
void
doRaise
(
AST_Raise
*
node
,
ExcInfo
exc_info
)
{
std
::
vector
<
llvm
::
Value
*>
args
;
llvm
::
Value
*
raise_func
=
g
.
funcs
.
raise0
;
if
(
node
->
arg0
)
{
raise_func
=
g
.
funcs
.
raise1
;
CompilerVariable
*
arg0
=
evalExpr
(
node
->
arg0
,
exc_info
);
ConcreteCompilerVariable
*
converted_arg0
=
arg0
->
makeConverted
(
emitter
,
arg0
->
getBoxType
());
arg0
->
decvref
(
emitter
);
args
.
push_back
(
converted_arg0
->
getValue
());
for
(
auto
a
:
{
node
->
arg0
,
node
->
arg1
,
node
->
arg2
})
{
if
(
a
)
{
CompilerVariable
*
v
=
evalExpr
(
a
,
exc_info
);
ConcreteCompilerVariable
*
converted
=
v
->
makeConverted
(
emitter
,
v
->
getBoxType
());
v
->
decvref
(
emitter
);
args
.
push_back
(
converted
->
getValue
());
}
else
{
args
.
push_back
(
embedConstantPtr
(
None
,
g
.
llvm_value_type_ptr
));
}
}
RELEASE_ASSERT
(
node
->
arg1
==
NULL
,
""
);
RELEASE_ASSERT
(
node
->
arg2
==
NULL
,
""
);
emitter
.
createCall
(
exc_info
,
raise_func
,
args
);
emitter
.
createCall
(
exc_info
,
g
.
funcs
.
raise3
,
args
);
emitter
.
getBuilder
()
->
CreateUnreachable
();
endBlock
(
DEAD
);
...
...
src/codegen/runtime_hooks.cpp
View file @
acbc8021
...
...
@@ -223,8 +223,7 @@ void initGlobalFuncs(GlobalState& g) {
GET
(
__cxa_begin_catch
);
g
.
funcs
.
__cxa_end_catch
=
addFunc
((
void
*
)
__cxa_end_catch
,
g
.
void_
);
GET
(
raise0
);
GET
(
raise1
);
GET
(
raise3
);
g
.
funcs
.
div_i64_i64
=
getFunc
((
void
*
)
div_i64_i64
,
"div_i64_i64"
);
g
.
funcs
.
mod_i64_i64
=
getFunc
((
void
*
)
mod_i64_i64
,
"mod_i64_i64"
);
...
...
src/codegen/runtime_hooks.h
View file @
acbc8021
...
...
@@ -45,7 +45,7 @@ struct GlobalFuncs {
llvm
::
Value
*
reoptCompiledFunc
,
*
compilePartialFunc
;
llvm
::
Value
*
__cxa_begin_catch
,
*
__cxa_end_catch
;
llvm
::
Value
*
raise
0
,
*
raise1
;
llvm
::
Value
*
raise
3
;
llvm
::
Value
*
div_i64_i64
,
*
mod_i64_i64
,
*
pow_i64_i64
;
llvm
::
Value
*
div_float_float
,
*
mod_float_float
,
*
pow_float_float
;
...
...
src/runtime/inline/link_forcer.cpp
View file @
acbc8021
...
...
@@ -95,7 +95,7 @@ void force() {
FORCE
(
callattr
);
FORCE
(
raise0
);
FORCE
(
raise
1
);
FORCE
(
raise
3
);
FORCE
(
div_i64_i64
);
FORCE
(
mod_i64_i64
);
...
...
src/runtime/objmodel.h
View file @
acbc8021
...
...
@@ -30,9 +30,8 @@ class BoxedString;
// user-level raise functions that implement python-level semantics
extern
"C"
void
raise0
()
__attribute__
((
__noreturn__
));
extern
"C"
void
raise1
(
Box
*
)
__attribute__
((
__noreturn__
));
extern
"C"
void
raise2
(
Box
*
,
Box
*
)
__attribute__
((
__noreturn__
));
extern
"C"
void
raise3
(
Box
*
,
Box
*
,
Box
*
)
__attribute__
((
__noreturn__
));
// helper function for raising from the runtime:
void
raiseExcHelper
(
BoxedClass
*
,
const
char
*
fmt
,
...)
__attribute__
((
__noreturn__
));
...
...
src/runtime/stacktrace.cpp
View file @
acbc8021
...
...
@@ -199,21 +199,30 @@ void raise0() {
raiseRaw
(
last_exc
);
}
void
raise1
(
Box
*
b
)
{
if
(
b
->
cls
==
type_cls
)
{
BoxedClass
*
c
=
static_cast
<
BoxedClass
*>
(
b
);
void
raise3
(
Box
*
arg0
,
Box
*
arg1
,
Box
*
arg2
)
{
RELEASE_ASSERT
(
arg2
==
None
,
"unsupported"
);
if
(
arg0
->
cls
==
type_cls
)
{
BoxedClass
*
c
=
static_cast
<
BoxedClass
*>
(
arg0
);
if
(
isSubclass
(
c
,
Exception
))
{
auto
exc_obj
=
exceptionNew1
(
c
);
Box
*
exc_obj
;
if
(
arg1
!=
None
)
exc_obj
=
exceptionNew2
(
c
,
arg1
);
else
exc_obj
=
exceptionNew1
(
c
);
raiseExc
(
exc_obj
);
}
else
{
raiseExcHelper
(
TypeError
,
"exceptions must be old-style classes or derived from BaseException, not %s"
,
getTypeName
(
b
)
->
c_str
());
getTypeName
(
arg0
)
->
c_str
());
}
}
if
(
arg1
!=
None
)
raiseExcHelper
(
TypeError
,
"instance exception may not have a separate value"
);
// TODO: should only allow throwing of old-style classes or things derived
// from BaseException:
raiseExc
(
b
);
raiseExc
(
arg0
);
}
void
raiseExcHelper
(
BoxedClass
*
cls
,
const
char
*
msg
,
...)
{
...
...
test/tests/exceptions.py
View file @
acbc8021
...
...
@@ -320,3 +320,19 @@ def f10():
with
expected_exception
(
ZeroDivisionError
):
raise
f10
()
def
f11
():
print
"f11"
# old style exception syntax"
try
:
raise
Exception
,
12345
except
Exception
,
e
:
print
e
try
:
raise
KeyError
(),
12345
except
TypeError
,
e
:
print
e
f11
()
test/tests/exceptions_basic.py
View file @
acbc8021
...
...
@@ -51,3 +51,19 @@ def f():
except
:
print
True
f
()
def
f11
():
print
"f11"
# old style exception syntax"
try
:
raise
KeyError
,
12345
except
KeyError
,
e
:
print
e
try
:
raise
KeyError
(),
12345
except
TypeError
,
e
:
print
e
f11
()
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