10.07.2015 Views

An ARM Backend for PyPyls Tracing JIT - STUPS Group

An ARM Backend for PyPyls Tracing JIT - STUPS Group

An ARM Backend for PyPyls Tracing JIT - STUPS Group

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

18 5 PYPY’S APPROACH TO TRACING <strong>JIT</strong>Sdef interpret(bytecode, a):regs = [0] * 256pc = 0while True:opcode = ord(bytecode[pc])pc += 1if opcode == JUMP_IF_A:target = ord(bytecode[pc])pc += 1if a:pc = targetelif opcode == MOV_A_R:n = ord(bytecode[pc])pc += 1regs[n] = aelif opcode == MOV_R_A:n = ord(bytecode[pc])pc += 1a = regs[n]elif opcode == ADD_R_TO_A:n = ord(bytecode[pc])pc += 1a += regs[n]elif opcode == DECR_A:a -= 1elif opcode == RETURN_A:return aFigure 6: A very simple bytecode interpreter with registers and an accumulator.MOV_A_R 0 # i = aMOV_A_R 1 # copy of ’a’# 4:MOV_R_A 0 # i--DECR_AMOV_A_R 0MOV_R_A 2 # res += aADD_R_TO_A 1MOV_A_R 2MOV_R_A 0 # if i!=0: goto 4JUMP_IF_A 4MOV_R_A 2 # return resRETURN_AFigure 7: Example bytecode: Compute the square of the accumulator

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!