Explorar o código

Use new Propagate::Return variant to return values

This removes the fake error used to return values by abusing the propagation
of errors. This is required for the whole reason for finally getting rid of
this hack - allowing `AmlError` to remain `Eq` (which is very useful), while
allowing `AmlValue` to not implement those traits (which it shouldn't; that
change will be made in a future commit).
Isaac Woods %!s(int64=4) %!d(string=hai) anos
pai
achega
4789261cc6
Modificáronse 2 ficheiros con 6 adicións e 12 borrados
  1. 3 8
      aml/src/lib.rs
  2. 3 4
      aml/src/type1.rs

+ 3 - 8
aml/src/lib.rs

@@ -200,8 +200,8 @@ impl AmlContext {
                 {
                     // If the method doesn't return a value, we implicitly return `0`
                     Ok(_) => Ok(AmlValue::Integer(0)),
-                    Err((_, _, AmlError::Return(result))) => Ok(result),
-                    Err((_, _, err)) => {
+                    Err((_, _, Propagate::Return(result))) => Ok(result),
+                    Err((_, _, Propagate::Err(err))) => {
                         error!("Failed to execute control method: {:?}", err);
                         Err(err)
                     }
@@ -639,7 +639,7 @@ pub trait Handler {
     fn write_pci_u32(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u32);
 }
 
-#[derive(Clone, Debug, PartialEq, Eq)]
+#[derive(Clone, PartialEq, Eq, Debug)]
 pub enum AmlError {
     /*
      * Errors produced parsing the AML stream.
@@ -696,11 +696,6 @@ pub enum AmlError {
     InvalidArgAccess(ArgNum),
     /// Produced when a method accesses a local that it has not stored into.
     InvalidLocalAccess(LocalNum),
-    /// This is not a real error, but is used to propagate return values from within the deep
-    /// parsing call-stack. It should only be emitted when parsing a `DefReturn`. We use the
-    /// error system here because the way errors are propagated matches how we want to handle
-    /// return values.
-    Return(AmlValue),
 
     /*
      * Errors produced parsing the PCI routing tables (_PRT objects).

+ 3 - 4
aml/src/type1.rs

@@ -1,9 +1,8 @@
 use crate::{
     opcode::{self, opcode},
-    parser::{choice, comment_scope, id, take_to_end_of_pkglength, ParseResult, Parser},
+    parser::{choice, comment_scope, id, take_to_end_of_pkglength, ParseResult, Parser, Propagate},
     pkg_length::{pkg_length, PkgLength},
     term_object::{term_arg, term_list},
-    AmlError,
     DebugVerbosity,
 };
 
@@ -110,14 +109,14 @@ where
         .then(comment_scope(
             DebugVerbosity::Scopes,
             "DefReturn",
-            term_arg().map(|return_arg| -> Result<(), AmlError> {
+            term_arg().map(|return_arg| -> Result<(), Propagate> {
                 /*
                  * To return a value, we want to halt execution of the method and propagate the
                  * return value all the way up to the start of the method invocation. To do this,
                  * we emit a special error that is intercepted during method invocation and turned
                  * into a valid result.
                  */
-                Err(AmlError::Return(return_arg))
+                Err(Propagate::Return(return_arg))
             }),
         ))
         .discard_result()