Skip to content

Commit cbceb73

Browse files
committed
AML: allow transparent references to be used in more places
1 parent beb2950 commit cbceb73

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/aml/mod.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
* TODO:
33
* - Field reads supporting custom handlers
44
* - Run `_REG` on supported op region handlers
5-
* - Sort out situation with `gain_mut` omg - thinking we should have a weird mutex thingy and
6-
* gain a 'token' to give us access to objects. Objects themselves should probs be in like an
7-
* `UnsafeCell` or something.
85
* - Count operations performed and time
96
* - Do stores properly :(
107
* - Load and LoadTable
@@ -442,7 +439,7 @@ where
442439
else {
443440
panic!()
444441
};
445-
let buffer_size = buffer_size.clone().unwrap_reference().as_integer()?;
442+
let buffer_size = buffer_size.clone().unwrap_transparent_reference().as_integer()?;
446443

447444
let buffer_len = pkg_length - (context.current_block.pc - start_pc);
448445
let mut buffer = vec![0; buffer_size as usize];
@@ -804,7 +801,8 @@ where
804801
panic!()
805802
};
806803
let total_elements =
807-
total_elements.clone().unwrap_reference().as_integer()? as usize;
804+
total_elements.clone().unwrap_transparent_reference().as_integer()?
805+
as usize;
808806

809807
// Update the expected number of arguments to terminate the in-flight op
810808
package_op.expected_arguments = total_elements;
@@ -1494,14 +1492,14 @@ where
14941492
}
14951493

14961494
let [Argument::Object(left), Argument::Object(right)] = &op.arguments[..] else { panic!() };
1495+
let left = left.clone().unwrap_transparent_reference();
1496+
let right = right.clone().unwrap_transparent_reference();
14971497

14981498
/*
14991499
* Some of these operations allow strings and buffers to be used as operands. Apparently
15001500
* NT's interpreter just takes the first 4 bytes of the string/buffer and casts them as an
15011501
* integer...
15021502
*/
1503-
let left = left.clone().unwrap_transparent_reference();
1504-
let right = right.clone().unwrap_transparent_reference();
15051503
let (left, right) = match *left {
15061504
Object::Integer(left) => (left, right.as_integer()?),
15071505
Object::String(ref left) => {
@@ -1559,8 +1557,9 @@ where
15591557

15601558
fn do_to_buffer(&self, context: &mut MethodContext, op: OpInFlight) -> Result<(), AmlError> {
15611559
let [Argument::Object(operand), target] = &op.arguments[..] else { panic!() };
1560+
let operand = operand.clone().unwrap_transparent_reference();
15621561

1563-
let result = match **operand {
1562+
let result = match *operand {
15641563
Object::Buffer(ref bytes) => Object::Buffer(bytes.clone()),
15651564
Object::Integer(value) => {
15661565
if self.dsdt_revision >= 2 {
@@ -1592,8 +1591,9 @@ where
15921591

15931592
fn do_to_integer(&self, context: &mut MethodContext, op: OpInFlight) -> Result<(), AmlError> {
15941593
let [Argument::Object(operand), target] = &op.arguments[..] else { panic!() };
1594+
let operand = operand.clone().unwrap_transparent_reference();
15951595

1596-
let result = match **operand {
1596+
let result = match *operand {
15971597
Object::Integer(value) => Object::Integer(value),
15981598
Object::Buffer(ref bytes) => {
15991599
/*
@@ -1636,8 +1636,9 @@ where
16361636

16371637
fn do_to_string(&self, context: &mut MethodContext, op: OpInFlight) -> Result<(), AmlError> {
16381638
let [Argument::Object(source), Argument::Object(length), target] = &op.arguments[..] else { panic!() };
1639+
let source = source.clone().unwrap_transparent_reference();
16391640
let source = source.as_buffer()?;
1640-
let length = length.as_integer()? as usize;
1641+
let length = length.clone().unwrap_transparent_reference().as_integer()? as usize;
16411642

16421643
let result = if source.is_empty() {
16431644
Object::String(String::new())
@@ -1677,7 +1678,6 @@ where
16771678
if bytes.is_empty() {
16781679
Object::String(String::new())
16791680
} else {
1680-
// TODO: there has GOT to be a better way to format directly into a string...
16811681
let mut string = String::new();
16821682
for byte in bytes {
16831683
let as_str = match op.op {
@@ -1711,8 +1711,8 @@ where
17111711
else {
17121712
panic!()
17131713
};
1714-
let index = index.as_integer()? as usize;
1715-
let length = length.as_integer()? as usize;
1714+
let index = index.clone().unwrap_transparent_reference().as_integer()? as usize;
1715+
let length = length.clone().unwrap_transparent_reference().as_integer()? as usize;
17161716

17171717
let result = match **source {
17181718
Object::String(ref string) => {
@@ -1740,12 +1740,14 @@ where
17401740
self.do_store(target, result.clone())?;
17411741
context.contribute_arg(Argument::Object(result));
17421742
context.retire_op(op);
1743-
17441743
Ok(())
17451744
}
17461745

17471746
fn do_concat(&self, context: &mut MethodContext, op: OpInFlight) -> Result<(), AmlError> {
17481747
let [Argument::Object(source1), Argument::Object(source2), target] = &op.arguments[..] else { panic!() };
1748+
let source1 = source1.clone().unwrap_transparent_reference();
1749+
let source2 = source2.clone().unwrap_transparent_reference();
1750+
17491751
fn resolve_as_string(obj: &Object) -> String {
17501752
match obj {
17511753
Object::Uninitialized => "[Uninitialized Object]".to_string(),
@@ -1838,7 +1840,7 @@ where
18381840

18391841
fn do_size_of(&self, context: &mut MethodContext, op: OpInFlight) -> Result<(), AmlError> {
18401842
let [Argument::Object(object)] = &op.arguments[..] else { panic!() };
1841-
let object = object.clone().unwrap_reference();
1843+
let object = object.clone().unwrap_transparent_reference();
18421844

18431845
let result = match *object {
18441846
Object::Buffer(ref buffer) => buffer.len(),
@@ -1856,9 +1858,10 @@ where
18561858
let [Argument::Object(object), Argument::Object(index_value), target] = &op.arguments[..] else {
18571859
panic!()
18581860
};
1859-
let index_value = index_value.as_integer()?;
1861+
let object = object.clone().unwrap_transparent_reference();
1862+
let index_value = index_value.clone().unwrap_transparent_reference().as_integer()?;
18601863

1861-
let result = match **object {
1864+
let result = match *object {
18621865
Object::Buffer(ref buffer) => {
18631866
if index_value as usize >= buffer.len() {
18641867
Err(AmlError::IndexOutOfBounds)?

0 commit comments

Comments
 (0)