def AmlValue.compare

bend-osdev-acpi@0.1.1.0 · aml_value.bend:286

import bend-osdev-acpi@0.1.1.0/aml_value.bend as AmlValue
import Base
import bend-osdev-word64@0.1.1.0/word64.bend as W
import bend-osdev-bytes@0.1.1.0/bytes.bend as B
import bend-osdev-acpi@0.1.1.0/error.bend as E

286# the comparison of a with b, b converted to a's type
287def AmlValue.compare(+wide: Bool, a: AmlValue, +b: AmlValue) -> Result<&2, &2, E.AcpiError, Cmp>:
288  match a:
289    case AmlInt{x}:
290      Result.map(&2, &2, E.AcpiError, W.W64, Cmp, y => W.W64.cmp(AmlInt.fit(wide, x), y), AmlValue.to_int(wide, b))
291    case AmlStr{s}:
292      Result.map(&2, &2, E.AcpiError, B.Octets, Cmp, t => val.bytes.cmp(B.Octets.to_list(s), B.Octets.to_list(t)), AmlValue.to_str(wide, b))
293    case AmlBuf{s}:
294      Result.map(&2, &2, E.AcpiError, B.Octets, Cmp, t => val.bytes.cmp(B.Octets.to_list(s), B.Octets.to_list(t)), AmlValue.to_buf(wide, b))
295    case _:
296      Fail{E.AcpiAmlBadType{"cannot compare"}}

Uses (15)

Used by (1)