Ejemplo n.º 1
0
def run_with_faked_primitive_methods(methods, func, active_context=None):

    # Install faked compiled methods that just invoke the primitive:
    for (w_class, primnum, argsize, methname) in methods:
        s_class = w_class.as_class_get_shadow(space)
        prim_meth = model.W_CompiledMethod(0)
        prim_meth.primitive = primnum
        prim_meth.argsize = argsize
        symbol = fakesymbol(methname)
        # somewhat evil:
        try:
            index = constants.find_selectorindex(methname)
        except ValueError:
            pass
        else:
            space.w_special_selectors.atput0(space, index, symbol)
            assert space.get_special_selector(methname) is symbol
        s_class.installmethod(symbol, prim_meth)

        assert space.w_nil._shadow is None
    try:
        func(active_context) if active_context else func()
    finally:
        # Uninstall those methods:
        assert space.w_nil._shadow is None
        for (w_class, _, _, methname) in methods:
            s_class = w_class.as_class_get_shadow(space)
            s_class.update()
            s_class.s_methoddict().update()
Ejemplo n.º 2
0
def run_with_faked_primitive_methods(methods, func, active_context=None):

    # Install faked compiled methods that just invoke the primitive:
    for (w_class, primnum, argsize, methname) in methods:
        s_class = w_class.as_class_get_shadow(space)
        prim_meth = model.W_CompiledMethod(space, 0)
        prim_meth._primitive = primnum
        prim_meth.argsize = argsize
        symbol = fakesymbol(methname)
        # somewhat evil:
        try:
            index = constants.find_selectorindex(methname)
        except ValueError:
            pass
        else:
            space.w_special_selectors.atput0(space, index, symbol)
            assert space.get_special_selector(methname) is symbol
        s_class.installmethod(symbol, prim_meth)
    try:
        func(active_context) if active_context else func()
    finally:
        # Uninstall those methods:
        for (w_class, _, _, methname) in methods:
            s_class = w_class.as_class_get_shadow(space)
            s_class.s_methoddict().sync_method_cache()
Ejemplo n.º 3
0
def test_callPrimitiveAndPush_fallback():
    w_frame, s_frame = new_frame(bytecodePrimAdd)
    shadow = mockclass(space, 0).as_class_get_shadow(space)
    w_method = model.W_CompiledMethod(0)
    w_method.argsize = 1
    w_method.tempsize = 1
    w_method.literalsize = 1
    w_symbol = fakesymbol("+")
    shadow.installmethod(w_symbol, w_method)
    # slightly evil
    space.w_special_selectors.atput0(space, constants.find_selectorindex("+"), w_symbol)

    w_object = shadow.new()
    s_frame.push(w_object)
    s_frame.push(space.w_one)
    w_active_context = step_in_interp(s_frame)
    s_active_context = w_active_context.as_context_get_shadow(space)
    assert w_active_context.as_methodcontext_get_shadow(space).s_method() == shadow.s_methoddict().methoddict[w_symbol]
    assert s_active_context.w_receiver() is w_object
    assert w_active_context.as_methodcontext_get_shadow(space).gettemp(0).is_same_object(space.w_one)
    assert s_active_context.stack() == []
Ejemplo n.º 4
0
def test_callPrimitiveAndPush_fallback():
    w_frame, s_frame = new_frame(bytecodePrimAdd)
    shadow = bootstrap_class(0).as_class_get_shadow(space)
    w_method = model.W_CompiledMethod(space, 0)
    w_method.argsize = 1
    w_method._tempsize = 1
    w_method.literalsize = 1
    w_symbol = fakesymbol("+")
    shadow.installmethod(w_symbol, w_method)
    # slightly evil
    space.w_special_selectors.atput0(space, constants.find_selectorindex("+"), w_symbol)

    w_object = shadow.new()
    s_frame.push(w_object)
    s_frame.push(space.w_one)
    w_active_context = step_in_interp(s_frame)
    s_active_context = w_active_context.as_context_get_shadow(space)
    assert w_active_context.as_methodcontext_get_shadow(space).w_method() == shadow.s_methoddict().methoddict[w_symbol]
    assert s_active_context.w_receiver() is w_object
    assert w_active_context.as_methodcontext_get_shadow(space).gettemp(0).is_same_object(space.w_one)
    assert s_active_context.stack() == []
Ejemplo n.º 5
0
 def get_special_selector(self, selector):
     i0 = constants.find_selectorindex(selector)
     self.w_special_selectors.as_cached_object_get_shadow(self)
     return self.w_special_selectors.fetch(self, i0)
Ejemplo n.º 6
0
 def get_special_selector(self, selector):
     i0 = constants.find_selectorindex(selector)
     self.w_special_selectors.as_cached_object_get_shadow(self)
     return self.w_special_selectors.fetch(self, i0)