| 1 |
from rpython.annotator import model as annmodel |
| 2 |
from rpython.tool.pairtype import pairtype |
| 3 |
from rpython.rtyper.rmodel import Repr |
| 4 |
from rpython.rtyper.rclass import (getinstancerepr, OBJECTPTR) |
| 5 |
from rpython.rtyper.lltypesystem import lltype |
| 6 |
from rpython.rtyper.error import TyperError |
| 7 |
|
| 8 |
|
| 9 |
class SomeVRef(annmodel.SomeObject): |
| 10 |
|
| 11 |
def __init__(self, s_instance=annmodel.s_None): |
| 12 |
assert (isinstance(s_instance, annmodel.SomeInstance) or |
| 13 |
annmodel.s_None.contains(s_instance)) |
| 14 |
self.s_instance = s_instance |
| 15 |
|
| 16 |
def can_be_none(self): |
| 17 |
return False |
| 18 |
|
| 19 |
|
| 20 |
def simple_call(self): |
| 21 |
return self.s_instance |
| 22 |
|
| 23 |
def getattr(self, s_attr): |
| 24 |
assert s_attr.const == 'virtual' |
| 25 |
return annmodel.s_Bool |
| 26 |
|
| 27 |
def rtyper_makerepr(self, rtyper): |
| 28 |
return vrefrepr |
| 29 |
|
| 30 |
def rtyper_makekey(self): |
| 31 |
return self.__class__, |
| 32 |
|
| 33 |
class __extend__(pairtype(SomeVRef, SomeVRef)): |
| 34 |
|
| 35 |
def union((vref1, vref2)): |
| 36 |
return SomeVRef(annmodel.unionof(vref1.s_instance, vref2.s_instance)) |
| 37 |
|
| 38 |
|
| 39 |
class VRefRepr(Repr): |
| 40 |
lowleveltype = OBJECTPTR |
| 41 |
|
| 42 |
def specialize_call(self, hop): |
| 43 |
r_generic_object = getinstancerepr(hop.rtyper, None) |
| 44 |
[v] = hop.inputargs(r_generic_object) |
| 45 |
hop.exception_cannot_occur() |
| 46 |
return v |
| 47 |
|
| 48 |
def rtype_simple_call(self, hop): |
| 49 |
[v] = hop.inputargs(self) |
| 50 |
hop.exception_is_here() |
| 51 |
v = hop.genop('jit_force_virtual', [v], resulttype = OBJECTPTR) |
| 52 |
return hop.genop('cast_pointer', [v], resulttype = hop.r_result) |
| 53 |
|
| 54 |
def convert_const(self, value): |
| 55 |
if value() is not None: |
| 56 |
raise TyperError("only supports virtual_ref_None as a" |
| 57 |
" prebuilt virtual_ref") |
| 58 |
return lltype.nullptr(OBJECTPTR.TO) |
| 59 |
|
| 60 |
def rtype_getattr(self, hop): |
| 61 |
s_attr = hop.args_s[1] |
| 62 |
assert s_attr.const == 'virtual' |
| 63 |
v = hop.inputarg(self, arg=0) |
| 64 |
hop.exception_cannot_occur() |
| 65 |
return hop.genop('jit_is_virtual', [v], resulttype = lltype.Bool) |
| 66 |
|
| 67 |
vrefrepr = VRefRepr() |