Skip to content

Commit

Permalink
AML: implement boolean field
Browse files Browse the repository at this point in the history
  • Loading branch information
rw-vanc committed Mar 8, 2024
1 parent 7db4539 commit 2b57238
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
10 changes: 5 additions & 5 deletions aml/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ where
DebugVerbosity::AllScopes,
"DefLOr",
term_arg().then(term_arg()).map_with_context(|(left_arg, right_arg), context| {
let left = try_with_context!(context, left_arg.as_bool());
let right = try_with_context!(context, right_arg.as_bool());
let left = try_with_context!(context, left_arg.as_bool(context));
let right = try_with_context!(context, right_arg.as_bool(context));
(Ok(AmlValue::Boolean(left && right)), context)
}),
))
Expand All @@ -397,8 +397,8 @@ where
DebugVerbosity::AllScopes,
"DefLOr",
term_arg().then(term_arg()).map_with_context(|(left_arg, right_arg), context| {
let left = try_with_context!(context, left_arg.as_bool());
let right = try_with_context!(context, right_arg.as_bool());
let left = try_with_context!(context, left_arg.as_bool(context));
let right = try_with_context!(context, right_arg.as_bool(context));
(Ok(AmlValue::Boolean(left || right)), context)
}),
))
Expand All @@ -418,7 +418,7 @@ where
DebugVerbosity::AllScopes,
"DefLNot",
term_arg().map_with_context(|arg, context| {
let operand = try_with_context!(context, arg.as_bool());
let operand = try_with_context!(context, arg.as_bool(context));
(Ok(AmlValue::Boolean(!operand)), context)
}),
))
Expand Down
12 changes: 8 additions & 4 deletions aml/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ where
pkg_length()
.then(term_arg())
.feed(|(length, predicate_arg)| {
take_to_end_of_pkglength(length)
.map(move |then_branch| Ok((predicate_arg.as_bool()?, then_branch)))
take_to_end_of_pkglength(length).map_with_context(move |then_branch, context| {
match predicate_arg.as_bool(context) {
Ok(pred_val) => (Ok((pred_val, then_branch)), context),
Err(e) => (Err(Propagate::Err(e)), context),
}
})
})
.then(choice!(
maybe_else_opcode
Expand Down Expand Up @@ -276,7 +280,7 @@ where
.map(move |body| Ok((first_predicate.clone(), predicate_stream, body)))
})
.map_with_context(|(first_predicate, predicate_stream, body), mut context| {
if !try_with_context!(context, first_predicate.as_bool()) {
if !try_with_context!(context, first_predicate.as_bool(context)) {
return (Ok(()), context);
}

Expand Down Expand Up @@ -307,7 +311,7 @@ where
{
Ok((_, new_context, result)) => {
context = new_context;
try_with_context!(context, result.as_bool())
try_with_context!(context, result.as_bool(context))
}
Err((_, context, err)) => return (Err(err), context),
};
Expand Down
7 changes: 6 additions & 1 deletion aml/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,15 @@ impl AmlValue {
}
}

pub fn as_bool(&self) -> Result<bool, AmlError> {
pub fn as_bool(&self, context: &mut AmlContext) -> Result<bool, AmlError> {
match self {
AmlValue::Boolean(value) => Ok(*value),
AmlValue::Integer(value) => Ok(*value != 0),
AmlValue::Field{ .. } => match self.as_integer(context) {
Ok(0) => Ok(false),
Ok(_) => Ok(true),
Err(e) => Err(e),
}
_ => Err(AmlError::IncompatibleValueConversion { current: self.type_of(), target: AmlType::Integer }),
}
}
Expand Down

0 comments on commit 2b57238

Please sign in to comment.