Skip to content

Commit

Permalink
Add support for DefContinue
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacWoods committed Aug 16, 2021
1 parent ae77cb7 commit ed04000
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions aml/src/lib.rs
Expand Up @@ -190,6 +190,7 @@ impl AmlContext {
Ok(_) => Ok(AmlValue::Integer(0)),
Err((_, _, Propagate::Return(result))) => Ok(result),
Err((_, _, Propagate::Break)) => Err(AmlError::BreakInInvalidPosition),
Err((_, _, Propagate::Continue)) => Err(AmlError::ContinueInInvalidPosition),
Err((_, _, Propagate::Err(err))) => {
error!("Failed to execute control method: {:?}", err);
Err(err)
Expand Down Expand Up @@ -743,6 +744,8 @@ pub enum AmlError {
TooManyArgs,
/// A `DefBreak` operation was performed outside of a `DefWhile` or `DefSwitch`.
BreakInInvalidPosition,
/// A `DefContinue` operation was performed outside of a `DefWhile`.
ContinueInInvalidPosition,

/*
* Errors produced parsing the PCI routing tables (_PRT objects).
Expand Down
1 change: 1 addition & 0 deletions aml/src/opcode.rs
Expand Up @@ -45,6 +45,7 @@ pub const EXT_DEF_THERMAL_ZONE_OP: u8 = 0x85;
/*
* Type 1 opcodes
*/
pub const DEF_CONTINUE_OP: u8 = 0x9f;
pub const DEF_IF_ELSE_OP: u8 = 0xa0;
pub const DEF_ELSE_OP: u8 = 0xa1;
pub const DEF_WHILE_OP: u8 = 0xa2;
Expand Down
1 change: 1 addition & 0 deletions aml/src/parser.rs
Expand Up @@ -22,6 +22,7 @@ pub enum Propagate {
Err(AmlError),
Return(AmlValue),
Break,
Continue,
}

impl From<AmlError> for Propagate {
Expand Down
34 changes: 32 additions & 2 deletions aml/src/type1.rs
Expand Up @@ -33,7 +33,16 @@ where
comment_scope(
DebugVerbosity::AllScopes,
"Type1Opcode",
choice!(def_break(), def_breakpoint(), def_fatal(), def_if_else(), def_noop(), def_return(), def_while()),
choice!(
def_break(),
def_breakpoint(),
def_continue(),
def_fatal(),
def_if_else(),
def_noop(),
def_return(),
def_while()
),
)
}

Expand Down Expand Up @@ -67,6 +76,22 @@ where
.discard_result()
}

fn def_continue<'a, 'c>() -> impl Parser<'a, 'c, ()>
where
'c: 'a,
{
/*
* DefContinue := 0x9f
*/
opcode(opcode::DEF_CONTINUE_OP)
.then(comment_scope(
DebugVerbosity::AllScopes,
"DefContinue",
id().map(|()| -> Result<(), Propagate> { Err(Propagate::Continue) }),
))
.discard_result()
}

fn def_fatal<'a, 'c>() -> impl Parser<'a, 'c, ()>
where
'c: 'a,
Expand Down Expand Up @@ -212,11 +237,16 @@ where
Ok((_, new_context, result)) => {
context = new_context;
}
// TODO: differentiate real errors and special Propagates (e.g. break, continue, etc.)
Err((_, new_context, Propagate::Break)) => {
context = new_context;
break;
}
Err((_, new_context, Propagate::Continue)) => {
// We don't need to do anything special here - the `Propagate::Continue` bubbles
// up, and then we can just move on to checking the predicate for the next
// iteration.
context = new_context;
}
Err((_, context, err)) => return (Err(err), context),
}

Expand Down

0 comments on commit ed04000

Please sign in to comment.