def invoke_interface_method(this_reg, m, args_asm): '''Invokes an interface method m off this_reg using the SIT''' from code_gen.manager import CodeGenManager offset = CodeGenManager.get_sit_offset(m) n_params = len(m.params) pop_asm = ['pop ebx ; Pop param to garbage' for x in range(m.c_num_params)] return [ '; Invoke interface method: {0}'.format(m.name), check_null('eax'), 'push eax ; Push "this" as the first param', args_asm, 'mov dword eax, [esp + 4*{0}] ; Get to "this"'.format(n_params), 'mov dword eax, [eax] ; Get to CIT for T[]', 'mov eax, [eax] ; Get to SIT for T[]', 'mov eax, [eax + {0}] ; Get the method loc in the SIT'.format(offset), 'call eax ; Call the method', pop_asm, ]