Skip to content

Commit 1998a26

Browse files
committed
AML: prepare for correct store result handling
1 parent cbceb73 commit 1998a26

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/aml/mod.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,8 +1431,7 @@ where
14311431
};
14321432

14331433
let result = Object::Integer(result).wrap();
1434-
// TODO: use result for arg
1435-
self.do_store(target, result.clone())?;
1434+
let result = self.do_store(target, result)?;
14361435
context.contribute_arg(Argument::Object(result));
14371436
context.retire_op(op);
14381437
Ok(())
@@ -1582,8 +1581,7 @@ where
15821581
}
15831582
.wrap();
15841583

1585-
// TODO: use result of store
1586-
self.do_store(target, result.clone())?;
1584+
let result = self.do_store(target, result)?;
15871585
context.contribute_arg(Argument::Object(result));
15881586
context.retire_op(op);
15891587
Ok(())
@@ -1627,8 +1625,7 @@ where
16271625
}
16281626
.wrap();
16291627

1630-
// TODO: use result of store
1631-
self.do_store(target, result.clone())?;
1628+
let result = self.do_store(target, result)?;
16321629
context.contribute_arg(Argument::Object(result));
16331630
context.retire_op(op);
16341631
Ok(())
@@ -1655,8 +1652,7 @@ where
16551652
}
16561653
.wrap();
16571654

1658-
// TODO: use result of store
1659-
self.do_store(target, result.clone())?;
1655+
let result = self.do_store(target, result)?;
16601656
context.contribute_arg(Argument::Object(result));
16611657
context.retire_op(op);
16621658
Ok(())
@@ -1698,8 +1694,7 @@ where
16981694
}
16991695
.wrap();
17001696

1701-
// TODO: use result of store
1702-
self.do_store(target, result.clone())?;
1697+
let result = self.do_store(target, result)?;
17031698
context.contribute_arg(Argument::Object(result));
17041699
context.retire_op(op);
17051700
Ok(())
@@ -1797,8 +1792,8 @@ where
17971792
Object::String(source1 + &source2).wrap()
17981793
}
17991794
};
1800-
// TODO: use result of store
1801-
self.do_store(target, result.clone())?;
1795+
1796+
let result = self.do_store(target, result)?;
18021797
context.contribute_arg(Argument::Object(result));
18031798
context.retire_op(op);
18041799
Ok(())
@@ -1906,18 +1901,21 @@ where
19061901
Ok(())
19071902
}
19081903

1909-
// TODO: this might actually do weird stuff to your data if written to a field with BufferAcc
1910-
// access. I guess we need to return something here really and use it instead of the result
1911-
// when returning?? We need to look carefully at all use-sites to make sure it actually returns
1912-
// the result of the store, not the object it passed to us.
1913-
fn do_store(&self, target: &Argument, object: WrappedObject) -> Result<(), AmlError> {
1914-
// TODO: find the destination (need to handle references, debug objects, etc.)
1915-
// TODO: convert object to be of the type of destination, in line with 19.3.5 of the spec
1916-
// TODO: write the object to the destination, including e.g. field writes that then lead to
1917-
// literally god knows what.
1904+
fn do_store(&self, target: &Argument, object: WrappedObject) -> Result<WrappedObject, AmlError> {
19181905
let object = object.unwrap_transparent_reference();
19191906
let token = self.object_token.lock();
19201907

1908+
/*
1909+
* TODO: stores should do more implicit conversion to the type of the destination in some
1910+
* cases, in line with section 19.3.5 of the spec
1911+
*
1912+
* TODO: stores to fields with `BufferAcc` can actually return a value of the store that
1913+
* differs from what was written into the field. This is used for complex field types with
1914+
* a write-then-read pattern. The return value is then used as the 'result' of the storing
1915+
* expression.
1916+
*/
1917+
let to_return = object.clone();
1918+
19211919
match target {
19221920
Argument::Object(target) => match unsafe { target.gain_mut(&*token) } {
19231921
Object::Integer(target) => match unsafe { object.gain_mut(&*token) } {
@@ -1975,12 +1973,13 @@ where
19751973
_ => panic!("Stores to objects like {:?} are not yet supported", target),
19761974
},
19771975

1978-
Argument::Namestring(_) => {}
1976+
Argument::Namestring(_) => todo!(),
19791977
Argument::ByteData(_) | Argument::DWordData(_) | Argument::TrackedPc(_) | Argument::PkgLength(_) => {
19801978
panic!()
19811979
}
19821980
}
1983-
Ok(())
1981+
1982+
Ok(to_return)
19841983
}
19851984

19861985
/// Do a read from a field by performing one or more well-formed accesses to the underlying

0 commit comments

Comments
 (0)