コード例 #1
0
 def _make_empty_type(self):
     if self.known_maxlength:
         return ootype.Record({
             "items": ootype.Array(),
             "length": ootype.Signed
         })
     else:
         return ootype.List()
コード例 #2
0
 def __init__(self, TYPE):
     DescrWithKey.__init__(self, TYPE)
     from pypy.jit.backend.llgraph.runner import boxresult
     from pypy.jit.metainterp.warmstate import unwrap
     ARRAY = ootype.Array(TYPE)
     def create():
         if isinstance(TYPE, ootype.OOType):
             return boxresult(TYPE, ootype.new(TYPE))
         return None
     def create_array(lengthbox):
         n = lengthbox.getint()
         return boxresult(ARRAY, ootype.oonewarray(ARRAY, n))
     def getarrayitem(arraybox, ibox):
         array = arraybox.getref(ARRAY)
         i = ibox.getint()
         if TYPE is not ootype.Void:
             return boxresult(TYPE, array.ll_getitem_fast(i))
     def setarrayitem(arraybox, ibox, valuebox):
         array = arraybox.getref(ARRAY)
         i = ibox.getint()
         value = unwrap(TYPE, valuebox)
         array.ll_setitem_fast(i, value)
     def getarraylength(arraybox):
         array = arraybox.getref(ARRAY)
         return boxresult(ootype.Signed, array.ll_length())
     def instanceof(box):
         if isinstance(TYPE, ootype.Instance):
             obj = box.getref(ootype.ROOT)
             return BoxInt(ootype.instanceof(obj, TYPE))
         return None
     self.create = create
     self.create_array = create_array
     self.getarrayitem = getarrayitem
     self.setarrayitem = setarrayitem
     self.getarraylength = getarraylength
     self.instanceof = instanceof
     self.ooclass = get_class_for_type(TYPE)
     self.typename = TYPE._short_name()
     self._is_array_of_pointers = (history.getkind(TYPE) == 'ref')
     self._is_array_of_floats = (history.getkind(TYPE) == 'float')
コード例 #3
0
ファイル: runner.py プロジェクト: purepython/pypy
    def __init__(self, TYPE):
        self.TYPE = TYPE
        self.ARRAY = ARRAY = ootype.Array(TYPE)

        def create():
            return boxresult(TYPE, ootype.new(TYPE))

        def create_array(lengthbox):
            n = lengthbox.getint()
            return boxresult(ARRAY, ootype.oonewarray(ARRAY, n))

        def getarrayitem(arraybox, ibox):
            array = arraybox.getref(ARRAY)
            i = ibox.getint()
            return boxresult(TYPE, array.ll_getitem_fast(i))

        def setarrayitem(arraybox, ibox, valuebox):
            array = arraybox.getref(ARRAY)
            i = ibox.getint()
            value = unwrap(TYPE, valuebox)
            array.ll_setitem_fast(i, value)

        def getarraylength(arraybox):
            array = arraybox.getref(ARRAY)
            return boxresult(ootype.Signed, array.ll_length())

        def instanceof(box):
            obj = box.getref(ootype.ROOT)
            return history.BoxInt(ootype.instanceof(obj, TYPE))

        self.create = create
        self.create_array = create_array
        self.getarrayitem = getarrayitem
        self.setarrayitem = setarrayitem
        self.getarraylength = getarraylength
        self.instanceof = instanceof
        self._is_array_of_pointers = (history.getkind(TYPE) == 'ref')
        self._is_array_of_floats = (history.getkind(TYPE) == 'float')
コード例 #4
0
class OOtypeMixin(object):
    type_system = 'ootype'

    def get_class_of_box(self, box):
        root = box.getref(ootype.ROOT)
        return ootype.classof(root)
    
    cpu = runner.OOtypeCPU(None)
    NODE = ootype.Instance('NODE', ootype.ROOT, {})
    NODE._add_fields({'value': ootype.Signed,
                      'floatval' : ootype.Float,
                      'next': NODE})
    NODE2 = ootype.Instance('NODE2', NODE, {'other': NODE})

    node_vtable = ootype.runtimeClass(NODE)
    node_vtable_adr = ootype.cast_to_object(node_vtable)
    node_vtable2 = ootype.runtimeClass(NODE2)
    node_vtable_adr2 = ootype.cast_to_object(node_vtable2)

    node = ootype.new(NODE)
    nodebox = BoxObj(ootype.cast_to_object(node))
    myptr = nodebox.value
    myptr2 = ootype.cast_to_object(ootype.new(NODE))
    nodebox2 = BoxObj(ootype.cast_to_object(node))
    valuedescr = cpu.fielddescrof(NODE, 'value')
    floatdescr = cpu.fielddescrof(NODE, 'floatval')
    nextdescr = cpu.fielddescrof(NODE, 'next')
    otherdescr = cpu.fielddescrof(NODE2, 'other')
    nodesize = cpu.typedescrof(NODE)
    nodesize2 = cpu.typedescrof(NODE2)

    arraydescr = cpu.arraydescrof(ootype.Array(ootype.Signed))
    floatarraydescr = cpu.arraydescrof(ootype.Array(ootype.Float))

    # a plain Record
    S = ootype.Record({'a': ootype.Signed, 'b': NODE})
    ssize = cpu.typedescrof(S)
    adescr = cpu.fielddescrof(S, 'a')
    bdescr = cpu.fielddescrof(S, 'b')
    sbox = BoxObj(ootype.cast_to_object(ootype.new(S)))
    arraydescr2 = cpu.arraydescrof(ootype.Array(S))

    T = ootype.Record({'c': ootype.Signed,
                       'd': ootype.Array(NODE)})
    tsize = cpu.typedescrof(T)
    cdescr = cpu.fielddescrof(T, 'c')
    ddescr = cpu.fielddescrof(T, 'd')
    arraydescr3 = cpu.arraydescrof(ootype.Array(NODE))

    U = ootype.Instance('U', ootype.ROOT, {'one': ootype.Array(NODE)})
    usize = cpu.typedescrof(U)
    onedescr = cpu.fielddescrof(U, 'one')
    u_vtable = ootype.runtimeClass(U)
    u_vtable_adr = ootype.cast_to_object(u_vtable)

    # force a consistent order
    valuedescr.sort_key()
    nextdescr.sort_key()
    adescr.sort_key()
    bdescr.sort_key()

    FUNC = lltype.FuncType([lltype.Signed], lltype.Signed)
    nonwritedescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT) # XXX fix ootype

    cpu.class_sizes = {node_vtable_adr: cpu.typedescrof(NODE),
                       node_vtable_adr2: cpu.typedescrof(NODE2),
                       u_vtable_adr: cpu.typedescrof(U)}
    namespace = locals()
コード例 #5
0
ファイル: test_effectinfo.py プロジェクト: njues/Sypy
def test_filter_out_ooarray_of_void():
    effects = frozenset([("array", ootype.Array(ootype.Void))])
    effectinfo = effectinfo_from_writeanalyze(effects, None)
    assert not effectinfo.readonly_descrs_fields
    assert not effectinfo.write_descrs_fields
    assert not effectinfo.write_descrs_arrays
コード例 #6
0
 def _make_empty_type(self):
     return ootype.Array()