optimize: avoid generating drop glue for StepResult
This commit is contained in:
@@ -18,9 +18,9 @@ impl<'gc> crate::Vm<'gc> {
|
||||
return step;
|
||||
}
|
||||
if self.call_depth > 10000 {
|
||||
return StepResult::Done(Err(Error::eval_error(
|
||||
return self.finish_err(Error::eval_error(
|
||||
"stack overflow; max-call-depth exceeded",
|
||||
)));
|
||||
));
|
||||
}
|
||||
self.call_depth += 1;
|
||||
let func = self.pop_stack();
|
||||
@@ -56,10 +56,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
mc: &Mutation<'gc>,
|
||||
) -> StepResult<'gc> {
|
||||
match self.handle_return(reader, ctx, mc) {
|
||||
Some(result) => StepResult::Done(result),
|
||||
None => StepResult::Continue,
|
||||
}
|
||||
self.handle_return(reader, ctx, mc)
|
||||
}
|
||||
|
||||
pub(crate) fn handle_return<C: crate::VmContext>(
|
||||
@@ -67,7 +64,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
ctx: &C,
|
||||
mc: &Mutation<'gc>,
|
||||
) -> Option<std::result::Result<fix_common::Value, Box<Error>>> {
|
||||
) -> StepResult<'gc> {
|
||||
let ret_inst_pc = reader.pc() - 1;
|
||||
let Some(CallFrame {
|
||||
pc: ret_pc,
|
||||
@@ -78,7 +75,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
}) = self.call_stack.pop()
|
||||
else {
|
||||
let val = self.pop_stack();
|
||||
return Some(Ok(ctx.convert_value(val)));
|
||||
return self.finish_ok(ctx.convert_value(val));
|
||||
};
|
||||
reader.set_pc(ret_pc);
|
||||
if let Some(outer_thunk) = thunk {
|
||||
@@ -121,7 +118,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
reader.set_pc(inner_ip);
|
||||
self.env = inner_env;
|
||||
self.with_env = inner_with_env;
|
||||
return None;
|
||||
return StepResult::Continue;
|
||||
}
|
||||
ThunkState::Evaluated(val) => {
|
||||
*outer_thunk.borrow_mut(mc) = ThunkState::Evaluated(val);
|
||||
@@ -136,9 +133,9 @@ impl<'gc> crate::Vm<'gc> {
|
||||
}
|
||||
ThunkState::Apply { func: _, arg: _ } => todo!("force Apply thunk"),
|
||||
ThunkState::Blackhole => {
|
||||
return Some(Err(Error::eval_error(
|
||||
return self.finish_err(Error::eval_error(
|
||||
"infinite recursion encountered",
|
||||
)));
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,6 +145,6 @@ impl<'gc> crate::Vm<'gc> {
|
||||
}
|
||||
self.env = env;
|
||||
self.with_env = with_env;
|
||||
None
|
||||
StepResult::Continue
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user