◐ Shell
reader mode source ↗
Skip to content
Closed
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
38 changes: 27 additions & 11 deletions compiler/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2258,9 +2258,9 @@ impl Compiler {

let mut loop_labels = vec![];
for generator in generators {
if generator.is_async {
unimplemented!("async for comprehensions");
}

// Setup for loop:
self.emit(Instruction::SetupLoop);
Expand All @@ -2271,21 +2271,37 @@ impl Compiler {
} else {
// Evaluate iterated item:
self.compile_expression(&generator.iter)?;

// Get iterator / turn item into an iterator
self.emit(Instruction::GetIter);
}

let loop_block = self.new_block();
let after_block = self.new_block();
loop_labels.push((loop_block, after_block));

self.switch_to_block(loop_block);
self.emit(Instruction::ForIter {
target: after_block,
});

self.compile_store(&generator.target)?;

// Now evaluate the ifs:
for if_condition in &generator.ifs {
Expand Down
Toggle all file notes Toggle all file annotations