def sendBytecodesTest(w_class, w_object, bytecodes):
    for bytecode, result in [
        (returnReceiver, w_object),
        (returnTrue, space.w_true),
        (returnFalse, space.w_false),
        (returnNil, space.w_nil),
        (returnTopFromMethod, space.w_one),
    ]:
        shadow = w_class.as_class_get_shadow(space)
        w_method = model.W_CompiledMethod(2)
        w_method.bytes = pushConstantOneBytecode + bytecode
        shadow.installmethod("foo", w_method)
        interp = new_interpreter(bytecodes)
        interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = fakeliterals(space, "foo")
        interp.s_active_context().push(w_object)
        callerContext = interp.w_active_context()
        interp.step()
        assert interp.s_active_context().w_sender() == callerContext
        assert interp.s_active_context().stack() == []
        assert interp.w_active_context().as_methodcontext_get_shadow(space).w_receiver().is_same_object(w_object)
        assert (
            interp.w_active_context()
            .as_methodcontext_get_shadow(space)
            .w_method()
            .is_same_object(shadow.s_methoddict().methoddict["foo"])
        )
        assert callerContext.as_context_get_shadow(space).stack() == []
        interp.step()
        interp.step()
        assert interp.w_active_context() == callerContext
        assert interp.s_active_context().stack() == [result]
def test_callPrimitiveAndPush_fallback():
    interp = new_interpreter(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
    shadow.installmethod("+", w_method)

    w_object = shadow.new()
    interp.s_active_context().push(w_object)
    interp.s_active_context().push(space.w_one)
    interp.step()
    assert (
        interp.w_active_context().as_methodcontext_get_shadow(space).w_method() == shadow.s_methoddict().methoddict["+"]
    )
    assert interp.s_active_context().w_receiver() is w_object
    assert interp.w_active_context().as_methodcontext_get_shadow(space).gettemp(0).is_same_object(space.w_one)
    assert interp.s_active_context().stack() == []
Exemple #3
0
def test_callPrimitiveAndPush_fallback():
    interp = new_interpreter(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
    shadow.installmethod("+", w_method) 
    
    w_object = shadow.new()
    interp.s_active_context().push(w_object)
    interp.s_active_context().push(space.w_one)
    interp.step()
    assert interp.w_active_context().as_methodcontext_get_shadow(space).w_method() == shadow.s_methoddict().methoddict["+"]
    assert interp.s_active_context().w_receiver() is w_object
    assert interp.w_active_context().as_methodcontext_get_shadow(space).gettemp(0).is_same_object(space.w_one)
    assert interp.s_active_context().stack() == []
Exemple #4
0
def sendBytecodesTest(w_class, w_object, bytecodes):
    for bytecode, result in [ (returnReceiver, w_object), 
          (returnTrue, space.w_true), 
          (returnFalse, space.w_false),
          (returnNil, space.w_nil),
          (returnTopFromMethod, space.w_one) ]:
        shadow = w_class.as_class_get_shadow(space)
        w_method = model.W_CompiledMethod(2)
        w_method.bytes = pushConstantOneBytecode + bytecode
        shadow.installmethod("foo", w_method)
        interp = new_interpreter(bytecodes)
        interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = fakeliterals(space, "foo")
        interp.s_active_context().push(w_object)
        callerContext = interp.w_active_context()
        interp.step()
        assert interp.s_active_context().w_sender() == callerContext
        assert interp.s_active_context().stack() == []
        assert interp.w_active_context().as_methodcontext_get_shadow(space).w_receiver().is_same_object(w_object)
        assert interp.w_active_context().as_methodcontext_get_shadow(space).w_method().is_same_object(shadow.s_methoddict().methoddict["foo"])
        assert callerContext.as_context_get_shadow(space).stack() == []
        interp.step()
        interp.step()
        assert interp.w_active_context() == callerContext
        assert interp.s_active_context().stack() == [result]