浏览代码

Provide constructors for AML numerical constants: ZERO, ONE, ONES

Isaac Woods 4 年之前
父节点
当前提交
0ec427443a
共有 2 个文件被更改,包括 15 次插入3 次删除
  1. 3 3
      aml/src/term_object.rs
  2. 12 0
      aml/src/value.rs

+ 3 - 3
aml/src/term_object.rs

@@ -588,9 +588,9 @@ where
             }
             opcode::QWORD_CONST => take_u64().map(|value| Ok(AmlValue::Integer(value))).parse(new_input, context),
             opcode::STRING_PREFIX => string_parser.parse(new_input, context),
-            opcode::ZERO_OP => Ok((new_input, context, AmlValue::Integer(0))),
-            opcode::ONE_OP => Ok((new_input, context, AmlValue::Integer(1))),
-            opcode::ONES_OP => Ok((new_input, context, AmlValue::Integer(u64::max_value()))),
+            opcode::ZERO_OP => Ok((new_input, context, AmlValue::zero())),
+            opcode::ONE_OP => Ok((new_input, context, AmlValue::one())),
+            opcode::ONES_OP => Ok((new_input, context, AmlValue::ones())),
 
             _ => Err((input, context, Propagate::Err(AmlError::WrongParser))),
         }

+ 12 - 0
aml/src/value.rs

@@ -193,6 +193,18 @@ pub enum AmlValue {
 }
 
 impl AmlValue {
+    pub fn zero() -> AmlValue {
+        AmlValue::Integer(0)
+    }
+
+    pub fn one() -> AmlValue {
+        AmlValue::Integer(1)
+    }
+
+    pub fn ones() -> AmlValue {
+        AmlValue::Integer(u64::max_value())
+    }
+
     pub fn type_of(&self) -> AmlType {
         match self {
             AmlValue::Boolean(_) => AmlType::Integer,