Make `do_action` execute out of a code stack.

This commit is contained in:
David Wendt 2019-09-14 19:12:12 -04:00 committed by Mike Welsh
parent 06c81d6cc1
commit 693e791d75
1 changed files with 123 additions and 116 deletions

View File

@ -100,9 +100,12 @@ impl<'gc> Avm1<'gc> {
context: &mut ActionContext<'_, 'gc, '_>,
code: &[u8],
) -> Result<(), Error> {
let mut reader = Reader::new(code, self.swf_version);
let mut pc_stack = vec![Reader::new(code, self.swf_version)];
while let Some(action) = reader.read_action()? {
while pc_stack.len() > 0 {
let mut reader = pc_stack.last_mut().unwrap();
if let Some(action) = reader.read_action()? {
use swf::avm1::types::Action;
let result = match action {
Action::Add => self.action_add(context),
@ -219,6 +222,10 @@ impl<'gc> Avm1<'gc> {
log::error!("AVM1 error: {}", e);
return result;
}
} else {
//Out of code. Return to the parent function.
pc_stack.pop();
}
}
Ok(())