Skip to content

Commit ed04000

Browse files
committed
Add support for DefContinue
1 parent ae77cb7 commit ed04000

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

aml/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ impl AmlContext {
190190
Ok(_) => Ok(AmlValue::Integer(0)),
191191
Err((_, _, Propagate::Return(result))) => Ok(result),
192192
Err((_, _, Propagate::Break)) => Err(AmlError::BreakInInvalidPosition),
193+
Err((_, _, Propagate::Continue)) => Err(AmlError::ContinueInInvalidPosition),
193194
Err((_, _, Propagate::Err(err))) => {
194195
error!("Failed to execute control method: {:?}", err);
195196
Err(err)
@@ -743,6 +744,8 @@ pub enum AmlError {
743744
TooManyArgs,
744745
/// A `DefBreak` operation was performed outside of a `DefWhile` or `DefSwitch`.
745746
BreakInInvalidPosition,
747+
/// A `DefContinue` operation was performed outside of a `DefWhile`.
748+
ContinueInInvalidPosition,
746749

747750
/*
748751
* Errors produced parsing the PCI routing tables (_PRT objects).

aml/src/opcode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub const EXT_DEF_THERMAL_ZONE_OP: u8 = 0x85;
4545
/*
4646
* Type 1 opcodes
4747
*/
48+
pub const DEF_CONTINUE_OP: u8 = 0x9f;
4849
pub const DEF_IF_ELSE_OP: u8 = 0xa0;
4950
pub const DEF_ELSE_OP: u8 = 0xa1;
5051
pub const DEF_WHILE_OP: u8 = 0xa2;

aml/src/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub enum Propagate {
2222
Err(AmlError),
2323
Return(AmlValue),
2424
Break,
25+
Continue,
2526
}
2627

2728
impl From<AmlError> for Propagate {

aml/src/type1.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ where
3333
comment_scope(
3434
DebugVerbosity::AllScopes,
3535
"Type1Opcode",
36-
choice!(def_break(), def_breakpoint(), def_fatal(), def_if_else(), def_noop(), def_return(), def_while()),
36+
choice!(
37+
def_break(),
38+
def_breakpoint(),
39+
def_continue(),
40+
def_fatal(),
41+
def_if_else(),
42+
def_noop(),
43+
def_return(),
44+
def_while()
45+
),
3746
)
3847
}
3948

@@ -67,6 +76,22 @@ where
6776
.discard_result()
6877
}
6978

79+
fn def_continue<'a, 'c>() -> impl Parser<'a, 'c, ()>
80+
where
81+
'c: 'a,
82+
{
83+
/*
84+
* DefContinue := 0x9f
85+
*/
86+
opcode(opcode::DEF_CONTINUE_OP)
87+
.then(comment_scope(
88+
DebugVerbosity::AllScopes,
89+
"DefContinue",
90+
id().map(|()| -> Result<(), Propagate> { Err(Propagate::Continue) }),
91+
))
92+
.discard_result()
93+
}
94+
7095
fn def_fatal<'a, 'c>() -> impl Parser<'a, 'c, ()>
7196
where
7297
'c: 'a,
@@ -212,11 +237,16 @@ where
212237
Ok((_, new_context, result)) => {
213238
context = new_context;
214239
}
215-
// TODO: differentiate real errors and special Propagates (e.g. break, continue, etc.)
216240
Err((_, new_context, Propagate::Break)) => {
217241
context = new_context;
218242
break;
219243
}
244+
Err((_, new_context, Propagate::Continue)) => {
245+
// We don't need to do anything special here - the `Propagate::Continue` bubbles
246+
// up, and then we can just move on to checking the predicate for the next
247+
// iteration.
248+
context = new_context;
249+
}
220250
Err((_, context, err)) => return (Err(err), context),
221251
}
222252

0 commit comments

Comments
 (0)