Skip to main content

ruda_kernel/dsl/frontend/element/
bool.rs

1use ruda_core::ir::{ConstantValue, ManagedVariable, Scope, StorageType, Type};
2
3use crate::dsl::{
4    frontend::{RudaPrimitive, RudaType},
5    prelude::Scalar,
6};
7use crate::dsl::{ir::ElemType, prelude::Const};
8
9use super::{IntoRuntime, NativeAssign, NativeExpand};
10
11/// Extension trait for [bool].
12pub trait BoolOps {
13    #[allow(clippy::new_ret_no_self)]
14    fn new(value: bool) -> bool {
15        value
16    }
17    fn __expand_new(_scope: &mut Scope, value: NativeExpand<bool>) -> NativeExpand<bool> {
18        ManagedVariable::Plain(ElemType::Bool.constant(value.expand.as_const().unwrap())).into()
19    }
20}
21
22impl BoolOps for bool {}
23
24impl RudaType for bool {
25    type ExpandType = NativeExpand<Self>;
26}
27
28impl Scalar for bool {}
29impl RudaPrimitive for bool {
30    type Scalar = Self;
31    type Size = Const<1>;
32    type WithScalar<S: Scalar> = S;
33
34    fn as_type_native() -> Option<Type> {
35        Some(StorageType::Scalar(ElemType::Bool).into())
36    }
37
38    fn from_const_value(value: ConstantValue) -> Self {
39        let ConstantValue::Bool(value) = value else {
40            unreachable!()
41        };
42        value
43    }
44}
45
46impl IntoRuntime for bool {
47    fn __expand_runtime_method(self, _scope: &mut Scope) -> NativeExpand<Self> {
48        self.into()
49    }
50}
51
52impl NativeAssign for bool {}