rust-osdev / acpi

Rust library for parsing ACPI tables and interpreting AML
Apache License 2.0
203 stars 65 forks source link

AML: Handle "if (field)" #210

Closed rw-vanc closed 8 months ago

rw-vanc commented 8 months ago

In real-world AML, I have encountered if (field). This requires evaluating the field as boolean. I would like to fix this by using as_integer to evaluate the field, but as_integer takes context as an argument, and as_bool does not. Most of the occurrences of as_bool have context readily available, but there is one case where it is not (the place where I actually need it).

https://github.com/rust-osdev/acpi/blob/main/aml/src/statement.rs#L145

Can you recommend the change to this line so I can call as_bool(context)?

rw-vanc commented 8 months ago

Fixed, ignore this issue.

IsaacWoods commented 8 months ago

As an aside, I've been questioning whether we should have a separate boolean type - afaik it's never existed in the actual spec and we just treat it as a special-cased integer type and conversions back and forth make it seamless. Lmk if you have thoughts either way, and if no objections I'll explore getting rid of it

rw-vanc commented 8 months ago

I don't think AmlValue::Boolean is necessary. as_bool is a useful thing, but it can probably just delegate to as_integer and do self.as_integer(context)? != 0.