예제 #1
0
파일: objspace.py 프로젝트: griels/pypy-sc
    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.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:
        w_nil = self.w_nil = model.w_nil
        w_nil.w_class = self.classtable['w_UndefinedObject']

        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)
        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
예제 #2
0
def test_word_atput():
    i = model.W_SmallInteger(100)
    b = model.W_WordsObject(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
예제 #3
0
def test_not_is_same_object(w_o1=model.W_PointersObject(None,0),w_o2=model.W_PointersObject(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)
예제 #4
0
파일: test_model.py 프로젝트: chyyuu/pygirl
def test_hashes():
    w_five = model.W_SmallInteger(5)
    assert w_five.gethash() == 5
    w_class = mockclass(0)
    w_inst = w_class.as_class_get_shadow().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
예제 #5
0
def tinyBenchmarks(space, image):
    interp = interpreter.Interpreter(space)

    w_object = model.W_SmallInteger(0)

    s_class = w_object.shadow_of_my_class(space)
    w_method = s_class.lookup("tinyBenchmarks")

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

    counter = 0

    from pypy.lang.smalltalk.interpreter import BYTECODE_TABLE
    return interp
예제 #6
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.w_active_context = w_frame

    print w_method
    print "Going to execute %d toplevel bytecodes" % (len(w_method.bytes), )
    counter = 0

    from pypy.lang.smalltalk.interpreter import BYTECODE_TABLE
    while True:
        try:
            counter += 1
            if interp.w_active_context == w_frame:
                print "Executing toplevel bytecode nr: %d of %d" % (
                    interp.w_active_context.pc + 1, len(w_method.bytes))
                cb = ord(interp.w_active_context.w_method().bytes[
                    interp.w_active_context.pc])
                print "= bytecode: %s %d" % (BYTECODE_TABLE[cb].__name__, cb)
            interp.step()
            #if hasattr(interp.w_active_context,"currentBytecode"):
            #    print "Executing bytecode: %s" % (BYTECODE_TABLE[interp.w_active_context.currentBytecode].__name__,)
            #else:
            #    print "Jump to new stackframe"
            # print interp.w_active_context.stack
            if counter == 100000:
                counter = 0
                sys.stderr.write("#")
        except interpreter.ReturnFromTopLevel, e:
            print e.object
            return
        except:
예제 #7
0
def tinyBenchmarks(image):
    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("tinyBenchmarks")

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

    print w_method
    print "Going to execute %d toplevel bytecodes" % (len(w_method.bytes), )
    counter = 0

    from pypy.lang.smalltalk.interpreter import BYTECODE_TABLE
    return interp
예제 #8
0
def tinyBenchmarks():
    from pypy.lang.smalltalk import objspace
    space = objspace.ObjSpace()
    image = create_squeakimage(space)
    interp = interpreter.Interpreter(space)

    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(space)
    w_method = s_class.lookup("tinyBenchmarks")

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

    counter = 0

    from pypy.lang.smalltalk.interpreter import BYTECODE_TABLE
    return interp
예제 #9
0
def test_lookup_abs_in_integer(int=10):
    image = get_image()
    interp = interpreter.Interpreter(space)

    w_object = model.W_SmallInteger(int)

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

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

    while True:
        try:
            interp.step()
        except interpreter.ReturnFromTopLevel, e:
            assert e.object.value == abs(int)
            return
예제 #10
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 pypy.lang.smalltalk.interpreter import BYTECODE_TABLE
    while True:
        try:
            interp.step()
        except interpreter.ReturnFromTopLevel, e:
            print e.object
            return
예제 #11
0
파일: objspace.py 프로젝트: griels/pypy-sc
 def wrap_int(self, val):
     from pypy.lang.smalltalk import constants
     if constants.TAGGED_MININT <= val <= constants.TAGGED_MAXINT:
         return model.W_SmallInteger(val)
     raise WrappingError("integer too large to fit into a tagged pointer")
예제 #12
0
파일: objspace.py 프로젝트: griels/pypy-sc
 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
예제 #13
0
def wrap_char_table():
    global CharacterTable

    def bld_char(i):
        w_cinst = classtable.w_Character.as_class_get_shadow().new()
        w_cinst.store(constants.CHARACTER_VALUE_INDEX, model.W_SmallInteger(i))
        return w_cinst

    CharacterTable = [bld_char(i) for i in range(256)]


wrap_char_table()

w_true = classtable.classtable['w_True'].as_class_get_shadow().new()
w_false = classtable.classtable['w_False'].as_class_get_shadow().new()
w_minus_one = model.W_SmallInteger(-1)
w_zero = model.W_SmallInteger(0)
w_one = model.W_SmallInteger(1)
w_two = model.W_SmallInteger(2)

# 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:
w_nil = model.w_nil
w_nil.w_class = classtable.classtable['w_UndefinedObject']

objtable = {}

for name in constants.objects_in_special_object_table:
    objtable["w_" + name] = globals()["w_" + name]
예제 #14
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))