From d6b32251f9f607780df1cb25069785da4a634e71 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 5 Apr 2026 22:21:30 +0100 Subject: Support array data values in patio-to-cranelift --- patio-to-cranelift/src/codegen/values.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/patio-to-cranelift/src/codegen/values.rs b/patio-to-cranelift/src/codegen/values.rs index abc43459..74eaa669 100644 --- a/patio-to-cranelift/src/codegen/values.rs +++ b/patio-to-cranelift/src/codegen/values.rs @@ -26,8 +26,12 @@ fn write_data_value( match value { PatioDataValue::Array { element_layout: _, - elements: _, - } => todo!(), + elements, + } => { + for element in elements { + write_data_value(element, bytes, target_triple); + } + } PatioDataValue::Bool(value) => bytes.push(if *value { 1 } else { 0 }), @@ -75,7 +79,10 @@ pub(crate) fn eval_int_value(value: &PatioIntValue, target_triple: &target_lexic mod data_value_to_bytes_test { use std::str::FromStr; - use crate::patio::values::{PatioDataValue, PatioIntValue}; + use crate::patio::{ + types::PatioDataLayout, + values::{PatioDataValue, PatioIntValue}, + }; fn data_value_to_bytes(data_value: PatioDataValue) -> Box<[u8]> { super::data_value_to_bytes( @@ -84,6 +91,24 @@ mod data_value_to_bytes_test { ) } + #[test] + fn array_is_written_as_elements() { + let data_value = PatioDataValue::Array { + element_layout: PatioDataLayout::Int32, + elements: vec![ + PatioDataValue::Int32(PatioIntValue::Literal { value: 0x12345678 }), + PatioDataValue::Int32(PatioIntValue::Literal { value: 0x23456789 }), + ], + }; + + let bytes = data_value_to_bytes(data_value); + + assert_eq!( + bytes.as_ref(), + &[0x78, 0x56, 0x34, 0x12, 0x89, 0x67, 0x45, 0x23] + ); + } + #[test] fn false_is_single_byte_0() { let data_value = PatioDataValue::Bool(false); -- cgit v1.2.3