more ReprTree refactoring

- <Vec Char>  ~>  <Vec ReprTree>  packing/unpacking
- remove Arc<RwLock<>> around EditTree
- gentle ListEditor update
- reactivate PosInt example
This commit is contained in:
Michael Sippel 2025-01-02 12:35:13 +01:00
parent 26186b3375
commit 47dd4ce747
Signed by: senvas
GPG key ID: F96CF119C34B64A6
20 changed files with 564 additions and 508 deletions

View file

@ -65,7 +65,7 @@ async fn main() {
let ctx = ctx.clone(); let ctx = ctx.clone();
let digit_edittree = rt_digit.edittree( &ctx ); let digit_edittree = rt_digit.edittree( &ctx );
move |ev| { move |ev| {
digit_edittree.get().write().unwrap().send_cmd_obj(ev.to_repr_tree(&ctx)); digit_edittree.get_mut().send_cmd_obj(ev.to_repr_tree(&ctx));
} }
}); });
@ -91,7 +91,7 @@ async fn main() {
.offset(Vector2::new(1,1))); .offset(Vector2::new(1,1)));
comp.push(rt_digit comp.push(rt_digit
.edittree( &ctx ).get().read().unwrap() .edittree( &ctx ).get()
.display_view() .display_view()
.offset(Vector2::new(3,2))); .offset(Vector2::new(3,2)));

View file

@ -41,53 +41,34 @@ async fn main() {
nested::editors::list::init_ctx( ctx.clone() ); nested::editors::list::init_ctx( ctx.clone() );
nested_tty::setup_edittree_hook(&ctx); nested_tty::setup_edittree_hook(&ctx);
/* Create a Representation-Tree of type <List Char> /* create a Representation-Tree of type <List Char>
*/ */
let mut ldata = VecBuffer::new(); let mut rt_data = ReprTree::from_str("Hello World!");
for c in "Hello World!".chars() { rt_data.write().unwrap().set_halo(
let rt = ReprTree::from_singleton_buffer( Context::parse(&ctx, "<List Char>")
Context::parse(&ctx, "Char"),
SingletonBuffer::new(c));
ldata.push(rt);
}
let mut ldata_rt = ReprTree::from_vec_buffer(
Context::parse(&ctx, "<Vec ReprTree>"),
ldata.clone()
); );
ldata_rt.write().unwrap().set_halo( /* specify required representations
Context::parse(&ctx, "<List Char>~<List ReprTree>") */
);
let mut ledit = nested::editors::list::ListEditor::with_data(
ctx.clone(),
Context::parse(&ctx, "Char"),
ldata
);
ledit.update_item_reprtrees(&Context::parse(&ctx, "Char"));
ledit.update_item_reprtrees(&Context::parse(&ctx, "Char~EditTree"));
let mut ledit = ledit.into_node(SingletonBuffer::new(0).get_port());
nested_tty::editors::list::PTYListStyle::for_node(&mut ledit, ("<", "", ">"));
nested_tty::editors::list::PTYListController::for_node(&mut ledit, None, None);
let ledittree = SingletonBuffer::new(Arc::new(RwLock::new(ledit)));
let rt_string_builder = ReprTreeBuilder::new( ctx.clone() ) let rt_string_builder = ReprTreeBuilder::new( ctx.clone() )
.require(Context::parse(&ctx, "<List Char>~<Vec Char>")) .require(Context::parse(&ctx, "<List Char>~<Vec Char>"))
.require(Context::parse(&ctx, "<List Char>")) .require(Context::parse(&ctx, "<List Char>"))
.require(Context::parse(&ctx, "<List Char>~EditTree")) .require(Context::parse(&ctx, "<List Char>~EditTree"))
; ;
let rt_string = rt_string_builder.build_from(ldata_rt).expect("could not build rt_string"); // initially, populate from <Vec Char> representation
eprintln!("rt_string = \n{}", rt_string.read().unwrap().fmt(&ctx, 0)); let mut rt_string = rt_string_builder.build_from(rt_data)
.expect("could not build rt_string");
// hand over control to EditTree representation
rt_string_builder.update( &rt_string, Context::parse(&ctx, "<List Char>~EditTree") )
.expect("could not update rt_string");
/* Now, get the ListView that serves our char-values. /* Now, get the ListView that serves our char-values.
* This view is a projection created by the morphism that was called above. * This view is a projection created by the morphism that was called above.
*/ */
let mut chars_view = rt_string let mut chars_view = rt_string
.read().unwrap()
.get_port::<dyn ListView<char>>() .get_port::<dyn ListView<char>>()
.unwrap(); .unwrap();
@ -108,13 +89,14 @@ async fn main() {
/* setup terminal /* setup terminal
*/ */
let app = TTYApplication::new({ let app = TTYApplication::new({
let edittree_list = ledittree.clone();//rt_string.edittree(&ctx).clone(); let edittree_list = rt_string.edittree(&ctx).clone();
/* event handler /* event handler
*/ */
let ctx = ctx.clone(); let ctx = ctx.clone();
move |ev| { move |ev| {
edittree_list.get().write().unwrap().send_cmd_obj(ev.to_repr_tree(&ctx)); let cmd = ev.to_repr_tree(&ctx);
edittree_list.get_mut().send_cmd_obj(cmd);
} }
}); });
@ -129,23 +111,23 @@ async fn main() {
{ {
let mut comp = compositor.write().unwrap(); let mut comp = compositor.write().unwrap();
let label_str = ctx.read().unwrap().type_term_to_str(&rt_string.read().unwrap().get_type()); let label_str = ctx.read().unwrap()
.type_term_to_str(&rt_string.read().unwrap().get_type());
comp.push( comp.push(
nested_tty::make_label(&label_str) nested_tty::make_label(&label_str)
.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))))
.offset(Vector2::new(1,1))); .offset(Vector2::new(1,1)));
comp.push( comp.push(
//rt_string.edittree(&ctx).get() rt_string.edittree(&ctx).get()
ledittree.get()
.read().unwrap()
.display_view() .display_view()
.offset(Vector2::new(3,2))); .offset(Vector2::new(3,2)));
comp.push( comp.push(
string_view_tty string_view_tty
.offset(Vector2::new(5,3))); .offset(Vector2::new(5,3)));
} }
/* 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

@ -22,11 +22,12 @@ use {
nested_tty::{ nested_tty::{
DisplaySegment, TTYApplication, DisplaySegment, TTYApplication,
TerminalCompositor, TerminalStyle, TerminalView, TerminalCompositor, TerminalStyle, TerminalView,
TerminalAtom, TerminalEvent TerminalAtom, TerminalEvent,
edit_tree::cursor_widget::TreeNavExt
}, },
r3vi::{ r3vi::{
buffer::{singleton::*, vec::*}, buffer::{singleton::*, vec::*},
view::{port::UpdateTask, singleton::*, list::*, sequence::*}, view::{port::UpdateTask, ViewPort, singleton::*, list::*, sequence::*},
projection::* projection::*
}, },
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
@ -49,11 +50,9 @@ 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> ~ <Seq~List <Digit 16>~Char> ~ EditTree"))
.require(Context::parse(&ctx,
" ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10>~Char> ~ EditTree"))
/* /*
.require(Context::parse(&ctx,
" ~ <PosInt 16 LittleEndian> ~ <Seq~List <Digit 16>> ~ EditTree"))
.require(Context::parse(&ctx,
" ~ <PosInt 16 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,
@ -61,7 +60,7 @@ async fn main() {
*/ */
; ;
let mut rt_int = nested::repr_tree::ReprTree::from_str("cff"); let mut rt_int = nested::repr_tree::ReprTree::from_str("f");
rt_int.write().unwrap().set_halo( rt_int.write().unwrap().set_halo(
/* HALO TYPE */ /* HALO TYPE */
Context::parse(&ctx, " Context::parse(&ctx, "
@ -72,36 +71,42 @@ async fn main() {
~ <List Char> ~ <List Char>
") ")
); );
rt_int = int_builder.build_from( rt_int )
.expect("cant build initial repr tree");
eprintln!("rt_int = \n{}\n", rt_int.read().unwrap().fmt(&ctx, 0)); eprintln!("rt_int = \n{}\n", rt_int.read().unwrap().fmt(&ctx, 0));
rt_int = int_builder.build_from( rt_int ).expect("cant build initial repr tree");
eprintln!("rt_int = \n{}\n", rt_int.read().unwrap().fmt(&ctx, 0));
return;
/* 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, "<Seq Char>"));
// add all desired editors to the list // add all desired editors to the list
for edit_leaf in int_builder.required_leaves { for edit_leaf in int_builder.required_leaves.iter() {
let leaf_rt = rt_int.descend(edit_leaf.clone()).unwrap(); let leaf_rt = rt_int.descend(edit_leaf.clone()).unwrap();
list_editor.data.push(leaf_rt); list_editor.data.push(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());
nested_tty::editors::list::PTYListController::for_node(&mut edittree, None, None);
/* cursors are a bit screwed initially so fix them up /* cursors are a bit screwed initially so fix them up
* TODO: how to fix this generally? * TODO: how to fix this generally?
*/ */
for edit_leaf in int_builder.required_leaves.iter() {
let leaf_rt = rt_int.descend(edit_leaf.clone()).unwrap();
leaf_rt.edittree(&ctx).get_mut().goto(TreeCursor::none());
}
let first_idx : usize = 1;
int_builder.update( &rt_int, int_builder.required_leaves[first_idx].clone() );
edittree.goto(TreeCursor{ edittree.goto(TreeCursor{
leaf_mode: nested::editors::list::ListCursorMode::Insert, leaf_mode: nested::editors::list::ListCursorMode::Insert,
tree_addr: vec![0,0] tree_addr: vec![first_idx as isize, 0]
}); });
let edittree = Arc::new(RwLock::new(edittree)); let edittree = Arc::new(RwLock::new(edittree));
/* setup terminal /* setup terminal
*/ */
let app = TTYApplication::new({ let app = TTYApplication::new({
@ -109,25 +114,20 @@ async fn main() {
*/ */
let ctx = ctx.clone(); let ctx = ctx.clone();
let rt_int = rt_int.clone(); let rt_int = rt_int.clone();
let last_idx = RwLock::new(0); let last_idx = RwLock::new(first_idx);
let int_builder = int_builder.clone();
let edittree = edittree.clone();
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 {
/* eprintln!("--------\nCHANGE MASTER EDITOR\n--------------------");
eprintln!("----------------------------------");
set_master(
&ctx,
&rt_int,
editor_types.clone(),
ci as usize
);
*/
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() );
*li = ci; eprintln!("-----\nDone\n----");
*li = ci as usize;
} }
} }
@ -146,24 +146,35 @@ async fn main() {
{ {
let mut comp = compositor.write().unwrap(); let mut comp = compositor.write().unwrap();
let et = edittree.read().unwrap();
comp.push(et.get_cursor_widget());
fn show_edit_tree( ctx: &Arc<RwLock<Context>>, comp: &mut TerminalCompositor, rt: &Arc<RwLock<ReprTree>>, y: i16 ) fn show_edit_tree( ctx: &Arc<RwLock<Context>>, comp: &mut TerminalCompositor, rt: &Arc<RwLock<ReprTree>>, y: i16 )
{ {
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.edittree( &ctx ); let edittree = rt_edittree.edittree( &ctx );
let box_port = ViewPort::new();
let ascii_box = nested_tty::widgets::ascii_box::AsciiBox::new(
Vector2::new(30, 1),
edittree.get().display_view(),
box_port.inner()
);
comp.push(
box_port.outer()
.offset(Vector2::new(1,y)));
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))))
.offset(Vector2::new(1,y))); .offset(Vector2::new(1,y)));
comp.push( edittree.get().read().unwrap().display_view()
.offset(Vector2::new(1,y+1)));
} }
let mut y = 1; let mut y = 2;
for t in int_builder.required_leaves.iter() { for t in int_builder.required_leaves.iter() {
show_edit_tree(&ctx, &mut comp, &rt_int.descend(t.clone()).expect(""), y); show_edit_tree(&ctx, &mut comp, &rt_int.descend(t.clone()).expect(""), y);
y += 3; y += 4;
} }
} }

View file

@ -181,6 +181,8 @@ async fn main() {
} }
let mut edittree = list_editor.into_node(SingletonBuffer::new(0).get_port()); let mut edittree = list_editor.into_node(SingletonBuffer::new(0).get_port());
nested_tty::editors::list::PTYListController::for_node(&mut edittree, None, None);
edittree.goto(TreeCursor{ edittree.goto(TreeCursor{
leaf_mode: nested::editors::list::ListCursorMode::Insert, leaf_mode: nested::editors::list::ListCursorMode::Insert,
tree_addr: vec![0, 0] tree_addr: vec![0, 0]
@ -244,8 +246,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

@ -148,7 +148,7 @@ impl LineEditor {
ctx.clone(), ctx.clone(),
Context::parse(&ctx, "<List Char>") Context::parse(&ctx, "<List Char>")
); );
let chars_seg_seq = ListSegmentSequence::new(chars_edit.get_cursor_port(), chars_edit.get_data_port()) let chars_seg_seq = ListSegmentSequence::new(chars_edit.get_cursor_port(), chars_edit.get_edittree_seq() )
.read().unwrap().get_view(); .read().unwrap().get_view();
let out_port = ViewPort::new(); let out_port = ViewPort::new();
@ -234,7 +234,7 @@ impl LinesEditor {
let lines_segments = nested::editors::list::ListSegmentSequence::new( let lines_segments = nested::editors::list::ListSegmentSequence::new(
list_edit.get_cursor_port(), list_edit.get_cursor_port(),
list_edit.get_data_port() list_edit.get_edittree_seq()
).read().unwrap().get_view(); ).read().unwrap().get_view();
let lines_view = lines_segments let lines_view = lines_segments
.map({ .map({
@ -284,7 +284,6 @@ impl LinesEditor {
let chars_rt = self.make_line(line_value); let chars_rt = self.make_line(line_value);
let chars_edittree = chars_rt let chars_edittree = chars_rt
.descend(Context::parse(&self.ctx, "EditTree")).unwrap()
.edittree(&self.ctx).get() .edittree(&self.ctx).get()
.read().unwrap().clone(); .read().unwrap().clone();
@ -303,19 +302,24 @@ impl LinesEditor {
ReprLeaf::from_view( line_port ) ReprLeaf::from_view( line_port )
); );
let mut le_rt = ReprTree::from_singleton_buffer(
Context::parse(&self.ctx, "EditTree"),
SingletonBuffer::new( Arc::new(RwLock::new(line_edittree)) )
);
le_rt.write().unwrap().set_halo(Context::parse(&self.ctx, "Line"));
le_rt = ReprTree::rise(le_rt);
self.edit.write().unwrap() self.edit.write().unwrap()
.get_edit::< ListEditor >().unwrap() .get_edit::< ListEditor >().unwrap()
.write().unwrap() .write().unwrap()
.data .data
.push( Arc::new(RwLock::new(line_edittree)) ); .push( le_rt );
} }
pub fn make_line(&self, line_value: &str) -> Arc<RwLock<ReprTree>> { pub fn make_line(&self, line_value: &str) -> Arc<RwLock<ReprTree>> {
let ctx = &self.ctx; let ctx = &self.ctx;
let mut rt_line = ReprTree::from_str( let mut rt_line = ReprTree::from_str(line_value);
Context::parse(&ctx, "<List Char>~<Vec Char>"), rt_line.write().unwrap().set_halo(Context::parse(&ctx, "<List Char>~<Vec Char>"));
line_value
);
// create Editor & transfer data to Editor // create Editor & transfer data to Editor
ctx.read().unwrap().apply_morphism( ctx.read().unwrap().apply_morphism(

View file

@ -33,6 +33,7 @@ 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(),
@ -49,12 +50,10 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
); );
rt.insert_leaf( rt.insert_leaf(
Context::parse(&ctx, "EditTree"), Context::parse(&ctx, "Char~EditTree"),
ReprLeaf::from_singleton_buffer( ReprLeaf::from_singleton_buffer(
SingletonBuffer::new( SingletonBuffer::new(edittree)
Arc::new(RwLock::new(edittree)) )
)
)
); );
ctx.read().unwrap().setup_edittree(rt); ctx.read().unwrap().setup_edittree(rt);
@ -71,15 +70,25 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
{ {
let mut b = rt let mut b = rt
.descend(Context::parse(&ctx, "EditTree")).unwrap() .descend(Context::parse(&ctx, "EditTree")).unwrap()
.view_singleton::<Arc<RwLock<EditTree>>>(); .singleton_buffer::<EditTree>();
if rt.write().unwrap().singleton_buffer::<char>().is_none() {
eprintln!("insert singleton buffer");
rt.insert_leaf(
Context::parse(&ctx, "Char"),
ReprLeaf::from_singleton_buffer(
SingletonBuffer::new('\0')
)
);
}
rt.attach_leaf_to( rt.attach_leaf_to(
Context::parse(&ctx, "Char"), Context::parse(&ctx, "Char"),
b.map(|x| b.get_port().map(
x.read().unwrap() |x| x.get_edit::<CharEditor>().unwrap()
.get_edit::<CharEditor>().unwrap()
.read().unwrap() .read().unwrap()
.get()) .get()
)
); );
} }
}); });

View file

@ -47,7 +47,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(Arc::new(RwLock::new(edittree))) SingletonBuffer::new(edittree)
) )
); );
@ -85,7 +85,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(Arc::new(RwLock::new(edittree))) SingletonBuffer::new(edittree)
) )
); );
@ -105,7 +105,6 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
let port = let port =
edittree edittree
.get() .get()
.read().unwrap()
.get_edit::<DigitEditor>().unwrap() .get_edit::<DigitEditor>().unwrap()
.read().unwrap() .read().unwrap()
.get_char_port(); .get_char_port();
@ -201,5 +200,3 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
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 );
} }

View file

@ -224,23 +224,21 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
) )
.unwrap() .unwrap()
.edittree( &ctx ) .edittree( &ctx )
.get().clone() .get();
.read().unwrap()
.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(),
ReprLeaf::from_singleton_buffer( ReprLeaf::from_singleton_buffer(
SingletonBuffer::new( SingletonBuffer::new(
Arc::new(RwLock::new(list_edittree)) list_edittree
) )
) )
); );
*/
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>")
@ -262,22 +260,19 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
.apply_substitution(&|x| σ.get(x).cloned()).clone()) .apply_substitution(&|x| σ.get(x).cloned()).clone())
.unwrap() .unwrap()
.edittree( &ctx ) .edittree( &ctx )
.get().clone() .get_mut();
.read().unwrap()
.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(),
ReprLeaf::from_singleton_buffer( ReprLeaf::from_singleton_buffer(
SingletonBuffer::new( SingletonBuffer::new(list_edittree)
Arc::new(RwLock::new(list_edittree))
)
) )
); );
*/
ctx.read().unwrap().setup_edittree( ctx.read().unwrap().setup_edittree(
&src_rt.descend( &src_rt.descend(
@ -299,4 +294,3 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_from_u64 ); ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_from_u64 );
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_to_u64 ); ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_to_u64 );
} }

View file

@ -50,7 +50,7 @@ impl ObjCommander for ListEditor {
match cur.mode { match cur.mode {
ListCursorMode::Select => { ListCursorMode::Select => {
if let Some(mut item) = self.get_cur_edittree() { if let Some(mut item) = self.get_cur_edittree() {
let mut item = item.write().unwrap(); //let mut item = item.write().unwrap();
let item_cur = item.get_cursor(); let item_cur = item.get_cursor();
match cmd.get() { match cmd.get() {

View file

@ -13,6 +13,185 @@ use {
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
pub fn init_ctx__seq_to_list( ctx: &Arc<RwLock<Context>> ) {
let seq_morph_to_list_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<Seq Char>"),
Context::parse(&ctx, "<Seq Char>~<List Char>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List Char>"),
src_rt.view_seq::<char>().to_list()
);
}
}
);
let seq_morph_to_list_u64 = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<Seq machine.UInt64>"),
Context::parse(&ctx, "<Seq machine.UInt64>~<List machine.UInt64>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List machine.UInt64>"),
src_rt.view_seq::<u64>().to_list()
);
}
}
);
ctx.write().unwrap().morphisms.add_morphism( seq_morph_to_list_char );
ctx.write().unwrap().morphisms.add_morphism( seq_morph_to_list_u64 );
}
pub fn init_ctx__vec_to_list( ctx: &Arc<RwLock<Context>> ) {
let list_morph_from_vec_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Char>~<Vec Char>"),
Context::parse(&ctx, "<List Char>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let src_port = src_rt.descend(
Context::parse(&ctx, "<List Char>~<Vec Char>")
)
.expect("descend")
.get_port::<RwLock<Vec<char>>>().unwrap();
src_rt.attach_leaf_to( Context::parse(&ctx, "<List Char>"), src_port.to_list() );
}
}
);
let list_morph_from_vec_rt = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List ReprTree>~<Vec ReprTree>"),
Context::parse(&ctx, "<List ReprTree>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let src_port = src_rt.descend(
Context::parse(&ctx, "<List ReprTree>~<Vec ReprTree>")
)
.expect("descend")
.get_port::<RwLock<Vec<ReprTreeArc>>>().unwrap();
src_rt.attach_leaf_to( Context::parse(&ctx, "<List ReprTree>"), src_port.to_list() );
}
}
);
ctx.write().unwrap().morphisms.add_morphism( list_morph_from_vec_char );
ctx.write().unwrap().morphisms.add_morphism( list_morph_from_vec_rt );
}
pub fn init_ctx__list_to_vec( ctx: &Arc<RwLock<Context>> ) {
let list_morph_to_vec_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Char>"),
Context::parse(&ctx, "<List Char>~<Vec Char>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<Vec Char>"),
src_rt.view_list::<char>()
);
}
}
);
let list_morph_to_vec_u64 = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List machine.UInt64>"),
Context::parse(&ctx, "<List machine.UInt64>~<Vec machine.UInt64>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<Vec machine.UInt64>"),
src_rt.view_list::<u64>()
);
}
}
);
let list_morph_to_vec_reprtree = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List ReprTree>"),
Context::parse(&ctx, "<List ReprTree>~<Vec ReprTree>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<Vec ReprTree>"),
src_rt.view_list::< ReprTreeArc >()
);
}
}
);
let list_morph_to_vec_edittree = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List EditTree>"),
Context::parse(&ctx, "<List EditTree>~<Vec EditTree>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let list_port = src_rt.get_port::<dyn ListView< EditTree >>().unwrap();
src_rt.attach_leaf_to( Context::parse(&ctx, "<Vec EditTree>"), list_port );
}
}
);
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_reprtree );
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_char );
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_u64 );
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_edittree );
}
pub fn init_ctx__unpack_reprtree( ctx: &Arc<RwLock<Context>> ) {
let list_morph_rt_to_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Char> ~ <List ReprTree>"),
Context::parse(&ctx, "<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(|rt| {
rt.view_singleton::<char>().get_view().get()
})
);
}
}
);
ctx.write().unwrap().morphisms.add_morphism( list_morph_rt_to_char );
}
pub fn init_ctx__pack_reprtree( ctx: &Arc<RwLock<Context>> ) {
let list_morph_rt_from_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Char>"),
Context::parse(&ctx, "<List Char> ~ <List ReprTree>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List Char>~<List ReprTree>"),
src_rt.view_list::<char>()
.map(|c| {
ReprTree::from_singleton_buffer(
TypeTerm::TypeID(TYPEID_char),
SingletonBuffer::<char>::new( *c )
)
})
);
}
}
);
ctx.write().unwrap().morphisms.add_morphism( list_morph_rt_from_char );
}
pub fn init_ctx(ctx: Arc<RwLock<Context>>) { pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
ctx.write().unwrap().add_varname("Item"); ctx.write().unwrap().add_varname("Item");
@ -24,28 +203,36 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
move |src_rt, σ| { move |src_rt, σ| {
let item_id = laddertypes::TypeID::Var(ctx.read().unwrap().get_var_typeid("Item").unwrap()); let item_id = laddertypes::TypeID::Var(ctx.read().unwrap().get_var_typeid("Item").unwrap());
if let Some( item_type ) = σ.get( &item_id ) { if let Some( item_type ) = σ.get( &item_id ) {
let mut item_vec_rt = src_rt let mut item_rt_vec = src_rt
.descend( .descend(Context::parse(&ctx, "<List ReprTree>~<Vec ReprTree>"))
Context::parse(&ctx, "<List ReprTree>~<Vec ReprTree>")
.apply_substitution(&|id| σ.get(id).cloned()).clone()
)
.expect("cant descend src repr"); .expect("cant descend src repr");
let item_vec_buffer = item_vec_rt.vec_buffer::< ReprTreeArc >(); let item_vec_buffer = item_rt_vec.vec_buffer::< ReprTreeArc >();
let mut list_editor = ListEditor::with_data(ctx.clone(), item_type.clone(), item_vec_buffer); if let Some(mut buf) = src_rt.descend_create(Context::parse(&ctx, "EditTree")).as_mut()
let edittree_list = list_editor.into_node( .expect("get_edittree rt")
SingletonBuffer::<usize>::new(0).get_port() .write().unwrap()
); .singleton_buffer::<EditTree>()
src_rt.insert_leaf( {
Context::parse(&ctx, "<List Item> ~ EditTree") let mut et = buf.get_mut();
.apply_substitution(&|id| σ.get(id).cloned()).clone(), let mut list_editor = et.get_edit::<ListEditor>().unwrap();
let mut list_editor = list_editor.write().unwrap();
ReprLeaf::from_singleton_buffer(
SingletonBuffer::new(Arc::new(RwLock::new(edittree_list)))
)
);
list_editor.data = item_vec_buffer;
list_editor.update_item_reprtrees(&item_type);
} else {
let mut list_editor = ListEditor::with_data(ctx.clone(), item_type.clone(), item_vec_buffer);
list_editor.update_item_reprtrees(&item_type);
let mut edittree_list = list_editor.into_node(
SingletonBuffer::<usize>::new(0).get_port()
);
src_rt.insert_branch(
ReprTree::from_singleton_buffer(
Context::parse(&ctx, "EditTree"),
SingletonBuffer::new(edittree_list)
)
);
}
ctx.read().unwrap().setup_edittree( &src_rt ); ctx.read().unwrap().setup_edittree( &src_rt );
} else { } else {
eprintln!("no item type"); eprintln!("no item type");
@ -53,176 +240,32 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
} }
} }
); );
/*
let list_morph_editsetup3 = GenericReprTreeMorphism::new( let list_morph_editsetup3 = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Item> ~ EditTree"), Context::parse(&ctx, "<List Item> ~ EditTree"),
Context::parse(&ctx, "<List Item> ~ <List EditTree>"), Context::parse(&ctx, "<List Item> ~ <List ReprTree> ~ <Vec ReprTree>"),
{ {
let ctx = ctx.clone(); let ctx = ctx.clone();
move |src_rt, σ| { move |src_rt, σ| {
let edittree = src_rt.edittree( &ctx ); let edittree = src_rt.edittree( &ctx );
let list_edit = edittree.get().read().unwrap().get_edit::< ListEditor >().unwrap(); let list_edit = edittree.get().get_edit::< ListEditor >().unwrap();
let edittree_items = list_edit.read().unwrap().data.get_port().to_list(); list_edit.write().unwrap().update_item_reprtrees(Context::parse(&ctx, "Item~EditTree")
.apply_substitution(&move |s| σ.get(s).cloned())
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
); );
}
}
);
*/
let list_morph_rt_to_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Char> ~ <List ReprTree>"),
Context::parse(&ctx, "<List Char>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to( src_rt.attach_leaf_to(
Context::parse(&ctx, "<List Char>"), Context::parse(&ctx, "<List EditTree> ~ <Vec ReprTree>"),
src_rt.descend(Context::parse(&ctx, "<List ReprTree>")).expect("cant descend") list_edit.read().unwrap().data.get_port().to_list()
.view_list::<ReprTreeArc>()
.map(|rt| {
rt.view_singleton::<char>().get_view().get()
})
); );
} }
} }
); );
let list_morph_rt_from_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Char>"),
Context::parse(&ctx, "<List Char> ~ <List ReprTree>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List Char>~<List ReprTree>"),
src_rt.view_list::<char>()
.map({|c| {
ReprTree::from_singleton_buffer(
TypeTerm::TypeID(TYPEID_char),
SingletonBuffer::<char>::new( *c )
)
}})
);
}
}
);
let seq_morph_to_list_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<Seq Char>"),
Context::parse(&ctx, "<Seq Char>~<List Char>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List Char>"),
src_rt.view_seq::<char>().to_list()
);
}
}
);
let list_morph_to_vec_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Char>"),
Context::parse(&ctx, "<List Char>~<Vec Char>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<Vec Char>"),
src_rt.view_list::<char>()
);
}
}
);
let seq_morph_to_list_u64 = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<Seq machine.UInt64>"),
Context::parse(&ctx, "<Seq machine.UInt64>~<List machine.UInt64>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List machine.UInt64>"),
src_rt.view_seq::<u64>().to_list()
);
}
}
);
let list_morph_to_vec_u64 = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List machine.UInt64>"),
Context::parse(&ctx, "<List machine.UInt64>~<Vec machine.UInt64>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
src_rt.attach_leaf_to(
Context::parse(&ctx, "<Vec machine.UInt64>"),
src_rt.view_list::<u64>()
);
}
}
);
let list_morph_from_vec_char = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Char>~<Vec Char>"),
Context::parse(&ctx, "<List Char>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let src_port = src_rt.descend(Context::parse(&ctx, "<List Char>~<Vec Char>")).expect("descend")
.get_port::<RwLock<Vec<char>>>().unwrap();
src_rt.attach_leaf_to( Context::parse(&ctx, "<List Char>"), src_port.to_list() );
}
}
);
let list_morph_from_vec_rt = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List ReprTree>~<Vec ReprTree>"),
Context::parse(&ctx, "<List ReprTree>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let src_port = src_rt.descend(Context::parse(&ctx, "<List ReprTree>~<Vec ReprTree>")).expect("descend")
.get_port::<RwLock<Vec<ReprTreeArc>>>().unwrap();
src_rt.attach_leaf_to( Context::parse(&ctx, "<List ReprTree>"), src_port.to_list() );
}
}
);
let list_morph_to_vec_edittree = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List EditTree>"),
Context::parse(&ctx, "<List EditTree> ~ <Vec EditTree>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
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_editsetup1 );
ctx.write().unwrap().morphisms.add_morphism( list_morph_rt_to_char ); ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup3 );
ctx.write().unwrap().morphisms.add_morphism( list_morph_rt_from_char );
ctx.write().unwrap().morphisms.add_morphism( list_morph_from_vec_char ); init_ctx__seq_to_list(&ctx);
ctx.write().unwrap().morphisms.add_morphism( list_morph_from_vec_rt ); init_ctx__vec_to_list(&ctx);
ctx.write().unwrap().morphisms.add_morphism( seq_morph_to_list_char ); init_ctx__list_to_vec(&ctx);
ctx.write().unwrap().morphisms.add_morphism( seq_morph_to_list_u64 ); init_ctx__pack_reprtree(&ctx);
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_char ); init_ctx__unpack_reprtree(&ctx);
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_u64 );
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_edittree );
} }

View file

@ -2,13 +2,13 @@ use {
crate::{ crate::{
edit_tree::{diagnostics::Diagnostics, EditTree, TreeCursor, TreeNav}, edit_tree::{diagnostics::Diagnostics, EditTree, TreeCursor, TreeNav},
editors::{list::{ListCmd, ListCursor, ListCursorMode}, ObjCommander}, editors::{list::{ListCmd, ListCursor, ListCursorMode}, ObjCommander},
repr_tree::{ReprTreeBuilder, context::TYPEID_edittree, node::ReprTreeArc, Context, ReprTree, ReprTreeExt} repr_tree::{context::{TYPEID_edittree, TYPEID_reprtree}, node::ReprTreeArc, Context, ReprTree, ReprTreeBuilder, ReprTreeExt}
}, },
laddertypes::TypeTerm, laddertypes::TypeTerm,
r3vi::{ r3vi::{
buffer::{singleton::*, vec::*}, buffer::{singleton::*, vec::*},
projection::*, projection::*,
view::{list::*, sequence::*, singleton::*, OuterViewPort} view::{list::*, port::UpdateTask, sequence::*, singleton::*, OuterViewPort}
}, },
std::sync::{Arc, RwLock} std::sync::{Arc, RwLock}
}; };
@ -25,11 +25,10 @@ pub struct ListEditor {
depth: OuterViewPort<dyn SingletonView<Item = usize>>, depth: OuterViewPort<dyn SingletonView<Item = usize>>,
pub item_type: TypeTerm,
pub master_repr: Arc<RwLock<TypeTerm>>,
pub item_builder: ReprTreeBuilder, pub item_builder: ReprTreeBuilder,
pub ctx: Arc<RwLock<Context>>, pub ctx: Arc<RwLock<Context>>,
/// item type
pub typ: TypeTerm,
} }
impl ListEditor { impl ListEditor {
@ -51,7 +50,7 @@ impl ListEditor {
) -> Self { ) -> Self {
let cursor = SingletonBuffer::new(ListCursor::default()); let cursor = SingletonBuffer::new(ListCursor::default());
ListEditor { let mut le = ListEditor {
mode_port: cursor mode_port: cursor
.get_port() .get_port()
.map({ .map({
@ -66,7 +65,6 @@ impl ListEditor {
if idx >= 0 && idx < data.len() as isize { if idx >= 0 && idx < data.len() as isize {
data.get(idx as usize) data.get(idx as usize)
.edittree(&ctx).get() .edittree(&ctx).get()
.read().unwrap()
.get_mode_view() .get_mode_view()
} else { } else {
ip ip
@ -95,7 +93,6 @@ impl ListEditor {
if idx >= 0 && idx < data.len() as isize { if idx >= 0 && idx < data.len() as isize {
return data.get(idx as usize) return data.get(idx as usize)
.edittree(&ctx).get() .edittree(&ctx).get()
.read().unwrap()
.get_addr_view(); .get_addr_view();
} }
} }
@ -119,49 +116,55 @@ impl ListEditor {
TypeTerm::TypeID(TYPEID_edittree) TypeTerm::TypeID(TYPEID_edittree)
])) ]))
.clone(), .clone(),
typ, master_repr: Arc::new(RwLock::new(typ.clone())),
item_type: typ,
ctx, ctx,
depth: SingletonBuffer::new(0).get_port() depth: SingletonBuffer::new(0).get_port(),
} };
le.update_item_reprtrees(&le.item_type.clone());
le
} }
pub fn into_node(mut self, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> EditTree { pub fn to_edittree(self, mut edittree: EditTree) -> EditTree {
let ctx = self.ctx.clone();
self.depth = depth.clone();
let editor = Arc::new(RwLock::new(self)); let editor = Arc::new(RwLock::new(self));
let e = editor.read().unwrap(); let e = editor.read().unwrap();
let mut node = EditTree::new(ctx, depth) edittree.ctrl.spillbuf = e.spillbuf.clone();
edittree
.set_editor(editor.clone()) .set_editor(editor.clone())
.set_nav(editor.clone()) .set_nav(editor.clone())
.set_cmd(editor.clone()) .set_cmd(editor.clone())
.set_diag(e.get_edittree_seq() .set_diag(e.get_edittree_seq()
.enumerate() .enumerate()
.map(|(idx, item_editor)| { .map(|(idx, item_editor)| {
let idx = *idx; let idx = *idx;
item_editor.get_msg_port() item_editor.get_msg_port()
.map(move |msg| { .map(move |msg| {
let mut msg = msg.clone(); let mut msg = msg.clone();
msg.addr.insert(0, idx); msg.addr.insert(0, idx);
msg msg
}) })
}) })
.flatten()); .flatten())
node.ctrl.spillbuf = e.spillbuf.clone();
node
} }
pub fn update_item_reprtrees(&self, master_repr: &TypeTerm) { pub fn into_node(mut self, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> EditTree {
let ctx = self.ctx.clone();
self.depth = depth.clone();
self.to_edittree(EditTree::new(ctx, depth))
}
pub fn update_item_reprtrees(&mut self, master_repr: &TypeTerm) {
self.data.get_port().0.update();
*self.master_repr.write().unwrap() = master_repr.clone();
for i in 0..self.data.len() { for i in 0..self.data.len() {
self.item_builder.update( &self.data.get(i), master_repr.clone() ); self.item_builder.update( &self.data.get(i), master_repr.clone() );
} }
} }
pub fn get_item_type(&self) -> TypeTerm { pub fn get_item_type(&self) -> TypeTerm {
self.typ.clone() self.item_type.clone()
} }
pub fn get_list_type(&self) -> TypeTerm { pub fn get_list_type(&self) -> TypeTerm {
@ -179,11 +182,17 @@ impl ListEditor {
self.data.get_port().to_list() self.data.get_port().to_list()
} }
pub fn get_edittree_list(&self) -> OuterViewPort<dyn ListView<EditTree>> { pub fn get_edittree_list(&self) -> OuterViewPort<dyn ListView< EditTree >> {
self.get_reprtree_list().map({ self.get_reprtree_list().map({
let ctx = self.ctx.clone(); let ctx = self.ctx.clone();
move|rt| { let item_builder = self.item_builder.clone();
rt.edittree(&ctx).get().read().unwrap().clone() let master_repr = self.master_repr.clone();
let item_type = self.item_type.clone();
move |rt| {
if rt.descend(TypeTerm::TypeID(TYPEID_edittree)).is_none() {
item_builder.update( &rt, item_type.clone() );
}
rt.edittree(&ctx).get()
} }
}) })
} }
@ -191,11 +200,12 @@ impl ListEditor {
pub fn get_edittree_seq(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> { pub fn get_edittree_seq(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
self.get_edittree_list().to_sequence() self.get_edittree_list().to_sequence()
} }
/* /*
pub fn get_data(&self) -> Arc<RwLock<ReprTree>> { pub fn get_data(&self) -> Arc<RwLock<ReprTree>> {
let data_view = self.get_data_port(); let data_view = self.get_data_port();
ReprTree::new_leaf( ReprTree::new_leaf(
self.get_seq_type(), self.get_list_type(),
data_view.into() data_view.into()
) )
} }
@ -226,11 +236,11 @@ impl ListEditor {
} }
} }
pub fn get_edittree(&self, idx: usize) -> Arc<RwLock<EditTree>> { pub fn get_edittree(&self, idx: usize) -> EditTree {
self.data.get(idx).edittree(&self.ctx).get() self.data.get(idx).edittree(&self.ctx).get()
} }
pub fn get_cur_edittree(&self) -> Option< Arc<RwLock<EditTree>> > { pub fn get_cur_edittree(&self) -> Option< EditTree > {
if let Some(idx) = self.cursor.get().idx { if let Some(idx) = self.cursor.get().idx {
let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize; let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize;
if idx < self.data.len() { if idx < self.data.len() {
@ -245,7 +255,7 @@ impl ListEditor {
/// is the element-type also a list-like editor (i.e. impls TreeNav) /// is the element-type also a list-like editor (i.e. impls TreeNav)
pub fn is_listlist(&self) -> bool { pub fn is_listlist(&self) -> bool {
self.ctx.read().unwrap().is_list_type(&self.typ) self.ctx.read().unwrap().is_list_type(&self.item_type)
} }
/// delete all items /// delete all items
@ -282,8 +292,10 @@ impl ListEditor {
/// insert a new element /// insert a new element
pub fn insert(&mut self, item: ReprTreeArc) { pub fn insert(&mut self, item: ReprTreeArc) {
let item_edit = item.edittree(&self.ctx).get(); self.item_builder.update( &item, self.master_repr.read().unwrap().clone() );
item_edit.read().unwrap().disp.depth.0.set_view(
let mut item_edit = item.edittree(&self.ctx).get_mut();
item_edit.disp.depth.0.set_view(
self.depth.map(|d| d+1).get_view() self.depth.map(|d| d+1).get_view()
); );
@ -295,7 +307,7 @@ impl ListEditor {
if self.is_listlist() { if self.is_listlist() {
cur.mode = ListCursorMode::Select; cur.mode = ListCursorMode::Select;
} else { } else {
item_edit.write().unwrap().goto(TreeCursor::none()); item_edit.goto(TreeCursor::none());
cur.idx = Some(idx + 1); cur.idx = Some(idx + 1);
} }
} }
@ -352,8 +364,7 @@ impl ListEditor {
let cur = self.get_cursor(); let cur = self.get_cursor();
if let Some(mut item) = self.get_item().clone() { if let Some(mut item) = self.get_item().clone() {
let item_edit = item.edittree(&self.ctx).get(); let mut ie = item.edittree(&self.ctx).get_mut();
let mut ie = item_edit.write().unwrap();
ie.send_cmd_obj(ListCmd::Split.into_repr_tree(&self.ctx)); ie.send_cmd_obj(ListCmd::Split.into_repr_tree(&self.ctx));
if cur.tree_addr.len() < 3 { if cur.tree_addr.len() < 3 {
@ -364,12 +375,11 @@ impl ListEditor {
let mut b = ie.ctrl.spillbuf.write().unwrap(); let mut b = ie.ctrl.spillbuf.write().unwrap();
let rt = ReprTree::new_arc(self.typ.clone()); let rt = ReprTree::new_arc(self.item_type.clone());
let mut et = self.ctx.read().unwrap().setup_edittree(&rt); let mut et = self.ctx.read().unwrap().setup_edittree(&rt);
if let Some(edittree) = et.as_mut(){ if let Some(edittree) = et.as_mut(){
let mut tail_node = edittree.get(); let mut tail_node = edittree.get_mut();
let mut tail_node = tail_node.write().unwrap();
tail_node.goto(TreeCursor::home()); tail_node.goto(TreeCursor::home());
for n in b.iter() { for n in b.iter() {
@ -399,10 +409,8 @@ impl ListEditor {
pub fn listlist_join_pxev(&mut self, idx: isize) { pub fn listlist_join_pxev(&mut self, idx: isize) {
{ {
let cur_editor = self.data.get(idx as usize).edittree(&self.ctx).get(); let mut cur_editor = self.data.get(idx as usize).edittree(&self.ctx).get_mut();
let pxv_editor = self.data.get(idx as usize-1).edittree(&self.ctx).get(); let mut pxv_editor = self.data.get(idx as usize-1).edittree(&self.ctx).get_mut();
let mut cur_editor = cur_editor.write().unwrap();
let mut pxv_editor = pxv_editor.write().unwrap();
let oc0 = cur_editor.get_cursor(); let oc0 = cur_editor.get_cursor();
@ -451,10 +459,8 @@ impl ListEditor {
pub fn listlist_join_nexd(&mut self, idx: usize) { pub fn listlist_join_nexd(&mut self, idx: usize) {
{ {
let cur_editor = self.data.get(idx).edittree(&self.ctx).get(); let mut cur_editor = self.data.get(idx).edittree(&self.ctx).get_mut();
let nxd_editor = self.data.get(idx + 1).edittree(&self.ctx).get(); let mut nxd_editor = self.data.get(idx + 1).edittree(&self.ctx).get_mut();
let mut cur_editor = cur_editor.write().unwrap();
let mut nxd_editor = nxd_editor.write().unwrap();
let oc0 = cur_editor.get_cursor(); let oc0 = cur_editor.get_cursor();

View file

@ -38,7 +38,6 @@ impl TreeNav for ListEditor {
_ => 0 _ => 0
}) })
.edittree(&self.ctx).get() .edittree(&self.ctx).get()
.read().unwrap()
.get_height(op) .get_height(op)
} else { } else {
1 1
@ -49,7 +48,6 @@ impl TreeNav for ListEditor {
.map(|i| self.data .map(|i| self.data
.get(i) .get(i)
.edittree(&self.ctx).get() .edittree(&self.ctx).get()
.read().unwrap()
.get_height(&TreeHeightOp::Max) .get_height(&TreeHeightOp::Max)
) )
.max() .max()
@ -75,7 +73,6 @@ impl TreeNav for ListEditor {
if let Some(i) = cur.idx { if let Some(i) = cur.idx {
if i < self.data.len() as isize { if i < self.data.len() as isize {
let mut sub_cur = self.get_edittree(i as usize) let mut sub_cur = self.get_edittree(i as usize)
.read().unwrap()
.get_cursor_warp(); .get_cursor_warp();
sub_cur.tree_addr.insert(0, i as isize - self.data.len() as isize); sub_cur.tree_addr.insert(0, i as isize - self.data.len() as isize);
return sub_cur; return sub_cur;
@ -108,7 +105,7 @@ impl TreeNav for ListEditor {
ListCursorMode::Select => { ListCursorMode::Select => {
if let Some(i) = cur.idx { if let Some(i) = cur.idx {
if i < self.data.len() as isize { if i < self.data.len() as isize {
let mut sub_cur = self.get_edittree(i as usize).read().unwrap().get_cursor(); let mut sub_cur = self.get_edittree(i as usize).get_cursor();
if sub_cur.tree_addr.len() > 0 { if sub_cur.tree_addr.len() > 0 {
sub_cur.tree_addr.insert(0, i as isize); sub_cur.tree_addr.insert(0, i as isize);
return sub_cur; return sub_cur;
@ -132,7 +129,7 @@ impl TreeNav for ListEditor {
let old_cur = self.cursor.get(); let old_cur = self.cursor.get();
if let Some(i) = old_cur.idx { if let Some(i) = old_cur.idx {
if i < self.data.len() as isize { if i < self.data.len() as isize {
self.get_edittree(i as usize).write().unwrap().goto(TreeCursor::none()); self.get_edittree(i as usize).goto(TreeCursor::none());
} }
} }
@ -154,7 +151,6 @@ impl TreeNav for ListEditor {
if new_cur.leaf_mode == ListCursorMode::Select && self.data.len() > 0 { if new_cur.leaf_mode == ListCursorMode::Select && self.data.len() > 0 {
self.get_edittree(idx as usize) self.get_edittree(idx as usize)
.write().unwrap()
.goto(TreeCursor { .goto(TreeCursor {
leaf_mode: ListCursorMode::Select, leaf_mode: ListCursorMode::Select,
tree_addr: vec![] tree_addr: vec![]
@ -173,7 +169,6 @@ impl TreeNav for ListEditor {
}); });
self.get_edittree(idx as usize) self.get_edittree(idx as usize)
.write().unwrap()
.goto(TreeCursor { .goto(TreeCursor {
leaf_mode: new_cur.leaf_mode, leaf_mode: new_cur.leaf_mode,
tree_addr: new_cur.tree_addr[1..].iter().cloned().collect(), tree_addr: new_cur.tree_addr[1..].iter().cloned().collect(),
@ -219,7 +214,6 @@ impl TreeNav for ListEditor {
if cur.tree_addr[0] < self.data.len() as isize { if cur.tree_addr[0] < self.data.len() as isize {
if self.get_edittree(cur.tree_addr[0] as usize) if self.get_edittree(cur.tree_addr[0] as usize)
.write().unwrap()
.goby(Vector2::new(direction.x, direction.y)) .goby(Vector2::new(direction.x, direction.y))
== TreeNavResult::Continue { == TreeNavResult::Continue {
self.cursor.set(ListCursor { self.cursor.set(ListCursor {
@ -253,11 +247,11 @@ impl TreeNav for ListEditor {
match cur.leaf_mode { match cur.leaf_mode {
ListCursorMode::Select => { ListCursorMode::Select => {
let cur_item = self.get_edittree(cur.tree_addr[0] as usize); let cur_item = self.get_edittree(cur.tree_addr[0] as usize);
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::Max); let cur_height = cur_item.get_height(&TreeHeightOp::Max);
let new_item = self.get_edittree(idx as usize); let new_item = self.get_edittree(idx as usize);
let height = new_item.read().unwrap().get_height( let height = new_item.get_height(
if direction.x < 0 { if direction.x < 0 {
&TreeHeightOp::Q &TreeHeightOp::Q
} else { } else {
@ -282,7 +276,7 @@ impl TreeNav for ListEditor {
{ {
if (cur.tree_addr[0] as usize) < self.data.len() { if (cur.tree_addr[0] as usize) < self.data.len() {
let cur_item = self.get_edittree(cur.tree_addr[0] as usize); let cur_item = self.get_edittree(cur.tree_addr[0] as usize);
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::P); let cur_height = cur_item.get_height(&TreeHeightOp::P);
if gravity && cur_height > 1 { if gravity && cur_height > 1 {
new_addr.push( cur.tree_addr[0] ); new_addr.push( cur.tree_addr[0] );
@ -294,7 +288,7 @@ impl TreeNav for ListEditor {
} else { } else {
if (idx as usize) < self.data.len() { if (idx as usize) < self.data.len() {
let pxv_item = self.get_edittree(idx as usize); let pxv_item = self.get_edittree(idx as usize);
let pxv_height = pxv_item.read().unwrap().get_height(&TreeHeightOp::P); let pxv_height = pxv_item.get_height(&TreeHeightOp::P);
if gravity && pxv_height > 1 { if gravity && pxv_height > 1 {
new_addr.push( idx ); new_addr.push( idx );
@ -328,8 +322,8 @@ impl TreeNav for ListEditor {
// nested // nested
if cur.tree_addr[0] < self.data.len() as isize { if cur.tree_addr[0] < self.data.len() as isize {
let cur_item = self.get_edittree(cur.tree_addr[0] as usize); let mut cur_item = self.get_edittree(cur.tree_addr[0] as usize);
let result = cur_item.write().unwrap().goby(direction); let result = cur_item.goby(direction);
match result match result
{ {
@ -356,8 +350,8 @@ impl TreeNav for ListEditor {
if direction.x < 0 { if direction.x < 0 {
let pxv_item = self.get_edittree(cur.tree_addr[0] as usize - 1); let pxv_item = self.get_edittree(cur.tree_addr[0] as usize - 1);
let pxv_height = pxv_item.read().unwrap().get_height(&TreeHeightOp::Q) as isize; let pxv_height = pxv_item.get_height(&TreeHeightOp::Q) as isize;
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::P) as isize; let cur_height = cur_item.get_height(&TreeHeightOp::P) as isize;
let dist_from_ground = cur_height - (depth as isize - 1); let dist_from_ground = cur_height - (depth as isize - 1);
let n_steps_down = let n_steps_down =
if gravity { if gravity {
@ -374,8 +368,8 @@ impl TreeNav for ListEditor {
} else { } else {
let nxd_item = self.get_edittree(cur.tree_addr[0] as usize + 1); let nxd_item = self.get_edittree(cur.tree_addr[0] as usize + 1);
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::Q) as isize; let cur_height = cur_item.get_height(&TreeHeightOp::Q) as isize;
let nxd_height = nxd_item.read().unwrap().get_height(&TreeHeightOp::P) as isize; let nxd_height = nxd_item.get_height(&TreeHeightOp::P) as isize;
let dist_from_ground = cur_height - (depth as isize - 1); let dist_from_ground = cur_height - (depth as isize - 1);
let n_steps_down = let n_steps_down =
if gravity { if gravity {

View file

@ -23,6 +23,8 @@ pub enum ListSegment {
} }
} }
/* todo: switch to ListView instead of SequenceView
*/
pub struct ListSegmentSequence { pub struct ListSegmentSequence {
data: Arc<dyn SequenceView<Item = EditTree>>, data: Arc<dyn SequenceView<Item = EditTree>>,
cursor: Arc<dyn SingletonView<Item = ListCursor>>, cursor: Arc<dyn SingletonView<Item = ListCursor>>,

View file

@ -11,7 +11,7 @@ use {
}, },
buffer::{singleton::*, vec::*} buffer::{singleton::*, vec::*}
}, },
laddertypes::{TypeTerm, TypeID}, laddertypes::{TypeTerm, TypeID, sugar::*},
std::{ std::{
collections::HashMap, collections::HashMap,
sync::{Arc, RwLock}, sync::{Arc, RwLock},
@ -45,7 +45,7 @@ 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, t: TypeTerm) -> Self {
self.required_leaves.push(t); self.required_leaves.push(t.normalize());
self self
} }
@ -63,6 +63,7 @@ impl ReprTreeBuilder {
let morphism_base = &self.ctx.read().unwrap().morphisms; let morphism_base = &self.ctx.read().unwrap().morphisms;
let mt = master_leaf_type.into(); let mt = master_leaf_type.into();
//eprintln!("REBUILD repr tree from {}", self.ctx.read().unwrap().type_term_to_str(&mt));
let mut leaves = self.required_leaves.clone(); let mut leaves = self.required_leaves.clone();
leaves.retain(|t| t != &mt); leaves.retain(|t| t != &mt);

View file

@ -1,7 +1,7 @@
use { use {
crate::{ crate::{
edit_tree::EditTree, edit_tree::EditTree,
repr_tree::{GenericReprTreeMorphism, ReprTree, ReprTreeExt, ReprTreeArc}, repr_tree::{GenericReprTreeMorphism, ReprTree, ReprTreeArc, ReprTreeExt},
}, },
laddertypes::{ laddertypes::{
parser::ParseLadderType, sugar::SugaredTypeTerm, unparser::UnparseLadderType, parser::ParseLadderType, sugar::SugaredTypeTerm, unparser::UnparseLadderType,
@ -12,18 +12,18 @@ use {
view::{singleton::*, OuterViewPort}, view::{singleton::*, OuterViewPort},
}, },
std::{ std::{
collections::HashMap, collections::HashMap, ops::DerefMut, sync::{Arc, RwLock}
sync::{Arc, RwLock}, },
}
}; };
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
pub static TYPEID_edittree : TypeID = TypeID::Fun(0); pub static TYPEID_reprtree: TypeID = TypeID::Fun(0);
pub static TYPEID_char : TypeID = TypeID::Fun(1); pub static TYPEID_edittree: TypeID = TypeID::Fun(1);
pub static TYPEID_u64 : TypeID = TypeID::Fun(2); pub static TYPEID_char: TypeID = TypeID::Fun(2);
pub static TYPEID_list : TypeID = TypeID::Fun(3); pub static TYPEID_u64: TypeID = TypeID::Fun(3);
pub static TYPEID_vec : TypeID = TypeID::Fun(4); pub static TYPEID_list: TypeID = TypeID::Fun(4);
pub static TYPEID_vec: TypeID = TypeID::Fun(5);
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
@ -32,18 +32,18 @@ pub struct Context {
/// assigns a name to every type /// assigns a name to every type
pub type_dict: Arc<RwLock<BimapTypeDict>>, pub type_dict: Arc<RwLock<BimapTypeDict>>,
pub morphisms: laddertypes::morphism::MorphismBase< GenericReprTreeMorphism >, pub morphisms: laddertypes::morphism::MorphismBase<GenericReprTreeMorphism>,
/// named vertices of the graph /// named vertices of the graph
nodes: HashMap< String, Arc<RwLock<ReprTree>> >, nodes: HashMap<String, ReprTreeArc>,
/// todo: beautify /// todo: beautify
/// types that can be edited as lists /// types that can be edited as lists
/// do we really need this? /// do we really need this?
pub list_types: Vec< TypeID >, pub list_types: Vec<TypeID>,
pub meta_chars: Vec< char >, pub meta_chars: Vec<char>,
edittree_hook: Arc< dyn Fn(&mut EditTree, TypeTerm) + Send +Sync +'static >, edittree_hook: Arc<dyn Fn(&mut EditTree, TypeTerm) + Send + Sync + 'static>,
/// recursion /// recursion
parent: Option<Arc<RwLock<Context>>>, parent: Option<Arc<RwLock<Context>>>,
@ -52,14 +52,13 @@ pub struct Context {
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
impl Context { impl Context {
pub fn with_parent( pub fn with_parent(parent: Option<Arc<RwLock<Context>>>) -> Self {
parent: Option<Arc<RwLock<Context>>>
) -> Self {
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 => {
let mut dict = BimapTypeDict::new(); let mut dict = BimapTypeDict::new();
assert_eq!(TYPEID_reprtree, dict.add_typename("ReprTree".into()));
assert_eq!(TYPEID_edittree, dict.add_typename("EditTree".into())); assert_eq!(TYPEID_edittree, dict.add_typename("EditTree".into()));
assert_eq!(TYPEID_char, dict.add_typename("Char".into())); assert_eq!(TYPEID_char, dict.add_typename("Char".into()));
assert_eq!(TYPEID_u64, dict.add_typename("machine.UInt64".into())); assert_eq!(TYPEID_u64, dict.add_typename("machine.UInt64".into()));
@ -69,18 +68,18 @@ impl Context {
Arc::new(RwLock::new(dict)) Arc::new(RwLock::new(dict))
} }
}, },
morphisms: MorphismBase::new( TYPEID_list ), morphisms: MorphismBase::new(TYPEID_list),
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(),
None => Vec::new() None => Vec::new(),
}, },
meta_chars: match parent.as_ref() { meta_chars: match parent.as_ref() {
Some(p) => p.read().unwrap().meta_chars.clone(), Some(p) => p.read().unwrap().meta_chars.clone(),
None => Vec::new() None => Vec::new(),
}, },
parent, parent,
edittree_hook: Arc::new(|_et, _t| {}) edittree_hook: Arc::new(|_et, _t| {}),
} }
} }
@ -88,7 +87,10 @@ impl Context {
Context::with_parent(None) Context::with_parent(None)
} }
pub fn set_edittree_hook(&mut self, hook: Arc< dyn Fn(&mut EditTree, TypeTerm) + Send +Sync +'static >) { pub fn set_edittree_hook(
&mut self,
hook: Arc<dyn Fn(&mut EditTree, TypeTerm) + Send + Sync + 'static>,
) {
self.edittree_hook = hook; self.edittree_hook = hook;
} }
@ -100,22 +102,20 @@ impl Context {
} }
} }
pub fn apply_morphism( &self, rt: &Arc<RwLock<ReprTree>>, ty: &MorphismType ) { pub fn apply_morphism(&self, rt: &Arc<RwLock<ReprTree>>, ty: &MorphismType) {
if let Some(path) if let Some(path) = self.morphisms.find_morphism_path(ty.clone().normalize()) {
= self.morphisms.find_morphism_path( ty.clone().normalize() )
{
let mut path = path.into_iter(); let mut path = path.into_iter();
if let Some(mut src_type) = path.next() { if let Some(mut src_type) = path.next() {
for dst_type in path { for dst_type in path {
if let Some(( m, mut τ, σ )) = if let Some((m, mut τ, σ)) =
self.morphisms.find_morphism_with_subtyping( self.morphisms
&laddertypes::MorphismType { .find_morphism_with_subtyping(&laddertypes::MorphismType {
src_type: src_type.clone(), src_type: src_type.clone(),
dst_type: dst_type.clone() dst_type: dst_type.clone(),
} })
) { {
let mut rt = rt.descend( τ ).expect("descend src repr"); let mut rt = rt.descend(τ).expect("descend src repr");
(m.setup_projection)( &mut rt, &σ ); (m.setup_projection)(&mut rt, &σ);
} }
src_type = dst_type; src_type = dst_type;
@ -127,7 +127,10 @@ impl Context {
} }
pub fn parse(ctx: &Arc<RwLock<Self>>, s: &str) -> TypeTerm { pub fn parse(ctx: &Arc<RwLock<Self>>, s: &str) -> TypeTerm {
ctx.read().unwrap().type_term_from_str(s).expect("could not parse type term") ctx.read()
.unwrap()
.type_term_from_str(s)
.expect("could not parse type term")
} }
pub fn add_typename(&mut self, tn: &str) -> TypeID { pub fn add_typename(&mut self, tn: &str) -> TypeID {
@ -139,21 +142,21 @@ impl Context {
} }
pub fn add_synonym(&mut self, new: &str, old: &str) { pub fn add_synonym(&mut self, new: &str, old: &str) {
self.type_dict.write().unwrap().add_synonym(new.to_string(), old.to_string()); self.type_dict
.write()
.unwrap()
.add_synonym(new.to_string(), old.to_string());
} }
pub fn add_list_typename(&mut self, tn: &str) { pub fn add_list_typename(&mut self, tn: &str) {
let tid = self.add_typename(tn); let tid = self.add_typename(tn);
self.list_types.push( tid ); self.list_types.push(tid);
} }
pub fn is_list_type(&self, t: &TypeTerm) -> bool { pub fn is_list_type(&self, t: &TypeTerm) -> bool {
match t { match t {
TypeTerm::TypeID(id) => { TypeTerm::TypeID(id) => self.list_types.contains(id),
self.list_types.contains(id) TypeTerm::Ladder(args) | TypeTerm::App(args) => {
}
TypeTerm::Ladder(args) |
TypeTerm::App(args) => {
if args.len() > 0 { if args.len() > 0 {
if self.is_list_type(&args[0]) { if self.is_list_type(&args[0]) {
true true
@ -164,7 +167,7 @@ impl Context {
false false
} }
} }
_ => false _ => false,
} }
} }
@ -175,7 +178,7 @@ impl Context {
pub fn get_fun_typeid(&self, tn: &str) -> Option<u64> { pub fn get_fun_typeid(&self, tn: &str) -> Option<u64> {
match self.get_typeid(tn) { match self.get_typeid(tn) {
Some(TypeID::Fun(x)) => Some(x), Some(TypeID::Fun(x)) => Some(x),
_ => None _ => None,
} }
} }
@ -186,11 +189,14 @@ impl Context {
pub fn get_var_typeid(&self, tn: &str) -> Option<u64> { pub fn get_var_typeid(&self, tn: &str) -> Option<u64> {
match self.get_typeid(tn) { match self.get_typeid(tn) {
Some(TypeID::Var(x)) => Some(x), Some(TypeID::Var(x)) => Some(x),
_ => None _ => None,
} }
} }
pub fn type_term_from_str(&self, tn: &str) -> Result<TypeTerm, laddertypes::parser::ParseError> { pub fn type_term_from_str(
&self,
tn: &str,
) -> Result<TypeTerm, laddertypes::parser::ParseError> {
self.type_dict.write().unwrap().parse(&tn) self.type_dict.write().unwrap().parse(&tn)
} }
@ -200,17 +206,22 @@ impl Context {
/// adds an object without any representations /// adds an object without any representations
pub fn add_obj(ctx: Arc<RwLock<Context>>, name: String, typename: &str) { pub fn add_obj(ctx: Arc<RwLock<Context>>, name: String, typename: &str) {
let type_tag = ctx.read().unwrap() let type_tag = ctx
.type_dict.write().unwrap() .read()
.parse(typename).unwrap(); .unwrap()
/* .type_dict
if let Some(node) = Context::make_node(&ctx, type_tag, SingletonBuffer::new(0).get_port()) { .write()
ctx.write().unwrap().nodes.insert(name, node); .unwrap()
} .parse(typename)
*/ .unwrap();
/*
if let Some(node) = Context::make_node(&ctx, type_tag, SingletonBuffer::new(0).get_port()) {
ctx.write().unwrap().nodes.insert(name, node);
}
*/
} }
pub fn get_obj(&self, name: &String) -> Option< ReprTreeArc > { pub fn get_obj(&self, name: &String) -> Option<ReprTreeArc> {
if let Some(obj) = self.nodes.get(name) { if let Some(obj) = self.nodes.get(name) {
Some(obj.clone()) Some(obj.clone())
} else if let Some(parent) = self.parent.as_ref() { } else if let Some(parent) = self.parent.as_ref() {
@ -222,22 +233,24 @@ impl Context {
pub fn setup_edittree( pub fn setup_edittree(
&self, &self,
rt: &Arc<RwLock<ReprTree>> rt: &Arc<RwLock<ReprTree>>,
) -> Option<SingletonBuffer<Arc<RwLock<EditTree>>>> { ) -> Option<SingletonBuffer<EditTree>> {
if let Some(new_edittree) = let edittree_rt = rt
rt.descend(self.type_term_from_str("EditTree").unwrap()) .descend(
{ self.type_term_from_str("EditTree")
let typ = rt.read().unwrap().get_type().clone(); .expect("cant descend to editTree"),
let buf = new_edittree.singleton_buffer::<Arc<RwLock<EditTree>>>(); )
(*self.edittree_hook)( .clone();
&mut *buf.get().write().unwrap(), if let Some(new_edittree) = edittree_rt {
typ let typ = rt.get_type();
); let mut buf = new_edittree.singleton_buffer::<EditTree>();
(*self.edittree_hook)(&mut *buf.get_mut(), typ);
Some(buf) Some(buf)
} else { } else {
eprintln!("cant find edit tree repr {} ~Ψ~ {}", eprintln!(
self.type_term_to_str(rt.read().unwrap().get_halo_type()), "cant find edit tree repr {} ~Ψ~ {}",
self.type_term_to_str(rt.read().unwrap().get_type()) self.type_term_to_str(&rt.get_halo_type()),
self.type_term_to_str(&rt.get_type())
); );
None None
} }

View file

@ -38,6 +38,7 @@ use {
pub trait ReprTreeExt { pub trait ReprTreeExt {
fn get_type(&self) -> TypeTerm; fn get_type(&self) -> TypeTerm;
fn get_halo_type(&self) -> TypeTerm;
fn get_full_type(&self) -> TypeTerm; fn get_full_type(&self) -> TypeTerm;
fn insert_leaf(&mut self, type_ladder: impl Into<TypeTerm>, leaf: ReprLeaf); fn insert_leaf(&mut self, type_ladder: impl Into<TypeTerm>, leaf: ReprLeaf);
@ -61,8 +62,8 @@ pub trait ReprTreeExt {
fn singleton_buffer<T: Clone + Send + Sync + 'static>(&self) -> SingletonBuffer<T>; fn singleton_buffer<T: Clone + Send + Sync + 'static>(&self) -> SingletonBuffer<T>;
fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> VecBuffer<T>; fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> VecBuffer<T>;
fn edittree(&self, ctx: &Arc<RwLock<Context>>) -> SingletonBuffer< Arc<RwLock<crate::edit_tree::EditTree>> > { fn edittree(&self, ctx: &Arc<RwLock<Context>>) -> SingletonBuffer< crate::edit_tree::EditTree > {
self.descend_create(Context::parse(&ctx, "EditTree")) self.descend(Context::parse(&ctx, "EditTree"))
.expect("failed to get EditTree") .expect("failed to get EditTree")
.singleton_buffer() .singleton_buffer()
} }
@ -73,6 +74,10 @@ impl ReprTreeExt for Arc<RwLock<ReprTree>> {
self.read().unwrap().get_type().clone() self.read().unwrap().get_type().clone()
} }
fn get_halo_type(&self) -> TypeTerm {
self.read().unwrap().get_halo_type().clone()
}
fn get_full_type(&self) -> TypeTerm { fn get_full_type(&self) -> TypeTerm {
self.read().unwrap().get_full_type().clone() self.read().unwrap().get_full_type().clone()
} }
@ -144,11 +149,11 @@ impl ReprTreeExt for Arc<RwLock<ReprTree>> {
} }
fn singleton_buffer<T: Clone + Send + Sync + 'static>(&self) -> SingletonBuffer<T> { fn singleton_buffer<T: Clone + Send + Sync + 'static>(&self) -> SingletonBuffer<T> {
self.write().unwrap().singleton_buffer::<T>().expect("") self.write().unwrap().singleton_buffer::<T>().expect("cant get singleton buffer")
} }
fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> VecBuffer<T> { fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> VecBuffer<T> {
self.write().unwrap().vec_buffer::<T>().expect("") self.write().unwrap().vec_buffer::<T>().expect("cant get vec buffer")
} }
} }

View file

@ -21,7 +21,7 @@ use {
Context, Context,
ReprLeaf, ReprLeaf,
ReprTreeExt, ReprTreeExt,
context::{TYPEID_list, TYPEID_vec, TYPEID_char, TYPEID_u64, TYPEID_edittree} context::{TYPEID_reprtree, TYPEID_list, TYPEID_vec, TYPEID_char, TYPEID_u64, TYPEID_edittree}
} }
}; };
@ -228,13 +228,22 @@ impl ReprTree {
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_reprtree)
]) {
let mut leaf = ReprLeaf::from_vec_buffer(
VecBuffer::<ReprTreeArc>::new()
);
leaf.attach_to(src_port);
self.leaf = Some(leaf);
}
else if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_vec), TypeTerm::TypeID(TYPEID_vec),
TypeTerm::TypeID(TYPEID_edittree) TypeTerm::TypeID(TYPEID_edittree)
]) { ]) {
let mut leaf = ReprLeaf::from_vec_buffer( let mut leaf = ReprLeaf::from_vec_buffer(
VecBuffer::< VecBuffer::<crate::edit_tree::EditTree>::new()
Arc<RwLock<crate::edit_tree::EditTree>>
>::new()
); );
leaf.attach_to(src_port); leaf.attach_to(src_port);
@ -261,7 +270,8 @@ impl ReprTree {
leaf.attach_to(src_port); leaf.attach_to(src_port);
self.leaf = Some(leaf); self.leaf = Some(leaf);
} else { }
else {
self.leaf = Some(ReprLeaf::from_view(src_port)); self.leaf = Some(ReprLeaf::from_view(src_port));
} }
} }
@ -272,9 +282,12 @@ impl ReprTree {
if self.type_tag == if self.type_tag ==
TypeTerm::TypeID(TYPEID_edittree) TypeTerm::TypeID(TYPEID_edittree)
{ {
leaf.detach::< dyn SingletonView< leaf.detach::< dyn SingletonView<Item = crate::edit_tree::EditTree> >();
Item = Arc<RwLock< crate::edit_tree::EditTree >> }
> >(); else if self.type_tag ==
TypeTerm::TypeID(TYPEID_reprtree)
{
leaf.detach::< dyn SingletonView<Item = ReprTreeArc> >();
} }
else if self.type_tag == else if self.type_tag ==
TypeTerm::TypeID(TYPEID_char) TypeTerm::TypeID(TYPEID_char)
@ -285,13 +298,17 @@ impl ReprTree {
{ {
leaf.detach::< dyn SingletonView<Item = u64> >(); leaf.detach::< dyn SingletonView<Item = u64> >();
} }
else if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_vec),
TypeTerm::TypeID(TYPEID_reprtree),
]) {
leaf.detach_vec::< ReprTreeArc >();
}
else if self.type_tag == TypeTerm::App(vec![ else if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_vec), TypeTerm::TypeID(TYPEID_vec),
TypeTerm::TypeID(TYPEID_edittree), TypeTerm::TypeID(TYPEID_edittree),
]) { ]) {
leaf.detach_vec::< leaf.detach_vec::<crate::edit_tree::EditTree>();
Arc<RwLock< crate::edit_tree::EditTree >>
>();
} }
else if self.type_tag == TypeTerm::App(vec![ else if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_vec), TypeTerm::TypeID(TYPEID_vec),
@ -309,7 +326,13 @@ impl ReprTree {
TypeTerm::TypeID(TYPEID_list), TypeTerm::TypeID(TYPEID_list),
TypeTerm::TypeID(TYPEID_edittree), TypeTerm::TypeID(TYPEID_edittree),
]) { ]) {
leaf.detach::< dyn ListView<Arc<RwLock<crate::edit_tree::EditTree>>> >(); leaf.detach::< dyn ListView<crate::edit_tree::EditTree> >();
}
else if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_list),
TypeTerm::TypeID(TYPEID_reprtree),
]) {
leaf.detach::< dyn ListView< ReprTreeArc > >();
} }
else if self.type_tag == TypeTerm::App(vec![ else if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_list), TypeTerm::TypeID(TYPEID_list),

View file

@ -98,6 +98,8 @@ impl PTYListStyle {
let editor = node.get_edit::<ListEditor>().unwrap(); let editor = node.get_edit::<ListEditor>().unwrap();
let editor = editor.read().unwrap(); let editor = editor.read().unwrap();
let pty_view = Self::new(style).pty_view(&editor); let pty_view = Self::new(style).pty_view(&editor);
eprintln!("reset TerminalView Leaf");
node.disp.view node.disp.view
.attach_leaf_to( .attach_leaf_to(
Context::parse(&node.ctx, "TerminalView"), Context::parse(&node.ctx, "TerminalView"),
@ -218,33 +220,14 @@ impl PTYListController {
let mut e = self.editor.write().unwrap(); let mut e = self.editor.write().unwrap();
let cur = e.cursor.get(); let cur = e.cursor.get();
let ctx = e.ctx.clone(); let ctx = e.ctx.clone();
let ctx = ctx.read().unwrap();
match cur.mode { match cur.mode {
ListCursorMode::Insert => { ListCursorMode::Insert => {
let rt = ReprTree::new_arc(e.typ.clone()); let mut rt = ReprTree::new_arc(e.item_type.clone());
rt = e.item_builder.build_from(rt).expect("cant creat EditTree for item");
let src_ladder = laddertypes::TypeTerm::Ladder(vec![ let mut ne = rt.edittree(&ctx).get_mut();
rt.read().unwrap().get_type().clone() match ne.send_cmd_obj(cmd_obj.clone()) {
]);
let dst_ladder = laddertypes::TypeTerm::Ladder(vec![
rt.read().unwrap().get_type().clone(),
ctx.type_term_from_str("EditTree").expect("")
]);
ctx.apply_morphism(
&rt,
&laddertypes::MorphismType {
src_type: src_ladder,
dst_type: dst_ladder
}
);
let new_edittree = ctx.setup_edittree( &rt );
if let Some(new_edittree) = new_edittree {
let mut ne = new_edittree.get();
let mut ne = ne.write().unwrap();
match ne.send_cmd_obj(cmd_obj.clone()) {
TreeNavResult::Continue => { TreeNavResult::Continue => {
drop(ne); drop(ne);
e.insert(rt); e.insert(rt);
@ -253,23 +236,19 @@ impl PTYListController {
TreeNavResult::Exit => { TreeNavResult::Exit => {
TreeNavResult::Exit TreeNavResult::Exit
} }
}
} else {
panic!("cant get edit tree");
TreeNavResult::Continue
} }
}, },
ListCursorMode::Select => { ListCursorMode::Select => {
if let Some(item) = e.get_cur_edittree() { if let Some(mut item) = e.get_cur_edittree() {
let res = item.write().unwrap().send_cmd_obj(cmd_obj.clone()); let res = item.send_cmd_obj(cmd_obj.clone());
let child_close_char = item.read().unwrap().ctrl.close_char.get(); let child_close_char = item.ctrl.close_char.get();
match res { match res {
TreeNavResult::Continue => TreeNavResult::Continue, TreeNavResult::Continue => TreeNavResult::Continue,
TreeNavResult::Exit => { TreeNavResult::Exit => {
// child editor returned control, probably for meta-char handling.. // child editor returned control, probably for meta-char handling..
if cmd_obj.read().unwrap().get_type().clone() == ctx.type_term_from_str("Char").unwrap() { if cmd_obj.read().unwrap().get_type().clone() == Context::parse(&ctx, "Char") {
let co = cmd_obj.read().unwrap(); let co = cmd_obj.read().unwrap();
if let Some(cmd_view) = co.get_view::<dyn SingletonView<Item = char>>() { if let Some(cmd_view) = co.get_view::<dyn SingletonView<Item = char>>() {
drop(co); drop(co);

View file

@ -13,7 +13,7 @@ pub mod tty_application;
pub mod editors; pub mod editors;
pub mod edit_tree; pub mod edit_tree;
//pub mod widgets; pub mod widgets;
// <<<<>>>><<>><><<>><<< * >>><<>><><<>><<<<>>>> \\ // <<<<>>>><<>><><<>><<< * >>><<>><><<>><<<<>>>> \\
@ -178,4 +178,3 @@ pub fn setup_edittree_hook(ctx: &Arc<RwLock<Context>>) {
); );
} }

View file

@ -1,15 +1,7 @@
use { use {
cgmath::{Point2, Vector2}, crate::{TerminalAtom, TerminalView}, cgmath::{Point2, Vector2}, r3vi::view::{
r3vi::{ index::*, InnerViewPort, Observer, ObserverBroadcast, OuterViewPort, View
view::{ }, std::sync::{Arc, RwLock}
InnerViewPort, Observer, ObserverBroadcast, OuterViewPort, View,
index::*
},
},
crate::{
terminal::{TerminalAtom, TerminalView},
},
std::sync::{Arc, RwLock},
}; };
pub struct AsciiBox { pub struct AsciiBox {