Compare commits

...

10 commits

14 changed files with 422 additions and 218 deletions

View file

@ -47,7 +47,7 @@ async fn main() {
* / | \
* / | \
* / | \
* u32 EditTree Char
* u64 EditTree Char
* - Editor \
* - Display EditTree
* / | \ - Editor
@ -109,13 +109,13 @@ async fn main() {
.map_item(|p, a| {
a.add_style_back(TerminalStyle::fg_color(((25 * p.x % 255) as u8, 200, 0)))
})
.offset(Vector2::new(5, 0)));
.offset(Vector2::new(5,0)));
let label_str = ctx.read().unwrap().type_term_to_str(&rt_digit.read().unwrap().get_type());
comp.push(
nested_tty::make_label(&label_str)
.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(rt_digit
.edittree( &ctx ).get().read().unwrap()

View file

@ -63,76 +63,66 @@ async fn main() {
/* initially copy values from Vec to EditTree...
*/
ctx.read().unwrap().apply_morphism(
ctx.read().unwrap().build_repr_tree(
&rt_int,
&nested::repr_tree::morphism::MorphismType {
src_type: Context::parse(&ctx, " ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ <Vec Char>"),
dst_type: Context::parse(&ctx, " ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree")
});
Context::parse(&ctx, " ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>~Char> ~ <Vec Char>"),
vec![
Context::parse(&ctx, " ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>> ~ EditTree"),
Context::parse(&ctx, " ~ <PosInt 16 LittleEndian> ~ <Seq~List <Digit 16>> ~ EditTree"),
]);
/* set Hex-editor to be master
*/
rt_int.write().unwrap().detach( &ctx );
ctx.read().unwrap().apply_morphism(
&rt_int,
&laddertypes::MorphismType {
src_type: Context::parse(&ctx, " ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree"),
dst_type: Context::parse(&ctx, " ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char> ~ EditTree")
fn set_master(
ctx: &Arc<RwLock<Context>>,
rt: &Arc<RwLock<ReprTree>>,
mut leaves: Vec< laddertypes::TypeTerm >,
master_idx: usize
) {
eprintln!("set master to {}", master_idx);
if master_idx < leaves.len() {
let master = leaves.remove( master_idx );
rt.write().unwrap().detach( &ctx );
ctx.read().unwrap().build_repr_tree(
rt,
master,
leaves
);
}
);
}
let edittree_hex_be_list =
rt_int
.descend(Context::parse(&ctx, "
<PosInt 16 BigEndian>
~ <Seq~List <Digit 16>~Char>
")).unwrap()
.edittree( &ctx );
let editor_types = vec![
Context::parse(&ctx,
" ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>> ~ EditTree"),
Context::parse(&ctx,
" ~ <PosInt 16 LittleEndian> ~ <Seq~List <Digit 16>> ~ EditTree"),
Context::parse(&ctx,
" ~ <PosInt 16 BigEndian> ~ EditTree"),
Context::parse(&ctx,
" ~ <PosInt 8 BigEndian> ~ EditTree"),
Context::parse(&ctx,
" ~ <PosInt 2 BigEndian> ~ EditTree"),
];
let edittree_dec_be_list =
rt_int
.descend(Context::parse(&ctx, "
<PosInt 10 BigEndian>
~ <Seq~List <Digit 10>~Char>
")).unwrap()
.edittree( &ctx );
set_master(&ctx, &rt_int, editor_types.clone(), 0);
let hex_digits_view = rt_int.descend(Context::parse(&ctx, "
<PosInt 16 LittleEndian>
~ <Seq <Digit 16> >
~ <List <Digit 16>
~ _2^64
~ machine.UInt64 >
")).expect("descend")
.view_list::<u64>()
.map(|v| TerminalAtom::from(char::from_digit(*v as u32, 16)))
.to_sequence()
.to_grid_horizontal();
let dec_digits_view = rt_int.descend(Context::parse(&ctx, "
<PosInt 10 LittleEndian>
~ <Seq <Digit 10>>
~ <List <Digit 10>
~ _2^64
~ machine.UInt64 >
")).expect("descend")
.view_list::<u64>()
.map(|v| TerminalAtom::from(char::from_digit(*v as u32, 10)))
.to_sequence()
.to_grid_horizontal();
/* list of both editors
/* list of editors
*/
let mut list_editor = nested::editors::list::ListEditor::new(ctx.clone(), Context::parse(&ctx, "<Seq Char>"));
list_editor.data.push( edittree_hex_be_list.get() );
list_editor.data.push( edittree_dec_be_list.get() );
// add all desired editors to the list
for leaf in editor_types.iter() {
let et =
rt_int
.descend(leaf.clone()).unwrap()
.edittree(&ctx).get();
et.write().unwrap().goto(TreeCursor::none());
list_editor.data.push(et);
}
let mut edittree = list_editor.into_node(SingletonBuffer::new(0).get_port());
/* cursors are a bit screwed initially so fix them up
* TODO: how to fix this generally?
*/
edittree_hex_be_list.get().write().unwrap().goto(TreeCursor::none());
edittree_dec_be_list.get().write().unwrap().goto(TreeCursor::none());
edittree.goto(TreeCursor{
leaf_mode: nested::editors::list::ListCursorMode::Insert,
tree_addr: vec![0,0]
@ -146,37 +136,23 @@ async fn main() {
*/
let ctx = ctx.clone();
let rt_int = rt_int.clone();
let last_idx = RwLock::new(1);
let last_idx = RwLock::new(0);
let editor_types = editor_types.clone();
move |ev| {
let cur = edittree.read().unwrap().get_cursor();
if cur.tree_addr.len() > 0 {
match cur.tree_addr[0] {
0 => {
let mut li = last_idx.write().unwrap();
if *li != 0 {
rt_int.write().unwrap().detach( &ctx );
ctx.read().unwrap().apply_morphism(&rt_int, &laddertypes::MorphismType {
src_type: Context::parse(&ctx, " ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char> ~ EditTree"),
dst_type: Context::parse(&ctx, " ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10> ~ Char> ~ EditTree")
});
let mut li = last_idx.write().unwrap();
let ci = cur.tree_addr[0];
*li = 0;
}
}
1 => {
let mut li = last_idx.write().unwrap();
if *li != 1 {
rt_int.write().unwrap().detach( &ctx );
ctx.read().unwrap().apply_morphism(&rt_int, &laddertypes::MorphismType {
src_type: Context::parse(&ctx, " ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10> ~ Char> ~ EditTree"),
dst_type: Context::parse(&ctx, " ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char> ~ EditTree")
});
*li = 1;
}
}
_=>{}
if *li != ci {
eprintln!("----------------------------------");
set_master(
&ctx,
&rt_int,
editor_types.clone(),
ci as usize
);
*li = ci;
}
}
@ -189,7 +165,7 @@ async fn main() {
* so it will be displayed on TTY-output.
*/
let compositor = TerminalCompositor::new(app.port.inner());
/* Now add some views to our compositor
*/
{
@ -199,30 +175,21 @@ async fn main() {
{
let rt_edittree = rt.descend(Context::parse(&ctx, "EditTree")).expect("descend");
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 );
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))))
.offset(Vector2::new(1,y)));
comp.push( edittree.display_view()
comp.push( edittree.get().read().unwrap().display_view()
.offset(Vector2::new(1,y+1)));
}
show_edit_tree(&ctx, &mut comp, &rt_int.descend(Context::parse(&ctx, "<PosInt 16 BigEndian> ~ <Seq~List <Digit 16>~Char>")).expect(""), 1);
show_edit_tree(&ctx, &mut comp, &rt_int.descend(Context::parse(&ctx, "<PosInt 10 BigEndian> ~ <Seq~List <Digit 10>~Char>")).expect(""), 4);
/* project the seq of u64 representations to a view
*/
comp.push(nested_tty::make_label("dec: ").offset(Vector2::new(3,7)));
comp.push(dec_digits_view.offset(Vector2::new(8,7)).map_item(|_,a| {
a.add_style_back(TerminalStyle::fg_color((30,90,200)))
}));
comp.push(nested_tty::make_label("hex: ").offset(Vector2::new(3,8)));
comp.push(hex_digits_view.offset(Vector2::new(8,8)).map_item(|_,a| {
a.add_style_back(TerminalStyle::fg_color((200, 200, 30)))
}));
let mut y = 1;
for t in editor_types.iter() {
show_edit_tree(&ctx, &mut comp, &rt_int.descend(t.clone()).expect(""), y);
y += 3;
}
}
/* write the changes in the view of `term_port` to the terminal

View file

@ -25,49 +25,63 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
{
let ctx = ctx.clone();
move |rt, σ| {
{
let mut b = rt.write().unwrap().singleton_buffer::<char>();
if let Some(buf) = b {
// buffer already exists
} else {
// create char buffer
rt.write().unwrap().insert_leaf(
vec![].into_iter(),
ReprLeaf::from_singleton_buffer(
SingletonBuffer::new('\0')
)
);
}
if let Some(buf) = b {
// buffer already exists
} else {
// create char buffer
rt.write().unwrap().insert_leaf(
vec![].into_iter(),
ReprLeaf::from_singleton_buffer(SingletonBuffer::new('\0'))
);
}
}
let char_buf = rt.singleton_buffer::<char>();
let mut edittree = CharEditor::new_edit_tree(
ctx.clone(),
char_buf,
SingletonBuffer::<usize>::new(0).get_port()
);
let char_buf = rt.singleton_buffer::<char>();
let mut edittree = CharEditor::new_edit_tree(
ctx.clone(),
char_buf,
SingletonBuffer::<usize>::new(0).get_port()
);
rt.insert_leaf(
rt.insert_leaf(
Context::parse(&ctx, "EditTree"),
ReprLeaf::from_singleton_buffer(
SingletonBuffer::new(
Arc::new(RwLock::new(edittree))
)
)
);
);
ctx.read().unwrap().setup_edittree(
rt.clone(),
SingletonBuffer::new(0).get_port()
);
}
ctx.read().unwrap().setup_edittree(rt);
}
}
);
let char_morph_from_edittree = GenericReprTreeMorphism::new(
Context::parse(&ctx, "Char~EditTree"),
Context::parse(&ctx, "Char"),
{
let ctx = ctx.clone();
move |rt, σ|
{
let mut b = rt
.descend(Context::parse(&ctx, "EditTree")).unwrap()
.view_singleton::<Arc<RwLock<EditTree>>>();
rt.attach_leaf_to(
Context::parse(&ctx, "Char"),
b.map(|x|
x.read().unwrap()
.get_edit::<CharEditor>().unwrap()
.read().unwrap()
.get())
);
}
});
ctx.write().unwrap().morphisms.add_morphism( char_morph_to_edittree );
ctx.write().unwrap().morphisms.add_morphism( char_morph_from_edittree );
}
pub struct CharEditor {

View file

@ -19,6 +19,43 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
// todo: proper scoping of Radix variable
ctx.write().unwrap().add_varname("Radix");
let digit_make_edittree = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<Digit Radix>"),
Context::parse(&ctx, "<Digit Radix>~EditTree"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let radix =
match σ.get( &laddertypes::TypeID::Var(ctx.read().unwrap().get_var_typeid("Radix").unwrap()) ) {
Some(TypeTerm::Num(n)) => *n as u32,
_ => 0
};
let char_buf = SingletonBuffer::<char>::new('?');
/* Create EditTree object
*/
let mut edittree = DigitEditor::new(
ctx.clone(),
radix,
char_buf
).into_node(
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
);
src_rt.write().unwrap()
.insert_branch(
ReprTree::from_singleton_buffer(
Context::parse(&ctx, "EditTree"),
SingletonBuffer::new(Arc::new(RwLock::new(edittree)))
)
);
ctx.read().unwrap().setup_edittree( src_rt );
}
}
);
let digit_morph_char_to_edittree = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<Digit Radix>~Char"),
Context::parse(&ctx, "<Digit Radix>~EditTree"),
@ -57,6 +94,30 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
}
);
let digit_morph_char_from_edittree = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<Digit Radix>~EditTree"),
Context::parse(&ctx, "<Digit Radix>~Char"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let edittree = src_rt.edittree( &ctx );
let port =
edittree
.get()
.read().unwrap()
.get_edit::<DigitEditor>().unwrap()
.read().unwrap()
.get_char_port();
src_rt.insert_leaf(
Context::parse(&ctx, "Char"),
ReprLeaf::from_view( port )
)
}
}
);
let digit_morph_char_to_u64 = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<Digit Radix>~Char"),
Context::parse(&ctx, "<Digit Radix>~_2^64~machine.UInt64"),
@ -134,7 +195,9 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
);
ctx.write().unwrap().morphisms.add_morphism( digit_make_edittree );
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_to_edittree );
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_from_edittree );
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_to_u64 );
ctx.write().unwrap().morphisms.add_morphism( digit_morph_u64_to_char );
}

View file

@ -59,6 +59,10 @@ impl DigitEditor {
*/
}
pub fn get_char_port(&self) -> OuterViewPort<dyn SingletonView<Item = char>> {
self.data.get_port()
}
pub fn get_data_port(&self) -> OuterViewPort<dyn SingletonView<Item = Result<u32, char>>> {
let radix = self.radix;
self.data.get_port().map(move |c|

View file

@ -1,7 +1,8 @@
use {
r3vi::{
view::{OuterViewPort, singleton::*, list::*}
view::{OuterViewPort, singleton::*, list::*},
buffer::singleton::SingletonBuffer
},
laddertypes::{TypeTerm, MorphismType},
crate::{
@ -170,9 +171,132 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
}
);
let posint_list_morph_from_u64 = GenericReprTreeMorphism::new(
Context::parse(&ctx, " ~ machine.UInt64"),
Context::parse(&ctx, " ~ <PosInt 0 LittleEndian> ~ <Seq~List <Digit 0>~_2^64~machine.UInt64>"),
{
let ctx = ctx.clone();
move |rt, σ| {
let digits = rt
.descend(Context::parse(&ctx, " ~ machine.UInt64")).unwrap()
.view_u64()
.to_sequence()
.to_list();
rt.attach_leaf_to(
Context::parse(&ctx, "~ <PosInt 0 LittleEndian> ~ <Seq~List <Digit 0>~_2^64~machine.UInt64>"),
digits
);
}
}
);
let posint_list_morph_to_u64 = GenericReprTreeMorphism::new(
Context::parse(&ctx, " ~ <PosInt 0 LittleEndian> ~ <Seq~List <Digit 0>~_2^64~machine.UInt64> ~ <Vec machine.UInt64>"),
Context::parse(&ctx, " ~ machine.UInt64"),
{
let ctx = ctx.clone();
move |rt, σ| {
let u64_view = rt
.descend(Context::parse(&ctx, "~ <PosInt 0 LittleEndian> ~ <Seq~List <Digit 0>~_2^64~machine.UInt64> ~ <Vec machine.UInt64>")).unwrap()
.get_port::< RwLock<Vec< u64 >> >().unwrap()
.to_singleton()
.map(|digits| {
digits.get(0).cloned().unwrap_or(0)
});
rt.attach_leaf_to(
Context::parse(&ctx, " ~ machine.UInt64"),
u64_view
);
}
}
);
let posint_make_edittree = GenericReprTreeMorphism::new(
Context::parse(&ctx, " ~ <PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>> ~ EditTree"),
Context::parse(&ctx, " ~ <PosInt Radix BigEndian> ~ EditTree"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let mut list_edittree = src_rt.descend(
Context::parse(&ctx, " ~ <PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>>")
.apply_substitution(&|x| σ.get(x).cloned()).clone()
)
.unwrap()
.edittree( &ctx )
.get().clone()
.read().unwrap()
.clone();
// clear display
list_edittree.disp.view = ReprTree::new_arc(Context::parse(&ctx, "Display"));
src_rt.insert_leaf(
Context::parse(&ctx, "<PosInt Radix BigEndian> ~ EditTree")
.apply_substitution(&|x| σ.get(x).cloned()).clone(),
ReprLeaf::from_singleton_buffer(
SingletonBuffer::new(
Arc::new(RwLock::new(list_edittree))
)
)
);
ctx.read().unwrap().setup_edittree(
&src_rt.descend(
Context::parse(&ctx, "<PosInt Radix BigEndian>")
.apply_substitution(&|x| σ.get(x).cloned()).clone()
).unwrap()
);
}
}
);
let posint_edittree_to_list = GenericReprTreeMorphism::new(
Context::parse(&ctx, " ~ <PosInt Radix BigEndian> ~ EditTree"),
Context::parse(&ctx, " ~ <PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>> ~ EditTree"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let mut list_edittree = src_rt.descend(
Context::parse(&ctx, " ~ <PosInt Radix BigEndian>")
.apply_substitution(&|x| σ.get(x).cloned()).clone())
.unwrap()
.edittree( &ctx )
.get().clone()
.read().unwrap()
.clone();
// clear display
list_edittree.disp.view = ReprTree::new_arc(Context::parse(&ctx, "Display"));
src_rt.insert_leaf(
Context::parse(&ctx, "<PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>>~EditTree")
.apply_substitution(&|x| σ.get(x).cloned()).clone(),
ReprLeaf::from_singleton_buffer(
SingletonBuffer::new(
Arc::new(RwLock::new(list_edittree))
)
)
);
ctx.read().unwrap().setup_edittree(
&src_rt.descend(
Context::parse(&ctx, "<PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>>")
.apply_substitution(&|x| σ.get(x).cloned()).clone()
).unwrap()
);
}
}
);
ctx.write().unwrap().morphisms.add_morphism( posint_make_edittree );
ctx.write().unwrap().morphisms.add_morphism( posint_edittree_to_list );
ctx.write().unwrap().morphisms.add_morphism( posint_seq_morph_big_to_little );
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_big_to_little );
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_little_to_big );
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_radix );
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_from_u64 );
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_to_u64 );
}

View file

@ -35,8 +35,10 @@ pub trait PositionalUInt : SequenceView<Item = u64> {
let mut val = 0;
let mut r = 1;
for i in 0..self.len().unwrap_or(0) {
val += r * self.get(&i).unwrap();
r *= self.get_radix();
if let Some(digit_val) = self.get(&i) {
val += r * digit_val;
r *= self.get_radix();
}
}
val

View file

@ -63,36 +63,24 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
}
);
let list_morph_editsetup2 = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Char>~EditTree"),
Context::parse(&ctx, "<List Char>"),
let list_morph_editsetup3 = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<List Item> ~ EditTree"),
Context::parse(&ctx, "<List Item> ~ <List EditTree>"),
{
let ctx = ctx.clone();
move |src_rt, σ| {
let edittree =
src_rt
.descend(Context::parse(&ctx, "<List Char>~EditTree")).unwrap()
.singleton_buffer::<Arc<RwLock<EditTree>>>();
let edittree = src_rt.edittree( &ctx );
let list_edit = edittree.get().read().unwrap().get_edit::< ListEditor >().unwrap();
let edittree_items = list_edit.read().unwrap().data.get_port().to_list();
src_rt.insert_leaf(
Context::parse(&ctx, "<List Char>"),
ReprLeaf::from_view(
edittree_items
.map(|edittree_char|
edittree_char
.read().unwrap()
.get_edit::<CharEditor>().unwrap()
.read().unwrap()
.get()
)
)
eprintln!("edittree_items.len() = {:?}", edittree_items.get_view().unwrap().len());
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List Item> ~ <List EditTree>")
.apply_substitution(&|x| σ.get(x).cloned()).clone(),
edittree_items
);
}
}
);
@ -132,21 +120,14 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
{
let ctx = ctx.clone();
move |src_rt, σ| {
let p =
src_rt
.descend(Context::parse(&ctx, "<List EditTree>")).expect("descend")
.get_port::<dyn ListView< Arc<RwLock<EditTree>> >>().unwrap();
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List EditTree> ~ <Vec EditTree>"),
p
);
let list_port = src_rt.get_port::<dyn ListView< Arc<RwLock<EditTree>> >>().unwrap();
src_rt.attach_leaf_to( Context::parse(&ctx, "<Vec EditTree>"), list_port );
}
}
);
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup1 );
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup2 );
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup3 );
ctx.write().unwrap().morphisms.add_morphism( list_morph_from_vec_char );
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_char );
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_edittree );

View file

@ -1,7 +1,8 @@
use {
r3vi::{
view::{OuterViewPort, singleton::*, sequence::*},
buffer::{singleton::*, vec::*}
buffer::{singleton::*, vec::*},
projection::*
},
laddertypes::{TypeTerm},
crate::{
@ -123,23 +124,18 @@ impl ListEditor {
.set_editor(editor.clone())
.set_nav(editor.clone())
.set_cmd(editor.clone())
.set_diag(e
.get_data_port()
.set_diag(e.get_data_port()
.enumerate()
.map(|(idx, item_editor)| {
let idx = *idx;
item_editor
.get_msg_port()
.map(
move |msg| {
let mut msg = msg.clone();
msg.addr.insert(0, idx);
msg
}
)
let idx = *idx;
item_editor.get_msg_port()
.map(move |msg| {
let mut msg = msg.clone();
msg.addr.insert(0, idx);
msg
})
})
.flatten()
);
.flatten());
node.ctrl.spillbuf = e.spillbuf.clone();
node
@ -161,9 +157,9 @@ impl ListEditor {
}
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
self.data.get_port().to_sequence().map(
self.data.get_port().to_list().map(
|x| x.read().unwrap().clone()
)
).to_sequence()
}
/*
pub fn get_data(&self) -> Arc<RwLock<ReprTree>> {
@ -185,7 +181,7 @@ impl ListEditor {
} else {
None
}
}
}
pub fn get_item_mut(&mut self) -> Option<MutableVecAccess<Arc<RwLock<EditTree>>>> {
if let Some(idx) = self.cursor.get().idx {
@ -319,11 +315,7 @@ impl ListEditor {
let mut b = item.ctrl.spillbuf.write().unwrap();
let rt = ReprTree::new_arc(self.typ.clone());
let mut et = self.ctx.read().unwrap()
.setup_edittree(
&rt
// , self.depth.map(|d| d+1)
);
let mut et = self.ctx.read().unwrap().setup_edittree(&rt);
if let Some(edittree) = et.as_mut(){

View file

@ -42,11 +42,12 @@ impl SequenceView for ListSegmentSequence {
type Item = ListSegment;
fn len(&self) -> Option<usize> {
let l = self.data.len()?;
match self.cur_cursor.mode {
ListCursorMode::Insert => {
Some(self.data.len()? + if self.cur_cursor.idx.is_some() { 1 } else { 0 })
Some(l + if self.cur_cursor.idx.is_some() { 1 } else { 0 })
}
_ => self.data.len(),
_ => Some(l),
}
}

View file

@ -120,6 +120,32 @@ impl Context {
}
}
pub fn build_repr_tree(
&self,
rt: &Arc<RwLock<ReprTree>>,
root: TypeTerm,
leaves: Vec< TypeTerm >
) {
let mut st_problem = laddertypes::steiner_tree::PathApproxSteinerTreeSolver::new(
root,
leaves
);
if let Some( steiner_tree ) = st_problem.solve( &self.morphisms ) {
for morphism_type in steiner_tree.into_edges() {
eprintln!("--> apply morph to {}", self.type_term_to_str(&morphism_type.dst_type));
if let Some(( morphism, mut τ, σ )) =
self.morphisms.find_morphism_with_subtyping( &morphism_type )
{
let mut rt = rt.descend( τ ).expect("descend src repr");
(morphism.setup_projection)( &mut rt, &σ );
}
}
} else {
eprintln!("could not find steiner tree to build the requested repr tree");
}
}
pub fn make_repr(ctx: &Arc<RwLock<Self>>, t: &TypeTerm) -> Arc<RwLock<ReprTree>> {
let rt = Arc::new(RwLock::new(ReprTree::new( TypeTerm::unit() )));
ctx.read().unwrap().apply_morphism( &rt, &MorphismType{ src_type: TypeTerm::unit(), dst_type: t.clone() } );
@ -223,7 +249,6 @@ impl Context {
pub fn setup_edittree(
&self,
rt: &Arc<RwLock<ReprTree>>
// depth: OuterViewPort<dyn SingletonView<Item = usize>>
) -> Option<SingletonBuffer<Arc<RwLock<EditTree>>>> {
if let Some(new_edittree) =
rt.descend(self.type_term_from_str("EditTree").unwrap())

View file

@ -19,7 +19,7 @@ use {
sync::{Arc, RwLock},
any::Any
},
super::{Context, ReprLeaf, ReprTreeExt, context::{TYPEID_vec, TYPEID_char, TYPEID_u64, TYPEID_edittree}}
super::{Context, ReprLeaf, ReprTreeExt, context::{TYPEID_list, TYPEID_vec, TYPEID_char, TYPEID_u64, TYPEID_edittree}}
};
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
@ -192,7 +192,7 @@ impl ReprTree {
V::Msg: Clone
{
while let Some(rung_type) = type_ladder.next() {
if &rung_type != self.get_type() {
if &rung_type != self.get_type() {
if let Some(next_repr) = self.branches.get(&rung_type) {
next_repr.write().unwrap().attach_leaf_to(type_ladder, src_port);
} else {
@ -285,8 +285,26 @@ impl ReprTree {
]) {
leaf.detach_vec::< u64 >();
}
else if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_list),
TypeTerm::TypeID(TYPEID_edittree),
]) {
leaf.detach::< dyn ListView<Arc<RwLock<crate::edit_tree::EditTree>>> >();
}
else if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_list),
TypeTerm::TypeID(TYPEID_char),
]) {
leaf.detach::< dyn ListView<char> >();
}
else if self.type_tag == TypeTerm::App(vec![
TypeTerm::TypeID(TYPEID_list),
TypeTerm::TypeID(TYPEID_u64),
]) {
leaf.detach::< dyn ListView<u64> >();
}
else {
eprintln!("cant detach type");
eprintln!("cant detach type {}", ctx.read().unwrap().type_term_to_str(&self.type_tag));
}
}

View file

@ -224,37 +224,37 @@ impl PTYListController {
ListCursorMode::Insert => {
let rt = ReprTree::new_arc(e.typ.clone());
let ladder = laddertypes::TypeTerm::Ladder(vec![
let src_ladder = laddertypes::TypeTerm::Ladder(vec![
rt.read().unwrap().get_type().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: rt.get_type(),
dst_type: ladder
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 => {
drop(ne);
e.insert(new_edittree.value.read().unwrap().clone());
TreeNavResult::Continue
let mut ne = new_edittree.get();
let mut ne = ne.write().unwrap();
match ne.send_cmd_obj(cmd_obj.clone()) {
TreeNavResult::Continue => {
drop(ne);
e.insert(new_edittree.value.read().unwrap().clone());
TreeNavResult::Continue
}
TreeNavResult::Exit => {
TreeNavResult::Exit
}
}
TreeNavResult::Exit => {
TreeNavResult::Exit
}
}
} else {
panic!("cant get edit tree");
TreeNavResult::Continue
}
@ -301,7 +301,7 @@ impl ObjCommander for PTYListController {
let cmd_type = cmd_obj.read().unwrap().get_type().clone();
if cmd_type == Context::parse(&e.ctx, "ListCmd").into()
|| cmd_type == Context::parse(&e.ctx, "NestedNode").into()
|| cmd_type == Context::parse(&e.ctx, "EditTree").into()
{
e.send_cmd_obj( cmd_obj )
}

View file

@ -121,7 +121,10 @@ pub fn setup_edittree_hook(ctx: &Arc<RwLock<Context>>) {
let char_type = Context::parse(&ctx, "Char");
let digit_type = Context::parse(&ctx, "<Digit Radix>");
let list_type = Context::parse(&ctx, "<List Item>");
let posint_type = Context::parse(&ctx, "<PosInt Radix>");
let posint_bin_type = Context::parse(&ctx, "<PosInt 2 BigEndian>");
let posint_oct_type = Context::parse(&ctx, "<PosInt 8 BigEndian>");
let posint_dec_type = Context::parse(&ctx, "<PosInt 10 BigEndian>");
let posint_hex_type = Context::parse(&ctx, "<PosInt 16 BigEndian>");
let item_tyid = ctx.read().unwrap().get_var_typeid("Item").unwrap();
ctx.write().unwrap().meta_chars.push(',');
@ -134,18 +137,28 @@ pub fn setup_edittree_hook(ctx: &Arc<RwLock<Context>>) {
ctx.write().unwrap().set_edittree_hook(
Arc::new(
move |et: &mut nested::edit_tree::EditTree, t: laddertypes::TypeTerm| {
// let mut et = et.write().unwrap();
if let Ok(σ) = laddertypes::unify(&t, &char_type.clone()) {
*et = crate::editors::edittree_make_char_view(et.clone());
}
else if let Ok(σ) = laddertypes::unify(&t, &digit_type) {
*et = crate::editors::edittree_make_digit_view(et.clone());
}
else if let Ok(σ) = laddertypes::unify(&t, &posint_type) {
else if let Ok(σ) = laddertypes::unify(&t, &posint_bin_type) {
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0b", "", ""));
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
}
else if let Ok(σ) = laddertypes::unify(&t, &posint_oct_type) {
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0o", "", ""));
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
}
else if let Ok(σ) = laddertypes::unify(&t, &posint_dec_type) {
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0d", "", ""));
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
}
else if let Ok(σ) = laddertypes::unify(&t, &posint_hex_type) {
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0x", "", ""));
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
}
else if let Ok(σ) = laddertypes::unify(&t, &list_type) {
let item_type = σ.get( &laddertypes::TypeID::Var(item_tyid) ).unwrap();