Skip to content

Commit 35f9fba

Browse files
authored
AML: implement boolean field (#211)
1 parent ca360cb commit 35f9fba

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

aml/src/expression.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ where
376376
DebugVerbosity::AllScopes,
377377
"DefLOr",
378378
term_arg().then(term_arg()).map_with_context(|(left_arg, right_arg), context| {
379-
let left = try_with_context!(context, left_arg.as_bool());
380-
let right = try_with_context!(context, right_arg.as_bool());
379+
let left = try_with_context!(context, left_arg.as_bool(context));
380+
let right = try_with_context!(context, right_arg.as_bool(context));
381381
(Ok(AmlValue::Boolean(left && right)), context)
382382
}),
383383
))
@@ -397,8 +397,8 @@ where
397397
DebugVerbosity::AllScopes,
398398
"DefLOr",
399399
term_arg().then(term_arg()).map_with_context(|(left_arg, right_arg), context| {
400-
let left = try_with_context!(context, left_arg.as_bool());
401-
let right = try_with_context!(context, right_arg.as_bool());
400+
let left = try_with_context!(context, left_arg.as_bool(context));
401+
let right = try_with_context!(context, right_arg.as_bool(context));
402402
(Ok(AmlValue::Boolean(left || right)), context)
403403
}),
404404
))
@@ -418,7 +418,7 @@ where
418418
DebugVerbosity::AllScopes,
419419
"DefLNot",
420420
term_arg().map_with_context(|arg, context| {
421-
let operand = try_with_context!(context, arg.as_bool());
421+
let operand = try_with_context!(context, arg.as_bool(context));
422422
(Ok(AmlValue::Boolean(!operand)), context)
423423
}),
424424
))

aml/src/statement.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,12 @@ where
141141
pkg_length()
142142
.then(term_arg())
143143
.feed(|(length, predicate_arg)| {
144-
take_to_end_of_pkglength(length)
145-
.map(move |then_branch| Ok((predicate_arg.as_bool()?, then_branch)))
144+
take_to_end_of_pkglength(length).map_with_context(move |then_branch, context| {
145+
match predicate_arg.as_bool(context) {
146+
Ok(pred_val) => (Ok((pred_val, then_branch)), context),
147+
Err(e) => (Err(Propagate::Err(e)), context),
148+
}
149+
})
146150
})
147151
.then(choice!(
148152
maybe_else_opcode
@@ -276,7 +280,7 @@ where
276280
.map(move |body| Ok((first_predicate.clone(), predicate_stream, body)))
277281
})
278282
.map_with_context(|(first_predicate, predicate_stream, body), mut context| {
279-
if !try_with_context!(context, first_predicate.as_bool()) {
283+
if !try_with_context!(context, first_predicate.as_bool(context)) {
280284
return (Ok(()), context);
281285
}
282286

@@ -307,7 +311,7 @@ where
307311
{
308312
Ok((_, new_context, result)) => {
309313
context = new_context;
310-
try_with_context!(context, result.as_bool())
314+
try_with_context!(context, result.as_bool(context))
311315
}
312316
Err((_, context, err)) => return (Err(err), context),
313317
};

aml/src/value.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ impl AmlValue {
260260
}
261261
}
262262

263-
pub fn as_bool(&self) -> Result<bool, AmlError> {
263+
pub fn as_bool(&self, context: &mut AmlContext) -> Result<bool, AmlError> {
264264
match self {
265265
AmlValue::Boolean(value) => Ok(*value),
266266
AmlValue::Integer(value) => Ok(*value != 0),
267+
AmlValue::Field{ .. } => Ok(self.as_integer(context)? != 0),
267268
_ => Err(AmlError::IncompatibleValueConversion { current: self.type_of(), target: AmlType::Integer }),
268269
}
269270
}

0 commit comments

Comments
 (0)