Class representing a byte-code instruction. A byte-code token is equivalent to Python 3's dis.instruction or the contents of one line as output by dis.dis().
| 45 | |
| 46 | |
| 47 | class Token: |
| 48 | """ |
| 49 | Class representing a byte-code instruction. |
| 50 | |
| 51 | A byte-code token is equivalent to Python 3's dis.instruction or |
| 52 | the contents of one line as output by dis.dis(). |
| 53 | """ |
| 54 | |
| 55 | # FIXME: match Python 3.4's terms: |
| 56 | # linestart = starts_line |
| 57 | # attr = argval |
| 58 | # pattr = argrepr |
| 59 | def __init__( |
| 60 | self, |
| 61 | opname, |
| 62 | attr=None, |
| 63 | pattr=None, |
| 64 | offset: Union[int, str] = -1, |
| 65 | linestart=None, |
| 66 | op=None, |
| 67 | has_arg=None, |
| 68 | opc=None, |
| 69 | has_extended_arg=False, |
| 70 | optype=None, |
| 71 | ): |
| 72 | self.kind = intern(opname) |
| 73 | self.has_arg = has_arg |
| 74 | self.attr: Optional[int] = attr |
| 75 | self.pattr = pattr |
| 76 | self.optype = optype |
| 77 | if has_extended_arg: |
| 78 | self.offset = "%d_%d" % (offset, offset + 2) |
| 79 | else: |
| 80 | self.offset = offset |
| 81 | |
| 82 | self.linestart = linestart |
| 83 | if has_arg is False: |
| 84 | self.attr = None |
| 85 | self.pattr = None |
| 86 | |
| 87 | if opc is None: |
| 88 | try: |
| 89 | from xdis.std import _std_api |
| 90 | except KeyError as e: |
| 91 | print(f"I don't know about Python version {e} yet.") |
| 92 | try: |
| 93 | version_tuple = tuple(int(i) for i in str(e)[1:-1].split(".")) |
| 94 | except Exception: |
| 95 | pass |
| 96 | else: |
| 97 | if version_tuple > (3, 9): |
| 98 | print("Python versions 3.9 and greater are not supported.") |
| 99 | else: |
| 100 | print(f"xdis might need to be informed about version {e}") |
| 101 | return |
| 102 | |
| 103 | self.opc = _std_api.opc |
| 104 | else: |
no outgoing calls