Reduce exception copying

This commit is contained in:
Andrew Morris
2023-07-01 09:21:47 +10:00
parent 7a7ba86921
commit 7ad17b73b6
12 changed files with 18 additions and 34 deletions

View File

@@ -1,4 +1,4 @@
//! test_output(3)
//! test_output(1)
// Should be: 0
/// <reference path="../../../concept-code/vs.d.ts" />

View File

@@ -146,9 +146,7 @@ impl StackFrameTrait for ArrayMappingFrame {
panic!("Not appropriate for MapFrame")
}
fn catch_exception(&mut self, _exception: Val) -> bool {
return false;
}
fn catch_exception(&mut self, _exception: &mut Val) {}
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())

View File

@@ -111,9 +111,7 @@ impl StackFrameTrait for ReduceFrame {
panic!("Not appropriate for ReduceFrame")
}
fn catch_exception(&mut self, _exception: Val) -> bool {
return false;
}
fn catch_exception(&mut self, _exception: &mut Val) {}
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())

View File

@@ -124,9 +124,7 @@ impl StackFrameTrait for ReduceRightFrame {
panic!("Not appropriate for ReduceRightFrame")
}
fn catch_exception(&mut self, _exception: Val) -> bool {
false
}
fn catch_exception(&mut self, _exception: &mut Val) {}
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())

View File

@@ -319,9 +319,7 @@ impl StackFrameTrait for SortFrame {
panic!("Not appropriate for SortFrame")
}
fn catch_exception(&mut self, _exception: Val) -> bool {
false
}
fn catch_exception(&mut self, _exception: &mut Val) {}
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())

View File

@@ -612,18 +612,16 @@ impl StackFrameTrait for BytecodeStackFrame {
panic!("Not appropriate for BytecodeStackFrame")
}
fn catch_exception(&mut self, exception: Val) -> bool {
fn catch_exception(&mut self, exception: &mut Val) {
if let Some(catch_setting) = &self.catch_setting {
let exception = take(exception);
if let Some(r) = catch_setting.register {
self.registers[r] = exception;
}
self.decoder.pos = catch_setting.pos;
self.catch_setting = None;
true
} else {
false
}
}

View File

@@ -145,9 +145,7 @@ impl StackFrameTrait for CatStackFrame {
panic!("Not appropriate for CatStackFrame");
}
fn catch_exception(&mut self, _exception: Val) -> bool {
false
}
fn catch_exception(&mut self, _exception: &mut Val) {}
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())

View File

@@ -40,7 +40,7 @@ impl StackFrameTrait for FirstStackFrame {
return self.call_result.clone();
}
fn catch_exception(&mut self, _exception: Val) -> bool {
fn catch_exception(&mut self, _exception: &mut Val) {
panic!("Not appropriate for FirstStackFrame");
}

View File

@@ -218,7 +218,7 @@ impl StackFrameTrait for GeneratorFrame {
panic!("Not appropriate for GeneratorFrame")
}
fn catch_exception(&mut self, exception: Val) -> bool {
fn catch_exception(&mut self, exception: &mut Val) {
self.generator.frame.catch_exception(exception)
}
@@ -331,9 +331,7 @@ impl StackFrameTrait for YieldStarFrame {
panic!("Not appropriate for YieldStarFrame")
}
fn catch_exception(&mut self, _exception: Val) -> bool {
false
}
fn catch_exception(&mut self, _exception: &mut Val) {}
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())

View File

@@ -50,7 +50,7 @@ impl StackFrameTrait for MakeGeneratorFrame {
panic!("Not appropriate for MakeGeneratorFrame")
}
fn catch_exception(&mut self, _exception: Val) -> bool {
fn catch_exception(&mut self, _exception: &mut Val) {
panic!("Not appropriate for MakeGeneratorFrame");
}

View File

@@ -24,7 +24,7 @@ pub trait StackFrameTrait {
fn step(&mut self) -> FrameStepResult;
fn apply_call_result(&mut self, call_result: CallResult);
fn get_call_result(&mut self) -> CallResult;
fn catch_exception(&mut self, exception: Val) -> bool;
fn catch_exception(&mut self, exception: &mut Val);
fn clone_to_stack_frame(&self) -> StackFrame;
}
@@ -63,9 +63,7 @@ impl StackFrameTrait for VoidStackFrame {
}
}
fn catch_exception(&mut self, _exception: Val) -> bool {
false
}
fn catch_exception(&mut self, _exception: &mut Val) {}
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())

View File

@@ -109,11 +109,11 @@ impl VirtualMachine {
std::mem::swap(&mut self.frame, &mut old_frame);
}
pub fn handle_exception(&mut self, exception: Val) -> Result<(), Val> {
pub fn handle_exception(&mut self, mut exception: Val) -> Result<(), Val> {
while !self.stack.is_empty() {
let handled = self.frame.catch_exception(exception.clone());
self.frame.catch_exception(&mut exception);
if handled {
if let Val::Void = exception {
return Ok(());
}