Compile throw expressions

This commit is contained in:
Andrew Morris
2023-03-21 14:29:38 +11:00
parent 8b535f4f03
commit f43e83cffe
3 changed files with 13 additions and 4 deletions

View File

@@ -293,7 +293,9 @@ impl CaptureFinder {
}
}
Switch(_) => std::panic!("Not implemented: Switch statement"),
Throw(_) => std::panic!("Not implemented: Throw statement"),
Throw(throw) => {
self.expr(scope, &throw.arg);
}
Try(_) => std::panic!("Not implemented: Try statement"),
While(while_) => {
self.expr(scope, &while_.test);

View File

@@ -796,7 +796,14 @@ impl FunctionCompiler {
self.if_(if_, scope);
}
Switch(switch) => self.todo(switch.span, "Switch statement"),
Throw(throw) => self.todo(throw.span, "Throw statement"),
Throw(throw) => {
let mut expression_compiler = ExpressionCompiler { fnc: self, scope };
let arg = expression_compiler.compile(&throw.arg, None);
let instr = Instruction::Throw(self.use_(arg));
self.push(instr);
}
Try(try_) => self.todo(try_.span, "Try statement"),
While(while_) => {
self.while_(while_, scope);

View File

@@ -1398,8 +1398,8 @@ impl ScopeAnalysis {
}
}
}
Stmt::Throw(throw_) => {
self.expr(&scope, &throw_.arg);
Stmt::Throw(throw) => {
self.expr(&scope, &throw.arg);
}
Stmt::Try(try_) => {
self.block_stmt(&scope, &try_.block);