add morphisms to create edittree from/to digit/char and generic lists
This commit is contained in:
parent
b3d0e4f03c
commit
aed4cad1e4
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();
|
let ctx = ctx.clone();
|
||||||
move |rt, σ| {
|
move |rt, σ| {
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut b = rt.write().unwrap().singleton_buffer::<char>();
|
let mut b = rt.write().unwrap().singleton_buffer::<char>();
|
||||||
if let Some(buf) = b {
|
if let Some(buf) = b {
|
||||||
// buffer already exists
|
// buffer already exists
|
||||||
} else {
|
} else {
|
||||||
// create char buffer
|
// create char buffer
|
||||||
rt.write().unwrap().insert_leaf(
|
rt.write().unwrap().insert_leaf(
|
||||||
vec![].into_iter(),
|
vec![].into_iter(),
|
||||||
ReprLeaf::from_singleton_buffer(
|
ReprLeaf::from_singleton_buffer(SingletonBuffer::new('\0'))
|
||||||
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>();
|
rt.insert_leaf(
|
||||||
|
|
||||||
let mut edittree = CharEditor::new_edit_tree(
|
|
||||||
ctx.clone(),
|
|
||||||
char_buf,
|
|
||||||
SingletonBuffer::<usize>::new(0).get_port()
|
|
||||||
);
|
|
||||||
|
|
||||||
rt.insert_leaf(
|
|
||||||
Context::parse(&ctx, "EditTree"),
|
Context::parse(&ctx, "EditTree"),
|
||||||
ReprLeaf::from_singleton_buffer(
|
ReprLeaf::from_singleton_buffer(
|
||||||
SingletonBuffer::new(
|
SingletonBuffer::new(
|
||||||
Arc::new(RwLock::new(edittree))
|
Arc::new(RwLock::new(edittree))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.read().unwrap().setup_edittree(
|
ctx.read().unwrap().setup_edittree(rt);
|
||||||
rt.clone(),
|
}
|
||||||
SingletonBuffer::new(0).get_port()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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_to_edittree );
|
||||||
|
ctx.write().unwrap().morphisms.add_morphism( char_morph_from_edittree );
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CharEditor {
|
pub struct CharEditor {
|
||||||
|
|
|
@ -19,6 +19,43 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
||||||
// todo: proper scoping of Radix variable
|
// todo: proper scoping of Radix variable
|
||||||
ctx.write().unwrap().add_varname("Radix");
|
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(
|
let digit_morph_char_to_edittree = GenericReprTreeMorphism::new(
|
||||||
Context::parse(&ctx, "<Digit Radix>~Char"),
|
Context::parse(&ctx, "<Digit Radix>~Char"),
|
||||||
Context::parse(&ctx, "<Digit Radix>~EditTree"),
|
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(
|
let digit_morph_char_to_u64 = GenericReprTreeMorphism::new(
|
||||||
Context::parse(&ctx, "<Digit Radix>~Char"),
|
Context::parse(&ctx, "<Digit Radix>~Char"),
|
||||||
Context::parse(&ctx, "<Digit Radix>~ℤ_2^64~machine.UInt64"),
|
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_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_char_to_u64 );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( digit_morph_u64_to_char );
|
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>>> {
|
pub fn get_data_port(&self) -> OuterViewPort<dyn SingletonView<Item = Result<u32, char>>> {
|
||||||
let radix = self.radix;
|
let radix = self.radix;
|
||||||
self.data.get_port().map(move |c|
|
self.data.get_port().map(move |c|
|
||||||
|
|
|
@ -63,36 +63,24 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let list_morph_editsetup3 = GenericReprTreeMorphism::new(
|
||||||
let list_morph_editsetup2 = GenericReprTreeMorphism::new(
|
Context::parse(&ctx, "<List Item> ~ EditTree"),
|
||||||
Context::parse(&ctx, "<List Char>~EditTree"),
|
Context::parse(&ctx, "<List Item> ~ <List EditTree>"),
|
||||||
Context::parse(&ctx, "<List Char>"),
|
|
||||||
{
|
{
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
move |src_rt, σ| {
|
move |src_rt, σ| {
|
||||||
let edittree =
|
let edittree = src_rt.edittree( &ctx );
|
||||||
src_rt
|
|
||||||
.descend(Context::parse(&ctx, "<List Char>~EditTree")).unwrap()
|
|
||||||
.singleton_buffer::<Arc<RwLock<EditTree>>>();
|
|
||||||
|
|
||||||
let list_edit = edittree.get().read().unwrap().get_edit::< ListEditor >().unwrap();
|
let list_edit = edittree.get().read().unwrap().get_edit::< ListEditor >().unwrap();
|
||||||
let edittree_items = list_edit.read().unwrap().data.get_port().to_list();
|
let edittree_items = list_edit.read().unwrap().data.get_port().to_list();
|
||||||
|
|
||||||
src_rt.insert_leaf(
|
eprintln!("edittree_items.len() = {:?}", edittree_items.get_view().unwrap().len());
|
||||||
Context::parse(&ctx, "<List Char>"),
|
|
||||||
ReprLeaf::from_view(
|
src_rt.attach_leaf_to(
|
||||||
edittree_items
|
Context::parse(&ctx, "<List Item> ~ <List EditTree>")
|
||||||
.map(|edittree_char|
|
.apply_substitution(&|x| σ.get(x).cloned()).clone(),
|
||||||
edittree_char
|
edittree_items
|
||||||
.read().unwrap()
|
|
||||||
.get_edit::<CharEditor>().unwrap()
|
|
||||||
.read().unwrap()
|
|
||||||
.get()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -132,21 +120,14 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
{
|
{
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
move |src_rt, σ| {
|
move |src_rt, σ| {
|
||||||
let p =
|
let list_port = src_rt.get_port::<dyn ListView< Arc<RwLock<EditTree>> >>().unwrap();
|
||||||
src_rt
|
src_rt.attach_leaf_to( Context::parse(&ctx, "<Vec EditTree>"), list_port );
|
||||||
.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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup1 );
|
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_from_vec_char );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_char );
|
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_char );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_edittree );
|
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_edittree );
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use {
|
use {
|
||||||
r3vi::{
|
r3vi::{
|
||||||
view::{OuterViewPort, singleton::*, sequence::*},
|
view::{OuterViewPort, singleton::*, sequence::*},
|
||||||
buffer::{singleton::*, vec::*}
|
buffer::{singleton::*, vec::*},
|
||||||
|
projection::*
|
||||||
},
|
},
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
|
@ -319,11 +320,7 @@ impl ListEditor {
|
||||||
let mut b = item.ctrl.spillbuf.write().unwrap();
|
let mut b = item.ctrl.spillbuf.write().unwrap();
|
||||||
|
|
||||||
let rt = ReprTree::new_arc(self.typ.clone());
|
let rt = ReprTree::new_arc(self.typ.clone());
|
||||||
let mut et = self.ctx.read().unwrap()
|
let mut et = self.ctx.read().unwrap().setup_edittree(&rt);
|
||||||
.setup_edittree(
|
|
||||||
&rt
|
|
||||||
// , self.depth.map(|d| d+1)
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(edittree) = et.as_mut(){
|
if let Some(edittree) = et.as_mut(){
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue