fix codegen for seq-map
This commit is contained in:
parent
98592aa596
commit
67cec64dfc
1 changed files with 33 additions and 42 deletions
75
src/c_gen.rs
75
src/c_gen.rs
|
@ -194,56 +194,47 @@ impl LdmcCTargetMorph {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
MorphismInstance2::MapSeq { ψ, seq_repr, item_morph } => {
|
MorphismInstance2::MapSeq { ψ, seq_repr, item_morph } => {
|
||||||
let i = 0; // <--todo
|
if let Ok(item_morph_inst) = self.add_instantiation(dict, item_morph.as_ref().clone()) {
|
||||||
self.add_instantiation(dict, item_morph.as_ref().clone()).expect("add instantiation");
|
if let Some(seq_repr) = seq_repr {
|
||||||
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());
|
let length_c_type = get_c_repr_type(dict, length_type.clone(), true).expect("cant c-repr type for array length");
|
||||||
if let Ok(γ) = laddertypes::unification_sugared::unify(
|
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");
|
||||||
&dict.parse("<LengthPrefix LengthType>").expect("parse type template").sugar(dict),
|
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");
|
||||||
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");
|
// todo: self.add_active_length_prefix_map()
|
||||||
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()
|
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_{}",
|
Ok(LdmcPrimMorph{
|
||||||
length_c_type, src_item_c_type, dst_item_c_type
|
symbol, type_args: Vec::new(), ty,
|
||||||
);
|
c_source
|
||||||
|
})
|
||||||
let src_buf = if i%2 == 0 { "bufA" } else { "bufB" };
|
} else {
|
||||||
let dst_buf = if i%2 == 0 { "bufB" } else { "bufA" };
|
eprintln!("Error: Unknown Seq- Representation!!");
|
||||||
let c_source = format!(r#"
|
Err(())
|
||||||
{{
|
}
|
||||||
{} 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
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Error: Unknown Seq- Representation!!");
|
eprintln!("Error: missing Seq- Representation!!");
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Error: missing Seq- Representation!!");
|
eprintln!("failed to add item-morph instantiation");
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue