From 2b572383aafe6ccdee0978bfe63196f30fea7fe3 Mon Sep 17 00:00:00 2001 From: Ron Williams Date: Fri, 8 Mar 2024 14:56:14 -0800 Subject: [PATCH] AML: implement boolean field --- aml/src/expression.rs | 10 +++++----- aml/src/statement.rs | 12 ++++++++---- aml/src/value.rs | 7 ++++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/aml/src/expression.rs b/aml/src/expression.rs index ea25613..a8f083b 100644 --- a/aml/src/expression.rs +++ b/aml/src/expression.rs @@ -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) }), )) @@ -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) }), )) @@ -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) }), )) diff --git a/aml/src/statement.rs b/aml/src/statement.rs index 46f8f9c..a24e78a 100644 --- a/aml/src/statement.rs +++ b/aml/src/statement.rs @@ -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 @@ -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); } @@ -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), }; diff --git a/aml/src/value.rs b/aml/src/value.rs index afeb132..ef5ccc0 100644 --- a/aml/src/value.rs +++ b/aml/src/value.rs @@ -260,10 +260,15 @@ impl AmlValue { } } - pub fn as_bool(&self) -> Result { + pub fn as_bool(&self, context: &mut AmlContext) -> Result { 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 }), } }