Implement review comments and improve parsing a bit.

This commit is contained in:
Windel Bouwman 2019-07-25 23:54:31 +02:00
parent 9f7ef2050e
commit 7e9b3ddc1f
2 changed files with 41 additions and 36 deletions

View file

@ -385,35 +385,47 @@ impl Compiler {
}
self.set_label(end_label);
}
With { items, body } => {
let end_label = self.new_label();
for item in items {
self.compile_expression(&item.context_expr)?;
self.emit(Instruction::SetupWith { end: end_label });
match &item.optional_vars {
Some(var) => {
self.compile_store(var)?;
}
None => {
self.emit(Instruction::Pop);
With {
is_async,
items,
body,
} => {
if *is_async {
unimplemented!("async with");
} else {
let end_label = self.new_label();
for item in items {
self.compile_expression(&item.context_expr)?;
self.emit(Instruction::SetupWith { end: end_label });
match &item.optional_vars {
Some(var) => {
self.compile_store(var)?;
}
None => {
self.emit(Instruction::Pop);
}
}
}
}
self.compile_statements(body)?;
for _ in 0..items.len() {
self.emit(Instruction::CleanupWith { end: end_label });
self.compile_statements(body)?;
for _ in 0..items.len() {
self.emit(Instruction::CleanupWith { end: end_label });
}
self.set_label(end_label);
}
self.set_label(end_label);
}
For {
is_async,
target,
iter,
body,
orelse,
} => self.compile_for(target, iter, body, orelse)?,
AsyncFor { .. } => {
unimplemented!("async for");
} => {
if *is_async {
unimplemented!("async for");
} else {
self.compile_for(target, iter, body, orelse)?
}
}
Raise { exception, cause } => match exception {
Some(value) => {
@ -439,14 +451,18 @@ impl Compiler {
finalbody,
} => self.compile_try_statement(body, handlers, orelse, finalbody)?,
FunctionDef {
is_async,
name,
args,
body,
decorator_list,
returns,
} => self.compile_function_def(name, args, body, decorator_list, returns)?,
AsyncFunctionDef { .. } => {
unimplemented!("async def");
} => {
if *is_async {
unimplemented!("async def");
} else {
self.compile_function_def(name, args, body, decorator_list, returns)?
}
}
ClassDef {
name,

View file

@ -240,13 +240,7 @@ impl SymbolTableBuilder {
args,
decorator_list,
returns,
}
| AsyncFunctionDef {
name,
body,
args,
decorator_list,
returns,
..
} => {
self.scan_expressions(decorator_list)?;
self.register_name(name, SymbolRole::Assigned)?;
@ -289,12 +283,7 @@ impl SymbolTableBuilder {
iter,
body,
orelse,
}
| AsyncFor {
target,
iter,
body,
orelse,
..
} => {
self.scan_expression(target)?;
self.scan_expression(iter)?;
@ -346,7 +335,7 @@ impl SymbolTableBuilder {
self.scan_expression(target)?;
self.scan_expression(value)?;
}
With { items, body } => {
With { items, body, .. } => {
for item in items {
self.scan_expression(&item.context_expr)?;
if let Some(expression) = &item.optional_vars {