<div dir="ltr">I have an interpreter inner loop that looks something like this:<div><br></div><div>jitdriver = JitDriver(greens=['ip', 'tos', 'bytecodes', 'consts'], reds=['locals', 'stack'])<br>
</div><div><br></div><div><div><div>def interpret(code, args):</div><div> assert isinstance(code, Code)</div><div> bytecodes = code.bytecodes</div><div> consts = code.consts</div><div> vars = code.vars</div><div>
locals = array_of_size(code.locals)</div><div> ip = 0</div><div> stack = array_of_size(code.stacksize)</div><div> tos = -1</div><div> while True:</div><div> jitdriver.jit_merge_point(ip=ip, tos=tos, bytecodes=bytecodes, consts=consts, locals=locals, stack=stack)</div>
<div> op = ord(bytecodes[ip])</div><div><br></div><div><br></div><div><br></div><div> if op == POP:</div><div> stack[tos] = None</div><div> tos -= 1</div><div> ip += 1</div><div>
continue</div><div><br></div><div> elif op == PUSH_CONST:</div><div> arg = ord(bytecodes[ip + 1])</div><div> tos += 1</div><div> stack[tos] = consts[arg]</div><div> ip += 2</div>
<div> continue</div></div><div><br><br>The jit traces from this aren't bad, but it insists on maintaining the stack and locals arrays. Since these arrays are reference arrays, my primitive types (Integers for example) are allocated when math is being performed. What can I do to force the JIT to not maintain a stack/locals array. Or should I construct the stack in a different way?<br>
<br>I tried digging into the PyPy source to find how how this is done there, but I haven't been able to find it yet. <br><br>Timothy</div></div></div>