| 1 |
from rpython.rtyper.annlowlevel import cast_instance_to_base_ptr |
| 2 |
from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance |
| 3 |
from rpython.rtyper.lltypesystem import lltype, llmemory |
| 4 |
from rpython.rtyper import rclass |
| 5 |
from rpython.rtyper.llinterp import LLException |
| 6 |
from rpython.rlib.objectmodel import we_are_translated |
| 7 |
from rpython.jit.codewriter import longlong |
| 8 |
|
| 9 |
|
| 10 |
class JitException(Exception): |
| 11 |
"""The base class for exceptions raised and caught in the JIT. |
| 12 |
The point is that the places that catch any user exception should avoid |
| 13 |
catching exceptions that inherit from JitException. |
| 14 |
""" |
| 15 |
_go_through_llinterp_uncaught_ = True |
| 16 |
|
| 17 |
class DoneWithThisFrameVoid(JitException): |
| 18 |
def __str__(self): |
| 19 |
return 'DoneWithThisFrameVoid()' |
| 20 |
|
| 21 |
class DoneWithThisFrameInt(JitException): |
| 22 |
def __init__(self, result): |
| 23 |
assert lltype.typeOf(result) is lltype.Signed |
| 24 |
self.result = result |
| 25 |
|
| 26 |
def __str__(self): |
| 27 |
return 'DoneWithThisFrameInt(%s)' % (self.result,) |
| 28 |
|
| 29 |
class DoneWithThisFrameRef(JitException): |
| 30 |
def __init__(self, result): |
| 31 |
assert lltype.typeOf(result) == llmemory.GCREF |
| 32 |
self.result = result |
| 33 |
|
| 34 |
def __str__(self): |
| 35 |
return 'DoneWithThisFrameRef(%s)' % (self.result,) |
| 36 |
|
| 37 |
class DoneWithThisFrameFloat(JitException): |
| 38 |
def __init__(self, result): |
| 39 |
assert lltype.typeOf(result) is longlong.FLOATSTORAGE |
| 40 |
self.result = result |
| 41 |
|
| 42 |
def __str__(self): |
| 43 |
return 'DoneWithThisFrameFloat(%s)' % (self.result,) |
| 44 |
|
| 45 |
class ExitFrameWithExceptionRef(JitException): |
| 46 |
def __init__(self, value): |
| 47 |
assert lltype.typeOf(value) == llmemory.GCREF |
| 48 |
self.value = value |
| 49 |
|
| 50 |
def __str__(self): |
| 51 |
return 'ExitFrameWithExceptionRef(%s)' % (self.value,) |
| 52 |
|
| 53 |
class ContinueRunningNormally(JitException): |
| 54 |
def __init__(self, gi, gr, gf, ri, rr, rf): |
| 55 |
|
| 56 |
|
| 57 |
self.green_int = gi |
| 58 |
self.green_ref = gr |
| 59 |
self.green_float = gf |
| 60 |
self.red_int = ri |
| 61 |
self.red_ref = rr |
| 62 |
self.red_float = rf |
| 63 |
def __str__(self): |
| 64 |
return 'ContinueRunningNormally(%s, %s, %s, %s, %s, %s)' % ( |
| 65 |
self.green_int, self.green_ref, self.green_float, |
| 66 |
self.red_int, self.red_ref, self.red_float) |
| 67 |
|
| 68 |
class NotAVectorizeableLoop(JitException): |
| 69 |
def __str__(self): |
| 70 |
return 'NotAVectorizeableLoop()' |
| 71 |
|
| 72 |
class NotAProfitableLoop(JitException): |
| 73 |
def __str__(self): |
| 74 |
return 'NotAProfitableLoop()' |
| 75 |
|
| 76 |
|
| 77 |
def _get_standard_error(rtyper, Class): |
| 78 |
exdata = rtyper.exceptiondata |
| 79 |
clsdef = rtyper.annotator.bookkeeper.getuniqueclassdef(Class) |
| 80 |
evalue = exdata.get_standard_ll_exc_instance(rtyper, clsdef) |
| 81 |
return evalue |
| 82 |
|
| 83 |
def get_llexception(cpu, e): |
| 84 |
if we_are_translated(): |
| 85 |
return cast_instance_to_base_ptr(e) |
| 86 |
assert not isinstance(e, JitException) |
| 87 |
if isinstance(e, LLException): |
| 88 |
return e.args[1] |
| 89 |
if isinstance(e, OverflowError): |
| 90 |
return _get_standard_error(cpu.rtyper, OverflowError) |
| 91 |
raise |
| 92 |
|
| 93 |
def reraise(lle): |
| 94 |
if we_are_translated(): |
| 95 |
e = cast_base_ptr_to_instance(Exception, lle) |
| 96 |
raise e |
| 97 |
else: |
| 98 |
etype = rclass.ll_type(lle) |
| 99 |
raise LLException(etype, lle) |