diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-05 22:09:25 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-05 22:09:25 +0100 |
| commit | 14487bcfb4806aa26105619764c68f4b27683729 (patch) | |
| tree | b335743f3d1e960c0cb91ac455eac6d446201714 /patio-to-cranelift | |
| parent | 3dda308da2b8a7a91048c18c67059ce8357cf4ce (diff) | |
Compile boolean data values
Diffstat (limited to 'patio-to-cranelift')
| -rw-r--r-- | patio-to-cranelift/src/codegen/values.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/patio-to-cranelift/src/codegen/values.rs b/patio-to-cranelift/src/codegen/values.rs index 2fe30c83..80212932 100644 --- a/patio-to-cranelift/src/codegen/values.rs +++ b/patio-to-cranelift/src/codegen/values.rs @@ -30,7 +30,9 @@ fn write_data_value( element_layout: _, elements: _, } => todo!(), - PatioDataValue::Bool(_) => todo!(), + + PatioDataValue::Bool(value) => bytes.push(if *value { 1 } else { 0 }), + PatioDataValue::Byte(_) => todo!(), PatioDataValue::DataPtr(_) => todo!(), PatioDataValue::Int(int_value) => { @@ -63,3 +65,35 @@ pub(crate) fn eval_int_value(value: &PatioIntValue, target_triple: &target_lexic PatioIntValue::Literal { value } => *value, } } + +#[cfg(test)] +mod data_value_to_bytes_test { + use std::str::FromStr; + + use crate::patio::values::PatioDataValue; + + fn data_value_to_bytes(data_value: PatioDataValue) -> Box<[u8]> { + super::data_value_to_bytes( + &data_value, + &target_lexicon::Triple::from_str("x86_64-unknown-linux-gnu").unwrap(), + ) + } + + #[test] + fn false_is_single_byte_0() { + let data_value = PatioDataValue::Bool(false); + + let bytes = data_value_to_bytes(data_value); + + assert_eq!(bytes.as_ref(), &[0]); + } + + #[test] + fn true_is_single_byte_1() { + let data_value = PatioDataValue::Bool(true); + + let bytes = data_value_to_bytes(data_value); + + assert_eq!(bytes.as_ref(), &[1]); + } +} |
