fix codegen for seq-map

This commit is contained in:
Michael Sippel 2025-04-02 15:01:45 +02:00
parent 98592aa596
commit 67cec64dfc
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -194,56 +194,47 @@ impl LdmcCTargetMorph {
})
}
MorphismInstance2::MapSeq { ψ, seq_repr, item_morph } => {
let i = 0; // <--todo
self.add_instantiation(dict, item_morph.as_ref().clone()).expect("add instantiation");
if let Some(seq_repr) = seq_repr {
if let Ok(item_morph_inst) = self.add_instantiation(dict, item_morph.as_ref().clone()) {
if let Some(seq_repr) = seq_repr {
dict.add_varname("LengthType".into());
if let Ok(γ) = laddertypes::unification_sugared::unify(
&dict.parse("<LengthPrefix LengthType>").expect("parse type template").sugar(dict),
seq_repr.as_ref()
) {
let length_type = γ.get(&dict.get_typeid(&"LengthType".into()).expect("")).expect("cant get LengthType");
let ty = morph_inst.get_type().strip_halo();
let symbol = encode_morph_type_to_symbol(dict, &morph_inst.get_haloless_type());
let item_morph_symbol = item_morph_inst.instantiated_symbol_name(dict, &HashMap::new());
dict.add_varname("LengthType".into());
if let Ok(γ) = laddertypes::unification_sugared::unify(
&dict.parse("<LengthPrefix LengthType>").expect("parse type template").sugar(dict),
seq_repr.as_ref()
) {
let length_type = γ.get(&dict.get_typeid(&"LengthType".into()).expect("")).expect("cant get LengthType");
let ty = morph_inst.get_type().strip_halo();
let symbol = encode_morph_type_to_symbol(dict, &morph_inst.get_haloless_type());
let item_morph_symbol = encode_morph_type_to_symbol(dict, &item_morph.get_haloless_type());
let length_c_type = get_c_repr_type(dict, length_type.clone(), true).expect("cant c-repr type for array length");
let src_item_c_type = get_c_repr_type(dict, item_morph.get_haloless_type().src_type, true).expect("cant c-repr type for src item");
let dst_item_c_type = get_c_repr_type(dict, item_morph.get_haloless_type().dst_type, true).expect("cant c-repr type for dst item");
let length_c_type = get_c_repr_type(dict, length_type.clone(), true).expect("cant c-repr type for array length");
let src_item_c_type = get_c_repr_type(dict, item_morph.get_haloless_type().src_type, true).expect("cant c-repr type for src item");
let dst_item_c_type = get_c_repr_type(dict, item_morph.get_haloless_type().dst_type, true).expect("cant c-repr type for dst item");
let src_c_type = encode_type_to_symbol(dict, &ty.src_type);
let dst_c_type = encode_type_to_symbol(dict, &ty.dst_type);
// todo: self.add_active_length_prefix_map()
// todo: self.add_active_length_prefix_map()
let map_fn = format!("length_prefix_{}_array_map_{}_to_{}",
length_c_type, src_item_c_type, dst_item_c_type
);
let c_source = format!(r#"
return {} ( {}, src, dst );"#,
map_fn,
item_morph_symbol,
);
let map_fn = format!("length_prefix_{}_array_map_{}_to_{}",
length_c_type, src_item_c_type, dst_item_c_type
);
let src_buf = if i%2 == 0 { "bufA" } else { "bufB" };
let dst_buf = if i%2 == 0 { "bufB" } else { "bufA" };
let c_source = format!(r#"
{{
{} const * restrict src = (void*) {};
{} * restrict dst = (void*) {};
FUSE( {} ( {}, src, dst );
}}"#,
src_c_type, src_buf,
dst_c_type, dst_buf,
map_fn,
item_morph_symbol,
);
Ok(LdmcPrimMorph{
symbol, type_args: Vec::new(), ty,
c_source
})
Ok(LdmcPrimMorph{
symbol, type_args: Vec::new(), ty,
c_source
})
} else {
eprintln!("Error: Unknown Seq- Representation!!");
Err(())
}
} else {
eprintln!("Error: Unknown Seq- Representation!!");
eprintln!("Error: missing Seq- Representation!!");
Err(())
}
} else {
eprintln!("Error: missing Seq- Representation!!");
eprintln!("failed to add item-morph instantiation");
Err(())
}
},