fix morphisms for Digit & PosInt editors

This commit is contained in:
Michael Sippel 2025-01-05 03:53:59 +01:00
parent 47dd4ce747
commit 278296cfbb
Signed by: senvas
GPG key ID: F96CF119C34B64A6
9 changed files with 254 additions and 114 deletions

View file

@ -49,20 +49,18 @@ async fn main() {
*/ */
let int_builder = ReprTreeBuilder::new( ctx.clone() ) let int_builder = ReprTreeBuilder::new( ctx.clone() )
.require(Context::parse(&ctx, .require(Context::parse(&ctx,
" ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>~Char> ~ EditTree")) " ~ <PosInt 16 BigEndian> ~ EditTree"))
.require(Context::parse(&ctx, .require(Context::parse(&ctx,
" ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10>~Char> ~ EditTree")) " ~ <PosInt 10 BigEndian> ~ EditTree"))
/*
.require(Context::parse(&ctx, .require(Context::parse(&ctx,
" ~ <PosInt 8 BigEndian> ~ EditTree")) " ~ <PosInt 8 BigEndian> ~ EditTree"))
.require(Context::parse(&ctx, .require(Context::parse(&ctx,
" ~ <PosInt 2 BigEndian> ~ EditTree")) " ~ <PosInt 2 BigEndian> ~ EditTree"))
*/
; ;
let mut rt_int = nested::repr_tree::ReprTree::from_str("f"); let mut rt_int = nested::repr_tree::ReprTree::from_str("3");
rt_int.write().unwrap().set_halo( rt_int.write().unwrap().set_halo(
/* HALO TYPE */ /* HALO TYPE (append to top of type ladder) */
Context::parse(&ctx, " Context::parse(&ctx, "
~ <PosInt 16 BigEndian> ~ <PosInt 16 BigEndian>
@ -78,7 +76,11 @@ async fn main() {
/* list of editors /* list of editors
*/ */
let mut list_editor = nested::editors::list::ListEditor::new(ctx.clone(), Context::parse(&ctx, "<Seq Char>")); let mut list_editor = nested::editors::list::ListEditor::new(
ctx.clone(),
Context::parse(&ctx, "EditTree"),
ReprTreeBuilder::new(ctx.clone())
);
// add all desired editors to the list // add all desired editors to the list
for edit_leaf in int_builder.required_leaves.iter() { for edit_leaf in int_builder.required_leaves.iter() {
@ -97,7 +99,7 @@ async fn main() {
leaf_rt.edittree(&ctx).get_mut().goto(TreeCursor::none()); leaf_rt.edittree(&ctx).get_mut().goto(TreeCursor::none());
} }
let first_idx : usize = 1; let first_idx : usize = 0;
int_builder.update( &rt_int, int_builder.required_leaves[first_idx].clone() ); int_builder.update( &rt_int, int_builder.required_leaves[first_idx].clone() );
edittree.goto(TreeCursor{ edittree.goto(TreeCursor{
@ -124,9 +126,7 @@ async fn main() {
let ci = cur.tree_addr[0]; let ci = cur.tree_addr[0];
if *li != ci as usize { if *li != ci as usize {
eprintln!("--------\nCHANGE MASTER EDITOR\n--------------------");
int_builder.update( &rt_int, int_builder.required_leaves[ci as usize].clone() ); int_builder.update( &rt_int, int_builder.required_leaves[ci as usize].clone() );
eprintln!("-----\nDone\n----");
*li = ci as usize; *li = ci as usize;
} }
} }

View file

@ -166,18 +166,23 @@ async fn main() {
")); "));
let symbol_builder = ReprTreeBuilder::new( ctx.clone() ) let symbol_builder = ReprTreeBuilder::new( ctx.clone() )
//.require(Context::parse(&ctx, "Instruction ~ Opcode ~ ~ <PosInt 10 BigEndian> ~ EditTree"))
.require(Context::parse(&ctx, "Instruction ~ Mnemonic ~ <Seq~List Char> ~ EditTree")) .require(Context::parse(&ctx, "Instruction ~ Mnemonic ~ <Seq~List Char> ~ EditTree"))
.require(Context::parse(&ctx, "Instruction ~ Opcode ~ ~ <PosInt 10 BigEndian> ~ EditTree"))
.require(Context::parse(&ctx, "Instruction ~ Opcode ~ ~ <PosInt 16 BigEndian> ~ EditTree"))
; ;
symbol_rt = symbol_builder.build_from(symbol_rt).expect("failed to build symbol repr-tree"); symbol_rt = symbol_builder.build_from(symbol_rt).expect("failed to build symbol repr-tree");
let mut list_editor = nested::editors::list::ListEditor::new(ctx.clone(), Context::parse(&ctx, "<Seq Char>")); let mut list_editor = nested::editors::list::ListEditor::new(
ctx.clone(),
Context::parse(&ctx, "<Seq Char>"),
ReprTreeBuilder::new(ctx.clone()),
);
// add all desired editors to the list // add all desired editors to the list
for edit_leaf in symbol_builder.required_leaves { for edit_leaf in symbol_builder.required_leaves.iter() {
let leaf_rt = symbol_rt.descend(edit_leaf.clone()).unwrap(); let leaf_rt = symbol_rt.descend(edit_leaf.clone()).unwrap();
list_editor.data.push(leaf_rt); list_editor.insert(leaf_rt);
} }
let mut edittree = list_editor.into_node(SingletonBuffer::new(0).get_port()); let mut edittree = list_editor.into_node(SingletonBuffer::new(0).get_port());
@ -195,17 +200,17 @@ async fn main() {
/* event handler /* event handler
*/ */
let ctx = ctx.clone(); let ctx = ctx.clone();
let symbol_rt = symbol_rt.clone(); let symbol_rt = symbol_rt.clone(); //let symbol_builder = symbol_builder.clone();
let last_idx = RwLock::new(0); let last_idx = RwLock::new(99999);
move |ev| { move |ev| {
let cur = edittree.read().unwrap().get_cursor(); let cur = edittree.read().unwrap().get_cursor();
if cur.tree_addr.len() > 0 { if cur.tree_addr.len() > 0 {
let mut li = last_idx.write().unwrap(); let mut li = last_idx.write().unwrap();
let ci = cur.tree_addr[0]; let ci = cur.tree_addr[0];
if *li != ci { if *li != ci as usize {
// symbol_builder.update() symbol_builder.update( &symbol_rt, symbol_builder.required_leaves[ci as usize].clone() );
*li = ci; *li = ci as usize;
} }
} }
@ -232,7 +237,7 @@ async fn main() {
) { ) {
let rt_edittree = rt.descend(Context::parse(&ctx, "EditTree")).expect("descend"); let rt_edittree = rt.descend(Context::parse(&ctx, "EditTree")).expect("descend");
let halo_type = rt_edittree.read().unwrap().get_halo_type().clone(); let halo_type = rt_edittree.read().unwrap().get_halo_type().clone();
let edittree = rt_edittree.read().unwrap().get_view::<dyn r3vi::view::singleton::SingletonView<Item = Arc<RwLock<EditTree>>>>().unwrap().get().read().unwrap().clone(); let edittree = rt_edittree.edittree(&ctx).get();
comp.push( nested_tty::make_label( &ctx.read().unwrap().type_term_to_str(&halo_type) ) comp.push( nested_tty::make_label( &ctx.read().unwrap().type_term_to_str(&halo_type) )
.map_item(|_pt, atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90)))) .map_item(|_pt, atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90))))
@ -246,8 +251,8 @@ async fn main() {
} }
show_edit_tree( &ctx, &mut comp, &symbol_rt.descend(Context::parse(&ctx, "Instruction ~ Mnemonic ~ <Seq~List Char>")).unwrap(), 1 ); show_edit_tree( &ctx, &mut comp, &symbol_rt.descend(Context::parse(&ctx, "Instruction ~ Mnemonic ~ <Seq~List Char>")).unwrap(), 1 );
//show_edit_tree( &ctx, &mut comp, &symbol_rt.descend(Context::parse(&ctx, "Instruction ~ Opcode ~ ~ <PosInt 10 BigEndian>")).unwrap(), 3 ); show_edit_tree( &ctx, &mut comp, &symbol_rt.descend(Context::parse(&ctx, "Instruction ~ Opcode ~ ~ <PosInt 10 BigEndian>")).unwrap(), 3 );
//show_edit_tree( &ctx, &mut comp, &symbol_rt.descend(Context::parse(&ctx, "Instruction ~ Opcode ~ ~ <PosInt 16 BigEndian>")).unwrap(), 5 ); show_edit_tree( &ctx, &mut comp, &symbol_rt.descend(Context::parse(&ctx, "Instruction ~ Opcode ~ ~ <PosInt 16 BigEndian>")).unwrap(), 5 );
} }
/* write the changes in the view of `term_port` to the terminal /* write the changes in the view of `term_port` to the terminal

View file

@ -33,7 +33,6 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
if let Some(buf) = b { if let Some(buf) = b {
// buffer already exists // buffer already exists
} else { } else {
eprintln!("create char buffer");
// create char buffer // create char buffer
rt.write().unwrap().insert_leaf( rt.write().unwrap().insert_leaf(
vec![].into_iter(), vec![].into_iter(),
@ -73,7 +72,6 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
.singleton_buffer::<EditTree>(); .singleton_buffer::<EditTree>();
if rt.write().unwrap().singleton_buffer::<char>().is_none() { if rt.write().unwrap().singleton_buffer::<char>().is_none() {
eprintln!("insert singleton buffer");
rt.insert_leaf( rt.insert_leaf(
Context::parse(&ctx, "Char"), Context::parse(&ctx, "Char"),
ReprLeaf::from_singleton_buffer( ReprLeaf::from_singleton_buffer(

View file

@ -31,10 +31,29 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
_ => 0 _ => 0
}; };
let char_rt = src_rt.descend_create(Context::parse(&ctx, "Char")).unwrap();
let char_buf = {
let mut b = char_rt.write().unwrap().singleton_buffer::<char>();
if let Some(buf) = b {
// buffer already exists
eprintln!("take existing char buffer");
buf
} else {
// create char buffer
eprintln!("create char buffer");
let char_buf = SingletonBuffer::<char>::new('?'); let char_buf = SingletonBuffer::<char>::new('?');
src_rt.insert_leaf(
Context::parse(&ctx, "Char"),
ReprLeaf::from_singleton_buffer(char_buf.clone())
);
char_buf
}
};
/* Create EditTree object /* Create EditTree object
*/ */
//if src_rt.descend(Context::parse(&ctx, "EditTree")).is_none() {
eprintln!("create Digit-Editor");
let mut edittree = DigitEditor::new( let mut edittree = DigitEditor::new(
ctx.clone(), ctx.clone(),
radix, radix,
@ -52,10 +71,28 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
); );
ctx.read().unwrap().setup_edittree( src_rt ); ctx.read().unwrap().setup_edittree( src_rt );
//}
} }
} }
); );
/*
let digit_morph_char_to_digit = GenericReprTreeMorphism::new(
Context::parse(&ctx, "Char"),
Context::parse(&ctx, "<Digit Radix>~Char"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.write().unwrap().set_halo(
Context::parse(&ctx, "<Digit Radix>")
.apply_substitution(&|k|σ.get(k).cloned())
.clone()
);
}
}
);
*/
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"),
@ -85,6 +122,7 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
.insert_branch( .insert_branch(
ReprTree::from_singleton_buffer( ReprTree::from_singleton_buffer(
Context::parse(&ctx, "EditTree"), Context::parse(&ctx, "EditTree"),
SingletonBuffer::new(edittree) SingletonBuffer::new(edittree)
) )
); );
@ -101,18 +139,20 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
{ {
let ctx = ctx.clone(); let ctx = ctx.clone();
move |src_rt, σ| { move |src_rt, σ| {
let edittree = src_rt.edittree( &ctx );
let port =
edittree
.get()
.get_edit::<DigitEditor>().unwrap()
.read().unwrap()
.get_char_port();
src_rt.insert_leaf( src_rt.attach_leaf_to(
Context::parse(&ctx, "Char"), Context::parse(&ctx, "Char"),
ReprLeaf::from_view( port ) src_rt.edittree(&ctx)
.get_port()
.map(
|edit| {
edit.get_edit::<DigitEditor>().unwrap()
.read().unwrap()
.get_char_port()
.get_view().get()
}
) )
);
} }
} }
); );

View file

@ -218,17 +218,20 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
{ {
let ctx = ctx.clone(); let ctx = ctx.clone();
move |src_rt, σ| { move |src_rt, σ| {
if src_rt.descend(
Context::parse(&ctx, " ~ <PosInt Radix BigEndian> ~ EditTree")
.apply_substitution(&|x| σ.get(x).cloned()).clone()
).is_none() {
let mut list_edittree = src_rt.descend( let mut list_edittree = src_rt.descend(
Context::parse(&ctx, " ~ <PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>>") Context::parse(&ctx, " ~ <PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>>")
.apply_substitution(&|x| σ.get(x).cloned()).clone() .apply_substitution(&|x| σ.get(x).cloned()).clone()
) )
.unwrap() .unwrap()
.edittree( &ctx ) .edittree( &ctx )
.get(); .get().clone();
// clear display // clear display
list_edittree.disp.view = ReprTree::new_arc(Context::parse(&ctx, "Display")); list_edittree.disp.view = ReprTree::new_arc(Context::parse(&ctx, "Display"));
/*
src_rt.insert_leaf( src_rt.insert_leaf(
Context::parse(&ctx, "<PosInt Radix BigEndian> ~ EditTree") Context::parse(&ctx, "<PosInt Radix BigEndian> ~ EditTree")
.apply_substitution(&|x| σ.get(x).cloned()).clone(), .apply_substitution(&|x| σ.get(x).cloned()).clone(),
@ -238,7 +241,7 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
) )
) )
); );
*/
ctx.read().unwrap().setup_edittree( ctx.read().unwrap().setup_edittree(
&src_rt.descend( &src_rt.descend(
Context::parse(&ctx, "<PosInt Radix BigEndian>") Context::parse(&ctx, "<PosInt Radix BigEndian>")
@ -247,6 +250,7 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
); );
} }
} }
}
); );
let posint_edittree_to_list = GenericReprTreeMorphism::new( let posint_edittree_to_list = GenericReprTreeMorphism::new(
@ -255,16 +259,20 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
{ {
let ctx = ctx.clone(); let ctx = ctx.clone();
move |src_rt, σ| { move |src_rt, σ| {
if src_rt.descend(
Context::parse(&ctx, " ~ <PosInt Radix BigEndian> ~<Seq~List <Digit Radix>> ~ EditTree")
.apply_substitution(&|x| σ.get(x).cloned()).clone()
).is_none() {
let mut list_edittree = src_rt.descend( let mut list_edittree = src_rt.descend(
Context::parse(&ctx, " ~ <PosInt Radix BigEndian>") Context::parse(&ctx, " ~ <PosInt Radix BigEndian> ~ EditTree")
.apply_substitution(&|x| σ.get(x).cloned()).clone()) .apply_substitution(&|x| σ.get(x).cloned()).clone())
.unwrap() .unwrap()
.edittree( &ctx ) .edittree( &ctx )
.get_mut(); .get().clone();
// clear display // clear display
list_edittree.disp.view = ReprTree::new_arc(Context::parse(&ctx, "Display")); list_edittree.disp.view = ReprTree::new_arc(Context::parse(&ctx, "Display"));
/*
src_rt.insert_leaf( src_rt.insert_leaf(
Context::parse(&ctx, "<PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>>~EditTree") Context::parse(&ctx, "<PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>>~EditTree")
.apply_substitution(&|x| σ.get(x).cloned()).clone(), .apply_substitution(&|x| σ.get(x).cloned()).clone(),
@ -272,7 +280,6 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
SingletonBuffer::new(list_edittree) SingletonBuffer::new(list_edittree)
) )
); );
*/
ctx.read().unwrap().setup_edittree( ctx.read().unwrap().setup_edittree(
&src_rt.descend( &src_rt.descend(
@ -282,6 +289,7 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
); );
} }
} }
}
); );
ctx.write().unwrap().morphisms.add_morphism( posint_make_edittree ); ctx.write().unwrap().morphisms.add_morphism( posint_make_edittree );

View file

@ -5,7 +5,7 @@ pub mod ctx;
pub use { pub use {
add::Add, add::Add,
editor::PosIntEditor, //editor::PosIntEditor,
radix::RadixProjection, radix::RadixProjection,
ctx::init_ctx ctx::init_ctx
}; };
@ -146,5 +146,3 @@ impl Observer<dyn PositionalUInt> for PosUIntToDigits {
self.cast.notify(idx); self.cast.notify(idx);
} }
} }

View file

@ -3,7 +3,7 @@ use {
edit_tree::EditTree, editors::{ edit_tree::EditTree, editors::{
char::CharEditor, char::CharEditor,
list::ListEditor list::ListEditor
}, repr_tree::{context::TYPEID_char, Context, GenericReprTreeMorphism, ReprLeaf, ReprTree, ReprTreeArc, ReprTreeExt} }, repr_tree::{context::TYPEID_char, Context, GenericReprTreeMorphism, ReprLeaf, ReprTree, ReprTreeArc, ReprTreeBuilder, ReprTreeExt}
}, laddertypes::TypeTerm, r3vi::{ }, laddertypes::TypeTerm, r3vi::{
buffer::{singleton::*, vec::*}, view::{ buffer::{singleton::*, vec::*}, view::{
list::*, port::UpdateTask, singleton::*, Observer, OuterViewPort, ViewPort list::*, port::UpdateTask, singleton::*, Observer, OuterViewPort, ViewPort
@ -166,7 +166,34 @@ pub fn init_ctx__unpack_reprtree( ctx: &Arc<RwLock<Context>> ) {
} }
); );
/*
* note: this requires ReprTree to contain Char repr.
* todo: how to formally require and enforce this?
*/
let list_morph_rt_to_digit_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List <Digit Radix>> ~ <List ReprTree>"),
Context::parse(&ctx, "<List <Digit Radix>> ~ <List Char>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List Char>"),
src_rt.descend(Context::parse(&ctx, "<List ReprTree>")).expect("cant descend")
.view_list::<ReprTreeArc>()
.map({ let ctx = ctx.clone();
move |rt| {
rt.descend(Context::parse(&ctx, "Char")).expect("cant descend to char")
.view_singleton::<char>()
.get_view()
.get()
}})
);
}
}
);
ctx.write().unwrap().morphisms.add_morphism( list_morph_rt_to_char ); ctx.write().unwrap().morphisms.add_morphism( list_morph_rt_to_char );
ctx.write().unwrap().morphisms.add_morphism( list_morph_rt_to_digit_char );
} }
pub fn init_ctx__pack_reprtree( ctx: &Arc<RwLock<Context>> ) { pub fn init_ctx__pack_reprtree( ctx: &Arc<RwLock<Context>> ) {
@ -189,7 +216,45 @@ pub fn init_ctx__pack_reprtree( ctx: &Arc<RwLock<Context>> ) {
} }
} }
); );
let list_morph_digit_rt_from_char_rt = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List <Digit Radix>> ~ <List Char> ~ <List ReprTree>"),
Context::parse(&ctx, "<List <Digit Radix>> ~ <List ReprTree>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let ty_digit = Context::parse(&ctx, "<Digit Radix>")
.apply_substitution(&|k|σ.get(k).cloned())
.clone();
let ty_digit_as_char = Context::parse(&ctx, "<Digit Radix> ~ Char")
.apply_substitution(&|k|σ.get(k).cloned())
.clone();
// list item builder
let item_builder = ReprTreeBuilder::new(ctx.clone())
.require(ty_digit_as_char.clone())
;
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List ReprTree>"),
src_rt.descend(Context::parse(&ctx, "<List Char~ReprTree>")).expect("cant descend to <List Char~ReprTree>")
.view_list::<ReprTreeArc>()
.map({ let ctx = ctx.clone();
let σ = σ.clone();
move |rt| {
rt.write().unwrap().set_halo(ty_digit.clone());
let new_rt = item_builder.build_from(rt.clone()).expect("cant build item repr tree");
eprintln!("morph <List <Digit 16>~Char> to <List ReprTree> :: new_rt = \n{}\n", new_rt.read().unwrap().fmt(&ctx, 0));
new_rt
}
})
);
}
}
);
ctx.write().unwrap().morphisms.add_morphism( list_morph_rt_from_char ); ctx.write().unwrap().morphisms.add_morphism( list_morph_rt_from_char );
ctx.write().unwrap().morphisms.add_morphism( list_morph_digit_rt_from_char_rt );
} }
pub fn init_ctx(ctx: Arc<RwLock<Context>>) { pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
@ -221,8 +286,26 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
list_editor.data = item_vec_buffer; list_editor.data = item_vec_buffer;
list_editor.update_item_reprtrees(&item_type); list_editor.update_item_reprtrees(&item_type);
} else { } else {
let mut list_editor = ListEditor::with_data(ctx.clone(), item_type.clone(), item_vec_buffer); let mut item_builder = ReprTreeBuilder::new(ctx.clone());
list_editor.update_item_reprtrees(&item_type); let mut item_type = item_type.clone();
/*
if item_type == &Context::parse(&ctx, "Char") {
item_builder = item_builder.require(
Context::parse(&ctx, "Char")
);
}
if item_type == &Context::parse(&ctx, "<Digit 16>") {
item_builder = item_builder.require(
Context::parse(&ctx, "<Digit 16>~Char")
);
}
if item_type == &Context::parse(&ctx, "<Digit 10>") {
item_builder = item_builder.require(
Context::parse(&ctx, "<Digit 10>~Char")
);
}
*/
let mut list_editor = ListEditor::with_data(ctx.clone(), item_type, item_builder, item_vec_buffer);
let mut edittree_list = list_editor.into_node( let mut edittree_list = list_editor.into_node(
SingletonBuffer::<usize>::new(0).get_port() SingletonBuffer::<usize>::new(0).get_port()
); );

View file

@ -34,11 +34,13 @@ pub struct ListEditor {
impl ListEditor { impl ListEditor {
pub fn new( pub fn new(
ctx: Arc<RwLock<Context>>, ctx: Arc<RwLock<Context>>,
typ: TypeTerm typ: TypeTerm,
item_builder: ReprTreeBuilder
) -> Self { ) -> Self {
Self::with_data( Self::with_data(
ctx, ctx,
typ, typ,
item_builder,
VecBuffer::new() VecBuffer::new()
) )
} }
@ -46,9 +48,11 @@ impl ListEditor {
pub fn with_data( pub fn with_data(
ctx: Arc<RwLock<Context>>, ctx: Arc<RwLock<Context>>,
typ: TypeTerm, typ: TypeTerm,
item_builder: ReprTreeBuilder,
data: VecBuffer< ReprTreeArc > data: VecBuffer< ReprTreeArc >
) -> Self { ) -> Self {
let cursor = SingletonBuffer::new(ListCursor::default()); let cursor = SingletonBuffer::new(ListCursor::default());
eprintln!("make list editor of type {}\n", ctx.read().unwrap().type_term_to_str(&typ) );
let mut le = ListEditor { let mut le = ListEditor {
mode_port: cursor mode_port: cursor
@ -109,8 +113,8 @@ impl ListEditor {
cursor, cursor,
data, data,
spillbuf: Arc::new(RwLock::new(Vec::new())), spillbuf: Arc::new(RwLock::new(Vec::new())),
item_builder: ReprTreeBuilder::new(ctx.clone()) item_builder: item_builder
.require( typ.clone() ) //.require( typ.clone() )
.require( TypeTerm::Ladder(vec![ .require( TypeTerm::Ladder(vec![
typ.clone(), typ.clone(),
TypeTerm::TypeID(TYPEID_edittree) TypeTerm::TypeID(TYPEID_edittree)
@ -292,6 +296,7 @@ impl ListEditor {
/// insert a new element /// insert a new element
pub fn insert(&mut self, item: ReprTreeArc) { pub fn insert(&mut self, item: ReprTreeArc) {
eprintln!("List: insert {}", item.read().unwrap().fmt(&self.ctx, 0));
self.item_builder.update( &item, self.master_repr.read().unwrap().clone() ); self.item_builder.update( &item, self.master_repr.read().unwrap().clone() );
let mut item_edit = item.edittree(&self.ctx).get_mut(); let mut item_edit = item.edittree(&self.ctx).get_mut();

View file

@ -44,8 +44,11 @@ impl ReprTreeBuilder {
} }
/// Add a type to the set of required representations. /// Add a type to the set of required representations.
pub fn require(mut self, t: TypeTerm) -> Self { pub fn require(mut self, mut t: TypeTerm) -> Self {
self.required_leaves.push(t.normalize()); t = t.normalize();
if !self.required_leaves.contains(&t) {
self.required_leaves.push(t);
}
self self
} }
@ -68,14 +71,14 @@ impl ReprTreeBuilder {
leaves.retain(|t| t != &mt); leaves.retain(|t| t != &mt);
let mut st_problem = laddertypes::steiner_tree::PathApproxSteinerTreeSolver::new( let mut st_problem = laddertypes::steiner_tree::PathApproxSteinerTreeSolver::new(
mt, mt.clone(),
leaves leaves
); );
if let Some( steiner_tree ) = st_problem.solve( &morphism_base ) { if let Some( steiner_tree ) = st_problem.solve( &morphism_base ) {
eprintln!("--> from {}", self.ctx.read().unwrap().type_term_to_str(&mt));
for morphism_type in steiner_tree.into_edges() { for morphism_type in steiner_tree.into_edges() {
eprintln!("--> morph {} to {}", eprintln!("--> morph to {}",
self.ctx.read().unwrap().type_term_to_str(&morphism_type.src_type),
self.ctx.read().unwrap().type_term_to_str(&morphism_type.dst_type)); self.ctx.read().unwrap().type_term_to_str(&morphism_type.dst_type));
if let Some(( morphism, mut τ, σ )) = if let Some(( morphism, mut τ, σ )) =