Esempio n. 1
0
def test_accessor_generators():
    w_o = W_PointersObject(space, None, 1)
    w = wrapper.LinkWrapper(space, w_o)
    w_o.store(space, 0, "hello")
    assert w.next_link() == "hello"
    w.store_next_link("boe")
    assert w.next_link() == "boe"
Esempio n. 2
0
def test_accessor_generators():
    w_o = W_PointersObject(space, None, 1)
    w = wrapper.LinkWrapper(space, w_o)
    w_o.store(space, 0, "hello")
    assert w.next_link() == "hello"
    w.store_next_link("boe")
    assert w.next_link() == "boe"
Esempio n. 3
0
def test_ContextPart_jump():
    """
    Code: Create a Block context that jumps back to its sender, instead of returning normally.
    The Block is not executed to the end, the sender chain is manipulated.
    The local variable should be the value pushed on the sender context before jumping to it.
    a := 5.
    a := [ thisContext sender push: 2. thisContext sender jump. 10 ] value.
    ^ a
    """
    ContextPart = space.w_MethodContext.as_class_get_shadow(space).s_superclass().w_self()
    push = find_symbol("push:", ContextPart)
    sender = find_symbol("sender", ContextPart)
    jump = find_symbol("jump", ContextPart)

    bytes = [0x21, 0x82, 0xc0, # Set a
           0x8f, 0x00, 0x00, 0x0b, # Push block
                0x89, 0xd3, # Send sender
                0x77, 0xe2, # Send push
                0x87, 0x89, 0xd3, 0xd4, # Send jump
                0x87, 0x25, 0x7d, # Block rest (not executed)
           0xc9, 0x82, 0xc0, 0x40, 0x7c] # Send value and return

    Association = space.w_Point # Wrong class, doesn't matter.
    assoc = W_PointersObject(space, Association, 2)
    assoc.store(space, 0, w('a'))
    assoc.store(space, 1, w(3))
    w_method = space.make_method(bytes, [assoc, w(5), push, sender, jump, w(10)])
    result = interp.execute_method(w_method)
    assert isinstance(result, W_SmallInteger)
    assert result.value == 2
Esempio n. 4
0
 def initialize_methoddict(self):
     if self._s_methoddict is None:
         w_methoddict = W_PointersObject(self.space, None, 2)
         w_methoddict.store(self.space, constants.METHODDICT_VALUES_INDEX,
                            W_PointersObject(self.space, None, 0))
         self.store_s_methoddict(
             w_methoddict.as_methoddict_get_shadow(self.space))
Esempio n. 5
0
def test_simpleread():
    w_o = W_PointersObject(space, None, 2)
    w = wrapper.Wrapper(space, w_o)
    w_o.store(space, 0, "hello")
    assert w.read(0) == "hello"
    w.write(1, "b")
    assert w.read(1) == "b"
    py.test.raises(WrapperException, "w.read(2)")
    py.test.raises(WrapperException, "w.write(2, \"test\")")
Esempio n. 6
0
def test_simpleread():
    w_o = W_PointersObject(space, None, 2)
    w = wrapper.Wrapper(space, w_o)
    w_o.store(space, 0, "hello")
    assert w.read(0) == "hello"
    w.write(1, "b")
    assert w.read(1) == "b"
    py.test.raises(WrapperException, "w.read(2)")
    py.test.raises(WrapperException, "w.write(2, \"test\")")
Esempio n. 7
0
def test_primImmutableFrom_pointers():
    size = 10
    w_pointers_cls = bootstrap_class(0)
    w_pointers_obj = W_PointersObject(space, w_pointers_cls, size)
    w_pointers_obj.store(space, 0, space.w_true)
    w_ipointers_obj = external_call(space, 'ImmutabilityPlugin',
                                    'primitiveImmutableFrom',
                                    [w_pointers_cls, w_pointers_obj])
    assert w_ipointers_obj.is_immutable()
    assert w_ipointers_obj.getclass(space).is_same_object(w_pointers_cls)
    assert w_ipointers_obj.size() == size
    assert w_ipointers_obj.fetch(space, 0) is space.w_true
    w_ipointers_obj.store(space, 0, space.w_false)
    assert w_ipointers_obj.fetch(space, 0) is space.w_true
def test_primImmutableFrom_pointers():
    size = 10
    w_pointers_cls = bootstrap_class(0)
    w_pointers_obj = W_PointersObject(space, w_pointers_cls, size)
    w_pointers_obj.store(space, 0, space.w_true)
    w_ipointers_obj = external_call(space,
        'ImmutabilityPlugin',
        'primitiveImmutableFrom',
        [w_pointers_cls, w_pointers_obj])
    assert w_ipointers_obj.is_immutable()
    assert w_ipointers_obj.getclass(space).is_same_object(w_pointers_cls)
    assert w_ipointers_obj.size() == size
    assert w_ipointers_obj.fetch(space, 0) is space.w_true;
    w_ipointers_obj.store(space, 0, space.w_false)
    assert w_ipointers_obj.fetch(space, 0) is space.w_true;
Esempio n. 9
0
def create_process(interp, s_frame):
    space = interp.space
    w_active_process = wrapper.scheduler(space).active_process()
    assert isinstance(w_active_process, W_PointersObject)
    w_benchmark_proc = W_PointersObject(
        space, w_active_process.getclass(space), w_active_process.size()
    )
    if interp.image.version.has_closures:
        # Priorities below 10 are not allowed in newer versions of Squeak.
        active_priority = space.unwrap_int(w_active_process.fetch(space, 2))
        priority = active_priority / 2 + 1
        priority = max(11, priority)
    else:
        priority = 7
    w_benchmark_proc.store(space, 1, s_frame.w_self())
    w_benchmark_proc.store(space, 2, space.wrap_int(priority))

    # Make process eligible for scheduling
    wrapper.ProcessWrapper(space, w_benchmark_proc).put_to_sleep()
Esempio n. 10
0
def create_process(interp, s_frame):
    space = interp.space
    w_active_process = wrapper.scheduler(space).active_process()
    assert isinstance(w_active_process, W_PointersObject)
    w_benchmark_proc = W_PointersObject(space,
                                        w_active_process.getclass(space),
                                        w_active_process.size())
    if interp.image.version.has_closures:
        # Priorities below 10 are not allowed in newer versions of Squeak.
        active_priority = space.unwrap_int(w_active_process.fetch(space, 2))
        priority = active_priority / 2 + 1
        priority = max(11, priority)
    else:
        priority = 7
    w_benchmark_proc.store(space, 1, s_frame.w_self())
    w_benchmark_proc.store(space, 2, space.wrap_int(priority))

    # Make process eligible for scheduling
    wrapper.ProcessWrapper(space, w_benchmark_proc).put_to_sleep()
Esempio n. 11
0
def test_semaphore():
    w_semaphore_cls = space.w_timerSemaphore().getclass(space)
    w_sema = image.find_symbol(space, reader, "Semaphore")
    w_fork = image.find_symbol(space, reader, "fork")
    w_wait = image.find_symbol(space, reader, "wait")
    w_yield = image.find_symbol(space, reader, "yield")
    w_processor = space.w_schedulerassociationpointer
    w_suspPrimOFail = image.find_symbol(space, reader, "suspendPrimitivelyOrFail")

    bytes = [
        0x40, # pushLit: Semaphore
        0xCC, # send: new
        0x6A, # popIntoTemp: 2
        0x12, # pushTemp: 2
        0x8F, 0x10, 0x00, 0x03, # closureNumCopied: 1 numArgs: 0 bytes 49 to 51
        0x10, # pushTemp: 0
        0xD2, # send: wait
        0x7D, # blockReturn
        0xD1, # send: fork
        0x69, # popIntoTemp: 1
        0x44, # pushLit: Processor
        0xD3, # send: yield
        0x87, # pop
        0x11, # pushTemp: 1
        0xD5, # send: suspendPrimitivelyOrFail
        0x68, # popIntoTemp: 0
        0x10, # pushTemp: 0
        0x7C, # returnTop
    ]

    Association = space.w_Point # Wrong class, doesn't matter.
    semaAssoc = W_PointersObject(space, Association, 2)
    semaAssoc.store(space, 0, w_sema)
    semaAssoc.store(space, 1, w_semaphore_cls)
    w_method = space.make_method(bytes, [semaAssoc, w_fork, w_wait, w_yield, w_processor, w_suspPrimOFail, w('nothing')])

    result = interp.execute_method(w_method)
    import pdb; pdb.set_trace()
    assert isinstance(result, W_PointersObject)
Esempio n. 12
0
def test_ContextPart_jump_nonlocal():
    """
    Like above test, but with three blocks to make the return non-local.
    Also, store the outer context beforehand.
    a := 5.
    outer := thisContext.
    a := [[[ outer push: 2. outer jump. 10 ] value ] value] value.
    ^ a
    """
    ContextPart = space.w_MethodContext.as_class_get_shadow(space).s_superclass().w_self()
    push = find_symbol("push:", ContextPart)
    jump = find_symbol("jump", ContextPart)

    bytes = [0x21, 0x82, 0xc0, # Set a
               0x89, 0x82, 0xc2, # Set outer
               0x8f, 0x00, 0x00, 0x15, # Push block
                    0x8f, 0x00, 0x00, 0x0f, # Push block
                        0x8f, 0x00, 0x00, 0x09, # Push block
                            0x42, 0x77, 0xe3, # Push 2
                            0x87, 0x42, 0xd4, # Send jump
                            0x87, 0x25, 0x7d, # Block rest (not executed)
                        0xc9, 0x7d, # Send value and return
                    0xc9, 0x7d, # Send value and return
               0xc9, 0x82, 0xc0, 0x40, 0x7c] # Send value and return

    Association = space.w_Point # Wrong class, doesn't matter.
    assoc = W_PointersObject(space, Association, 2)
    assoc.store(space, 0, w('a'))
    assoc.store(space, 1, space.w_nil)
    assoc2 = W_PointersObject(space, Association, 2)
    assoc2.store(space, 0, w('outer'))
    assoc2.store(space, 1, space.w_nil)
    w_method = space.make_method(bytes, [assoc, w(5), assoc2, push, jump, w(10)])
    result = interp.execute_method(w_method)
    assert isinstance(result, W_SmallInteger)
    assert result.value == 2
Esempio n. 13
0
    def store(self, space, n0, w_value):
        self.ivar_cache[n0] = w_value

        cls = w_value.getclass(space)
        if (cls.is_same_object(space.w_String)):
            aType = TEXT
        elif cls.is_same_object(space.w_SmallInteger):
            aType = INTEGER
        elif cls.is_same_object(space.w_Float):
            aType = REAL
        elif cls.is_same_object(space.w_nil):
            aType = NIL
        else:
            if isinstance(w_value, W_DBObject):
                aType = BLOB
                W_DBObject.state.db_objects[w_value.id] = w_value
                # Save id in database.
                w_value = w_value.w_id
            else:
                # print 'Unable to unwrap %s' % w_value.getclass(space)
                # print 'Falling back to standard store.'
                return W_PointersObject.store(self, space, n0, w_value)

        aType = jit.promote(aType)
        class_name = self.class_name(space)

        if (aType is not NIL and
                W_DBObject.state.get_column_type(class_name, n0) is NIL):
            connection = dbm.connection()
            connection.execute(space, alter_sql(class_name, n0, aType))
            # print "invalidate cache"
            connection.statement_cache.invalidate()
            W_DBObject.state.set_column_type(class_name, n0, aType)

        connection = dbm.connection()
        connection.execute(space, update_sql(class_name, n0),
                           [w_value, self.w_id])
Esempio n. 14
0
    def store(self, space, n0, w_value):
        self.ivar_cache[n0] = w_value

        cls = w_value.getclass(space)
        if (cls.is_same_object(space.w_String)):
            aType = TEXT
        elif cls.is_same_object(space.w_SmallInteger):
            aType = INTEGER
        elif cls.is_same_object(space.w_Float):
            aType = REAL
        elif cls.is_same_object(space.w_nil):
            aType = NIL
        else:
            if isinstance(w_value, W_DBObject):
                aType = BLOB
                W_DBObject.state.db_objects[w_value.id] = w_value
                # Save id in database.
                w_value = w_value.w_id
            else:
                # print 'Unable to unwrap %s' % w_value.getclass(space)
                # print 'Falling back to standard store.'
                return W_PointersObject.store(self, space, n0, w_value)

        aType = jit.promote(aType)
        class_name = self.class_name(space)

        if (aType is not NIL
                and W_DBObject.state.get_column_type(class_name, n0) is NIL):
            connection = dbm.connection()
            connection.execute(space, alter_sql(class_name, n0, aType))
            # print "invalidate cache"
            connection.statement_cache.invalidate()
            W_DBObject.state.set_column_type(class_name, n0, aType)

        connection = dbm.connection()
        connection.execute(space, update_sql(class_name, n0),
                           [w_value, self.w_id])
Esempio n. 15
0
def build_smalltalk_class(name, format, w_superclass=None,
                          w_classofclass=None, methods={}, space=None):
    if space is None:
        space = globals()["space"]
    if w_superclass is None:
        w_superclass = w_Object
    if w_classofclass is None:
        w_classofclass = build_smalltalk_class(None, 0x94,
                                               w_superclass.getclass(space),
                                               w_Metaclass)
    w_methoddict = build_methoddict(methods)
    size = constants.CLASS_NAME_INDEX + 1
    w_class = W_PointersObject(space, w_classofclass, size)
    w_class.store(space, constants.CLASS_SUPERCLASS_INDEX, w_superclass)
    w_class.store(space, constants.CLASS_METHODDICT_INDEX, w_methoddict)
    w_class.store(space, constants.CLASS_FORMAT_INDEX, space.wrap_int(format))
    if name is not None:
        w_class.store(space, constants.CLASS_NAME_INDEX, space.wrap_string(name))
    w_class.as_class_get_shadow(space).s_methoddict().sync_method_cache()
    return w_class
Esempio n. 16
0
def blockcontext(w_sender=None, pc=13, stackpointer=1, stacksize=5,
                  home=None):
    if w_sender is None:
        w_sender = space.w_nil
    if home is None:
        home = methodcontext()
    w_object = W_PointersObject(space, space.w_BlockContext, constants.MTHDCTX_TEMP_FRAME_START+stacksize)
    w_object.store(space, constants.CTXPART_SENDER_INDEX, w_sender)
    w_object.store(space, constants.CTXPART_PC_INDEX, space.wrap_int(pc))
    w_object.store(space, constants.CTXPART_STACKP_INDEX, space.wrap_int(stackpointer))
    w_object.store(space, constants.BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX, space.wrap_int(54))
    w_object.store(space, constants.BLKCTX_INITIAL_IP_INDEX, space.wrap_int(17))
    w_object.store(space, constants.BLKCTX_HOME_INDEX, home)
    w_object.store(space, constants.BLKCTX_STACK_START, space.wrap_string('el'))
    return w_object
Esempio n. 17
0
def methodcontext(w_sender=None, pc=13, stackpointer=0, stacksize=5,
                  method=None):
    if w_sender is None:
        w_sender = space.w_nil
    if method is None:
        method = create_method()
    w_object = W_PointersObject(space, space.w_MethodContext, constants.MTHDCTX_TEMP_FRAME_START+method.tempsize()+stacksize)
    w_object.store(space, constants.CTXPART_SENDER_INDEX, w_sender)
    w_object.store(space, constants.CTXPART_PC_INDEX, space.wrap_int(pc))
    w_object.store(space, constants.CTXPART_STACKP_INDEX, space.wrap_int(method.tempsize()+stackpointer))
    w_object.store(space, constants.MTHDCTX_METHOD, method)
    # XXX
    w_object.store(space, constants.MTHDCTX_CLOSURE_OR_NIL, space.w_nil)
    w_object.store(space, constants.MTHDCTX_RECEIVER, space.wrap_string('receiver'))

    w_object.store(space, constants.MTHDCTX_TEMP_FRAME_START, space.wrap_string('el'))
    return w_object
Esempio n. 18
0
def test_primitive_be_display():
    assert space.w_display() is space.w_nil
    mock_display = W_PointersObject(space, space.w_Point, 4)
    w_wordbmp = W_WordsObject(space, space.w_Bitmap, 10)
    mock_display.store(space, 0, w_wordbmp)  # bitmap
    mock_display.store(space, 1, space.wrap_int(32))  # width
    mock_display.store(space, 2, space.wrap_int(10))  # height
    mock_display.store(space, 3, space.wrap_int(1))  # depth
    prim(BE_DISPLAY, [mock_display])
    assert space.w_display() is mock_display
    w_bitmap = mock_display.fetch(space, 0)
    assert w_bitmap is not w_wordbmp
    assert isinstance(w_bitmap, W_DisplayBitmap)
    sdldisplay = w_bitmap.display()
    assert isinstance(sdldisplay, display.SDLDisplay)

    mock_display2 = W_PointersObject(space, space.w_Point, 4)
    mock_display2.store(space, 0, W_WordsObject(space, space.w_Bitmap,
                                                10))  # bitmap
    mock_display2.store(space, 1, space.wrap_int(32))  # width
    mock_display2.store(space, 2, space.wrap_int(10))  # height
    mock_display2.store(space, 3, space.wrap_int(1))  # depth
    prim(BE_DISPLAY, [mock_display2])
    assert space.w_display() is mock_display2
    w_bitmap2 = mock_display.fetch(space, 0)
    assert isinstance(w_bitmap2, W_DisplayBitmap)
    assert w_bitmap.display() is w_bitmap2.display()
    assert sdldisplay.width == 32
    assert sdldisplay.height == 10

    prim(BE_DISPLAY, [mock_display])
    assert space.w_display() is mock_display
    assert mock_display.fetch(space, 0) is w_bitmap
Esempio n. 19
0
def test_primitive_be_display():
    assert space.w_display() is space.w_nil
    mock_display = W_PointersObject(space, space.w_Point, 4)
    w_wordbmp = W_WordsObject(space, space.w_Bitmap, 10)
    mock_display.store(space, 0, w_wordbmp)  # bitmap
    mock_display.store(space, 1, space.wrap_int(32))  # width
    mock_display.store(space, 2, space.wrap_int(10))  # height
    mock_display.store(space, 3, space.wrap_int(1))  # depth
    prim(BE_DISPLAY, [mock_display])
    assert space.w_display() is mock_display
    w_bitmap = mock_display.fetch(space, 0)
    assert w_bitmap is not w_wordbmp
    assert isinstance(w_bitmap, W_DisplayBitmap)
    sdldisplay = w_bitmap.display()
    assert isinstance(sdldisplay, display.SDLDisplay)

    mock_display2 = W_PointersObject(space, space.w_Point, 4)
    mock_display2.store(space, 0, W_WordsObject(space, space.w_Bitmap, 10))  # bitmap
    mock_display2.store(space, 1, space.wrap_int(32))  # width
    mock_display2.store(space, 2, space.wrap_int(10))  # height
    mock_display2.store(space, 3, space.wrap_int(1))  # depth
    prim(BE_DISPLAY, [mock_display2])
    assert space.w_display() is mock_display2
    w_bitmap2 = mock_display.fetch(space, 0)
    assert isinstance(w_bitmap2, W_DisplayBitmap)
    assert w_bitmap.display() is w_bitmap2.display()
    assert sdldisplay.width == 32
    assert sdldisplay.height == 10

    prim(BE_DISPLAY, [mock_display])
    assert space.w_display() is mock_display
    assert mock_display.fetch(space, 0) is w_bitmap
Esempio n. 20
0
def test_contextOn_do_():
    """
    contextOn:do: is some very heavy meta programming. It creates and returns a separate stack frame,
    settings it's sender to nil, thereby manipulating the senders of two contexts.
    The Point in there should actually be UnhandledError or something.
    The test here is just that this works.
    ctx := ContextPart contextOn: Point do: ['nothing']
    """
    ContextPart = space.w_MethodContext.as_class_get_shadow(space).s_superclass().w_self()
    ContextPartClass = ContextPart.getclass(space).as_class_get_shadow(space).w_self()
    contextOnDo = find_symbol("contextOn:do:", ContextPartClass)

    bytes = [
        0x42, 0x43, # Push the classes
        0x8f, 0x00, 0x00, 0x02, # Push block,
            0x24, 0x7d, # in the block
        0xf1, 0x81, 0xc0, 0x7c # Send contextOn:do:
    ]

    Association = space.w_Point # Wrong class, doesn't matter.
    ctxAssoc = W_PointersObject(space, Association, 2)
    ctxAssoc.store(space, 0, w('ctx'))
    ctxAssoc.store(space, 1, space.w_nil)
    contextPartAssoc = W_PointersObject(space, Association, 2)
    contextPartAssoc.store(space, 0, w('ContextPart'))
    contextPartAssoc.store(space, 1, ContextPart)
    errorAssoc = W_PointersObject(space, Association, 2)
    errorAssoc.store(space, 0, w('Point'))
    errorAssoc.store(space, 1, Association)
    w_method = space.make_method(bytes, [ctxAssoc, contextOnDo, contextPartAssoc, errorAssoc, w('nothing')])

    result = interp.execute_method(w_method)
    assert isinstance(result, W_PointersObject)
    s = result.as_context_get_shadow(space)
    assert s.w_method().lookup_selector == "on:do:"
    assert s.w_method().primitive() == 199
    assert s.s_sender() == None
Esempio n. 21
0
 def initialize_methoddict(self):
     if self._s_methoddict is None:
         w_methoddict = W_PointersObject(self.space, None, 2)
         w_methoddict.store(self.space, constants.METHODDICT_VALUES_INDEX, W_PointersObject(self.space, None, 0))
         self.store_s_methoddict(w_methoddict.as_methoddict_get_shadow(self.space))
Esempio n. 22
0
def func(interp, s_frame, w_rcvr):
    x, y = interp.space.display().mouse_point()
    w_point = W_PointersObject(interp.space, interp.space.w_Point, 2)
    w_point.store(interp.space, 0, interp.space.wrap_int(x))
    w_point.store(interp.space, 1, interp.space.wrap_int(y))
    return w_point