浏览代码

Parse LOr

Isaac Woods 4 年之前
父节点
当前提交
b78bd47f5c
共有 2 个文件被更改,包括 24 次插入1 次删除
  1. 2 1
      aml/src/opcode.rs
  2. 22 0
      aml/src/type2.rs

+ 2 - 1
aml/src/opcode.rs

@@ -42,10 +42,11 @@ pub const DEF_RETURN_OP: u8 = 0xa4;
 /*
  * Type 2 opcodes
  */
-pub const DEF_L_EQUAL_OP: u8 = 0x93;
 pub const DEF_STORE_OP: u8 = 0x70;
 pub const DEF_SHIFT_LEFT: u8 = 0x79;
 pub const DEF_SHIFT_RIGHT: u8 = 0x7a;
+pub const DEF_L_OR_OP: u8 = 0x91;
+pub const DEF_L_EQUAL_OP: u8 = 0x93;
 
 /*
  * Miscellaneous objects

+ 22 - 0
aml/src/type2.rs

@@ -44,6 +44,7 @@ where
         choice!(
             def_buffer(),
             def_l_equal(),
+            def_l_or(),
             def_package(),
             def_shift_left(),
             def_shift_right(),
@@ -79,6 +80,27 @@ where
         .map(|((), (bytes, buffer_size))| Ok(AmlValue::Buffer { bytes, size: buffer_size }))
 }
 
+fn def_l_or<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
+where
+    'c: 'a,
+{
+    /*
+     * DefLOr := 0x91 Operand Operand
+     * Operand := TermArg => Integer
+     */
+    opcode(opcode::DEF_L_OR_OP)
+        .then(comment_scope(
+            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());
+                (Ok(AmlValue::Boolean(left || right)), context)
+            }),
+        ))
+        .map(|((), result)| Ok(result))
+}
+
 fn def_l_equal<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
 where
     'c: 'a,