2
0
Эх сурвалжийг харах

Set scope correctly when invoking a control method

This is slightly quick and dirty, but all the bad code will be ripped out
when we move to support executing methods inside other methods, so it
doesn't matter too much.
Isaac Woods 5 жил өмнө
parent
commit
a587df0a20

+ 1 - 1
aml_parser/src/lib.rs

@@ -151,7 +151,7 @@ impl AmlContext {
             None => return Err(AmlError::ObjectDoesNotExist(path.as_string())),
         };
 
-        method.invoke(self, args)
+        method.invoke(self, args, path.clone())
     }
 
     /// Resolves a given path relative to the current scope (if the given path is not absolute).

+ 7 - 3
aml_parser/src/value.rs

@@ -8,7 +8,7 @@ use crate::{
 };
 use alloc::{boxed::Box, string::String, vec::Vec};
 use bit_field::BitField;
-use log::info;
+use log::{error, info};
 
 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
 pub enum RegionSpace {
@@ -151,12 +151,13 @@ impl AmlValue {
 
     /// If this value is a control method, invoke it. Returns `AmlError::IncompatibleValueConversion` if this
     /// is not a method.
-    pub fn invoke(&self, context: &mut AmlContext, args: Args) -> Result<AmlValue, AmlError> {
+    pub fn invoke(&self, context: &mut AmlContext, args: Args, scope: AmlName) -> Result<AmlValue, AmlError> {
         if let AmlValue::Method { flags, ref code } = self {
             /*
              * First, set up the state we expect to enter the method with, but clearing local
              * variables to "null" and setting the arguments.
              */
+            context.current_scope = scope;
             context.current_args = Some(args);
             context.local_0 = None;
             context.local_1 = None;
@@ -167,7 +168,10 @@ impl AmlValue {
             context.local_6 = None;
             context.local_7 = None;
 
-            let result = term_list(PkgLength::from_raw_length(code, code.len() as u32)).parse(code, context);
+            match term_list(PkgLength::from_raw_length(code, code.len() as u32)).parse(code, context) {
+                Ok((remaining, context, result)) => {}
+                Err((remaining, context, err)) => error!("Failed to execute control method: {:?}", err),
+            }
 
             /*
              * Now clear the state.