2626from bytecode .flags import CompilerFlags
2727from bytecode .instr import (
2828 _UNSET ,
29+ BINARY_OPS ,
2930 BITFLAG2_OPCODES ,
3031 BITFLAG_OPCODES ,
32+ COMMON_CONSTANT_OPS ,
3133 DUAL_ARG_OPCODES ,
3234 DUAL_ARG_OPCODES_SINGLE_OPS ,
35+ FORMAT_VALUE_OPS ,
3336 INTRINSIC ,
3437 INTRINSIC_1OP ,
3538 INTRINSIC_2OP ,
3639 PLACEHOLDER_LABEL ,
40+ SPECIAL_OPS ,
3741 UNSET ,
3842 BaseInstr ,
43+ BinaryOp ,
3944 CellVar ,
45+ CommonConstant ,
4046 Compare ,
47+ FormatValue ,
4148 FreeVar ,
4249 Instr ,
4350 InstrArg ,
4653 Intrinsic2Op ,
4754 Label ,
4855 SetLineno ,
56+ SpecialMethod ,
4957 TryBegin ,
5058 TryEnd ,
5159 _check_arg_int ,
@@ -1056,7 +1064,10 @@ def to_bytecode(
10561064 arg = locals_lookup [c_arg ]
10571065 elif opcode in _opcode .hasname :
10581066 if opcode in BITFLAG_OPCODES :
1059- arg = (bool (c_arg & 1 ), self .names [c_arg >> 1 ])
1067+ arg = (
1068+ bool (c_arg & 1 ),
1069+ self .names [c_arg >> 1 ],
1070+ )
10601071 elif opcode in BITFLAG2_OPCODES :
10611072 arg = (bool (c_arg & 1 ), bool (c_arg & 2 ), self .names [c_arg >> 2 ])
10621073 else :
@@ -1082,6 +1093,20 @@ def to_bytecode(
10821093 arg = Intrinsic1Op (c_arg )
10831094 elif opcode in INTRINSIC_2OP :
10841095 arg = Intrinsic2Op (c_arg )
1096+ elif opcode in BINARY_OPS :
1097+ arg = BinaryOp (c_arg )
1098+ elif opcode in COMMON_CONSTANT_OPS :
1099+ arg = CommonConstant (c_arg )
1100+ elif opcode in SPECIAL_OPS :
1101+ arg = SpecialMethod (c_arg )
1102+ elif opcode in FORMAT_VALUE_OPS :
1103+ if opcode in BITFLAG_OPCODES :
1104+ arg = (
1105+ bool (c_arg & 1 ),
1106+ FormatValue (c_arg >> 1 ),
1107+ )
1108+ else :
1109+ arg = FormatValue (c_arg )
10851110 else :
10861111 arg = c_arg
10871112
@@ -1143,7 +1168,7 @@ def to_bytecode(
11431168
11441169
11451170class _ConvertBytecodeToConcrete :
1146- # XXX document attributes
1171+ # FIXME document attributes
11471172
11481173 #: Default number of passes of compute_jumps() before giving up. Refer to
11491174 #: assemble_jump_offsets() in compile.c for background.
@@ -1316,9 +1341,13 @@ def concrete_instructions(self) -> None:
13161341 isinstance (arg , tuple )
13171342 and len (arg ) == 2
13181343 and isinstance (arg [0 ], bool )
1319- and isinstance (arg [1 ], str )
13201344 ), arg
1321- index = self .add (self .names , arg [1 ])
1345+ if isinstance (arg [1 ], str ):
1346+ index = self .add (self .names , arg [1 ])
1347+ elif isinstance (arg , FormatValue ):
1348+ index = int (arg )
1349+ else :
1350+ assert False , arg # noqa
13221351 c_arg = int (arg [0 ]) + (index << 1 )
13231352 elif opcode in BITFLAG2_OPCODES :
13241353 assert (
0 commit comments