Skip to content

Commit 39f54aa

Browse files
Merge pull request RustPython#1324 from RustPython/subscript-bytecode
Make subscript its own bytecode.
2 parents 78e9f01 + 2517207 commit 39f54aa

File tree

3 files changed

+249
-240
lines changed

3 files changed

+249
-240
lines changed

bytecode/src/bytecode.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub enum Instruction {
115115
DeleteName {
116116
name: String,
117117
},
118+
Subscript,
118119
StoreSubscript,
119120
DeleteSubscript,
120121
StoreAttr {
@@ -145,7 +146,6 @@ pub enum Instruction {
145146
},
146147
Duplicate,
147148
GetIter,
148-
Pass,
149149
Continue,
150150
Break,
151151
Jump {
@@ -316,7 +316,6 @@ pub enum BinaryOperator {
316316
Modulo,
317317
Add,
318318
Subtract,
319-
Subscript,
320319
Lshift,
321320
Rshift,
322321
And,
@@ -467,6 +466,7 @@ impl Instruction {
467466
LoadName { name, scope } => w!(LoadName, name, format!("{:?}", scope)),
468467
StoreName { name, scope } => w!(StoreName, name, format!("{:?}", scope)),
469468
DeleteName { name } => w!(DeleteName, name),
469+
Subscript => w!(Subscript),
470470
StoreSubscript => w!(StoreSubscript),
471471
DeleteSubscript => w!(DeleteSubscript),
472472
StoreAttr { name } => w!(StoreAttr, name),
@@ -487,7 +487,6 @@ impl Instruction {
487487
Rotate { amount } => w!(Rotate, amount),
488488
Duplicate => w!(Duplicate),
489489
GetIter => w!(GetIter),
490-
Pass => w!(Pass),
491490
Continue => w!(Continue),
492491
Break => w!(Break),
493492
Jump { target } => w!(Jump, label_map[target]),

compiler/src/compile.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ impl<O: OutputStream> Compiler<O> {
584584
}
585585
}
586586
Pass => {
587-
self.emit(Instruction::Pass);
587+
// No need to emit any code here :)
588588
}
589589
}
590590
Ok(())
@@ -1443,10 +1443,7 @@ impl<O: OutputStream> Compiler<O> {
14431443
Subscript { a, b } => {
14441444
self.compile_expression(a)?;
14451445
self.compile_expression(b)?;
1446-
self.emit(Instruction::BinaryOperation {
1447-
op: bytecode::BinaryOperator::Subscript,
1448-
inplace: false,
1449-
});
1446+
self.emit(Instruction::Subscript);
14501447
}
14511448
Unop { op, a } => {
14521449
self.compile_expression(a)?;
@@ -2129,7 +2126,6 @@ mod tests {
21292126
JumpIfFalse {
21302127
target: Label::new(0)
21312128
},
2132-
Pass,
21332129
LoadConst { value: None },
21342130
ReturnValue
21352131
],
@@ -2160,7 +2156,6 @@ mod tests {
21602156
JumpIfFalse {
21612157
target: Label::new(0)
21622158
},
2163-
Pass,
21642159
LoadConst { value: None },
21652160
ReturnValue
21662161
],
@@ -2197,7 +2192,6 @@ mod tests {
21972192
JumpIfFalse {
21982193
target: Label::new(0)
21992194
},
2200-
Pass,
22012195
LoadConst { value: None },
22022196
ReturnValue
22032197
],

0 commit comments

Comments
 (0)