Ejemplo n.º 1
0
    def make_bootstrap_objects(self):
        self.make_bootstrap_object("w_charactertable")
        self.make_bootstrap_object("w_true")
        self.make_bootstrap_object("w_false")
        self.make_bootstrap_object("w_special_selectors")
        self.add_bootstrap_object("w_minus_one", model.W_SmallInteger(-1))
        self.add_bootstrap_object("w_zero", model.W_SmallInteger(0))
        self.add_bootstrap_object("w_one", model.W_SmallInteger(1))
        self.add_bootstrap_object("w_two", model.W_SmallInteger(2))

        # Certain special objects are already created. The rest will be
        # populated when the image is loaded, but prepare empty slots for them.
        for name in constants.objects_in_special_object_table:
            name = "w_" + name
            if not name in self.objtable:
                self.add_bootstrap_object(name, None)
Ejemplo n.º 2
0
    def make_bootstrap_objects(self):
        def bld_char(i):
            w_cinst = self.w_Character.as_class_get_shadow(self).new()
            w_cinst.store(self, constants.CHARACTER_VALUE_INDEX,
                          model.W_SmallInteger(i))
            return w_cinst

        w_charactertable = model.W_PointersObject(self,
                                                  self.classtable['w_Array'],
                                                  256)
        self.w_charactertable = w_charactertable
        for i in range(256):
            self.w_charactertable.atput0(self, i, bld_char(i))

        # Very special nil hack: in order to allow W_PointersObject's to
        # initialize their fields to nil, we have to create it in the model
        # package, and then patch up its fields here:
        def patch_nil(w_nil):
            from spyvm.fieldtypes import nilTyper
            w_nil.space = self
            w_nil.fieldtypes = nilTyper
            w_nil.s_class = self.classtable[
                'w_UndefinedObject'].as_class_get_penumbra(self)
            return w_nil

        w_nil = self.w_nil = patch_nil(model.w_nil)

        w_true = self.classtable['w_True'].as_class_get_shadow(self).new()
        self.w_true = w_true
        w_false = self.classtable['w_False'].as_class_get_shadow(self).new()
        self.w_false = w_false
        self.w_minus_one = model.W_SmallInteger(-1)
        self.w_zero = model.W_SmallInteger(0)
        self.w_one = model.W_SmallInteger(1)
        self.w_two = model.W_SmallInteger(2)
        w_special_selectors = model.W_PointersObject(
            self, self.classtable['w_Array'],
            len(constants.SPECIAL_SELECTORS) * 2)
        self.w_special_selectors = w_special_selectors

        self.objtable = {}
        for name in constants.objects_in_special_object_table:
            name = "w_" + name
            try:
                self.objtable[name] = locals()[name]
            except KeyError, e:
                self.objtable[name] = None
Ejemplo n.º 3
0
 def wrap_positive_32bit_int(self, val):
     # This will always return a positive value.
     # XXX: For now, we assume that val is at most 32bit, i.e. overflows are
     # checked for before wrapping. Also, we ignore tagging.
     if int_between(0, val, constants.MAXINT):
         return model.W_SmallInteger(val)
     else:
         return model.W_LargePositiveInteger1Word(val)
Ejemplo n.º 4
0
def test_weak_pointers():
    w_cls = bootstrap_class(2)
    s_cls = w_cls.as_class_get_shadow(space)
    s_cls.instance_kind = storage_classes.WEAK_POINTERS

    weak_object = s_cls.new()
    referenced = model.W_SmallInteger(10)
    referenced2 = model.W_SmallInteger(20)
    weak_object.store(space, 0, referenced)
    weak_object.store(space, 1, referenced2)

    assert weak_object.fetch(space, 0) is referenced
    del referenced
    # When executed using pypy, del is not immediately executed.
    # Thus the reference may linger until the next gc...
    import gc
    gc.collect()
    assert weak_object.fetch(space, 0).is_nil(space)
    assert weak_object.fetch(space, 1).value == 20
Ejemplo n.º 5
0
def test_hashes():
    w_five = model.W_SmallInteger(5)
    assert w_five.gethash() == 5
    w_class = mockclass(space, 0)
    w_inst = w_class.as_class_get_shadow(space).new()
    assert w_inst.hash == w_inst.UNASSIGNED_HASH
    h1 = w_inst.gethash()
    h2 = w_inst.gethash()
    assert h1 == h2
    assert h1 == w_inst.hash
Ejemplo n.º 6
0
def test_not_is_same_object(w_o1=model.W_PointersObject(space, None, 0),
                            w_o2=model.W_PointersObject(space, None, 0)):
    assert not w_o1.is_same_object(w_o2)
    assert not w_o2.is_same_object(w_o1)
    w_o2 = model.W_SmallInteger(2)
    assert not w_o1.is_same_object(w_o2)
    assert not w_o2.is_same_object(w_o1)
    w_o2 = model.W_Float(5.5)
    assert not w_o1.is_same_object(w_o2)
    assert not w_o2.is_same_object(w_o1)
Ejemplo n.º 7
0
def test_word_atput():
    i = model.W_SmallInteger(100)
    b = model.W_WordsObject(space, None, 1)
    b.atput0(space, 0, i)
    assert 100 == b.getword(0)
    i = space.classtable['w_LargePositiveInteger'].as_class_get_shadow(
        space).new(4)
    i.atput0(space, 3, space.wrap_int(192))
    b.atput0(space, 0, i)
    assert b.getword(0) == 3221225472
def setup():
    from spyvm import objspace
    space = objspace.ObjSpace()
    image = create_testimage(space)
    interp = interpreter.Interpreter(space, image)
    w_selector = interp.perform(space.wrap_string("loopTest"), "asSymbol")
    w_object = model.W_SmallInteger(0)
    s_class = w_object.shadow_of_my_class(space)
    s_method = s_class.lookup(w_selector)
    s_frame = s_method.create_frame(space, w_object, [])
    return interp, s_frame
Ejemplo n.º 9
0
def setup():
    space = objspace.ObjSpace()
    stream = squeakimage.Stream(filename=imagefile)
    image = squeakimage.ImageReader(space, stream).create_image()
    interp = interpreter.Interpreter(space, image)
    w_selector = interp.perform(space.wrap_string("loopTest"), "asSymbol")
    w_object = model.W_SmallInteger(0)
    s_class = w_object.class_shadow(space)
    w_method = s_class.lookup(w_selector)
    s_frame = w_method.create_frame(space, w_object)
    return interp, s_frame
Ejemplo n.º 10
0
 def wrap_int(self, val):
     if isinstance(val, r_longlong) and not is_valid_int(val):
         if val > 0 and r_ulonglong(val) < r_uint(constants.U_MAXINT):
             return self.wrap_positive_32bit_int(intmask(val))
         else:
             raise WrappingError
     elif isinstance(val, r_uint):
         return self.wrap_positive_32bit_int(intmask(val))
     elif not is_valid_int(val):
         raise WrappingError
     # we don't do tagging
     return model.W_SmallInteger(intmask(val))
Ejemplo n.º 11
0
def test_not_is_same_object(w_o1=None, w_o2=None):
    if w_o1 is None:
        w_o1 = model.W_PointersObject(space, None, 0)
    if w_o2 is None:
        w_o2 = model.W_PointersObject(space, None, 0)
    assert not w_o1.is_same_object(w_o2)
    assert not w_o2.is_same_object(w_o1)
    w_o2 = model.W_SmallInteger(2)
    assert not w_o1.is_same_object(w_o2)
    assert not w_o2.is_same_object(w_o1)
    w_o2 = model.W_Float(5.5)
    assert not w_o1.is_same_object(w_o2)
    assert not w_o2.is_same_object(w_o1)
Ejemplo n.º 12
0
    def patch_bootstrap_objects(self):
        def patch_bootstrap_object(obj, cls, size):
            obj.w_class = cls
            obj.initialize_storage(self, size)

        patch_bootstrap_object(self.w_nil, self.w_UndefinedObject, 0)
        patch_bootstrap_object(self.w_true, self.w_True, 0)
        patch_bootstrap_object(self.w_false, self.w_False, 0)
        patch_bootstrap_object(self.w_special_selectors, self.w_Array,
                               len(constants.SPECIAL_SELECTORS) * 2)
        patch_bootstrap_object(self.w_charactertable, self.w_Array, 256)

        # Bootstrap character table
        for i in range(256):
            w_cinst = model.W_PointersObject(self, self.w_Character, 1)
            w_cinst.store(self, constants.CHARACTER_VALUE_INDEX,
                          model.W_SmallInteger(i))
            self.w_charactertable.store(self, i, w_cinst)
Ejemplo n.º 13
0
def test_weak_pointers():
    from spyvm.shadow import WEAK_POINTERS

    w_cls = mockclass(space, 1)
    s_cls = w_cls.as_class_get_shadow(space)
    s_cls.instance_kind = WEAK_POINTERS

    weak_object = s_cls.new()
    referenced = model.W_SmallInteger(10)
    weak_object.store(space, 0, referenced)

    assert weak_object.fetch(space, 0) is referenced
    del referenced
    # When executed using pypy, del is not immediately executed.
    # Thus the reference may linger until the next gc...
    import gc
    gc.collect()
    assert weak_object.fetch(space, 0) is space.w_nil
Ejemplo n.º 14
0
def tinyBenchmarks():
    image = create_squeakimage()
    interp = interpreter.Interpreter()

    w_object = model.W_SmallInteger(0)

    # Should get this from w_object
    w_smallint_class = image.special(constants.SO_SMALLINTEGER_CLASS)
    s_class = w_object.shadow_of_my_class()
    #w_method = s_class.lookup("benchFib")
    w_method = s_class.lookup("tinyBenchmarks")

    assert w_method
    w_frame = w_method.create_frame(w_object, [])
    interp.store_w_active_context(w_frame)

    from spyvm.interpreter import BYTECODE_TABLE
    while True:
        try:
            interp.step()
        except interpreter.ReturnFromTopLevel, e:
            print e.object
            return
Ejemplo n.º 15
0
 def wrap_int(self, val):
     from spyvm import constants
     assert isinstance(val, int)
     # we don't do tagging
     return model.W_SmallInteger(val)
Ejemplo n.º 16
0
def test_lookup_abs_in_integer():
    w_abs = interp.perform(w("abs"), "asSymbol")
    for value in [10, -3, 0]:
        w_object = model.W_SmallInteger(value)
        w_res = interp.perform(w_object, w_abs)
        assert w_res.value == abs(value)
Ejemplo n.º 17
0
def test_intfloat_notis_same_object():
    test_not_is_same_object(model.W_SmallInteger(1), model.W_Float(1))
    test_not_is_same_object(model.W_Float(100), model.W_SmallInteger(100))
    test_not_is_same_object(model.W_Float(1.100), model.W_Float(1.200))
    test_not_is_same_object(model.W_SmallInteger(101),
                            model.W_SmallInteger(100))
Ejemplo n.º 18
0
 def interp_w():
     interp.perform(model.W_SmallInteger(1000), w_selector)
Ejemplo n.º 19
0
 def bld_char(i):
     w_cinst = self.w_Character.as_class_get_shadow(self).new()
     w_cinst.store(self, constants.CHARACTER_VALUE_INDEX,
                   model.W_SmallInteger(i))
     return w_cinst