MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / list_literal

Method list_literal

compiler/src/modules/parser/literals.rs:71–97  ·  view source on GitHub ↗

`[]`: list literal or list-comp; always eat(Rsqb) to keep `bracket_stack` in sync. */

(&mut self)

Source from the content-addressed store, hash-verified

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) {

Callers 1

parse_atomMethod · 0.80

Calls 9

advanceMethod · 0.80
emitMethod · 0.80
eat_ifMethod · 0.80
exprMethod · 0.80
list_tailMethod · 0.80
collectMethod · 0.80
comprehension_loopMethod · 0.80
eatMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected