Selaa lähdekoodia

AML: implement boolean field (#211)

rw-vanc 1 vuosi sitten
vanhempi
commit
35f9fba0ae
3 muutettua tiedostoa jossa 15 lisäystä ja 10 poistoa
  1. 5 5
      aml/src/expression.rs
  2. 8 4
      aml/src/statement.rs
  3. 2 1
      aml/src/value.rs

+ 5 - 5
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)
             }),
         ))

+ 8 - 4
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),
                             };

+ 2 - 1
aml/src/value.rs

@@ -260,10 +260,11 @@ 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{ .. } => Ok(self.as_integer(context)? != 0),
             _ => Err(AmlError::IncompatibleValueConversion { current: self.type_of(), target: AmlType::Integer }),
         }
     }