Align opcode names in dis (#6526)

* opcodes dis repr like cpython. POP-> POP_TOP

* Adjust frame.rs

* Fix codegen

* snapshots

* Add doc for `PopTop`

* fix jit
This commit is contained in:
Shahar Naveh
2025-12-25 14:17:31 +01:00
committed by GitHub
parent 61ddd98b89
commit bcdf37bef1
8 changed files with 234 additions and 230 deletions

View File

@@ -1063,7 +1063,7 @@ impl Compiler {
}
);
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
} else {
self.compile_statement(statement)?;
}
@@ -1079,7 +1079,7 @@ impl Compiler {
}
);
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
} else {
self.compile_statement(last)?;
self.emit_load_const(ConstantData::None);
@@ -1104,7 +1104,7 @@ impl Compiler {
if let Some(last_statement) = body.last() {
match last_statement {
Stmt::Expr(_) => {
self.current_block().instructions.pop(); // pop Instruction::Pop
self.current_block().instructions.pop(); // pop Instruction::PopTop
}
Stmt::FunctionDef(_) | Stmt::ClassDef(_) => {
let pop_instructions = self.current_block().instructions.pop();
@@ -1401,14 +1401,14 @@ impl Compiler {
}
// Pop module from stack:
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
}
}
Stmt::Expr(StmtExpr { value, .. }) => {
self.compile_expression(value)?;
// Pop result of stack, since we not use it:
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
}
Stmt::Global(_) | Stmt::Nonlocal(_) => {
// Handled during symbol table construction.
@@ -2051,12 +2051,12 @@ impl Compiler {
self.store_name(alias.as_str())?
} else {
// Drop exception from top of stack:
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
}
} else {
// Catch all!
// Drop exception from top of stack:
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
}
// Handler code:
@@ -2950,7 +2950,7 @@ impl Compiler {
self.compile_store(var)?;
}
None => {
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
}
}
final_block
@@ -3143,7 +3143,7 @@ impl Compiler {
for &label in pc.fail_pop.iter().skip(1).rev() {
self.switch_to_block(label);
// Emit the POP instruction.
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
}
// Finally, use the first label.
self.switch_to_block(pc.fail_pop[0]);
@@ -3187,7 +3187,7 @@ impl Compiler {
match n {
// If no name is provided, simply pop the top of the stack.
None => {
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
Ok(())
}
Some(name) => {
@@ -3313,7 +3313,7 @@ impl Compiler {
}
// Pop the subject off the stack.
pc.on_top -= 1;
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
Ok(())
}
@@ -3497,7 +3497,7 @@ impl Compiler {
pc.on_top -= 1;
if is_true_wildcard {
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
continue; // Don't compile wildcard patterns
}
@@ -3548,7 +3548,7 @@ impl Compiler {
if size == 0 && star_target.is_none() {
// If the pattern is just "{}", we're done! Pop the subject
pc.on_top -= 1;
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
return Ok(());
}
@@ -3703,8 +3703,8 @@ impl Compiler {
// Non-rest pattern: just clean up the stack
// Pop them as we're not using them
emit!(self, Instruction::Pop); // Pop keys_tuple
emit!(self, Instruction::Pop); // Pop subject
emit!(self, Instruction::PopTop); // Pop keys_tuple
emit!(self, Instruction::PopTop); // Pop subject
}
Ok(())
@@ -3792,7 +3792,7 @@ impl Compiler {
// In Rust, old_pc is a local clone, so we need not worry about that.
// No alternative matched: pop the subject and fail.
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
self.jump_to_fail_pop(pc, JumpOp::Jump)?;
// Use the label "end".
@@ -3814,7 +3814,7 @@ impl Compiler {
// Old context and control will be dropped automatically.
// Finally, pop the copy of the subject.
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
Ok(())
}
@@ -3888,7 +3888,7 @@ impl Compiler {
pc.on_top -= 1;
if only_wildcard {
// Patterns like: [] / [_] / [_, _] / [*_] / [_, *_] / [_, _, *_] / etc.
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
} else if star_wildcard {
self.pattern_helper_sequence_subscr(patterns, star.unwrap(), pc)?;
} else {
@@ -4012,7 +4012,7 @@ impl Compiler {
}
if i != case_count - 1 {
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
}
self.compile_statements(&m.body)?;
@@ -4023,7 +4023,7 @@ impl Compiler {
if has_default {
let m = &cases[num_cases - 1];
if num_cases == 1 {
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
} else {
emit!(self, Instruction::Nop);
}
@@ -4125,7 +4125,7 @@ impl Compiler {
// early exit left us with stack: `rhs, comparison_result`. We need to clean up rhs.
self.switch_to_block(break_block);
emit!(self, Instruction::Swap { index: 2 });
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
self.switch_to_block(after_block);
}
@@ -4192,7 +4192,7 @@ impl Compiler {
emit!(self, Instruction::StoreSubscript);
} else {
// Drop annotation if not assigned to simple identifier.
emit!(self, Instruction::Pop);
emit!(self, Instruction::PopTop);
}
Ok(())
@@ -4823,7 +4823,7 @@ impl Compiler {
arg: bytecode::ResumeType::AfterYield as u32
}
);
emit!(compiler, Instruction::Pop);
emit!(compiler, Instruction::PopTop);
Ok(())
},

View File

@@ -1,12 +1,12 @@
---
source: compiler/codegen/src/compile.rs
source: crates/codegen/src/compile.rs
expression: "compile_exec(\"\\\nif True and False and False:\n pass\n\")"
---
1 0 LoadConst (True)
1 PopJumpIfFalse (6)
2 LoadConst (False)
3 PopJumpIfFalse (6)
4 LoadConst (False)
5 PopJumpIfFalse (6)
1 0 LOAD_CONST (True)
1 POP_JUMP_IF_FALSE (6)
2 LOAD_CONST (False)
3 POP_JUMP_IF_FALSE (6)
4 LOAD_CONST (False)
5 POP_JUMP_IF_FALSE (6)
2 >> 6 ReturnConst (None)
2 >> 6 RETURN_CONST (None)

View File

@@ -1,14 +1,14 @@
---
source: compiler/codegen/src/compile.rs
source: crates/codegen/src/compile.rs
expression: "compile_exec(\"\\\nif (True and False) or (False and True):\n pass\n\")"
---
1 0 LoadConst (True)
1 PopJumpIfFalse (4)
2 LoadConst (False)
3 PopJumpIfTrue (8)
>> 4 LoadConst (False)
5 PopJumpIfFalse (8)
6 LoadConst (True)
7 PopJumpIfFalse (8)
1 0 LOAD_CONST (True)
1 POP_JUMP_IF_FALSE (4)
2 LOAD_CONST (False)
3 POP_JUMP_IF_TRUE (8)
>> 4 LOAD_CONST (False)
5 POP_JUMP_IF_FALSE (8)
6 LOAD_CONST (True)
7 POP_JUMP_IF_FALSE (8)
2 >> 8 ReturnConst (None)
2 >> 8 RETURN_CONST (None)

View File

@@ -1,12 +1,12 @@
---
source: compiler/codegen/src/compile.rs
source: crates/codegen/src/compile.rs
expression: "compile_exec(\"\\\nif True or False or False:\n pass\n\")"
---
1 0 LoadConst (True)
1 PopJumpIfTrue (6)
2 LoadConst (False)
3 PopJumpIfTrue (6)
4 LoadConst (False)
5 PopJumpIfFalse (6)
1 0 LOAD_CONST (True)
1 POP_JUMP_IF_TRUE (6)
2 LOAD_CONST (False)
3 POP_JUMP_IF_TRUE (6)
4 LOAD_CONST (False)
5 POP_JUMP_IF_FALSE (6)
2 >> 6 ReturnConst (None)
2 >> 6 RETURN_CONST (None)

View File

@@ -2,85 +2,85 @@
source: crates/codegen/src/compile.rs
expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):\n with self.subTest(type=type(stop_exc)):\n try:\n async with egg():\n raise stop_exc\n except Exception as ex:\n self.assertIs(ex, stop_exc)\n else:\n self.fail(f'{stop_exc} was suppressed')\n\")"
---
1 0 SetupLoop
1 LoadNameAny (0, StopIteration)
2 LoadConst ("spam")
3 CallFunctionPositional(1)
4 LoadNameAny (1, StopAsyncIteration)
5 LoadConst ("ham")
6 CallFunctionPositional(1)
7 BuildTuple (2)
8 GetIter
>> 9 ForIter (71)
10 StoreLocal (2, stop_exc)
1 0 SETUP_LOOP
1 LOAD_NAME_ANY (0, StopIteration)
2 LOAD_CONST ("spam")
3 CALL_FUNCTION_POSITIONAL(1)
4 LOAD_NAME_ANY (1, StopAsyncIteration)
5 LOAD_CONST ("ham")
6 CALL_FUNCTION_POSITIONAL(1)
7 BUILD_TUPLE (2)
8 GET_ITER
>> 9 FOR_ITER (71)
10 STORE_LOCAL (2, stop_exc)
2 11 LoadNameAny (3, self)
12 LoadMethod (4, subTest)
13 LoadNameAny (5, type)
14 LoadNameAny (2, stop_exc)
15 CallFunctionPositional(1)
16 LoadConst (("type"))
17 CallMethodKeyword (1)
18 SetupWith (68)
19 Pop
2 11 LOAD_NAME_ANY (3, self)
12 LOAD_METHOD (4, subTest)
13 LOAD_NAME_ANY (5, type)
14 LOAD_NAME_ANY (2, stop_exc)
15 CALL_FUNCTION_POSITIONAL(1)
16 LOAD_CONST (("type"))
17 CALL_METHOD_KEYWORD (1)
18 SETUP_WITH (68)
19 POP_TOP
3 20 SetupExcept (42)
3 20 SETUP_EXCEPT (42)
4 21 LoadNameAny (6, egg)
22 CallFunctionPositional(0)
23 BeforeAsyncWith
24 GetAwaitable
25 LoadConst (None)
26 YieldFrom
27 Resume (3)
28 SetupAsyncWith (34)
29 Pop
4 21 LOAD_NAME_ANY (6, egg)
22 CALL_FUNCTION_POSITIONAL(0)
23 BEFORE_ASYNC_WITH
24 GET_AWAITABLE
25 LOAD_CONST (None)
26 YIELD_FROM
27 RESUME (3)
28 SETUP_ASYNC_WITH (34)
29 POP_TOP
5 30 LoadNameAny (2, stop_exc)
31 Raise (Raise)
5 30 LOAD_NAME_ANY (2, stop_exc)
31 RAISE (Raise)
4 32 PopBlock
33 EnterFinally
>> 34 WithCleanupStart
35 GetAwaitable
36 LoadConst (None)
37 YieldFrom
38 Resume (3)
39 WithCleanupFinish
40 PopBlock
41 Jump (58)
>> 42 CopyItem (1)
4 32 POP_BLOCK
33 ENTER_FINALLY
>> 34 WITH_CLEANUP_START
35 GET_AWAITABLE
36 LOAD_CONST (None)
37 YIELD_FROM
38 RESUME (3)
39 WITH_CLEANUP_FINISH
40 POP_BLOCK
41 JUMP (58)
>> 42 COPY (1)
6 43 LoadNameAny (7, Exception)
6 43 LOAD_NAME_ANY (7, Exception)
44 JUMP_IF_NOT_EXC_MATCH(57)
45 StoreLocal (8, ex)
45 STORE_LOCAL (8, ex)
7 46 LoadNameAny (3, self)
47 LoadMethod (9, assertIs)
48 LoadNameAny (8, ex)
49 LoadNameAny (2, stop_exc)
50 CallMethodPositional (2)
51 Pop
52 PopException
53 LoadConst (None)
54 StoreLocal (8, ex)
55 DeleteLocal (8, ex)
56 Jump (66)
>> 57 Raise (Reraise)
7 46 LOAD_NAME_ANY (3, self)
47 LOAD_METHOD (9, assertIs)
48 LOAD_NAME_ANY (8, ex)
49 LOAD_NAME_ANY (2, stop_exc)
50 CALL_METHOD_POSITIONAL(2)
51 POP_TOP
52 POP_EXCEPTION
53 LOAD_CONST (None)
54 STORE_LOCAL (8, ex)
55 DELETE_LOCAL (8, ex)
56 JUMP (66)
>> 57 RAISE (Reraise)
9 >> 58 LoadNameAny (3, self)
59 LoadMethod (10, fail)
60 LoadNameAny (2, stop_exc)
9 >> 58 LOAD_NAME_ANY (3, self)
59 LOAD_METHOD (10, fail)
60 LOAD_NAME_ANY (2, stop_exc)
61 FORMAT_SIMPLE
62 LoadConst (" was suppressed")
63 BuildString (2)
64 CallMethodPositional (1)
65 Pop
62 LOAD_CONST (" was suppressed")
63 BUILD_STRING (2)
64 CALL_METHOD_POSITIONAL(1)
65 POP_TOP
2 >> 66 PopBlock
67 EnterFinally
>> 68 WithCleanupStart
69 WithCleanupFinish
70 Jump (9)
>> 71 PopBlock
72 ReturnConst (None)
2 >> 66 POP_BLOCK
67 ENTER_FINALLY
>> 68 WITH_CLEANUP_START
69 WITH_CLEANUP_FINISH
70 JUMP (9)
>> 71 POP_BLOCK
72 RETURN_CONST (None)

View File

@@ -782,7 +782,6 @@ pub enum Instruction {
MatchMapping,
MatchSequence,
Nop,
Pop,
PopBlock,
PopException,
/// Pop the top of the stack, and jump if this value is false.
@@ -793,6 +792,11 @@ pub enum Instruction {
PopJumpIfTrue {
target: Arg<Label>,
},
/// Removes the top-of-stack item:
/// ```py
/// STACK.pop()
/// ```
PopTop,
Raise {
kind: Arg<RaiseKind>,
},
@@ -1685,7 +1689,7 @@ impl Instruction {
BinaryOp { .. } | CompareOperation { .. } => -1,
BinarySubscript => -1,
CopyItem { .. } => 1,
Pop => -1,
PopTop => -1,
Swap { .. } => 0,
ToBool => 0,
GetIter => 0,
@@ -1860,112 +1864,112 @@ impl Instruction {
};
match self {
BeforeAsyncWith => w!(BeforeAsyncWith),
BeforeAsyncWith => w!(BEFORE_ASYNC_WITH),
BinaryOp { op } => write!(f, "{:pad$}({})", "BINARY_OP", op.get(arg)),
BinarySubscript => w!(BinarySubscript),
Break { target } => w!(Break, target),
BuildListFromTuples { size } => w!(BuildListFromTuples, size),
BuildList { size } => w!(BuildList, size),
BuildMapForCall { size } => w!(BuildMapForCall, size),
BuildMap { size } => w!(BuildMap, size),
BuildSetFromTuples { size } => w!(BuildSetFromTuples, size),
BuildSet { size } => w!(BuildSet, size),
BuildSlice { argc } => w!(BuildSlice, ?argc),
BuildString { size } => w!(BuildString, size),
BuildTupleFromIter => w!(BuildTupleFromIter),
BuildTupleFromTuples { size } => w!(BuildTupleFromTuples, size),
BuildTuple { size } => w!(BuildTuple, size),
CallFunctionEx { has_kwargs } => w!(CallFunctionEx, has_kwargs),
CallFunctionKeyword { nargs } => w!(CallFunctionKeyword, nargs),
CallFunctionPositional { nargs } => w!(CallFunctionPositional, nargs),
CallIntrinsic1 { func } => w!(CallIntrinsic1, ?func),
CallIntrinsic2 { func } => w!(CallIntrinsic2, ?func),
CallMethodEx { has_kwargs } => w!(CallMethodEx, has_kwargs),
CallMethodKeyword { nargs } => w!(CallMethodKeyword, nargs),
CallMethodPositional { nargs } => w!(CallMethodPositional, nargs),
CompareOperation { op } => w!(CompareOperation, ?op),
BinarySubscript => w!(BINARY_SUBSCRIPT),
Break { target } => w!(BREAK, target),
BuildListFromTuples { size } => w!(BUILD_LIST_FROM_TUPLES, size),
BuildList { size } => w!(BUILD_LIST, size),
BuildMapForCall { size } => w!(BUILD_MAP_FOR_CALL, size),
BuildMap { size } => w!(BUILD_MAP, size),
BuildSetFromTuples { size } => w!(BUILD_SET_FROM_TUPLES, size),
BuildSet { size } => w!(BUILD_SET, size),
BuildSlice { argc } => w!(BUILD_SLICE, ?argc),
BuildString { size } => w!(BUILD_STRING, size),
BuildTupleFromIter => w!(BUILD_TUPLE_FROM_ITER),
BuildTupleFromTuples { size } => w!(BUILD_TUPLE_FROM_TUPLES, size),
BuildTuple { size } => w!(BUILD_TUPLE, size),
CallFunctionEx { has_kwargs } => w!(CALL_FUNCTION_EX, has_kwargs),
CallFunctionKeyword { nargs } => w!(CALL_FUNCTION_KEYWORD, nargs),
CallFunctionPositional { nargs } => w!(CALL_FUNCTION_POSITIONAL, nargs),
CallIntrinsic1 { func } => w!(CALL_INTRINSIC_1, ?func),
CallIntrinsic2 { func } => w!(CALL_INTRINSIC_2, ?func),
CallMethodEx { has_kwargs } => w!(CALL_METHOD_EX, has_kwargs),
CallMethodKeyword { nargs } => w!(CALL_METHOD_KEYWORD, nargs),
CallMethodPositional { nargs } => w!(CALL_METHOD_POSITIONAL, nargs),
CompareOperation { op } => w!(COMPARE_OPERATION, ?op),
ContainsOp(inv) => w!(CONTAINS_OP, ?inv),
Continue { target } => w!(Continue, target),
Continue { target } => w!(CONTINUE, target),
ConvertValue { oparg } => write!(f, "{:pad$}{}", "CONVERT_VALUE", oparg.get(arg)),
CopyItem { index } => w!(CopyItem, index),
DeleteAttr { idx } => w!(DeleteAttr, name = idx),
DeleteDeref(idx) => w!(DeleteDeref, cell_name = idx),
DeleteFast(idx) => w!(DeleteFast, varname = idx),
DeleteGlobal(idx) => w!(DeleteGlobal, name = idx),
DeleteLocal(idx) => w!(DeleteLocal, name = idx),
DeleteSubscript => w!(DeleteSubscript),
DictUpdate { index } => w!(DictUpdate, index),
EndAsyncFor => w!(EndAsyncFor),
EndFinally => w!(EndFinally),
EnterFinally => w!(EnterFinally),
ExtendedArg => w!(ExtendedArg, Arg::<u32>::marker()),
ForIter { target } => w!(ForIter, target),
CopyItem { index } => w!(COPY, index),
DeleteAttr { idx } => w!(DELETE_ATTR, name = idx),
DeleteDeref(idx) => w!(DELETE_DEREF, cell_name = idx),
DeleteFast(idx) => w!(DELETE_FAST, varname = idx),
DeleteGlobal(idx) => w!(DELETE_GLOBAL, name = idx),
DeleteLocal(idx) => w!(DELETE_LOCAL, name = idx),
DeleteSubscript => w!(DELETE_SUBSCRIPT),
DictUpdate { index } => w!(DICT_UPDATE, index),
EndAsyncFor => w!(END_ASYNC_FOR),
EndFinally => w!(END_FINALLY),
EnterFinally => w!(ENTER_FINALLY),
ExtendedArg => w!(EXTENDED_ARG, Arg::<u32>::marker()),
ForIter { target } => w!(FOR_ITER, target),
FormatSimple => w!(FORMAT_SIMPLE),
FormatWithSpec => w!(FORMAT_WITH_SPEC),
GetAIter => w!(GetAIter),
GetANext => w!(GetANext),
GetAwaitable => w!(GetAwaitable),
GetIter => w!(GetIter),
GetLen => w!(GetLen),
ImportFrom { idx } => w!(ImportFrom, name = idx),
ImportName { idx } => w!(ImportName, name = idx),
GetAIter => w!(GET_AITER),
GetANext => w!(GET_ANEXT),
GetAwaitable => w!(GET_AWAITABLE),
GetIter => w!(GET_ITER),
GetLen => w!(GET_LEN),
ImportFrom { idx } => w!(IMPORT_FROM, name = idx),
ImportName { idx } => w!(IMPORT_NAME, name = idx),
IsOp(inv) => w!(IS_OP, ?inv),
JumpIfFalseOrPop { target } => w!(JumpIfFalseOrPop, target),
JumpIfFalseOrPop { target } => w!(JUMP_IF_FALSE_OR_POP, target),
JumpIfNotExcMatch(target) => w!(JUMP_IF_NOT_EXC_MATCH, target),
JumpIfTrueOrPop { target } => w!(JumpIfTrueOrPop, target),
Jump { target } => w!(Jump, target),
ListAppend { i } => w!(ListAppend, i),
LoadAttr { idx } => w!(LoadAttr, name = idx),
LoadBuildClass => w!(LoadBuildClass),
LoadClassDeref(idx) => w!(LoadClassDeref, cell_name = idx),
LoadClosure(i) => w!(LoadClosure, cell_name = i),
LoadConst { idx } => fmt_const("LoadConst", arg, f, idx),
LoadDeref(idx) => w!(LoadDeref, cell_name = idx),
LoadFast(idx) => w!(LoadFast, varname = idx),
LoadGlobal(idx) => w!(LoadGlobal, name = idx),
LoadMethod { idx } => w!(LoadMethod, name = idx),
LoadNameAny(idx) => w!(LoadNameAny, name = idx),
MakeFunction => w!(MakeFunction),
MapAdd { i } => w!(MapAdd, i),
MatchClass(arg) => w!(MatchClass, arg),
MatchKeys => w!(MatchKeys),
MatchMapping => w!(MatchMapping),
MatchSequence => w!(MatchSequence),
Nop => w!(Nop),
Pop => w!(Pop),
PopBlock => w!(PopBlock),
PopException => w!(PopException),
PopJumpIfFalse { target } => w!(PopJumpIfFalse, target),
PopJumpIfTrue { target } => w!(PopJumpIfTrue, target),
Raise { kind } => w!(Raise, ?kind),
Resume { arg } => w!(Resume, arg),
ReturnConst { idx } => fmt_const("ReturnConst", arg, f, idx),
ReturnValue => w!(ReturnValue),
Reverse { amount } => w!(Reverse, amount),
SetAdd { i } => w!(SetAdd, i),
SetFunctionAttribute { attr } => w!(SetFunctionAttribute, ?attr),
SetupAnnotation => w!(SetupAnnotation),
SetupAsyncWith { end } => w!(SetupAsyncWith, end),
SetupExcept { handler } => w!(SetupExcept, handler),
SetupFinally { handler } => w!(SetupFinally, handler),
SetupLoop => w!(SetupLoop),
SetupWith { end } => w!(SetupWith, end),
StoreAttr { idx } => w!(StoreAttr, name = idx),
StoreDeref(idx) => w!(StoreDeref, cell_name = idx),
StoreFast(idx) => w!(StoreFast, varname = idx),
StoreGlobal(idx) => w!(StoreGlobal, name = idx),
StoreLocal(idx) => w!(StoreLocal, name = idx),
StoreSubscript => w!(StoreSubscript),
Subscript => w!(Subscript),
Swap { index } => w!(Swap, index),
ToBool => w!(ToBool),
UnaryOperation { op } => w!(UnaryOperation, ?op),
UnpackEx { args } => w!(UnpackEx, args),
UnpackSequence { size } => w!(UnpackSequence, size),
WithCleanupFinish => w!(WithCleanupFinish),
WithCleanupStart => w!(WithCleanupStart),
YieldFrom => w!(YieldFrom),
YieldValue => w!(YieldValue),
JumpIfTrueOrPop { target } => w!(JUMP_IF_TRUE_OR_POP, target),
Jump { target } => w!(JUMP, target),
ListAppend { i } => w!(LIST_APPEND, i),
LoadAttr { idx } => w!(LOAD_ATTR, name = idx),
LoadBuildClass => w!(LOAD_BUILD_CLASS),
LoadClassDeref(idx) => w!(LOAD_CLASS_DEREF, cell_name = idx),
LoadClosure(i) => w!(LOAD_CLOSURE, cell_name = i),
LoadConst { idx } => fmt_const("LOAD_CONST", arg, f, idx),
LoadDeref(idx) => w!(LOAD_DEREF, cell_name = idx),
LoadFast(idx) => w!(LOAD_FAST, varname = idx),
LoadGlobal(idx) => w!(LOAD_GLOBAL, name = idx),
LoadMethod { idx } => w!(LOAD_METHOD, name = idx),
LoadNameAny(idx) => w!(LOAD_NAME_ANY, name = idx),
MakeFunction => w!(MAKE_FUNCTION),
MapAdd { i } => w!(MAP_ADD, i),
MatchClass(arg) => w!(MATCH_CLASS, arg),
MatchKeys => w!(MATCH_KEYS),
MatchMapping => w!(MATCH_MAPPING),
MatchSequence => w!(MATCH_SEQUENCE),
Nop => w!(NOP),
PopBlock => w!(POP_BLOCK),
PopException => w!(POP_EXCEPTION),
PopJumpIfFalse { target } => w!(POP_JUMP_IF_FALSE, target),
PopJumpIfTrue { target } => w!(POP_JUMP_IF_TRUE, target),
PopTop => w!(POP_TOP),
Raise { kind } => w!(RAISE, ?kind),
Resume { arg } => w!(RESUME, arg),
ReturnConst { idx } => fmt_const("RETURN_CONST", arg, f, idx),
ReturnValue => w!(RETURN_VALUE),
Reverse { amount } => w!(REVERSE, amount),
SetAdd { i } => w!(SET_ADD, i),
SetFunctionAttribute { attr } => w!(SET_FUNCTION_ATTRIBUTE, ?attr),
SetupAnnotation => w!(SETUP_ANNOTATION),
SetupAsyncWith { end } => w!(SETUP_ASYNC_WITH, end),
SetupExcept { handler } => w!(SETUP_EXCEPT, handler),
SetupFinally { handler } => w!(SETUP_FINALLY, handler),
SetupLoop => w!(SETUP_LOOP),
SetupWith { end } => w!(SETUP_WITH, end),
StoreAttr { idx } => w!(STORE_ATTR, name = idx),
StoreDeref(idx) => w!(STORE_DEREF, cell_name = idx),
StoreFast(idx) => w!(STORE_FAST, varname = idx),
StoreGlobal(idx) => w!(STORE_GLOBAL, name = idx),
StoreLocal(idx) => w!(STORE_LOCAL, name = idx),
StoreSubscript => w!(STORE_SUBSCRIPT),
Subscript => w!(SUBSCRIPT),
Swap { index } => w!(SWAP, index),
ToBool => w!(TO_BOOL),
UnaryOperation { op } => w!(UNARY_OPERATION, ?op),
UnpackEx { args } => w!(UNPACK_EX, args),
UnpackSequence { size } => w!(UNPACK_SEQUENCE, size),
WithCleanupFinish => w!(WITH_CLEANUP_FINISH),
WithCleanupStart => w!(WITH_CLEANUP_START),
YieldFrom => w!(YIELD_FROM),
YieldValue => w!(YIELD_VALUE),
}
}
}

View File

@@ -547,10 +547,6 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
}
}
Instruction::Nop => Ok(()),
Instruction::Pop => {
self.stack.pop();
Ok(())
}
Instruction::PopBlock => {
// TODO: block support
Ok(())
@@ -581,6 +577,10 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
Ok(())
}
Instruction::PopTop => {
self.stack.pop();
Ok(())
}
Instruction::Resume { arg: _resume_arg } => {
// TODO: Implement the resume instruction
Ok(())

View File

@@ -1337,11 +1337,6 @@ impl ExecutingFrame<'_> {
Ok(None)
}
bytecode::Instruction::Nop => Ok(None),
bytecode::Instruction::Pop => {
// Pop value from stack and ignore.
self.pop_value();
Ok(None)
}
bytecode::Instruction::PopBlock => {
self.pop_block();
Ok(None)
@@ -1361,6 +1356,11 @@ impl ExecutingFrame<'_> {
bytecode::Instruction::PopJumpIfTrue { target } => {
self.pop_jump_if(vm, target.get(arg), true)
}
bytecode::Instruction::PopTop => {
// Pop value from stack and ignore.
self.pop_value();
Ok(None)
}
bytecode::Instruction::Raise { kind } => self.execute_raise(vm, kind.get(arg)),
bytecode::Instruction::Resume { arg: resume_arg } => {
// Resume execution after yield, await, or at function start