File: interp_opcode.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (40 lines) | stat: -rw-r--r-- 1,661 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import WrappedDefault, unwrap_spec
from pypy.tool import stdlib_opcode
from pypy.interpreter.astcompiler.assemble import (_opcode_stack_effect,
    _opcode_stack_effect_jump)


@unwrap_spec(opcode=int)
def stack_effect(space, opcode, w_oparg=None, w_jump=None):
    "Compute the stack effect of the opcode."
    if opcode == stdlib_opcode.EXTENDED_ARG:
        if space.is_none(w_oparg):
            raise oefmt(space.w_ValueError,
                "stack_effect: opcode requires oparg but oparg was not specified")
        return space.newint(0)
    if opcode >= stdlib_opcode.HAVE_ARGUMENT:
        if space.is_none(w_oparg):
            raise oefmt(space.w_ValueError,
                "stack_effect: opcode requires oparg but oparg was not specified")
        oparg = space.int_w(w_oparg)
    else:
        if not space.is_none(w_oparg):
            raise oefmt(space.w_ValueError,
                "stack_effect: opcode does not permit oparg but oparg was specified")
        oparg = -1
    try:
        withoutjump = _opcode_stack_effect(opcode, oparg)
    except KeyError:
        raise oefmt(space.w_ValueError,
            "invalid opcode or oparg")
    hasjump = opcode in stdlib_opcode.hasjrel or opcode in stdlib_opcode.hasjabs
    if hasjump:
        withjump = _opcode_stack_effect_jump(opcode)
        if space.is_none(w_jump):
            return space.newint(max(withoutjump, withjump))
        elif space.is_true(w_jump):
            return space.newint(withjump)
        else:
            return space.newint(withoutjump)
    return space.newint(withoutjump)