From 5e4f61f889bc46ceb6bceb5bd38715f5e4538914 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Mon, 5 Jan 2026 15:38:48 +0200 Subject: [PATCH 01/18] All opcodes have id --- crates/compiler-core/src/bytecode.rs | 457 ++++++++------------------- 1 file changed, 124 insertions(+), 333 deletions(-) diff --git a/crates/compiler-core/src/bytecode.rs b/crates/compiler-core/src/bytecode.rs index dc61e3b9b5a..5bb9434492c 100644 --- a/crates/compiler-core/src/bytecode.rs +++ b/crates/compiler-core/src/bytecode.rs @@ -676,436 +676,227 @@ pub type NameIdx = u32; #[repr(u8)] pub enum Instruction { // ==================== No-argument instructions (opcode < 44) ==================== - // 0: CACHE - placeholder for inline cache (not executed) - Cache, - // 1: BEFORE_ASYNC_WITH - BeforeAsyncWith, - // 2: BEFORE_WITH - BeforeWith, - // 3: Reserved (BINARY_OP_INPLACE_ADD_UNICODE in CPython) - Reserved3, - // 4: BINARY_SLICE - not implemented, placeholder - BinarySlice, - // 5: BINARY_SUBSCR - BinarySubscript, - // 6: CHECK_EG_MATCH - CheckEgMatch, - // 7: CHECK_EXC_MATCH - CheckExcMatch, - // 8: CLEANUP_THROW - CleanupThrow, - // 9: DELETE_SUBSCR - DeleteSubscript, - // 10: END_ASYNC_FOR - EndAsyncFor, - // 11: END_FOR - not implemented, placeholder - EndFor, - // 12: END_SEND - EndSend, - // 13: EXIT_INIT_CHECK - not implemented, placeholder - ExitInitCheck, - // 14: FORMAT_SIMPLE - FormatSimple, - // 15: FORMAT_WITH_SPEC - FormatWithSpec, - // 16: GET_AITER - GetAIter, - // 17: RESERVED - Reserved17, - // 18: GET_ANEXT - GetANext, - // 19: GET_ITER - GetIter, - // 20: GET_LEN - GetLen, - // 21: GET_YIELD_FROM_ITER - not implemented, placeholder - GetYieldFromIter, - // 22: INTERPRETER_EXIT - not implemented, placeholder - InterpreterExit, - // 23: LOAD_ASSERTION_ERROR - not implemented, placeholder - LoadAssertionError, - // 24: LOAD_BUILD_CLASS - LoadBuildClass, - // 25: LOAD_LOCALS - not implemented, placeholder - LoadLocals, - // 26: MAKE_FUNCTION - MakeFunction, - // 27: MATCH_KEYS - MatchKeys, - // 28: MATCH_MAPPING - MatchMapping, - // 29: MATCH_SEQUENCE - MatchSequence, - // 30: NOP - Nop, - // 31: POP_EXCEPT - PopException, - // 32: POP_TOP - PopTop, - // 33: PUSH_EXC_INFO - PushExcInfo, - // 34: PUSH_NULL - not implemented, placeholder - PushNull, - // 35: RETURN_GENERATOR - not implemented, placeholder - ReturnGenerator, - // 36: RETURN_VALUE - ReturnValue, - // 37: SETUP_ANNOTATIONS - SetupAnnotation, - // 38: STORE_SLICE - not implemented, placeholder - StoreSlice, - // 39: STORE_SUBSCR - StoreSubscript, - // 40: TO_BOOL - ToBool, - // 41: UNARY_INVERT - UnaryInvert, - // 42: UNARY_NEGATIVE - UnaryNegative, - // 43: UNARY_NOT - UnaryNot, - // ==================== With-argument instructions (opcode >= 44) ==================== - // 44: WITH_EXCEPT_START - WithExceptStart, - // 45: BINARY_OP + BeforeAsyncWith = 1, + BeforeWith = 2, + BinarySubscr = 5, + CheckEgMatch = 6, + CheckExcMatch = 7, + CleanupThrow = 8, + DeleteSubscr = 9, + EndAsyncFor = 10, + EndSend = 12, + FormatSimple = 14, + FormatWithSpec = 15, + GetAIter = 16, + Reserved = 17, + GetANext = 18, + GetIter = 19, + GetLen = 20, + LoadBuildClass = 24, + MakeFunction = 26, + MatchKeys = 27, + MatchMapping = 28, + MatchSequence = 29, + Nop = 30, + PopExcept = 31, + PopTop = 32, + PushExcInfo = 33, + ReturnValue = 36, + SetupAnnotations = 37, + StoreSubscr = 39, + ToBool = 40, + WithExceptStart = 44, + // ==================== With-argument instructions (opcode > 44) ==================== BinaryOp { op: Arg, - }, - // 46: BUILD_CONST_KEY_MAP - not implemented, placeholder - BuildConstKeyMap { - size: Arg, - }, - // 47: BUILD_LIST + } = 45, BuildList { size: Arg, - }, - // 48: BUILD_MAP + } = 47, BuildMap { size: Arg, - }, - // 49: BUILD_SET + } = 48, BuildSet { size: Arg, - }, - // 50: BUILD_SLICE + } = 49, BuildSlice { argc: Arg, - }, - // 51: BUILD_STRING + } = 50, BuildString { size: Arg, - }, - // 52: BUILD_TUPLE + } = 51, BuildTuple { size: Arg, - }, - // 53: CALL - CallFunctionPositional { + } = 52, + Call { nargs: Arg, - }, - // 54: CALL_FUNCTION_EX + } = 53, CallFunctionEx { has_kwargs: Arg, - }, - // 55: CALL_INTRINSIC_1 + } = 54, CallIntrinsic1 { func: Arg, - }, - // 56: CALL_INTRINSIC_2 + } = 55, CallIntrinsic2 { func: Arg, - }, - // 57: CALL_KW - CallFunctionKeyword { + } = 56, + CallKw { nargs: Arg, - }, - // 58: COMPARE_OP - CompareOperation { + } = 57, + CompareOp { op: Arg, - }, - // 59: CONTAINS_OP - ContainsOp(Arg), - // 60: CONVERT_VALUE + } = 58, + ContainsOp(Arg) = 59, ConvertValue { oparg: Arg, - }, - // 61: COPY + } = 60, CopyItem { index: Arg, - }, - // 62: COPY_FREE_VARS - not implemented, placeholder - CopyFreeVars { - count: Arg, - }, - // 63: DELETE_ATTR + } = 61, DeleteAttr { idx: Arg, - }, - // 64: DELETE_DEREF - DeleteDeref(Arg), - // 65: DELETE_FAST - DeleteFast(Arg), - // 66: DELETE_GLOBAL - DeleteGlobal(Arg), - // 67: DELETE_NAME - DeleteLocal(Arg), - // 68: DICT_MERGE - not implemented, placeholder - DictMerge { - index: Arg, - }, - // 69: DICT_UPDATE + } = 63, + DeleteDeref(Arg) = 64, + DeleteFast(Arg) = 65, + DeleteGlobal(Arg) = 66, + DeleteName(Arg) = 67, DictUpdate { index: Arg, - }, - // 70: ENTER_EXECUTOR - not implemented, placeholder - EnterExecutor { - index: Arg, - }, - // 71: EXTENDED_ARG - ExtendedArg, - // 72: FOR_ITER + } = 69, + ExtendedArg = 71, ForIter { target: Arg