예제 #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"
예제 #2
0
def test_is_same_object(w_o1=None, w_o2=None):
    if w_o1 is None:
        w_o1 = W_PointersObject(space, None, 0)
    if w_o2 is None:
        w_o2 = w_o1
    assert w_o1.is_same_object(w_o2)
    assert w_o2.is_same_object(w_o1)
예제 #3
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"
예제 #4
0
def external_call(space, module_name, method_name, stack):
    stack = [space.w(o) for o in stack]
    w_description = W_PointersObject(space, space.w_Array, 2)
    w_description.atput0(space, 0, space.w(module_name))
    w_description.atput0(space, 1, space.w(method_name))
    context = space.make_frame("<not called>", [w_description], stack[0],
                               stack[1:])[0]
    return _prim(space, EXTERNAL_CALL, stack, context)
예제 #5
0
파일: util.py 프로젝트: HPI-SWA-Lab/RSqueak
def external_call(space, module_name, method_name, stack):
    stack = [space.w(o) for o in stack]
    w_description = W_PointersObject(space, space.w_Array, 2)
    w_description.atput0(space, 0, space.w(module_name))
    w_description.atput0(space, 1, space.w(method_name))
    context = space.make_frame("<not called>",
                               [w_description],
                               stack[0], stack[1:])[0]
    return _prim(space, EXTERNAL_CALL, stack, context)
예제 #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\")")
예제 #7
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\")")
예제 #8
0
 def w_self(self):
     if self._w_self is not None:
         return self._w_self
     else:
         space = self.space
         w_self = W_PointersObject(space, space.w_MethodContext, self._w_self_size)
         w_self.store_strategy(self)
         self._w_self = w_self
         return w_self
예제 #9
0
def external_call(plugin, name, stack):
    stack = [space.w(o) for o in stack]
    w_description = W_PointersObject(space, space.w_Array, 2)
    w_description.atput0(space, 0, space.w(plugin))
    w_description.atput0(space, 1, space.w(name))
    func = prim_holder.prim_table[EXTERNAL_CALL]
    s_frame = space.make_frame("not called", [w_description], space.w_nil, stack)[1]
    s_frame.store_stack_ptr(len(stack))
    func(interp, s_frame, len(stack) - 1, s_frame.w_method())
    return s_frame.pop()
예제 #10
0
 def w_self(self):
     if self._w_self is not None:
         return self._w_self
     else:
         space = self.space
         w_self = W_PointersObject(space, space.w_MethodContext,
                                   self._w_self_size)
         w_self.store_strategy(self)
         self._w_self = w_self
         return w_self
예제 #11
0
    def build_block_context(space, s_home, argcnt, pc):
        size = s_home.own_size() - s_home.tempsize()
        w_self = W_PointersObject(space, space.w_BlockContext, size)

        ctx = ContextPartShadow(space, w_self, size, space.w_BlockContext)
        ctx.store_expected_argument_count(argcnt)
        ctx.store_w_home(s_home.w_self())
        ctx.store_initialip(pc)
        ctx.store_pc(pc)
        w_self.store_strategy(ctx)
        ctx.init_temps_and_stack()
        return ctx
예제 #12
0
    def build_block_context(space, s_home, argcnt, pc):
        size = s_home.own_size() - s_home.tempsize()
        w_self = W_PointersObject(space, space.w_BlockContext, size)

        ctx = ContextPartShadow(space, w_self, size, space.w_BlockContext)
        ctx.store_expected_argument_count(argcnt)
        ctx.store_w_home(s_home.w_self())
        ctx.store_initialip(pc)
        ctx.store_pc(pc)
        w_self.store_strategy(ctx)
        ctx.init_temps_and_stack()
        return ctx
예제 #13
0
def test_not_is_same_object(w_o1=None,w_o2=None):
    if w_o1 is None:
        w_o1 = W_PointersObject(space, None, 0)
    if w_o2 is None:
        w_o2 = 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 = W_SmallInteger(2)
    assert not w_o1.is_same_object(w_o2)
    assert not w_o2.is_same_object(w_o1)
    w_o2 = W_Float(5.5)
    assert not w_o1.is_same_object(w_o2)
    assert not w_o2.is_same_object(w_o1)
예제 #14
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;
예제 #16
0
 def __init__(self, space, w_class, size, weak=False, w_id=None,
              cache=None):
     W_PointersObject.__init__(self, space, w_class, size, weak)
     self.ivar_cache = cache if cache else [None] * size
     if w_id is not None:
         self.id = space.unwrap_int(w_id)
         self.w_id = w_id
         return
     self.id = W_DBObject.next_id()
     self.w_id = space.wrap_int(self.id)
     class_name = self.class_name(space)
     W_DBObject.state.init_column_types_if_neccessary(class_name, size)
     connection = dbm.connection()
     W_DBObject.state.create_table_if_neccessary(space, class_name,
                                                 connection)
     connection.execute(space, insert_sql(class_name), [self.w_id])
예제 #17
0
def test_linked_list():
    w_object = W_PointersObject(space, None, 4)
    w_last = link(space.w_nil)
    w_lb1 = link(w_last)
    w_lb2 = link(w_lb1)
    w_lb3 = link(w_lb2)
    w_lb4 = link(w_lb3)
    w_first = link(w_lb4)
    linkedlist = wrapper.LinkedListWrapper(space, w_object)
    linkedlist.store_first_link(w_first)
    linkedlist.store_last_link(w_last)
    assert w_first is linkedlist.first_link()
    assert w_last is linkedlist.last_link()
    assert linkedlist.remove_first_link_of_list() is w_first
    assert linkedlist.remove_first_link_of_list() is w_lb4
    assert linkedlist.remove_first_link_of_list() is w_lb3
    assert not linkedlist.is_empty_list()
    assert linkedlist.remove_first_link_of_list() is w_lb2
    assert linkedlist.remove_first_link_of_list() is w_lb1
    assert linkedlist.remove_first_link_of_list() is w_last
    assert linkedlist.is_empty_list()
    linkedlist.add_last_link(w_first)
    assert linkedlist.first_link() is w_first
    assert linkedlist.last_link() is w_first
    linkedlist.add_last_link(w_last)
    assert linkedlist.first_link() is w_first
    assert linkedlist.last_link() is w_last
    assert linkedlist.remove(space.w_nil) is None
    linkedlist.remove(w_first)
    assert linkedlist.remove(w_first) is None
    assert linkedlist.first_link() is w_last
    linkedlist.store_first_link(w_first)
    wrapper.LinkWrapper(space, w_first).store_next_link(w_last)
    linkedlist.remove(w_last)
    assert linkedlist.last_link() is w_first
예제 #18
0
 def new(self, extrasize=0):
     w_cls = self.w_self()
     instance_kind = self.get_instance_kind()
     if instance_kind == POINTERS:
         size = self.instsize() + extrasize
         w_new = self.make_pointers_object(w_cls, size)
     elif instance_kind == WORDS:
         w_new = W_WordsObject(self.space, w_cls, extrasize)
     elif instance_kind == BYTES:
         w_new = W_BytesObject(self.space, w_cls, extrasize)
     elif instance_kind == COMPILED_METHOD:
         if self.space.is_spur.is_set():
             w_new = W_SpurCompiledMethod(self.space, extrasize)
         else:
             w_new = W_PreSpurCompiledMethod(self.space, extrasize)
     elif instance_kind == FLOAT:
         w_new = W_MutableFloat(0)
     elif instance_kind == LARGE_INTEGER:
         # w_new = W_LargeInteger(self.space, w_cls, NULLRBIGINT, extrasize)
         # When somebody creates a large integer in image, they'll probably
         # want to fill it in.
         w_new = W_BytesObject(self.space, w_cls, extrasize)
     elif instance_kind == WEAK_POINTERS:
         size = self.instsize() + extrasize
         w_new = W_PointersObject(self.space, w_cls, size, weak=True)
     else:
         raise NotImplementedError(instance_kind)
     return w_new
예제 #19
0
def test_W_Immutable_PointersObjects():
    w_class = bootstrap_class(0)
    for i in range(20):
        w_pointers = W_PointersObject(space, w_class, i)
        cls = select_immutable_pointers_class(w_pointers.fetch_all(space))
        assert (i == len(cls._immutable_fields_)
                or cls._immutable_fields_ == ['_storage[*]'])
        placeholder = object()
        w_ipointers = cls(space, w_class, [placeholder] * i)
        assert w_ipointers.is_immutable()
        assert w_ipointers.getclass(space).is_same_object(w_class)
        assert w_ipointers.size() == i
        if i > 0:
            assert w_ipointers.fetch(space, 0) is placeholder
            w_ipointers.store(space, 0, space.w_true)
            assert w_ipointers.fetch(space, 0) is placeholder
def test_W_Immutable_PointersObjects():
    w_class = bootstrap_class(0)
    for i in range(20):
        w_pointers = W_PointersObject(space, w_class, i)
        cls = select_immutable_pointers_class(w_pointers.fetch_all(space))
        assert (i == len(cls._immutable_fields_) or
                cls._immutable_fields_ == ['_storage[*]'])
        placeholder = object()
        w_ipointers = cls(space, w_class, [placeholder] * i)
        assert w_ipointers.is_immutable()
        assert w_ipointers.getclass(space).is_same_object(w_class)
        assert w_ipointers.size() == i
        if i > 0:
            assert w_ipointers.fetch(space, 0) is placeholder
            w_ipointers.store(space, 0, space.w_true)
            assert w_ipointers.fetch(space, 0) is placeholder
예제 #21
0
def new_scheduler(w_process=None, prioritydict=None):
    if w_process is None:
        w_process = space.w_nil
    priority_list = new_prioritylist(prioritydict)
    w_scheduler = W_PointersObject(space, None, 2)
    scheduler = wrapper.SchedulerWrapper(space, w_scheduler)
    scheduler.store_active_process(w_process)
    scheduler.write(0, priority_list.wrapped)
    return scheduler
예제 #22
0
def test_dbobject_fetch_and_store_with_pointers_object():
    space = create_space(bootstrap=True)
    instsize = 10
    obj = W_DBObject(space, _bootstrap_class(instsize, "Foo"), instsize)
    val = W_PointersObject(space, _bootstrap_class(instsize, "Foo"), instsize)
    obj.store(space, 0, val)
    returned_val = obj.fetch(space, 0)

    assert val == returned_val
예제 #23
0
파일: main.py 프로젝트: HPI-SWA-Lab/RSqueak
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()
예제 #24
0
 def bootstrap_class(self,
                     instsize,
                     w_superclass=None,
                     w_metaclass=None,
                     name='?',
                     format=storage_classes.POINTERS,
                     varsized=False):
     w_class = W_PointersObject(self, w_metaclass, 6)
     self.patch_class(w_class, instsize, w_superclass, w_metaclass, name,
                      format, varsized)
     return w_class
예제 #25
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
예제 #26
0
 def make_method(self, bytes, literals=None, numargs=0):
     if not isinstance(bytes, str):
         bytes = "".join([chr(x) for x in bytes])
     w_method = W_PreSpurCompiledMethod(self, len(bytes))
     w_method.islarge = 1
     w_method.bytes = bytes
     w_method.argsize = numargs
     w_method._tempsize = 8
     if literals is None:
         literals = [W_PointersObject(self, None, 2)]
     w_method.setliterals(literals)
     return w_method
예제 #27
0
def new_prioritylist(prioritydict=None):
    if prioritydict is not None:
        maxpriority = max(prioritydict.keys())
    else:
        maxpriority = 5
        prioritydict = {}
    w_prioritylist = W_PointersObject(space, None, maxpriority)
    prioritylist = wrapper.Wrapper(space, w_prioritylist)
    for i in range(maxpriority):
        prioritylist.write(i, new_processlist(prioritydict.get(i, [])).wrapped)

    return prioritylist
예제 #28
0
def new_processlist(processes_w=[]):
    w_processlist = W_PointersObject(space, None, 2)
    w_first = space.w_nil
    w_last = space.w_nil
    for w_process in processes_w[::-1]:
        w_first = newprocess(w_first, w_processlist).wrapped
        if w_last.is_nil(space):
            w_last = w_first
    pl = wrapper.LinkedListWrapper(space, w_processlist)
    pl.store_first_link(w_first)
    pl.store_last_link(w_last)
    return pl
예제 #29
0
 def __init__(self,
              space,
              w_class,
              size,
              weak=False,
              w_id=None,
              cache=None):
     W_PointersObject.__init__(self, space, w_class, size, weak)
     self.ivar_cache = cache if cache else [None] * size
     if w_id is not None:
         self.id = space.unwrap_int(w_id)
         self.w_id = w_id
         return
     self.id = W_DBObject.next_id()
     self.w_id = space.wrap_int(self.id)
     class_name = self.class_name(space)
     W_DBObject.state.init_column_types_if_neccessary(class_name, size)
     connection = dbm.connection()
     W_DBObject.state.create_table_if_neccessary(space, class_name,
                                                 connection)
     connection.execute(space, insert_sql(class_name), [self.w_id])
예제 #30
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))
예제 #31
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
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
예제 #33
0
def external_call(plugin, name, stack):
    stack = [space.w(o) for o in stack]
    w_description = W_PointersObject(space, space.w_Array, 2)
    w_description.atput0(space, 0, space.w(plugin))
    w_description.atput0(space, 1, space.w(name))
    func = prim_holder.prim_table[EXTERNAL_CALL]
    s_frame = space.make_frame("not called", [w_description], space.w_nil,
                               stack)[1]
    s_frame.store_stack_ptr(len(stack))
    func(interp, s_frame, len(stack) - 1, s_frame.w_method())
    return s_frame.pop()
예제 #34
0
def new_process(w_next=None,
                w_my_list=None,
                w_suspended_context=None,
                priority=0):
    if w_next is None:
        w_next = space.w_nil
    if w_my_list is None:
        w_my_list = space.w_nil
    if w_suspended_context is None:
        w_suspended_context = space.w_nil
    w_priority = space.wrap_int(priority)
    w_process = W_PointersObject(space, None, 4)
    process = wrapper.ProcessWrapper(space, w_process)
    process.store_next_link(w_next)
    process.store_my_list(w_my_list)
    process.store_suspended_context(w_suspended_context)
    process.write(2, w_priority)
    return process
예제 #35
0
    def fetch(self, space, n0):
        class_name = self.class_name(space)
        if W_DBObject.state.get_column_type(class_name, n0) is NIL:
            # print "Can't find column. Falling back to default fetch."
            return W_PointersObject.fetch(self, space, n0)

        if self.ivar_cache[n0] is not None:
            return self.ivar_cache[n0]

        cursor = dbm.connection().execute(
            space, select_sql(class_name, n0), [self.w_id])

        w_result = cursor.next(space).fetch(space, 0)
        if w_result:
            if W_DBObject.state.get_column_type(class_name, n0) is BLOB:
                db_id = space.unwrap_int(w_result)
                w_result = W_DBObject.state.db_objects[db_id]

            self.ivar_cache[n0] = w_result
            return w_result
        else:
            raise PrimitiveFailedError
예제 #36
0
    def fetch(self, space, n0):
        class_name = self.class_name(space)
        if W_DBObject.state.get_column_type(class_name, n0) is NIL:
            # print "Can't find column. Falling back to default fetch."
            return W_PointersObject.fetch(self, space, n0)

        if self.ivar_cache[n0] is not None:
            return self.ivar_cache[n0]

        cursor = dbm.connection().execute(space, select_sql(class_name, n0),
                                          [self.w_id])

        w_result = cursor.next(space).fetch(space, 0)
        if w_result:
            if W_DBObject.state.get_column_type(class_name, n0) is BLOB:
                db_id = space.unwrap_int(w_result)
                w_result = W_DBObject.state.db_objects[db_id]

            self.ivar_cache[n0] = w_result
            return w_result
        else:
            raise PrimitiveFailedError
예제 #37
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])
예제 #38
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])
예제 #39
0
파일: main.py 프로젝트: swipswaps/RSqueak
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()
예제 #40
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)
예제 #41
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
예제 #42
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
예제 #43
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
예제 #44
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
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
예제 #46
0
 def make_pointers_object(self, w_cls, size):
     return W_PointersObject(self.space, w_cls, size)
예제 #47
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))
예제 #48
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