add static TypeIDs to create basic types without context
This commit is contained in:
parent
e7331b36ae
commit
fb796cda04
3 changed files with 95 additions and 29 deletions
|
@ -13,6 +13,14 @@ use {
|
|||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
pub static TYPEID_edittree : TypeID = TypeID::Fun(0);
|
||||
pub static TYPEID_char : TypeID = TypeID::Fun(1);
|
||||
pub static TYPEID_u64 : TypeID = TypeID::Fun(2);
|
||||
pub static TYPEID_list : TypeID = TypeID::Fun(3);
|
||||
pub static TYPEID_vec : TypeID = TypeID::Fun(4);
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Context {
|
||||
/// assigns a name to every type
|
||||
|
@ -35,19 +43,27 @@ pub struct Context {
|
|||
parent: Option<Arc<RwLock<Context>>>,
|
||||
}
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
impl Context {
|
||||
pub fn with_parent(
|
||||
parent: Option<Arc<RwLock<Context>>>
|
||||
) -> Self {
|
||||
let mut dict = TypeDict::new();
|
||||
let list_typeid = dict.add_typename("List".into());
|
||||
|
||||
Context {
|
||||
type_dict: match parent.as_ref() {
|
||||
Some(p) => p.read().unwrap().type_dict.clone(),
|
||||
None => Arc::new(RwLock::new(dict))
|
||||
None => {
|
||||
let mut dict = TypeDict::new();
|
||||
assert_eq!( TYPEID_edittree, dict.add_typename("EditTree".into()) );
|
||||
assert_eq!( TYPEID_char, dict.add_typename("Char".into()) );
|
||||
assert_eq!( TYPEID_u64, dict.add_typename("machine.UInt64".into()) );
|
||||
assert_eq!( TYPEID_list, dict.add_typename("List".into()) );
|
||||
assert_eq!( TYPEID_vec, dict.add_typename("Vec".into()) );
|
||||
|
||||
Arc::new(RwLock::new(dict))
|
||||
}
|
||||
},
|
||||
morphisms: MorphismBase::new( list_typeid ),
|
||||
morphisms: MorphismBase::new( TYPEID_list ),
|
||||
nodes: HashMap::new(),
|
||||
list_types: match parent.as_ref() {
|
||||
Some(p) => p.read().unwrap().list_types.clone(),
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
use {
|
||||
laddertypes::{TypeTerm, TypeID, morphism::Morphism},
|
||||
r3vi::view::{AnyOuterViewPort, port::UpdateTask},
|
||||
r3vi::view::{AnyOuterViewPort, port::*, list::*},
|
||||
crate::{
|
||||
repr_tree::{ReprTree, ReprTreeExt, ReprLeaf},
|
||||
repr_tree::{
|
||||
ReprTree, ReprTreeExt, ReprLeaf,
|
||||
context::{*}
|
||||
},
|
||||
},
|
||||
std::{
|
||||
sync::{Arc, RwLock},
|
||||
|
@ -123,28 +126,63 @@ impl GenericReprTreeMorphism {
|
|||
pub fn into_list_map_dyn(&self, typeid_list: TypeID)
|
||||
-> Option< GenericReprTreeMorphism >
|
||||
{
|
||||
let typeid_char = TypeID::Fun(1);
|
||||
let typeid_u64 = TypeID::Fun(5);
|
||||
let typeid_edittree = TypeID::Fun(2);
|
||||
|
||||
let src_item_type_lnf = self.morph_type.src_type.clone().get_lnf_vec();
|
||||
let dst_item_type_lnf = self.morph_type.dst_type.clone().get_lnf_vec();
|
||||
|
||||
if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(typeid_char)) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(typeid_u64))
|
||||
eprintln!("into list map dyn");
|
||||
|
||||
if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_char)) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_char))
|
||||
{
|
||||
Some( self.into_list_map::< char, u64 >(typeid_list) )
|
||||
Some( self.into_list_map::< char, char >(TYPEID_list) )
|
||||
}
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(typeid_u64)) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(typeid_char))
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_u64)) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_u64))
|
||||
{
|
||||
Some( self.into_list_map::< u64, char >(typeid_list) )
|
||||
Some( self.into_list_map::< u64, u64 >(TYPEID_list) )
|
||||
}
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(typeid_char)) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(typeid_edittree))
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_char)) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_u64))
|
||||
{
|
||||
Some( self.into_list_map::< char, Arc<RwLock<crate::edit_tree::EditTree>> >(typeid_list) )
|
||||
Some( self.into_list_map::< char, u64 >(TYPEID_list) )
|
||||
}
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_u64)) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_char))
|
||||
{
|
||||
Some( self.into_list_map::< u64, char >(TYPEID_list) )
|
||||
}
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_char)) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_edittree))
|
||||
{
|
||||
Some( self.into_list_map::< char, Arc<RwLock<crate::edit_tree::EditTree>> >(TYPEID_list) )
|
||||
}
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_edittree)) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_char))
|
||||
{
|
||||
Some( self.into_list_map::< Arc<RwLock<crate::edit_tree::EditTree>>, char >(TYPEID_list) )
|
||||
}
|
||||
/*
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::App(vec![ TypeTerm::TypeID(typeid_list), TypeTerm::TypeID(typeid_char) ])) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::App(vec![ TypeTerm::TypeID(typeid_list), TypeTerm::TypeID(typeid_char) ]))
|
||||
{
|
||||
Some( self.into_list_map::< char, char >(typeid_list) )
|
||||
}
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::App(vec![ TypeTerm::TypeID(typeid_list), TypeTerm::TypeID(typeid_u64) ])) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::App(vec![ TypeTerm::TypeID(typeid_list), TypeTerm::TypeID(typeid_u64) ]))
|
||||
{
|
||||
Some( self.into_list_map::< u64, u64 >(typeid_list) )
|
||||
}
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::App(vec![ TypeTerm::TypeID(typeid_list), TypeTerm::TypeID(typeid_char) ])) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::App(vec![ TypeTerm::TypeID(typeid_list), TypeTerm::TypeID(typeid_u64) ]))
|
||||
{
|
||||
Some( self.into_list_map::< OuterViewPort<dyn ListView<char>>, OuterViewPort<dyn ListView<u64>> >(typeid_list) )
|
||||
}
|
||||
else if src_item_type_lnf.last() == Some(&TypeTerm::App(vec![ TypeTerm::TypeID(typeid_list), TypeTerm::TypeID(typeid_u64) ])) &&
|
||||
dst_item_type_lnf.last() == Some(&TypeTerm::App(vec![ TypeTerm::TypeID(typeid_list), TypeTerm::TypeID(typeid_char) ]))
|
||||
{
|
||||
Some( self.into_list_map::< OuterViewPort<dyn ListView<u64>>, OuterViewPort<dyn ListView<char>> >(typeid_list) )
|
||||
}
|
||||
*/
|
||||
else
|
||||
{
|
||||
eprintln!("no list map type for {:?}", dst_item_type_lnf.last());
|
||||
|
|
|
@ -19,7 +19,7 @@ use {
|
|||
sync::{Arc, RwLock},
|
||||
any::Any
|
||||
},
|
||||
super::{Context, ReprLeaf, ReprTreeExt}
|
||||
super::{Context, ReprLeaf, ReprTreeExt, context::{TYPEID_vec, TYPEID_char, TYPEID_u64, TYPEID_edittree}}
|
||||
};
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
@ -139,7 +139,6 @@ impl ReprTree {
|
|||
Arc::new(RwLock::new(rt))
|
||||
}
|
||||
|
||||
|
||||
pub fn from_str(
|
||||
type_tag: impl Into<TypeTerm>,
|
||||
val: &str
|
||||
|
@ -209,8 +208,8 @@ impl ReprTree {
|
|||
leaf.attach_to(src_port);
|
||||
} else {
|
||||
if self.type_tag == TypeTerm::App(vec![
|
||||
TypeTerm::TypeID(TypeID::Fun(11)),
|
||||
TypeTerm::TypeID(TypeID::Fun(2))
|
||||
TypeTerm::TypeID(TYPEID_vec),
|
||||
TypeTerm::TypeID(TYPEID_edittree)
|
||||
]) {
|
||||
let mut leaf = ReprLeaf::from_vec_buffer(
|
||||
VecBuffer::<
|
||||
|
@ -222,8 +221,8 @@ impl ReprTree {
|
|||
self.leaf = Some(leaf);
|
||||
}
|
||||
else if self.type_tag == TypeTerm::App(vec![
|
||||
TypeTerm::TypeID(TypeID::Fun(11)),
|
||||
TypeTerm::TypeID(TypeID::Fun(1))
|
||||
TypeTerm::TypeID(TYPEID_vec),
|
||||
TypeTerm::TypeID(TYPEID_char)
|
||||
]) {
|
||||
let mut leaf = ReprLeaf::from_vec_buffer(
|
||||
VecBuffer::<char>::new()
|
||||
|
@ -231,13 +230,25 @@ impl ReprTree {
|
|||
|
||||
leaf.attach_to(src_port);
|
||||
self.leaf = Some(leaf);
|
||||
} else {
|
||||
}
|
||||
else if self.type_tag == TypeTerm::App(vec![
|
||||
TypeTerm::TypeID(TYPEID_vec),
|
||||
TypeTerm::TypeID(TYPEID_u64)
|
||||
]) {
|
||||
let mut leaf = ReprLeaf::from_vec_buffer(
|
||||
VecBuffer::<u64>::new()
|
||||
);
|
||||
|
||||
leaf.attach_to(src_port);
|
||||
self.leaf = Some(leaf);
|
||||
} else {
|
||||
self.leaf = Some(ReprLeaf::from_view(src_port));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn detach(&mut self, ctx: &Arc<RwLock<Context>>) {
|
||||
// eprintln!("DETACH {:?}", self.get_type());
|
||||
if let Some(leaf) = self.leaf.as_mut() {
|
||||
if self.type_tag == Context::parse(&ctx, "Char") {
|
||||
leaf.detach::<dyn SingletonView<Item = char>>();
|
||||
|
@ -392,3 +403,4 @@ impl ReprTree {
|
|||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue