adapt to changed MorphismInstance in lib-laddertypes
This commit is contained in:
parent
0564845951
commit
6897b5e274
3 changed files with 39 additions and 21 deletions
src
|
@ -6,9 +6,8 @@ use {
|
|||
morphism::LdmcPrimMorph
|
||||
},
|
||||
laddertypes::{
|
||||
parser::*, Morphism, MorphismInstance, MorphismType, TypeDict, TypeTerm
|
||||
},
|
||||
std::collections::HashMap
|
||||
parser::*, Morphism, MorphismInstance, MorphismType, Substitution, TypeDict, TypeID, TypeTerm
|
||||
}, std::{collections::HashMap, ops::Deref}
|
||||
};
|
||||
|
||||
pub struct LdmcCTargetMorph {
|
||||
|
@ -110,7 +109,8 @@ impl LdmcCTargetMorph {
|
|||
dict: &mut impl TypeDict,
|
||||
morph: MorphismInstance<LdmcPrimMorph>,
|
||||
) -> Result<LdmcPrimMorph, ()> {
|
||||
let new_inst = self.bake_morphism(dict, morph)?;
|
||||
let mut σ = HashMap::new();
|
||||
let new_inst = self.bake_morphism(dict, TypeTerm::unit(), &mut σ, morph)?;
|
||||
if ! self.active_morphisms.contains(&new_inst) {
|
||||
self.active_morphisms.push(new_inst.clone());
|
||||
}
|
||||
|
@ -124,6 +124,7 @@ impl LdmcCTargetMorph {
|
|||
|
||||
pub fn into_c_source(mut self, dict: &mut impl TypeDict) -> String {
|
||||
let mut source = String::new();
|
||||
self.active_headers.sort();
|
||||
self.active_headers.dedup();
|
||||
self.typedefs.dedup();
|
||||
self.macro_calls.dedup();
|
||||
|
@ -156,31 +157,40 @@ impl LdmcCTargetMorph {
|
|||
pub fn bake_morphism(
|
||||
&mut self,
|
||||
dict: &mut impl laddertypes::TypeDict,
|
||||
mut ψ: TypeTerm,
|
||||
σ: &mut HashMap<TypeID, TypeTerm>,
|
||||
morph_inst: MorphismInstance<LdmcPrimMorph>,
|
||||
) -> Result<LdmcPrimMorph, ()> {
|
||||
let ty = morph_inst.get_type();
|
||||
let symbol = encode_morph_type_to_symbol(dict, &ty);
|
||||
|
||||
match &morph_inst {
|
||||
MorphismInstance::Id { ψ } => {
|
||||
MorphismInstance::Id { τ } => {
|
||||
self.add_required_header_block("#include <string.h>".into());
|
||||
Ok(LdmcPrimMorph {
|
||||
symbol,
|
||||
type_args: Vec::new(),
|
||||
ty: MorphismType { src_type: ψ.clone(), dst_type: ψ.clone() },
|
||||
ty: MorphismType { src_type: τ.clone(), dst_type: τ.clone() },
|
||||
c_source: String::from("memcpy(dst, src, sizeof(*src));")
|
||||
})
|
||||
}
|
||||
MorphismInstance::Primitive { ψ, σ, morph } => {
|
||||
MorphismInstance::Sub { ψ:ψ1, m } => {
|
||||
ψ = TypeTerm::Ladder(vec![ ψ1.clone(), ψ.clone() ]).normalize();
|
||||
self.bake_morphism(dict, ψ, σ, m.deref().clone())
|
||||
}
|
||||
MorphismInstance::Specialize { σ:σ1, m } => {
|
||||
*σ = σ.clone().append(&σ1);
|
||||
self.bake_morphism(dict, ψ, σ, m.deref().clone())
|
||||
}
|
||||
MorphismInstance::Primitive { m: morph } => {
|
||||
if let Some(i) = self.header_dependencies.get(&morph.get_type()) {
|
||||
self.active_headers.push(*i);
|
||||
}
|
||||
|
||||
|
||||
let mut c_source = String::new();
|
||||
for (ty_id, kind) in morph.type_args.iter() {
|
||||
if let laddertypes::TypeID::Var(var_id) = ty_id {
|
||||
if let Some(val) = σ.get(ty_id) {
|
||||
if let Some(val) = σ.get(&ty_id) {
|
||||
let type_var_value =
|
||||
if kind == "Type" {
|
||||
get_c_repr_type(dict, val)
|
||||
|
@ -236,7 +246,7 @@ impl LdmcCTargetMorph {
|
|||
c_source
|
||||
})
|
||||
}
|
||||
MorphismInstance::MapSeq { ψ, seq_repr, item_morph } => {
|
||||
MorphismInstance::MapSeq { seq_repr, item_morph } => {
|
||||
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("Length".into());
|
||||
|
@ -342,7 +352,7 @@ impl LdmcCTargetMorph {
|
|||
Err(())
|
||||
}
|
||||
},
|
||||
MorphismInstance::MapStruct { ψ, src_struct_repr, dst_struct_repr, member_morph } => {
|
||||
MorphismInstance::MapStruct { src_struct_repr, dst_struct_repr, member_morph } => {
|
||||
|
||||
let mut c_source = String::new();
|
||||
|
||||
|
@ -367,7 +377,7 @@ impl LdmcCTargetMorph {
|
|||
c_source
|
||||
})
|
||||
}
|
||||
MorphismInstance::MapEnum { ψ, enum_repr, variant_morph } => {
|
||||
MorphismInstance::MapEnum { enum_repr, variant_morph } => {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,10 @@ use {
|
|||
crate::{
|
||||
morphism::LdmcPrimMorph,
|
||||
parser::morphism_base_parser,
|
||||
viz::{Visualization, MorphbaseVisualizationPane},
|
||||
viz::{MorphbaseVisualizationPane, Visualization},
|
||||
},
|
||||
ariadne::{Color, Label, Report, ReportKind, Source}, clap::Parser, laddertypes::{
|
||||
morphism::MorphismType, BimapTypeDict, Morphism
|
||||
morphism::MorphismType, morphism_graph::MorphismGraph, BimapTypeDict, Morphism
|
||||
},
|
||||
parser::morphism_type_parser, std::{io::Write, path::PathBuf, str::FromStr, sync::{Arc, RwLock}},
|
||||
tiny_ansi::TinyAnsi,
|
||||
|
@ -128,11 +128,12 @@ fn main() {
|
|||
|
||||
// 2. Generate Morphisms
|
||||
let mut instances = Vec::new();
|
||||
let mut morph_graph = MorphismGraph::new(morphism_base);
|
||||
for morph_decl in args.morphisms.iter() {
|
||||
use chumsky::Parser;
|
||||
if let Ok((name, src_type, dst_type)) = morphism_type_parser(type_dict.clone()).parse(morph_decl.as_str()) {
|
||||
let ty = MorphismType{ src_type, dst_type };
|
||||
let morph_inst = morphism_base.get_morphism_instance( &ty ).expect("failed to find morphism");
|
||||
let morph_inst = morph_graph.search( ty, &mut type_dict ).expect("failed to find morphism");
|
||||
viz.add_module(name.clone());
|
||||
viz.add_morph_inst(name.clone(), morph_inst.clone(), &mut type_dict);
|
||||
instances.push( (name, morph_inst) );
|
||||
|
|
|
@ -254,20 +254,27 @@ impl Layout {
|
|||
|
||||
subnames: &mut Vec<String>,
|
||||
) {
|
||||
let ψ = TypeTerm::unit();
|
||||
match inst {
|
||||
MorphismInstance::Id { ψ } => {
|
||||
MorphismInstance::Id { τ } => {
|
||||
|
||||
}
|
||||
MorphismInstance::Primitive { ψ, σ, morph } => {
|
||||
MorphismInstance::Sub { ψ:ψ1, m } => {
|
||||
|
||||
}
|
||||
MorphismInstance::Specialize { σ, m } => {
|
||||
|
||||
}
|
||||
MorphismInstance::Primitive { m: morph } => {
|
||||
subnames.push( morph.symbol.clone() );
|
||||
self.add_chained_type(nodes, edges, ψ.clone(), morph.get_type().dst_type, morph.symbol.clone());
|
||||
self.add_chained_type(nodes, edges, ψ, morph.get_type().dst_type, morph.symbol.clone());
|
||||
},
|
||||
MorphismInstance::Chain { path } => {
|
||||
for m in path.iter() {
|
||||
self.add_morph_inst(nodes, edges, m, dict, subnames);
|
||||
}
|
||||
},
|
||||
MorphismInstance::MapSeq { ψ, seq_repr, item_morph } => {
|
||||
MorphismInstance::MapSeq { seq_repr, item_morph } => {
|
||||
let mut map_group_svg = String::new();
|
||||
let name = format!("{}-{}-SeqItem", self.nameprefix, self.i);
|
||||
|
||||
|
@ -320,7 +327,7 @@ impl Layout {
|
|||
|
||||
self.pos.0 += ( pane.get_extent().end.0 - pane.get_extent().begin.0 );
|
||||
},
|
||||
MorphismInstance::MapStruct { ψ, src_struct_repr, dst_struct_repr, member_morph } => {
|
||||
MorphismInstance::MapStruct { src_struct_repr, dst_struct_repr, member_morph } => {
|
||||
let mut map_group_svg = String::new();
|
||||
|
||||
map_group_svg.push_str(&format!(r##"<g class="map-group" transform="translate({},{})">"##, self.pos.0, self.pos.1 ));
|
||||
|
@ -381,7 +388,7 @@ impl Layout {
|
|||
|
||||
self.pos.0 += ( members_extent.end.0 - members_extent.begin.0 );
|
||||
},
|
||||
MorphismInstance::MapEnum { ψ, enum_repr, variant_morph } => {
|
||||
MorphismInstance::MapEnum { enum_repr, variant_morph } => {
|
||||
todo!()
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue