Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add placeholder opcodes
  • Loading branch information
ShaharNaveh committed Jan 9, 2026
commit 89c20f691a0492a11260b17872e3c5e62c5f5bf3
29 changes: 29 additions & 0 deletions Lib/_opcode_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
_specialized_opmap = {}

opmap = {
'CACHE': 0,
'BEFORE_ASYNC_WITH': 1,
'BEFORE_WITH': 2,
'BINARY_OP_INPLACE_ADD_UNICODE': 3,
'BINARY_SLICE': 4,
'BINARY_SUBSCR': 5,
'CHECK_EG_MATCH': 6,
'CHECK_EXC_MATCH': 7,
'CLEANUP_THROW': 8,
'DELETE_SUBSCR': 9,
'END_ASYNC_FOR': 10,
'END_FOR': 11,
'END_SEND': 12,
'EXIT_INIT_CHECK': 13,
'FORMAT_SIMPLE': 14,
'FORMAT_WITH_SPEC': 15,
'GET_AITER': 16,
Expand All @@ -24,7 +29,10 @@
'GET_ITER': 19,
'GET_LEN': 20,
'GET_YIELD_FROM_ITER': 21,
'INTERPRETER_EXIT': 22,
'LOAD_ASSERTION_ERROR': 23,
'LOAD_BUILD_CLASS': 24,
'LOAD_LOCALS': 25,
'MAKE_FUNCTION': 26,
'MATCH_KEYS': 27,
'MATCH_MAPPING': 28,
Expand All @@ -33,15 +41,19 @@
'POP_EXCEPT': 31,
'POP_TOP': 32,
'PUSH_EXC_INFO': 33,
'PUSH_NULL': 34,
'RETURN_GENERATOR': 35,
'RETURN_VALUE': 36,
'SETUP_ANNOTATIONS': 37,
'STORE_SLICE': 38,
'STORE_SUBSCR': 39,
'TO_BOOL': 40,
'UNARY_INVERT': 41,
'UNARY_NEGATIVE': 42,
'UNARY_NOT': 43,
'WITH_EXCEPT_START': 44,
'BINARY_OP': 45,
'BUILD_CONST_KEY_MAP': 46,
'BUILD_LIST': 47,
'BUILD_MAP': 48,
'BUILD_SET': 49,
Expand All @@ -57,40 +69,57 @@
'CONTAINS_OP': 59,
'CONVERT_VALUE': 60,
'COPY': 61,
'COPY_FREE_VARS': 62,
'DELETE_ATTR': 63,
'DELETE_DEREF': 64,
'DELETE_FAST': 65,
'DELETE_GLOBAL': 66,
'DELETE_NAME': 67,
'DICT_MERGE': 68,
'DICT_UPDATE': 69,
'ENTER_EXECUTOR': 70,
'EXTENDED_ARG': 71,
'FOR_ITER': 72,
'GET_AWAITABLE': 73,
'IMPORT_FROM': 74,
'IMPORT_NAME': 75,
'IS_OP': 76,
'JUMP_BACKWARD': 77,
'JUMP_BACKWARD_NO_INTERRUPT': 78,
'JUMP_FORWARD': 79,
'LIST_APPEND': 80,
'LIST_EXTEND': 81,
'LOAD_ATTR': 82,
'LOAD_CONST': 83,
'LOAD_DEREF': 84,
'LOAD_FAST': 85,
'LOAD_FAST_AND_CLEAR': 86,
'LOAD_FAST_CHECK': 87,
'LOAD_FAST_LOAD_FAST': 88,
'LOAD_FROM_DICT_OR_DEREF': 89,
'LOAD_FROM_DICT_OR_GLOBALS': 90,
'LOAD_GLOBAL': 91,
'LOAD_NAME': 92,
'LOAD_SUPER_ATTR': 93,
'MAKE_CELL': 94,
'MAP_ADD': 95,
'MATCH_CLASS': 96,
'POP_JUMP_IF_FALSE': 97,
'POP_JUMP_IF_NONE': 98,
'POP_JUMP_IF_NOT_NONE': 99,
'POP_JUMP_IF_TRUE': 100,
'RAISE_VARARGS': 101,
'RERAISE': 102,
'RETURN_CONST': 103,
'SEND': 104,
'SET_ADD': 105,
'SET_FUNCTION_ATTRIBUTE': 106,
'SET_UPDATE': 107,
'STORE_ATTR': 108,
'STORE_DEREF': 109,
'STORE_FAST': 110,
'STORE_FAST_LOAD_FAST': 111,
'STORE_FAST_STORE_FAST': 112,
'STORE_GLOBAL': 113,
'STORE_NAME': 114,
'SWAP': 115,
Expand Down
98 changes: 74 additions & 24 deletions crates/compiler-core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,15 +676,20 @@ pub type NameIdx = u32;
#[repr(u8)]
pub enum Instruction {
// ==================== No-argument instructions (opcode < 44) ====================
Cache = 0, // Placeholder
BeforeAsyncWith = 1,
BeforeWith = 2,
BinaryOpInplaceAddUnicode = 3, // Placeholder
BinarySlice = 4, // Placeholder
BinarySubscr = 5,
CheckEgMatch = 6,
CheckExcMatch = 7,
CleanupThrow = 8,
DeleteSubscr = 9,
EndAsyncFor = 10,
EndFor = 11, // Placeholder
EndSend = 12,
ExitInitCheck = 13, // Placeholder
FormatSimple = 14,
FormatWithSpec = 15,
GetAIter = 16,
Expand All @@ -693,7 +698,10 @@ pub enum Instruction {
GetIter = 19,
GetLen = 20,
GetYieldFromIter = 21,
InterpreterExit = 22, // Placeholder
LoadAssertionError = 23, // Placeholder
LoadBuildClass = 24,
LoadLocals = 25, // Placeholder
MakeFunction = 26,
MatchKeys = 27,
MatchMapping = 28,
Expand All @@ -702,8 +710,11 @@ pub enum Instruction {
PopExcept = 31,
PopTop = 32,
PushExcInfo = 33,
PushNull = 34, // Placeholder
ReturnGenerator = 35, // Placeholder
ReturnValue = 36,
SetupAnnotations = 37,
StoreSlice = 38, // Placeholder
StoreSubscr = 39,
ToBool = 40,
UnaryInvert = 41,
Expand All @@ -714,6 +725,9 @@ pub enum Instruction {
BinaryOp {
op: Arg<BinaryOperator>,
} = 45,
BuildConstKeyMap {
size: Arg<u32>,
} = 46, // Placeholder
BuildList {
size: Arg<u32>,
} = 47,
Expand Down Expand Up @@ -757,16 +771,23 @@ pub enum Instruction {
CopyItem {
index: Arg<u32>,
} = 61,
CopyFreeVars {
count: Arg<u32>,
} = 62, // Placeholder
DeleteAttr {
idx: Arg<NameIdx>,
} = 63,
DeleteDeref(Arg<NameIdx>) = 64,
DeleteFast(Arg<NameIdx>) = 65,
DeleteGlobal(Arg<NameIdx>) = 66,
DeleteName(Arg<NameIdx>) = 67,
DictMerge {
index: Arg<u32>,
} = 68, // Placeholder
DictUpdate {
index: Arg<u32>,
} = 69,
EnterExecutor = 70, // Placeholder
ExtendedArg = 71,
ForIter {
target: Arg<Label>,
Expand All @@ -779,9 +800,21 @@ pub enum Instruction {
idx: Arg<NameIdx>,
} = 75,
IsOp(Arg<Invert>) = 76,
JumpBackward {
target: Arg<Label>,
} = 77, // Placeholder
JumpBackwardNoInterrupt {
target: Arg<Label>,
} = 78, // Placeholder
JumpForward {
target: Arg<Label>,
} = 79, // Placeholder
ListAppend {
i: Arg<u32>,
} = 80,
ListExtend {
i: Arg<u32>,
} = 81, // Placeholder
LoadAttr {
idx: Arg<NameIdx>,
} = 82,
Expand All @@ -791,15 +824,31 @@ pub enum Instruction {
LoadDeref(Arg<NameIdx>) = 84,
LoadFast(Arg<NameIdx>) = 85,
LoadFastAndClear(Arg<NameIdx>) = 86,
LoadFastCheck(Arg<NameIdx>) = 87, // Placeholder
LoadFastLoadFast {
arg: Arg<u32>,
} = 88, // Placeholder
LoadFromDictOrDeref(Arg<NameIdx>) = 89, // Placeholder
LoadFromDictOrGlobals(Arg<NameIdx>) = 90, // Placeholder
LoadGlobal(Arg<NameIdx>) = 91,
LoadName(Arg<NameIdx>) = 92,
LoadSuperAttr {
arg: Arg<u32>,
} = 93, // Placeholder
MakeCell(Arg<NameIdx>) = 94, // Placeholder
MapAdd {
i: Arg<u32>,
} = 95,
MatchClass(Arg<u32>) = 96,
PopJumpIfFalse {
target: Arg<Label>,
} = 97,
PopJumpIfNone {
target: Arg<Label>,
} = 98, // Placeholder
PopJumpIfNotNone {
target: Arg<Label>,
} = 99, // Placeholder
PopJumpIfTrue {
target: Arg<Label>,
} = 100,
Expand All @@ -821,6 +870,9 @@ pub enum Instruction {
SetFunctionAttribute {
attr: Arg<MakeFunctionFlags>,
} = 106,
SetUpdate {
i: Arg<u32>,
} = 107, // Placeholder
StoreAttr {
idx: Arg<NameIdx>,
} = 108,
Expand All @@ -830,6 +882,9 @@ pub enum Instruction {
store_idx: Arg<NameIdx>,
load_idx: Arg<NameIdx>,
} = 111,
StoreFastStoreFast {
arg: Arg<u32>,
} = 112, // Placeholder
StoreGlobal(Arg<NameIdx>) = 113,
StoreName(Arg<NameIdx>) = 114,
Swap {
Expand Down Expand Up @@ -909,31 +964,26 @@ impl TryFrom<u8> for Instruction {

#[inline]
fn try_from(value: u8) -> Result<Self, MarshalError> {
let cpython_start = Instruction::Cache as u8;
let cpython_end = Instruction::YieldValue as u8;

let resume_id = Instruction::Resume { arg: Arg::marker() } as u8;

let custom_start = Instruction::Break {
target: Arg::marker(),
} as u8;
let custom_end = Instruction::Subscript as u8;

let pseudo_start = Instruction::Jump {
target: Arg::marker(),
} as u8;
let pseudo_end = Instruction::PopBlock as u8;

match value {
1
| 2
| 5..=10
| 12
| 14..=21
| 24
| 26..=33
| 36
| 37
| 39..=45
| 47..=61
| 63..=67
| 69
| 71..=76
| 80
| 82..=86
| 91
| 92
| 95..=97
| 100..=106
| 108..=111
| 113..=135
| 149
| 252..=255 => Ok(unsafe { core::mem::transmute::<u8, Self>(value) }),
cpython_start..=cpython_end
| resume_id
| custom_start..=custom_end
| pseudo_start..=pseudo_end => Ok(unsafe { core::mem::transmute::<u8, Self>(value) }),
_ => Err(Self::Error::InvalidBytecode),
}
}
Expand Down