Compare commits

..

No commits in common. "7226cb0162a8ea04530f7dbcbed717caad55507a" and "0bcfd7a65aeb8696c79530df49f29fc520f93bf1" have entirely different histories.

4 changed files with 30 additions and 97 deletions

View file

@ -116,13 +116,9 @@ impl RadixProjection {
if val == 0 { if val == 0 {
self.dst_digits.push(0); self.dst_digits.push(0);
} else { } else {
if self.dst_radix == 0 { while val > 0 {
self.dst_digits.push(val); self.dst_digits.push(val % self.dst_radix);
} else { val /= self.dst_radix;
while val > 0 {
self.dst_digits.push(val % self.dst_radix);
val /= self.dst_radix;
}
} }
} }
} }

View file

@ -13,14 +13,6 @@ 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)] #[derive(Clone)]
pub struct Context { pub struct Context {
/// assigns a name to every type /// assigns a name to every type
@ -43,27 +35,19 @@ pub struct Context {
parent: Option<Arc<RwLock<Context>>>, parent: Option<Arc<RwLock<Context>>>,
} }
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
impl Context { impl Context {
pub fn with_parent( pub fn with_parent(
parent: Option<Arc<RwLock<Context>>> parent: Option<Arc<RwLock<Context>>>
) -> Self { ) -> Self {
let mut dict = TypeDict::new();
let list_typeid = dict.add_typename("List".into());
Context { Context {
type_dict: match parent.as_ref() { type_dict: match parent.as_ref() {
Some(p) => p.read().unwrap().type_dict.clone(), Some(p) => p.read().unwrap().type_dict.clone(),
None => { None => Arc::new(RwLock::new(dict))
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( TYPEID_list ), morphisms: MorphismBase::new( list_typeid ),
nodes: HashMap::new(), nodes: HashMap::new(),
list_types: match parent.as_ref() { list_types: match parent.as_ref() {
Some(p) => p.read().unwrap().list_types.clone(), Some(p) => p.read().unwrap().list_types.clone(),

View file

@ -122,64 +122,29 @@ impl GenericReprTreeMorphism {
pub fn into_list_map_dyn(&self, typeid_list: TypeID) pub fn into_list_map_dyn(&self, typeid_list: TypeID)
-> Option< GenericReprTreeMorphism > -> 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 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(); let dst_item_type_lnf = self.morph_type.dst_type.clone().get_lnf_vec();
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_u64))
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, char >(TYPEID_list) ) Some( self.into_list_map::< char, u64 >(typeid_list) )
} }
else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_u64)) && else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(typeid_u64)) &&
dst_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, u64 >(TYPEID_list) ) Some( self.into_list_map::< u64, char >(typeid_list) )
} }
else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_char)) && else if src_item_type_lnf.last() == Some(&TypeTerm::TypeID(typeid_char)) &&
dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(TYPEID_u64)) dst_item_type_lnf.last() == Some(&TypeTerm::TypeID(typeid_edittree))
{ {
Some( self.into_list_map::< char, u64 >(TYPEID_list) ) 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_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 else
{ {
eprintln!("no list map type for {:?}", dst_item_type_lnf.last()); eprintln!("no list map type for {:?}", dst_item_type_lnf.last());

View file

@ -19,7 +19,7 @@ use {
sync::{Arc, RwLock}, sync::{Arc, RwLock},
any::Any any::Any
}, },
super::{Context, ReprLeaf, ReprTreeExt, context::{TYPEID_vec, TYPEID_char, TYPEID_u64, TYPEID_edittree}} super::{Context, ReprLeaf, ReprTreeExt}
}; };
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
@ -139,6 +139,7 @@ impl ReprTree {
Arc::new(RwLock::new(rt)) Arc::new(RwLock::new(rt))
} }
pub fn from_str( pub fn from_str(
type_tag: impl Into<TypeTerm>, type_tag: impl Into<TypeTerm>,
val: &str val: &str
@ -203,13 +204,13 @@ impl ReprTree {
return; return;
} }
} }
if let Some(leaf) = self.leaf.as_mut() { if let Some(leaf) = self.leaf.as_mut() {
leaf.attach_to(src_port); leaf.attach_to(src_port);
} else { } else {
if self.type_tag == TypeTerm::App(vec![ if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_vec), TypeTerm::TypeID(TypeID::Fun(11)),
TypeTerm::TypeID(TYPEID_edittree) TypeTerm::TypeID(TypeID::Fun(2))
]) { ]) {
let mut leaf = ReprLeaf::from_vec_buffer( let mut leaf = ReprLeaf::from_vec_buffer(
VecBuffer::< VecBuffer::<
@ -221,8 +222,8 @@ impl ReprTree {
self.leaf = Some(leaf); self.leaf = Some(leaf);
} }
else if self.type_tag == TypeTerm::App(vec![ else if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_vec), TypeTerm::TypeID(TypeID::Fun(11)),
TypeTerm::TypeID(TYPEID_char) TypeTerm::TypeID(TypeID::Fun(1))
]) { ]) {
let mut leaf = ReprLeaf::from_vec_buffer( let mut leaf = ReprLeaf::from_vec_buffer(
VecBuffer::<char>::new() VecBuffer::<char>::new()
@ -230,25 +231,13 @@ impl ReprTree {
leaf.attach_to(src_port); leaf.attach_to(src_port);
self.leaf = Some(leaf); 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)); self.leaf = Some(ReprLeaf::from_view(src_port));
} }
} }
} }
pub fn detach(&mut self, ctx: &Arc<RwLock<Context>>) { pub fn detach(&mut self, ctx: &Arc<RwLock<Context>>) {
// eprintln!("DETACH {:?}", self.get_type());
if let Some(leaf) = self.leaf.as_mut() { if let Some(leaf) = self.leaf.as_mut() {
if self.type_tag == Context::parse(&ctx, "Char") { if self.type_tag == Context::parse(&ctx, "Char") {
leaf.detach::<dyn SingletonView<Item = char>>(); leaf.detach::<dyn SingletonView<Item = char>>();
@ -403,4 +392,3 @@ impl ReprTree {
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>