add morphisms to create edittree from/to digit/char and generic lists
This commit is contained in:
parent
2749e41fce
commit
fea21dbda1
5 changed files with 125 additions and 66 deletions
|
@ -25,49 +25,63 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
|||
{
|
||||
let ctx = ctx.clone();
|
||||
move |rt, σ| {
|
||||
|
||||
{
|
||||
let mut b = rt.write().unwrap().singleton_buffer::<char>();
|
||||
if let Some(buf) = b {
|
||||
// buffer already exists
|
||||
} else {
|
||||
// create char buffer
|
||||
rt.write().unwrap().insert_leaf(
|
||||
vec![].into_iter(),
|
||||
ReprLeaf::from_singleton_buffer(
|
||||
SingletonBuffer::new('\0')
|
||||
)
|
||||
);
|
||||
}
|
||||
if let Some(buf) = b {
|
||||
// buffer already exists
|
||||
} else {
|
||||
// create char buffer
|
||||
rt.write().unwrap().insert_leaf(
|
||||
vec![].into_iter(),
|
||||
ReprLeaf::from_singleton_buffer(SingletonBuffer::new('\0'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let char_buf = rt.singleton_buffer::<char>();
|
||||
let mut edittree = CharEditor::new_edit_tree(
|
||||
ctx.clone(),
|
||||
char_buf,
|
||||
SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
let char_buf = rt.singleton_buffer::<char>();
|
||||
|
||||
let mut edittree = CharEditor::new_edit_tree(
|
||||
ctx.clone(),
|
||||
char_buf,
|
||||
SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
rt.insert_leaf(
|
||||
rt.insert_leaf(
|
||||
Context::parse(&ctx, "EditTree"),
|
||||
ReprLeaf::from_singleton_buffer(
|
||||
SingletonBuffer::new(
|
||||
Arc::new(RwLock::new(edittree))
|
||||
)
|
||||
)
|
||||
);
|
||||
);
|
||||
|
||||
ctx.read().unwrap().setup_edittree(
|
||||
rt.clone(),
|
||||
SingletonBuffer::new(0).get_port()
|
||||
);
|
||||
}
|
||||
|
||||
ctx.read().unwrap().setup_edittree(rt);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
let char_morph_from_edittree = GenericReprTreeMorphism::new(
|
||||
Context::parse(&ctx, "Char~EditTree"),
|
||||
Context::parse(&ctx, "Char"),
|
||||
{
|
||||
let ctx = ctx.clone();
|
||||
move |rt, σ|
|
||||
{
|
||||
let mut b = rt
|
||||
.descend(Context::parse(&ctx, "EditTree")).unwrap()
|
||||
.view_singleton::<Arc<RwLock<EditTree>>>();
|
||||
|
||||
rt.attach_leaf_to(
|
||||
Context::parse(&ctx, "Char"),
|
||||
b.map(|x|
|
||||
x.read().unwrap()
|
||||
.get_edit::<CharEditor>().unwrap()
|
||||
.read().unwrap()
|
||||
.get())
|
||||
);
|
||||
}
|
||||
});
|
||||
ctx.write().unwrap().morphisms.add_morphism( char_morph_to_edittree );
|
||||
ctx.write().unwrap().morphisms.add_morphism( char_morph_from_edittree );
|
||||
}
|
||||
|
||||
pub struct CharEditor {
|
||||
|
|
|
@ -19,6 +19,43 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
|||
// todo: proper scoping of Radix variable
|
||||
ctx.write().unwrap().add_varname("Radix");
|
||||
|
||||
let digit_make_edittree = GenericReprTreeMorphism::new(
|
||||
Context::parse(&ctx, "<Digit Radix>"),
|
||||
Context::parse(&ctx, "<Digit Radix>~EditTree"),
|
||||
{
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let radix =
|
||||
match σ.get( &laddertypes::TypeID::Var(ctx.read().unwrap().get_var_typeid("Radix").unwrap()) ) {
|
||||
Some(TypeTerm::Num(n)) => *n as u32,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
let char_buf = SingletonBuffer::<char>::new('?');
|
||||
|
||||
/* Create EditTree object
|
||||
*/
|
||||
let mut edittree = DigitEditor::new(
|
||||
ctx.clone(),
|
||||
radix,
|
||||
char_buf
|
||||
).into_node(
|
||||
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
src_rt.write().unwrap()
|
||||
.insert_branch(
|
||||
ReprTree::from_singleton_buffer(
|
||||
Context::parse(&ctx, "EditTree"),
|
||||
SingletonBuffer::new(Arc::new(RwLock::new(edittree)))
|
||||
)
|
||||
);
|
||||
|
||||
ctx.read().unwrap().setup_edittree( src_rt );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
let digit_morph_char_to_edittree = GenericReprTreeMorphism::new(
|
||||
Context::parse(&ctx, "<Digit Radix>~Char"),
|
||||
Context::parse(&ctx, "<Digit Radix>~EditTree"),
|
||||
|
@ -57,6 +94,30 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
|||
}
|
||||
);
|
||||
|
||||
let digit_morph_char_from_edittree = GenericReprTreeMorphism::new(
|
||||
Context::parse(&ctx, "<Digit Radix>~EditTree"),
|
||||
Context::parse(&ctx, "<Digit Radix>~Char"),
|
||||
|
||||
{
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let edittree = src_rt.edittree( &ctx );
|
||||
let port =
|
||||
edittree
|
||||
.get()
|
||||
.read().unwrap()
|
||||
.get_edit::<DigitEditor>().unwrap()
|
||||
.read().unwrap()
|
||||
.get_char_port();
|
||||
|
||||
src_rt.insert_leaf(
|
||||
Context::parse(&ctx, "Char"),
|
||||
ReprLeaf::from_view( port )
|
||||
)
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
let digit_morph_char_to_u64 = GenericReprTreeMorphism::new(
|
||||
Context::parse(&ctx, "<Digit Radix>~Char"),
|
||||
Context::parse(&ctx, "<Digit Radix>~ℤ_2^64~machine.UInt64"),
|
||||
|
@ -134,7 +195,9 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
|||
);
|
||||
|
||||
|
||||
ctx.write().unwrap().morphisms.add_morphism( digit_make_edittree );
|
||||
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_to_edittree );
|
||||
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_from_edittree );
|
||||
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_to_u64 );
|
||||
ctx.write().unwrap().morphisms.add_morphism( digit_morph_u64_to_char );
|
||||
}
|
||||
|
|
|
@ -59,6 +59,10 @@ impl DigitEditor {
|
|||
*/
|
||||
}
|
||||
|
||||
pub fn get_char_port(&self) -> OuterViewPort<dyn SingletonView<Item = char>> {
|
||||
self.data.get_port()
|
||||
}
|
||||
|
||||
pub fn get_data_port(&self) -> OuterViewPort<dyn SingletonView<Item = Result<u32, char>>> {
|
||||
let radix = self.radix;
|
||||
self.data.get_port().map(move |c|
|
||||
|
|
|
@ -63,36 +63,24 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
}
|
||||
);
|
||||
|
||||
|
||||
let list_morph_editsetup2 = GenericReprTreeMorphism::new(
|
||||
Context::parse(&ctx, "<List Char>~EditTree"),
|
||||
Context::parse(&ctx, "<List Char>"),
|
||||
let list_morph_editsetup3 = GenericReprTreeMorphism::new(
|
||||
Context::parse(&ctx, "<List Item> ~ EditTree"),
|
||||
Context::parse(&ctx, "<List Item> ~ <List EditTree>"),
|
||||
{
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let edittree =
|
||||
src_rt
|
||||
.descend(Context::parse(&ctx, "<List Char>~EditTree")).unwrap()
|
||||
.singleton_buffer::<Arc<RwLock<EditTree>>>();
|
||||
|
||||
let edittree = src_rt.edittree( &ctx );
|
||||
let list_edit = edittree.get().read().unwrap().get_edit::< ListEditor >().unwrap();
|
||||
let edittree_items = list_edit.read().unwrap().data.get_port().to_list();
|
||||
|
||||
src_rt.insert_leaf(
|
||||
Context::parse(&ctx, "<List Char>"),
|
||||
ReprLeaf::from_view(
|
||||
edittree_items
|
||||
.map(|edittree_char|
|
||||
edittree_char
|
||||
.read().unwrap()
|
||||
.get_edit::<CharEditor>().unwrap()
|
||||
.read().unwrap()
|
||||
.get()
|
||||
)
|
||||
)
|
||||
eprintln!("edittree_items.len() = {:?}", edittree_items.get_view().unwrap().len());
|
||||
|
||||
src_rt.attach_leaf_to(
|
||||
Context::parse(&ctx, "<List Item> ~ <List EditTree>")
|
||||
.apply_substitution(&|x| σ.get(x).cloned()).clone(),
|
||||
edittree_items
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -132,21 +120,14 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
{
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let p =
|
||||
src_rt
|
||||
.descend(Context::parse(&ctx, "<List EditTree>")).expect("descend")
|
||||
.get_port::<dyn ListView< Arc<RwLock<EditTree>> >>().unwrap();
|
||||
|
||||
src_rt.attach_leaf_to(
|
||||
Context::parse(&ctx, "<List EditTree> ~ <Vec EditTree>"),
|
||||
p
|
||||
);
|
||||
let list_port = src_rt.get_port::<dyn ListView< Arc<RwLock<EditTree>> >>().unwrap();
|
||||
src_rt.attach_leaf_to( Context::parse(&ctx, "<Vec EditTree>"), list_port );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup1 );
|
||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup2 );
|
||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup3 );
|
||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_from_vec_char );
|
||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_char );
|
||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_edittree );
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use {
|
||||
r3vi::{
|
||||
view::{OuterViewPort, singleton::*, sequence::*},
|
||||
buffer::{singleton::*, vec::*}
|
||||
buffer::{singleton::*, vec::*},
|
||||
projection::*
|
||||
},
|
||||
laddertypes::{TypeTerm},
|
||||
crate::{
|
||||
|
@ -319,11 +320,7 @@ impl ListEditor {
|
|||
let mut b = item.ctrl.spillbuf.write().unwrap();
|
||||
|
||||
let rt = ReprTree::new_arc(self.typ.clone());
|
||||
let mut et = self.ctx.read().unwrap()
|
||||
.setup_edittree(
|
||||
&rt
|
||||
// , self.depth.map(|d| d+1)
|
||||
);
|
||||
let mut et = self.ctx.read().unwrap().setup_edittree(&rt);
|
||||
|
||||
if let Some(edittree) = et.as_mut(){
|
||||
|
||||
|
|
Loading…
Reference in a new issue