`[]`: list literal or list-comp; always eat(Rsqb) to keep `bracket_stack` in sync. */
(&mut self)
| 69 | |
| 70 | /* `[]`: list literal or list-comp; always eat(Rsqb) to keep `bracket_stack` in sync. */ |
| 71 | pub(super) fn list_literal(&mut self) { |
| 72 | if matches!(self.peek(), Some(TokenType::Rsqb)) { |
| 73 | self.advance(); |
| 74 | self.chunk.emit(OpCode::BuildList, 0); |
| 75 | return; |
| 76 | } |
| 77 | // `[*it, ...]`: leading iterable-unpack => list built incrementally. |
| 78 | if self.eat_if(TokenType::Star) { |
| 79 | self.chunk.emit(OpCode::BuildList, 0); |
| 80 | self.expr(); |
| 81 | self.chunk.emit(OpCode::ListExtend, 0); |
| 82 | self.list_tail(0, true); |
| 83 | return; |
| 84 | } |
| 85 | let elem_start = self.chunk.instructions.len(); |
| 86 | self.expr(); |
| 87 | if matches!(self.peek(), Some(TokenType::For)) { |
| 88 | let versions_before = self.ssa_versions.clone(); |
| 89 | let elem_ins: Vec<Instruction> = self.chunk.instructions.drain(elem_start..).collect(); |
| 90 | self.chunk.emit(OpCode::BuildList, 0); |
| 91 | self.comprehension_loop(&[(elem_start, elem_ins)], OpCode::ListAppend, &versions_before); |
| 92 | self.eat(TokenType::Rsqb); |
| 93 | } else { |
| 94 | // First element already emitted; list_tail consolidates if a later `*` appears. |
| 95 | self.list_tail(1, false); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /* Finishes a `{}` dict after the first pair. `pairs` = loose key/val pairs on the stack; `incremental` = a Dict object is already on the stack. On the first `**` the loose pairs are consolidated with `BuildDict pairs`, then merges use `DictUpdate`/`MapAdd`. */ |
| 100 | fn dict_tail(&mut self, mut pairs: u16, mut incremental: bool) { |
no test coverage detected