diff --git a/lib-nested-core/src/repr_tree/context.rs b/lib-nested-core/src/repr_tree/context.rs index e7cad72..37f16ae 100644 --- a/lib-nested-core/src/repr_tree/context.rs +++ b/lib-nested-core/src/repr_tree/context.rs @@ -1,7 +1,7 @@ use { crate::{ edit_tree::EditTree, - repr_tree::{GenericReprTreeMorphism, ReprTree, ReprTreeExt}, + repr_tree::{GenericReprTreeMorphism, ReprTree, ReprTreeExt, ReprTreeArc}, }, laddertypes::{ parser::ParseLadderType, sugar::SugaredTypeTerm, unparser::UnparseLadderType, @@ -152,7 +152,7 @@ impl Context { } } - pub fn make_repr(ctx: &Arc>, t: &TypeTerm) -> Arc> { + pub fn make_repr(ctx: &Arc>, t: &TypeTerm) -> ReprTreeArc { let rt = Arc::new(RwLock::new(ReprTree::new( TypeTerm::unit() ))); ctx.read().unwrap().apply_morphism( &rt, &MorphismType{ src_type: TypeTerm::unit(), dst_type: t.clone() } ); rt @@ -242,7 +242,7 @@ impl Context { */ } - pub fn get_obj(&self, name: &String) -> Option< Arc> > { + pub fn get_obj(&self, name: &String) -> Option< ReprTreeArc > { if let Some(obj) = self.nodes.get(name) { Some(obj.clone()) } else if let Some(parent) = self.parent.as_ref() { diff --git a/lib-nested-core/src/repr_tree/mod.rs b/lib-nested-core/src/repr_tree/mod.rs index 8af48f8..e77774f 100644 --- a/lib-nested-core/src/repr_tree/mod.rs +++ b/lib-nested-core/src/repr_tree/mod.rs @@ -9,7 +9,7 @@ mod tests; pub use { context::{Context}, leaf::ReprLeaf, - node::ReprTree, + node::{ReprTree, ReprTreeArc}, morphism::{GenericReprTreeMorphism} }; @@ -42,7 +42,7 @@ pub trait ReprTreeExt { fn insert_leaf(&mut self, type_ladder: impl Into, leaf: ReprLeaf); fn insert_branch(&mut self, repr: Arc>); fn create_branch(&mut self, rung: impl Into); - fn descend(&self, target_type: impl Into) -> Option>>; + fn descend(&self, target_type: impl Into) -> Option< ReprTreeArc >; fn attach_leaf_to(&self, t: impl Into, v: OuterViewPort) where V::Msg: Clone; fn get_port(&self) -> Option> where V::Msg: Clone; @@ -100,7 +100,7 @@ impl ReprTreeExt for Arc> { self.write().unwrap().attach_leaf_to::(type_ladder.into().get_lnf_vec().into_iter(), v) } - fn descend(&self, target_type: impl Into) -> Option>> { + fn descend(&self, target_type: impl Into) -> Option< ReprTreeArc > { ReprTree::descend( self, target_type ) } diff --git a/lib-nested-core/src/repr_tree/node.rs b/lib-nested-core/src/repr_tree/node.rs index 837092e..bef682b 100644 --- a/lib-nested-core/src/repr_tree/node.rs +++ b/lib-nested-core/src/repr_tree/node.rs @@ -28,10 +28,12 @@ use { pub struct ReprTree { halo: TypeTerm, type_tag: TypeTerm, - branches: HashMap>>, + branches: HashMap, leaf: Option< ReprLeaf > } +pub type ReprTreeArc = Arc>; + //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> impl std::fmt::Debug for ReprTree { @@ -67,7 +69,7 @@ impl ReprTree { } } - pub fn new_arc(type_tag: impl Into) -> Arc> { + pub fn new_arc(type_tag: impl Into) -> ReprTreeArc { Arc::new(RwLock::new(Self::new(type_tag))) } @@ -106,7 +108,7 @@ impl ReprTree { leaf_types } - pub fn insert_branch(&mut self, repr: Arc>) { + pub fn insert_branch(&mut self, repr: ReprTreeArc) { let branch_type = repr.read().unwrap().get_type().clone(); assert!(branch_type.is_flat()); @@ -119,14 +121,14 @@ impl ReprTree { self.branches.insert(branch_type, repr.clone()); } - pub fn from_char(ctx: &Arc>, c: char ) -> Arc> { + pub fn from_char(ctx: &Arc>, c: char ) -> ReprTreeArc { ReprTree::from_singleton_buffer( Context::parse(ctx, "Char"), SingletonBuffer::new(c) ) } - pub fn from_view( type_tag: impl Into, view: OuterViewPort ) -> Arc> + pub fn from_view( type_tag: impl Into, view: OuterViewPort ) -> ReprTreeArc where V: View + ?Sized + 'static, V::Msg: Clone { @@ -135,7 +137,7 @@ impl ReprTree { Arc::new(RwLock::new(rt)) } - pub fn from_singleton_buffer( type_tag: impl Into, buf: SingletonBuffer ) -> Arc> + pub fn from_singleton_buffer( type_tag: impl Into, buf: SingletonBuffer ) -> ReprTreeArc where T: Clone + Send + Sync + 'static { let mut rt = ReprTree::new(type_tag); @@ -146,7 +148,7 @@ impl ReprTree { pub fn from_str( type_tag: impl Into, val: &str - ) -> Arc> { + ) -> ReprTreeArc { let mut lnf = type_tag.into().get_lnf_vec(); let mut rt = ReprTree::from_vec_buffer( @@ -163,7 +165,7 @@ impl ReprTree { rt } - pub fn from_vec_buffer( type_tag: impl Into, buf: VecBuffer ) -> Arc> + pub fn from_vec_buffer( type_tag: impl Into, buf: VecBuffer ) -> ReprTreeArc where T: Clone + Send + Sync + 'static { let mut rt = ReprTree::new(type_tag); @@ -340,13 +342,13 @@ impl ReprTree { //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - pub fn descend_one(&self, dst_type: impl Into) -> Option>> { + pub fn descend_one(&self, dst_type: impl Into) -> Option< ReprTreeArc > { let dst_type = dst_type.into(); assert!( dst_type.is_flat() ); self.branches.get(&dst_type).cloned() } - pub fn descend_ladder(rt: &Arc>, mut repr_ladder: impl Iterator) -> Option>> { + pub fn descend_ladder(rt: &Arc>, mut repr_ladder: impl Iterator) -> Option< ReprTreeArc > { if let Some(first) = repr_ladder.next() { let rt = rt.read().unwrap(); repr_ladder.fold( @@ -357,7 +359,7 @@ impl ReprTree { } } - pub fn descend(rt: &Arc>, dst_type: impl Into) -> Option>> { + pub fn descend(rt: &Arc>, dst_type: impl Into) -> Option< ReprTreeArc > { let mut lnf = dst_type.into().get_lnf_vec(); if lnf.len() > 0 { if lnf[0] == rt.get_type() {