Exemplo n.º 1
0
def test_BytesObject_short_at():
    target = model.W_BytesObject(space, None, 4)
    target.setchar(0, chr(0x00))
    target.setchar(1, chr(0x01))
    target.setchar(2, chr(0x10))
    target.setchar(3, chr(0x81))
    assert target.short_at0(space, 0).value == 0x0100
    assert target.short_at0(space, 1).value == intmask(0xffff8110)
Exemplo n.º 2
0
def test_BytesObject_short_atput():
    target = model.W_BytesObject(space, None, 4)
    target.short_atput0(space, 0, space.wrap_int(0x0100))
    target.short_atput0(space, 1, space.wrap_int(intmask(0xffff8110)))
    assert target.getchar(0) == chr(0x00)
    assert target.getchar(1) == chr(0x01)
    assert target.getchar(2) == chr(0x10)
    assert target.getchar(3) == chr(0x81)
Exemplo n.º 3
0
 def wrap_long(self, any):
     assert any >= 0
     import struct
     bytes = struct.pack('L', any)
     w_b = model.W_BytesObject(self, self.w_LargePositiveInteger,
                               len(bytes))
     w_b.bytes = [c for c in bytes]
     return w_b
Exemplo n.º 4
0
 def new(self, extrasize=0):
     w_cls = self.w_self()
     if self.instance_kind == POINTERS:
         size = self.instsize() + extrasize
         w_new = model.W_PointersObject(self.space, w_cls, size)
     elif self.instance_kind == WORDS:
         w_new = model.W_WordsObject(self.space, w_cls, extrasize)
     elif self.instance_kind == BYTES:
         w_new = model.W_BytesObject(self.space, w_cls, extrasize)
     elif self.instance_kind == COMPILED_METHOD:
         w_new = model.W_CompiledMethod(self.space, extrasize)
     elif self.instance_kind == FLOAT:
         w_new = model.W_Float(0)  # Squeak gives a random piece of memory
     elif self.instance_kind == LARGE_POSITIVE_INTEGER:
         if extrasize <= 4:
             w_new = model.W_LargePositiveInteger1Word(0, extrasize)
         else:
             w_new = model.W_BytesObject(self.space, w_cls, extrasize)
     elif self.instance_kind == WEAK_POINTERS:
         size = self.instsize() + extrasize
         w_new = model.W_PointersObject(self.space, w_cls, size, weak=True)
     else:
         raise NotImplementedError(self.instance_kind)
     return w_new