Ejemplo n.º 1
0
def test_unwrap():
    S = lltype.GcStruct('S')
    p = lltype.malloc(S)
    po = lltype.cast_opaque_ptr(llmemory.GCREF, p)
    assert unwrap(lltype.Void, BoxInt(42)) is None
    assert unwrap(lltype.Signed, BoxInt(42)) == 42
    assert unwrap(lltype.Char, BoxInt(42)) == chr(42)
    assert unwrap(lltype.Float, BoxFloat(42.5)) == 42.5
    assert unwrap(lltype.Ptr(S), BoxPtr(po)) == p
Ejemplo n.º 2
0
 def write_boxes(virtualizable, boxes):
     i = 0
     for FIELDTYPE, fieldname in unroll_static_fields:
         x = unwrap(FIELDTYPE, boxes[i])
         setattr(virtualizable, fieldname, x)
         i = i + 1
     for ARRAYITEMTYPE, fieldname in unroll_array_fields:
         lst = getattr(virtualizable, fieldname)
         for j in range(getlength(lst)):
             x = unwrap(ARRAYITEMTYPE, boxes[i])
             setarrayitem(lst, j, x)
             i = i + 1
     assert len(boxes) == i + 1
Ejemplo n.º 3
0
 def check_boxes(virtualizable, boxes):
     # for debugging
     i = 0
     for FIELDTYPE, fieldname in unroll_static_fields:
         x = unwrap(FIELDTYPE, boxes[i])
         assert getattr(virtualizable, fieldname) == x
         i = i + 1
     for ARRAYITEMTYPE, fieldname in unroll_array_fields:
         lst = getattr(virtualizable, fieldname)
         for j in range(getlength(lst)):
             x = unwrap(ARRAYITEMTYPE, boxes[i])
             assert getarrayitem(lst, j) == x
             i = i + 1
     assert len(boxes) == i + 1
Ejemplo n.º 4
0
 def __init__(self, argboxes):
     # accepts boxes as argument, but unpacks them immediately
     # before we raise the exception -- the boxes' values will
     # be modified in a 'finally' by restore_patched_boxes().
     from pypy.jit.metainterp.warmstate import unwrap
     for i, name, ARG in portalfunc_ARGS:
         v = unwrap(ARG, argboxes[i])
         setattr(self, name, v)
Ejemplo n.º 5
0
Archivo: runner.py Proyecto: ieure/pypy
 def getargs(argboxes):
     funcargs = ()
     assert len(argboxes) == args_n
     i = 0
     for ARG in argsiter:
         if ARG is ootype.Void:
             funcargs += (None,)
         else:
             box = argboxes[i]
             i+=1
             funcargs += (unwrap(ARG, box),)
     return funcargs
Ejemplo n.º 6
0
 def getargs(argboxes):
     funcargs = ()
     assert len(argboxes) == args_n
     i = 0
     for ARG in argsiter:
         if ARG is ootype.Void:
             funcargs += (None, )
         else:
             box = argboxes[i]
             i += 1
             funcargs += (unwrap(ARG, box), )
     return funcargs
Ejemplo n.º 7
0
def test_unwrap():
    S = lltype.GcStruct('S')
    RS = lltype.Struct('S')
    p = lltype.malloc(S)
    po = lltype.cast_opaque_ptr(llmemory.GCREF, p)
    assert unwrap(lltype.Void, BoxInt(42)) is None
    assert unwrap(lltype.Signed, BoxInt(42)) == 42
    assert unwrap(lltype.Char, BoxInt(42)) == chr(42)
    assert unwrap(lltype.Float, boxfloat(42.5)) == 42.5
    assert unwrap(lltype.Ptr(S), BoxPtr(po)) == p
    assert unwrap(lltype.Ptr(RS), BoxInt(0)) == lltype.nullptr(RS)
Ejemplo n.º 8
0
 def setfield(objbox, valuebox):
     obj = objbox.getref(TYPE)
     value = unwrap(T, valuebox)
     setattr(obj, fieldname, value)
Ejemplo n.º 9
0
 def setarrayitem(arraybox, ibox, valuebox):
     array = arraybox.getref(ARRAY)
     i = ibox.getint()
     value = unwrap(TYPE, valuebox)
     array.ll_setitem_fast(i, value)