mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Reduce exception copying
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//! test_output(3)
|
||||
//! test_output(1)
|
||||
// Should be: 0
|
||||
|
||||
/// <reference path="../../../concept-code/vs.d.ts" />
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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(());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user