def build(): bytecode = ''.join(map(chr, [ 16, 119, 178, 154, 118, 164, 11, 112, 16, 118, 177, 224, 112, 16, 119, 177, 224, 176, 124 ])) shadow = mockclass(0).as_class_get_shadow() method = model.W_CompiledMethod(1, bytecode, 1) method.literals = fakeliterals("fib:") shadow.installmethod("fib:", method) w_object = shadow.new() interp = new_interpreter(sendLiteralSelectorBytecode(16) + returnTopFromMethod) interp.w_active_context.w_method().literals = fakeliterals("fib:") return interp, w_object
def test_callPrimitiveAndPush_fallback(): interp = new_interpreter(bytecodePrimAdd) shadow = mockclass(0).as_class_get_shadow() w_method = model.W_CompiledMethod(0) w_method.argsize = 1 w_method.literalsize = 1 shadow.installmethod("+", w_method) w_object = shadow.new() interp.w_active_context.push(w_object) interp.w_active_context.push(interp.ONE) interp.step() assert interp.w_active_context.w_method() == shadow.methoddict["+"] assert interp.w_active_context.w_receiver is w_object assert interp.w_active_context.gettemp(0) == interp.ONE assert interp.w_active_context.stack == []
def test_fibWithArgument(): bytecode = ''.join(map(chr, [ 16, 119, 178, 154, 118, 164, 11, 112, 16, 118, 177, 224, 112, 16, 119, 177, 224, 176, 124 ])) shadow = mockclass(0).as_class_get_shadow() method = model.W_CompiledMethod(len(bytecode)) method.literalsize = 1 method.bytes = bytecode method.argsize = 1 method.literals = fakeliterals("fib:") shadow.installmethod("fib:", method) w_object = shadow.new() interp = new_interpreter(sendLiteralSelectorBytecode(16) + returnTopFromMethod) interp.w_active_context.w_method().literals = fakeliterals("fib:") interp.w_active_context.push(w_object) interp.w_active_context.push(wrap_int(8)) result = interp.interpret() assert unwrap_int(result) == 34
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() == []
def test_fibWithArgument(): bytecode = ''.join(map(chr, [ 16, 119, 178, 154, 118, 164, 11, 112, 16, 118, 177, 224, 112, 16, 119, 177, 224, 176, 124 ])) shadow = mockclass(space, 0).as_class_get_shadow(space) method = model.W_CompiledMethod(len(bytecode)) method.literalsize = 1 method.bytes = bytecode method.argsize = 1 method.tempsize = 1 method.literals = fakeliterals(space, "fib:") shadow.installmethod("fib:", method) w_object = shadow.new() interp = new_interpreter(sendLiteralSelectorBytecode(16) + returnTopFromMethod) interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = fakeliterals(space, "fib:") interp.s_active_context().push(w_object) interp.s_active_context().push(space.wrap_int(8)) result = interp.interpret() assert space.unwrap_int(result) == 34
def test_storeAndPopReceiverVariableBytecode(bytecode=storeAndPopReceiverVariableBytecode, popped=True): shadow = mockclass(space, 8).as_class_get_shadow(space) for index in range(8): w_object = shadow.new() interp = new_interpreter(pushConstantTrueBytecode + bytecode(index)) interp.w_active_context().as_methodcontext_get_shadow(space).store_w_receiver(w_object) interp.step() interp.step() if popped: assert interp.s_active_context().stack() == [] else: assert interp.s_active_context().stack() == [space.w_true] for test_index in range(8): if test_index == index: assert w_object.fetch(space, test_index).is_same_object(space.w_true) else: assert w_object.fetch(space, test_index) is space.w_nil
def test_storeAndPopReceiverVariableBytecode( bytecode=storeAndPopReceiverVariableBytecode, popped=True): shadow = mockclass(8).as_class_get_shadow() for index in range(8): w_object = shadow.new() interp = new_interpreter(pushConstantTrueBytecode + bytecode(index)) interp.w_active_context.w_receiver = w_object interp.step() interp.step() if popped: assert interp.w_active_context.stack == [] else: assert interp.w_active_context.stack == [interp.TRUE] for test_index in range(8): if test_index == index: assert w_object.fetch(test_index) == interp.TRUE else: assert w_object.fetch(test_index) is objtable.w_nil
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() == []
def test_storeAndPopReceiverVariableBytecode(bytecode=storeAndPopReceiverVariableBytecode, popped=True): shadow = mockclass(8).as_class_get_shadow() for index in range(8): w_object = shadow.new() interp = new_interpreter(pushConstantTrueBytecode + bytecode(index)) interp.w_active_context.w_receiver = w_object interp.step() interp.step() if popped: assert interp.w_active_context.stack == [] else: assert interp.w_active_context.stack == [interp.TRUE] for test_index in range(8): if test_index == index: assert w_object.fetch(test_index) == interp.TRUE else: assert w_object.fetch(test_index) is objtable.w_nil