Beispiel #1
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)
Beispiel #2
0
def test_accessor_generators():
    w_o = model.W_PointersObject(None, 1)
    w = wrapper.LinkWrapper(space, w_o)
    w_o._vars[0] = "hello"
    assert w.next_link() == "hello"
    w.store_next_link("boe")
    assert w.next_link() == "boe"
Beispiel #3
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.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
Beispiel #4
0
def new_scheduler(w_process=space.w_nil, prioritydict=None):
    priority_list = new_prioritylist(prioritydict)
    w_scheduler = model.W_PointersObject(None, 2)
    scheduler = wrapper.SchedulerWrapper(space, w_scheduler)
    scheduler.store_active_process(w_process)
    scheduler.write(0, priority_list.w_self)
    return scheduler
Beispiel #5
0
def test_linked_list():
    w_object = model.W_PointersObject(None, 2)
    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
    py.test.raises(WrapperException, linkedlist.remove, space.w_nil)
    linkedlist.remove(w_first)
    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
Beispiel #6
0
def test_simpleread():
    w_o = model.W_PointersObject(None, 2)
    w = wrapper.Wrapper(space, w_o)
    w_o._vars[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\")")
Beispiel #7
0
def new_prioritylist(prioritydict=None):
    if prioritydict is not None:
        maxpriority = max(prioritydict.keys())
    else:
        maxpriority = 5
        prioritydict = {}
    w_prioritylist = model.W_PointersObject(None, maxpriority)
    prioritylist = wrapper.Wrapper(space, w_prioritylist)
    for i in range(maxpriority):
        prioritylist.write(i, new_processlist(prioritydict.get(i, [])).w_self)

    return prioritylist
Beispiel #8
0
def new_processlist(processes_w=[]):
    w_processlist = model.W_PointersObject(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).w_self
        if w_last is space.w_nil:
            w_last = w_first
    pl = wrapper.ProcessListWrapper(space, w_processlist)
    pl.store_first_link(w_first)
    pl.store_last_link(w_last)
    return pl
Beispiel #9
0
def new_process(w_next=space.w_nil,
                w_my_list=space.w_nil,
                w_suspended_context=space.w_nil,
                priority=0):
    w_priority = space.wrap_int(priority)
    w_process = model.W_PointersObject(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
Beispiel #10
0
 def make_context(space, w_home, w_sender, argcnt, initialip):
     # create and attach a shadow manually, to not have to carefully put things
     # into the right places in the W_PointersObject
     # XXX could hack some more to never have to create the _vars of w_result
     contextsize = w_home.as_methodcontext_get_shadow(space).myblocksize()
     w_result = model.W_PointersObject(space.w_BlockContext, contextsize)
     s_result = BlockContextShadow(space, w_result)
     w_result.store_shadow(s_result)
     s_result.store_expected_argument_count(argcnt)
     s_result.store_initialip(initialip)
     s_result.store_w_home(w_home)
     s_result.store_pc(initialip)
     return w_result
Beispiel #11
0
 def new(self, extrasize=0):
     w_cls = self.w_self()
     if self.instance_kind == POINTERS:
         w_new = model.W_PointersObject(w_cls,
                                        self.instance_size + extrasize)
     elif self.instance_kind == WORDS:
         w_new = model.W_WordsObject(w_cls, extrasize)
     elif self.instance_kind == BYTES:
         w_new = model.W_BytesObject(w_cls, extrasize)
     elif self.instance_kind == COMPILED_METHOD:
         w_new = model.W_CompiledMethod(extrasize)
     else:
         raise NotImplementedError(self.instance_kind)
     return w_new
Beispiel #12
0
def blockcontext(w_sender=space.w_nil,
                 pc=1,
                 stackpointer=1,
                 stacksize=5,
                 home=methodcontext()):
    w_object = model.W_PointersObject(
        space.w_MethodContext, 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, 'el')
    return w_object
Beispiel #13
0
def build_smalltalk_class(name,
                          format,
                          w_superclass=w_Object,
                          w_classofclass=None,
                          methods={}):
    if w_classofclass is None:
        w_classofclass = build_smalltalk_class(None, 0x94,
                                               w_superclass.w_class,
                                               w_Metaclass)
    w_methoddict = build_methoddict(methods)
    size = constants.CLASS_NAME_INDEX + 1
    w_class = model.W_PointersObject(w_classofclass, size)
    w_class.store(constants.CLASS_SUPERCLASS_INDEX, w_superclass)
    w_class.store(constants.CLASS_METHODDICT_INDEX, w_methoddict)
    w_class.store(constants.CLASS_FORMAT_INDEX, utility.wrap_int(format))
    if name is not None:
        w_class.store(constants.CLASS_NAME_INDEX, utility.wrap_string(name))
    return w_class
Beispiel #14
0
def methodcontext(w_sender=space.w_nil,
                  pc=1,
                  stackpointer=0,
                  stacksize=5,
                  method=method()):
    w_object = model.W_PointersObject(
        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_RECEIVER_MAP, '???')
    w_object.store(space, constants.MTHDCTX_RECEIVER, 'receiver')

    w_object.store(space, constants.MTHDCTX_TEMP_FRAME_START, 'el')
    return w_object
Beispiel #15
0
def bootstrap_class(instsize,
                    w_superclass=None,
                    w_metaclass=None,
                    name='?',
                    format=shadow.POINTERS,
                    varsized=False):
    from pypy.lang.smalltalk import model
    w_class = model.W_PointersObject(w_metaclass, 0)
    # a dummy placeholder for testing
    s = shadow.ClassShadow(w_class)
    s.methoddict = {}
    if w_superclass is not None:
        s.s_superclass = w_superclass.as_class_get_shadow()
    s.name = name
    s.instance_size = instsize
    s.instance_kind = format
    s.instance_varsized = varsized or format != shadow.POINTERS
    s.invalid = False
    w_class._shadow = s
    return w_class
Beispiel #16
0
    def new(self, extrasize=0):
        from pypy.lang.smalltalk import classtable
        w_cls = self.w_self

        if w_cls == classtable.w_BlockContext:
            return model.W_BlockContext(None, None, 0, 0)
        elif w_cls == classtable.w_MethodContext:
            # From slang: Contexts must only be created with newForMethod:
            raise error.PrimitiveFailedError

        if self.instance_kind == POINTERS:
            return model.W_PointersObject(w_cls,
                                          self.instance_size + extrasize)
        elif self.instance_kind == WORDS:
            return model.W_WordsObject(w_cls, extrasize)
        elif self.instance_kind == BYTES:
            return model.W_BytesObject(w_cls, extrasize)
        elif self.instance_kind == COMPILED_METHOD:
            return model.W_CompiledMethod(extrasize)
        else:
            raise NotImplementedError(self.instance_kind)
Beispiel #17
0
def bootstrap_class(space,
                    instsize,
                    w_superclass=None,
                    w_metaclass=None,
                    name='?',
                    format=shadow.POINTERS,
                    varsized=False):
    from pypy.lang.smalltalk import model
    w_class = model.W_PointersObject(w_metaclass, 0)
    # a dummy placeholder for testing
    # XXX
    s = instantiate(shadow.ClassShadow)
    s.space = space
    s._w_self = w_class
    s.w_superclass = w_superclass
    s.name = name
    s.instance_size = instsize
    s.instance_kind = format
    s.w_methoddict = None
    s.instance_varsized = varsized or format != shadow.POINTERS
    s.invalid = False
    w_class.store_shadow(s)
    return w_class
Beispiel #18
0
def new_semaphore(excess_signals=0):
    w_semaphore = model.W_PointersObject(None, 3)
    semaphore = wrapper.SemaphoreWrapper(space, w_semaphore)
    semaphore.store_excess_signals(space, excess_signals)
    return semaphore
Beispiel #19
0
 def initialize_methoddict(self):
     "NOT_RPYTHON"  # this is only for testing.
     if self.w_methoddict is None:
         self.w_methoddict = model.W_PointersObject(None, 2)
         self.w_methoddict._store(1, model.W_PointersObject(None, 0))
         self.s_methoddict().invalid = False
Beispiel #20
0
def test_is_same_object(w_o1=model.W_PointersObject(None,0), w_o2=None):
    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)
Beispiel #21
0
def link(w_next='foo'):
    w_object = model.W_PointersObject(None, 1)
    wrapper.LinkWrapper(space, w_object).store_next_link(w_next)
    return w_object