Compare commits
2 commits
ab51ea5d3d
...
e86070da50
Author | SHA1 | Date | |
---|---|---|---|
e86070da50 | |||
bb846afc7c |
10 changed files with 634 additions and 450 deletions
|
@ -32,170 +32,56 @@ use {
|
|||
std::sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
/* setup context
|
||||
*/
|
||||
let ctx = Arc::new(RwLock::new(Context::new()));
|
||||
nested::editors::char::init_ctx( ctx.clone() );
|
||||
nested::editors::digit::init_ctx( ctx.clone() );
|
||||
nested::editors::integer::init_ctx( ctx.clone() );
|
||||
nested::editors::list::init_ctx( ctx.clone() );
|
||||
nested_tty::setup_edittree_hook(&ctx);
|
||||
|
||||
/* Create a Representation-Tree of type `ℕ`
|
||||
*/
|
||||
let mut rt_int = ReprTree::new_arc( Context::parse(&ctx, "ℕ") );
|
||||
|
||||
/* Add a specific Representation-Path (big-endian hexadecimal)
|
||||
*/
|
||||
rt_int.create_branch(
|
||||
Context::parse(&ctx, "<PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16>~Char>")
|
||||
);
|
||||
rt_int.create_branch(
|
||||
Context::parse(&ctx, "<PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16>~Char>")
|
||||
);
|
||||
rt_int.create_branch(
|
||||
Context::parse(&ctx, "<PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10>~Char>")
|
||||
);
|
||||
|
||||
eprintln!("make big endian hex repr");
|
||||
let mut b = VecBuffer::with_data(vec![ 'c', 'f', 'f' ]);
|
||||
rt_int.insert_leaf(
|
||||
Context::parse(&ctx, "<PosInt 16 BigEndian>~<Seq <Digit 16>>~<List <Digit 16>>~<List Char>"),
|
||||
nested::repr_tree::ReprLeaf::from_view( b.get_port().to_list() )
|
||||
);
|
||||
|
||||
let mut b_le = VecBuffer::with_data(vec!['3', '2', '1']);
|
||||
rt_int.insert_leaf(
|
||||
Context::parse(&ctx, "<PosInt 16 LittleEndian>~<Seq <Digit 16>>~<List <Digit 16>>~<List Char>"),
|
||||
nested::repr_tree::ReprLeaf::from_view( b_le.get_port().to_list() )
|
||||
);
|
||||
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
<PosInt 16 LittleEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>>
|
||||
~ <List Char>
|
||||
")).expect("descend"),
|
||||
&Context::parse(&ctx, "<List Char>"),
|
||||
&Context::parse(&ctx, "<List Char~EditTree>")
|
||||
);
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
<PosInt 16 LittleEndian>
|
||||
~ <Seq <Digit 16> >
|
||||
~ <List <Digit 16>~Char~EditTree >
|
||||
")).expect("descend"),
|
||||
&Context::parse(&ctx, "<List EditTree>"),
|
||||
&Context::parse(&ctx, "<List EditTree>~<Vec EditTree>")
|
||||
);
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
<PosInt 16 LittleEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>~Char>
|
||||
")).expect("descend"),
|
||||
&Context::parse(&ctx, "<List Char>~<List EditTree>~<Vec EditTree>"),
|
||||
&Context::parse(&ctx, "<List Char>~EditTree")
|
||||
);
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
<PosInt 16 LittleEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>~Char >
|
||||
")).expect("descend"),
|
||||
&Context::parse(&ctx, "<List Char>~EditTree"),
|
||||
&Context::parse(&ctx, "<List Char>")
|
||||
);
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.clone(),
|
||||
&Context::parse(&ctx, "
|
||||
ℕ
|
||||
~ <PosInt 16 LittleEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>>
|
||||
~ <List Char>
|
||||
"),
|
||||
&Context::parse(&ctx, "
|
||||
ℕ
|
||||
~ <PosInt 16 BigEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>>
|
||||
~ <List Char>
|
||||
")
|
||||
);
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.clone(),
|
||||
&Context::parse(&ctx, "
|
||||
ℕ
|
||||
~ <PosInt 16 BigEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>>
|
||||
~ <List Char>
|
||||
"),
|
||||
&Context::parse(&ctx, "
|
||||
ℕ
|
||||
~ <PosInt 16 LittleEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>>
|
||||
~ <List Char>
|
||||
")
|
||||
);
|
||||
|
||||
let edittree_hex_le_list = ctx.read().unwrap()
|
||||
.setup_edittree(
|
||||
rt_int.descend(Context::parse(&ctx,"
|
||||
<PosInt 16 LittleEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>~Char >
|
||||
")).expect("descend"),
|
||||
SingletonBuffer::new(0).get_port()
|
||||
fn rebuild_projections(
|
||||
ctx: Arc<RwLock<Context>>,
|
||||
repr_tree: Arc<RwLock<ReprTree>>,
|
||||
morph_types: Vec< (laddertypes::TypeTerm, laddertypes::TypeTerm) >
|
||||
) {
|
||||
repr_tree.write().unwrap().detach(&ctx);
|
||||
for (src_type, dst_type) in morph_types.iter() {
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
repr_tree.clone(),
|
||||
&src_type,
|
||||
&dst_type
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
<PosInt 16 BigEndian>~<Seq <Digit 16>>~<List <Digit 16>~Char>
|
||||
")).expect("descend"),
|
||||
&Context::parse(&ctx, "<List Char>"),
|
||||
&Context::parse(&ctx, "<List Char~EditTree>")
|
||||
);
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
<PosInt 16 BigEndian>~<Seq <Digit 16>>~<List <Digit 16>~Char~EditTree>
|
||||
")).expect("descend"),
|
||||
&Context::parse(&ctx, "<List EditTree>"),
|
||||
&Context::parse(&ctx, "<List EditTree>~<Vec EditTree>")
|
||||
);
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
<PosInt 16 BigEndian>~<Seq <Digit 16>>~<List <Digit 16>~Char>
|
||||
")).expect("descend"),
|
||||
&Context::parse(&ctx, "<List Char>~<List EditTree>~<Vec EditTree>"),
|
||||
&Context::parse(&ctx, "<List Char>~EditTree")
|
||||
);
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
<PosInt 16 BigEndian>~<Seq <Digit 16>>~<List <Digit 16>~Char>
|
||||
")).expect("descend"),
|
||||
&Context::parse(&ctx, "<List Char>~EditTree"),
|
||||
&Context::parse(&ctx, "<List Char>")
|
||||
);
|
||||
fn setup_le_master(ctx: &Arc<RwLock<Context>>, rt_int: &Arc<RwLock<ReprTree>>) {
|
||||
rebuild_projections(
|
||||
ctx.clone(),
|
||||
rt_int.clone(),
|
||||
vec![
|
||||
// Little Endian Editor
|
||||
(
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree",
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
||||
),
|
||||
|
||||
/* Setup an Editor for the big-endian hexadecimal representation
|
||||
* (this will add the representation `<List <Digit 16>>~EditTree` to the ReprTree)
|
||||
*/
|
||||
let edittree_hex_be_list = ctx.read().unwrap()
|
||||
.setup_edittree(
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
<PosInt 16 BigEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>>
|
||||
~ <List Char>
|
||||
")).expect("cant descend reprtree"),
|
||||
SingletonBuffer::new(0).get_port()
|
||||
);
|
||||
// Convert Endianness
|
||||
(
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
||||
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
||||
),
|
||||
|
||||
// Big Endian Editor
|
||||
(
|
||||
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
||||
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree>"
|
||||
),
|
||||
(
|
||||
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree>",
|
||||
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree> ~ <Vec EditTree>"
|
||||
),
|
||||
(
|
||||
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree> ~ <Vec EditTree>",
|
||||
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree"
|
||||
),
|
||||
].into_iter()
|
||||
.map(|(s,d)| (Context::parse(&ctx, s), Context::parse(&ctx, d)))
|
||||
.collect()
|
||||
);
|
||||
/*
|
||||
|
||||
/*
|
||||
* map seq of chars to seq of u64 digits
|
||||
|
@ -225,87 +111,203 @@ async fn main() {
|
|||
}
|
||||
);
|
||||
|
||||
rt_int.insert_leaf(Context::parse(&ctx, "
|
||||
rt_int.attach_leaf_to(Context::parse(&ctx, "
|
||||
<PosInt 16 BigEndian>
|
||||
~ <Seq <Digit 16>
|
||||
~ ℤ_2^64
|
||||
~ machine.UInt64 >
|
||||
"),
|
||||
nested::repr_tree::ReprLeaf::from_view( digits_view.clone() )
|
||||
digits_view.clone()
|
||||
);
|
||||
|
||||
//ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
|
||||
//
|
||||
*/
|
||||
}
|
||||
|
||||
/* convert to little endian
|
||||
*/
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
fn setup_be_master(ctx: &Arc<RwLock<Context>>, rt_int: &Arc<RwLock<ReprTree>>) {
|
||||
rebuild_projections(
|
||||
ctx.clone(),
|
||||
rt_int.clone(),
|
||||
&Context::parse(&ctx, "
|
||||
ℕ
|
||||
~ <PosInt 16 BigEndian>
|
||||
~ <Seq <Digit 16>
|
||||
~ ℤ_2^64
|
||||
~ machine.UInt64 >
|
||||
"),
|
||||
&Context::parse(&ctx, "
|
||||
ℕ
|
||||
~ <PosInt 16 LittleEndian>
|
||||
~ <Seq <Digit 16>
|
||||
~ ℤ_2^64
|
||||
~ machine.UInt64 >
|
||||
")
|
||||
vec![
|
||||
// Big Endian Editor
|
||||
(
|
||||
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree",
|
||||
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
||||
),
|
||||
|
||||
// Convert Endianness
|
||||
(
|
||||
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
||||
),
|
||||
|
||||
// Big Endian Editor
|
||||
(
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree>"
|
||||
),
|
||||
(
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree>",
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree> ~ <Vec EditTree>"
|
||||
),
|
||||
(
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree> ~ <Vec EditTree>",
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree"
|
||||
),
|
||||
].into_iter()
|
||||
.map(|(s,d)| (Context::parse(&ctx, s), Context::parse(&ctx, d)))
|
||||
.collect()
|
||||
);
|
||||
|
||||
/* convert to decimal
|
||||
*/
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.clone(),
|
||||
&Context::parse(&ctx, "ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>~ℤ_2^64~machine.UInt64>"),
|
||||
&Context::parse(&ctx, "ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10>~ℤ_2^64~machine.UInt64>")
|
||||
);
|
||||
|
||||
/* convert back to big endian
|
||||
*/
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_int.clone(),
|
||||
&Context::parse(&ctx, "ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10>~ℤ_2^64~machine.UInt64>"),
|
||||
&Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>~ℤ_2^64~machine.UInt64>")
|
||||
);
|
||||
|
||||
|
||||
/* map seq of u64 digits to seq of chars
|
||||
/*
|
||||
/*
|
||||
* map seq of chars to seq of u64 digits
|
||||
* and add this projection to the ReprTree
|
||||
*/
|
||||
|
||||
//
|
||||
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
||||
let dec_digits_view =
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
< PosInt 10 BigEndian >
|
||||
~ < Seq <Digit 10>
|
||||
~ ℤ_2^64
|
||||
~ machine.UInt64 >
|
||||
")).expect("cant descend repr tree")
|
||||
.read().unwrap()
|
||||
.get_port::<dyn SequenceView<Item = u64>>().unwrap()
|
||||
.map(|digit| TerminalAtom::from(char::from_digit(*digit as u32, 10)))
|
||||
.to_grid_horizontal();
|
||||
//ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
|
||||
//
|
||||
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
||||
let hex_digits_view =
|
||||
rt_int.descend(Context::parse(&ctx, "
|
||||
< PosInt 16 BigEndian >
|
||||
~ < Seq <Digit 16>
|
||||
~ ℤ_2^64
|
||||
~ machine.UInt64 >
|
||||
let mut chars_view = rt_int.descend(Context::parse(&ctx, "
|
||||
<PosInt 16 BigEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>~Char>
|
||||
")).expect("cant descend")
|
||||
.read().unwrap()
|
||||
.view_seq::< u64 >()
|
||||
.map(|digit| TerminalAtom::from(char::from_digit(*digit as u32, 16)))
|
||||
.to_grid_horizontal();
|
||||
.get_port::<dyn ListView<char>>()
|
||||
.unwrap();
|
||||
|
||||
let mut digits_view = chars_view
|
||||
.to_sequence()
|
||||
.filter_map(
|
||||
|digit_char|
|
||||
|
||||
/* TODO: call morphism for each item
|
||||
*/
|
||||
match digit_char.to_digit(16) {
|
||||
Some(d) => Some(d as u64),
|
||||
None => None
|
||||
}
|
||||
);
|
||||
|
||||
rt_int.attach_leaf_to(Context::parse(&ctx, "
|
||||
<PosInt 16 BigEndian>
|
||||
~ <Seq <Digit 16>
|
||||
~ ℤ_2^64
|
||||
~ machine.UInt64 >
|
||||
"),
|
||||
digits_view.clone()
|
||||
);
|
||||
|
||||
//ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
|
||||
//
|
||||
*/
|
||||
}
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
/* setup context
|
||||
*/
|
||||
let ctx = Arc::new(RwLock::new(Context::new()));
|
||||
nested::editors::char::init_ctx( ctx.clone() );
|
||||
nested::editors::digit::init_ctx( ctx.clone() );
|
||||
nested::editors::integer::init_ctx( ctx.clone() );
|
||||
nested::editors::list::init_ctx( ctx.clone() );
|
||||
nested_tty::setup_edittree_hook(&ctx);
|
||||
|
||||
/* Create a Representation-Tree of type `ℕ`
|
||||
*/
|
||||
let mut rt_int = ReprTree::new_arc( Context::parse(&ctx, "ℕ") );
|
||||
|
||||
/* Add a specific Representation-Path (big-endian hexadecimal)
|
||||
*/
|
||||
let mut digits_be = VecBuffer::with_data(vec![ 'c', 'f', 'f' ]);
|
||||
rt_int.insert_leaf(
|
||||
Context::parse(&ctx, "<PosInt 16 BigEndian>~<Seq <Digit 16>>~<List <Digit 16>>~<List Char>~<Vec Char>"),
|
||||
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_be.clone() )
|
||||
);
|
||||
|
||||
let mut digits_le = VecBuffer::with_data(vec!['3', '2', '1']);
|
||||
rt_int.insert_leaf(
|
||||
Context::parse(&ctx, "<PosInt 16 LittleEndian>~<Seq <Digit 16>>~<List <Digit 16>>~<List Char>~<Vec Char>"),
|
||||
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_le.clone() )
|
||||
);
|
||||
|
||||
let mut digits_le_editvec = VecBuffer::<Arc<RwLock<EditTree>>>::new();
|
||||
rt_int.insert_leaf(
|
||||
Context::parse(&ctx, "
|
||||
<PosInt 16 LittleEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>
|
||||
~ Char
|
||||
~ EditTree>
|
||||
~ <Vec EditTree>
|
||||
"),
|
||||
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_le_editvec.clone() )
|
||||
);
|
||||
|
||||
let mut digits_be_editvec = VecBuffer::<Arc<RwLock<EditTree>>>::new();
|
||||
rt_int.insert_leaf(
|
||||
Context::parse(&ctx, "
|
||||
<PosInt 16 BigEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>
|
||||
~ Char
|
||||
~ EditTree>
|
||||
~ <Vec EditTree>
|
||||
"),
|
||||
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_be_editvec.clone() )
|
||||
);
|
||||
|
||||
/* initially copy values from Vec to EditTree...
|
||||
*/
|
||||
rebuild_projections(
|
||||
ctx.clone(),
|
||||
rt_int.clone(),
|
||||
// master representation
|
||||
vec![
|
||||
(
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ <Vec Char>",
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
||||
),
|
||||
(
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree>"
|
||||
),
|
||||
(
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ <List EditTree>",
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ <List EditTree> ~ <Vec EditTree>"
|
||||
),
|
||||
(
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ <List EditTree> ~ <Vec EditTree>",
|
||||
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree"
|
||||
),
|
||||
].into_iter()
|
||||
.map(|(s,d)| (Context::parse(&ctx, s), Context::parse(&ctx, d)))
|
||||
.collect()
|
||||
);
|
||||
|
||||
setup_le_master(&ctx, &rt_int);
|
||||
|
||||
let edittree_hex_le_list = ctx.read().unwrap()
|
||||
.setup_edittree(
|
||||
rt_int.descend(Context::parse(&ctx,"
|
||||
<PosInt 16 LittleEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>>
|
||||
~ <List Char>
|
||||
")).expect("descend"),
|
||||
SingletonBuffer::new(0).get_port()
|
||||
).unwrap();
|
||||
let edittree_hex_be_list = ctx.read().unwrap()
|
||||
.setup_edittree(
|
||||
rt_int.descend(Context::parse(&ctx,"
|
||||
<PosInt 16 BigEndian>
|
||||
~ <Seq <Digit 16>>
|
||||
~ <List <Digit 16>>
|
||||
~ <List Char>
|
||||
")).expect("descend"),
|
||||
SingletonBuffer::new(0).get_port()
|
||||
).unwrap();
|
||||
|
||||
/* list of both editors
|
||||
*/
|
||||
|
@ -321,7 +323,7 @@ async fn main() {
|
|||
edittree_hex_le_list.get().goto(TreeCursor::none());
|
||||
edittree.goto(TreeCursor{
|
||||
leaf_mode: nested::editors::list::ListCursorMode::Insert,
|
||||
tree_addr: vec![0,0]
|
||||
tree_addr: vec![1,0]
|
||||
});
|
||||
let edittree = Arc::new(RwLock::new(edittree));
|
||||
|
||||
|
@ -331,7 +333,31 @@ async fn main() {
|
|||
/* event handler
|
||||
*/
|
||||
let ctx = ctx.clone();
|
||||
let rt_int = rt_int.clone();
|
||||
let last_idx = RwLock::new(1);
|
||||
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 {
|
||||
setup_be_master(&ctx, &rt_int);
|
||||
*li = 0;
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
let mut li = last_idx.write().unwrap();
|
||||
if *li != 1 {
|
||||
setup_le_master(&ctx, &rt_int);
|
||||
*li = 1;
|
||||
}
|
||||
}
|
||||
_=>{}
|
||||
}
|
||||
}
|
||||
|
||||
edittree.write().unwrap().send_cmd_obj(ev.to_repr_tree(&ctx));
|
||||
}
|
||||
});
|
||||
|
@ -366,15 +392,18 @@ async fn main() {
|
|||
|
||||
/* 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)))
|
||||
}));
|
||||
*/
|
||||
}
|
||||
|
||||
/* write the changes in the view of `term_port` to the terminal
|
||||
|
|
|
@ -32,16 +32,17 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
|||
let ctx = ctx.clone();
|
||||
move |rt, σ| {
|
||||
{
|
||||
let mut rt = rt.write().unwrap();
|
||||
if let Some(buf) = rt.singleton_buffer::<char>() {
|
||||
let mut b = rt.write().unwrap().singleton_buffer::<char>();
|
||||
if let Some(buf) = b {
|
||||
// buffer already exists
|
||||
} else {
|
||||
// create char buffer
|
||||
rt.insert_leaf(
|
||||
rt.write().unwrap().insert_leaf(
|
||||
vec![].into_iter(),
|
||||
ReprLeaf::from_singleton_buffer(
|
||||
SingletonBuffer::new('\0')
|
||||
));
|
||||
SingletonBuffer::new('\0')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,13 +54,10 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
|||
SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
rt.write().unwrap()
|
||||
.insert_branch(
|
||||
ReprTree::from_singleton_buffer(
|
||||
Context::parse(&ctx, "EditTree"),
|
||||
SingletonBuffer::new(edittree)
|
||||
)
|
||||
);
|
||||
rt.insert_leaf(
|
||||
Context::parse(&ctx, "EditTree"),
|
||||
ReprLeaf::from_singleton_buffer(SingletonBuffer::new(edittree))
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -20,6 +20,10 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
ctx.write().unwrap().add_varname("SrcRadix");
|
||||
ctx.write().unwrap().add_varname("DstRadix");
|
||||
|
||||
|
||||
/*
|
||||
* MACHINE INT, SEQ
|
||||
*/
|
||||
let morphism_type =
|
||||
MorphismType {
|
||||
src_type: Context::parse(&ctx, "
|
||||
|
@ -49,21 +53,22 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
.apply_substitution(&|k|σ.get(k).cloned())
|
||||
.clone()
|
||||
).expect("cant descend")
|
||||
.read().unwrap()
|
||||
.view_seq::< u64 >();
|
||||
.view_seq::< u64 >();
|
||||
|
||||
src_rt.insert_leaf(Context::parse(&ctx, "
|
||||
src_rt.attach_leaf_to(Context::parse(&ctx, "
|
||||
<PosInt Radix LittleEndian>
|
||||
~ <Seq <Digit Radix>
|
||||
~ ℤ_2^64
|
||||
~ machine.UInt64 >
|
||||
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||
ReprLeaf::from_view( src_digits.reverse() )
|
||||
src_digits.reverse()
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/* MACHINE INT, LIST
|
||||
*/
|
||||
let morphism_type = MorphismType {
|
||||
src_type: Context::parse(&ctx, "
|
||||
ℕ
|
||||
|
@ -95,16 +100,15 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
")
|
||||
.apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||
).expect("cant descend")
|
||||
.read().unwrap()
|
||||
.get_port::< dyn ListView<u64> >().unwrap();
|
||||
.get_port::< dyn ListView<u64> >().unwrap();
|
||||
|
||||
src_rt.insert_leaf(
|
||||
src_rt.attach_leaf_to(
|
||||
Context::parse(&ctx, "
|
||||
<PosInt Radix LittleEndian>
|
||||
~ <Seq <Digit Radix>>
|
||||
~ <List <Digit Radix> ~ ℤ_2^64 ~ machine.UInt64>
|
||||
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
|
||||
ReprLeaf::from_view( src_digits.reverse() )
|
||||
src_digits.reverse()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -113,14 +117,14 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
|
||||
let mt = MorphismType {
|
||||
src_type: Context::parse(&ctx, "
|
||||
ℕ
|
||||
ℕ
|
||||
~ <PosInt Radix BigEndian>
|
||||
~ <Seq <Digit Radix>>
|
||||
~ <List <Digit Radix>>
|
||||
~ <List Char>
|
||||
"),
|
||||
dst_type: Context::parse(&ctx, "
|
||||
ℕ
|
||||
ℕ
|
||||
~ <PosInt Radix LittleEndian>
|
||||
~ <Seq <Digit Radix>>
|
||||
~ <List <Digit Radix>>
|
||||
|
@ -132,22 +136,23 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
{
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let radix = σ.get( &laddertypes::TypeID::Var(ctx.read().unwrap().get_var_typeid("Radix").unwrap()) );
|
||||
let src_digits = src_rt.descend(Context::parse(&ctx, "
|
||||
<PosInt Radix BigEndian>
|
||||
<PosInt Radix BigEndian>
|
||||
~ <Seq <Digit Radix>>
|
||||
~ <List <Digit Radix>~Char >
|
||||
").apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||
).expect("cant descend")
|
||||
.read().unwrap()
|
||||
.get_port::< dyn ListView<char> >().unwrap();
|
||||
|
||||
src_rt.insert_leaf(
|
||||
let rev_port = src_digits.reverse();
|
||||
src_rt.attach_leaf_to(
|
||||
Context::parse(&ctx, "
|
||||
< PosInt Radix LittleEndian >
|
||||
< PosInt Radix LittleEndian >
|
||||
~ < Seq <Digit Radix> >
|
||||
~ < List <Digit Radix>~Char >
|
||||
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
|
||||
ReprLeaf::from_view( src_digits.reverse() )
|
||||
rev_port
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -176,21 +181,14 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
")
|
||||
.apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||
).expect("cant descend")
|
||||
.read().unwrap()
|
||||
.view_seq::< u64 >();
|
||||
.view_seq::< u64 >();
|
||||
|
||||
src_rt.write().unwrap().insert_leaf(
|
||||
vec![
|
||||
Context::parse(&ctx, "<PosInt Radix BigEndian>")
|
||||
.apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||
Context::parse(&ctx, "<Seq <Digit Radix>>")
|
||||
.apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||
Context::parse(&ctx, "<Seq ℤ_2^64>"),
|
||||
Context::parse(&ctx, "<Seq machine.UInt64>")
|
||||
].into_iter(),
|
||||
|
||||
ReprLeaf::from_view( src_digits.reverse() )
|
||||
);
|
||||
src_rt.attach_leaf_to(Context::parse(&ctx, "
|
||||
<PosInt Radix BigEndian>
|
||||
~ <Seq <Digit Radix> ~ ℤ_2^64 ~ machine.UInt64>
|
||||
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||
src_digits.reverse()
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -219,32 +217,29 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
let ctx = ctx.clone();
|
||||
move |src_rt, σ|
|
||||
{
|
||||
let src_digits = ReprTree::descend(
|
||||
&src_rt,
|
||||
Context::parse(&ctx, "
|
||||
let src_digits = src_rt.descend(
|
||||
Context::parse(&ctx, "
|
||||
<PosInt Radix LittleEndian>
|
||||
~ <Seq <Digit Radix>>
|
||||
~ <List <Digit Radix>~ℤ_2^64~machine.UInt64 >
|
||||
")
|
||||
.apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||
).expect("cant descend")
|
||||
.read().unwrap()
|
||||
.get_port::< dyn ListView<u64> >().unwrap();
|
||||
").apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||
)
|
||||
.expect("cant descend")
|
||||
.view_list::<u64>();
|
||||
|
||||
src_rt.insert_leaf(
|
||||
src_rt.attach_leaf_to(
|
||||
Context::parse(&ctx, "
|
||||
<PosInt Radix BigEndian>
|
||||
~ <Seq <Digit Radix>>
|
||||
~ <List <Digit Radix>~ℤ_2^64~machine.UInt64 >
|
||||
"),
|
||||
ReprLeaf::from_view( src_digits.reverse() )
|
||||
);
|
||||
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||
src_digits.reverse()
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
let mt = MorphismType {
|
||||
src_type: Context::parse(&ctx, "
|
||||
ℕ
|
||||
|
@ -273,16 +268,15 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
~ <List <Digit Radix>~Char >
|
||||
").apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||
).expect("cant descend")
|
||||
.read().unwrap()
|
||||
.get_port::< dyn ListView<char> >().unwrap();
|
||||
.view_list::<char>();
|
||||
|
||||
src_rt.insert_leaf(
|
||||
src_rt.attach_leaf_to(
|
||||
Context::parse(&ctx, "
|
||||
< PosInt Radix BigEndian >
|
||||
~ < Seq <Digit Radix> >
|
||||
~ < List <Digit Radix>~Char >
|
||||
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
|
||||
ReprLeaf::from_view( src_digits.reverse() )
|
||||
src_digits.reverse()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -327,30 +321,24 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
_ => 0
|
||||
};
|
||||
|
||||
let src_digits_rt = ReprTree::descend(
|
||||
src_rt,
|
||||
Context::parse(&ctx, "
|
||||
let src_digits_rt = src_rt.descend(Context::parse(&ctx, "
|
||||
<PosInt SrcRadix LittleEndian>
|
||||
~ <Seq <Digit SrcRadix> ~ ℤ_2^64 ~ machine.UInt64 >"
|
||||
).apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||
~ <Seq <Digit SrcRadix> ~ ℤ_2^64 ~ machine.UInt64 >
|
||||
").apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||
).expect("cant descend repr tree");
|
||||
|
||||
let dst_digits_port =
|
||||
src_digits_rt.read().unwrap()
|
||||
.view_seq::<u64>()
|
||||
src_digits_rt.view_seq::<u64>()
|
||||
.to_positional_uint( src_radix )
|
||||
.transform_radix( dst_radix );
|
||||
|
||||
src_rt.write().unwrap()
|
||||
.insert_leaf(
|
||||
vec![
|
||||
Context::parse(&ctx, "<PosInt DstRadix LittleEndian>").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||
Context::parse(&ctx, "<Seq <Digit DstRadix>>").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||
Context::parse(&ctx, "<Seq ℤ_2^64>"),
|
||||
Context::parse(&ctx, "<Seq machine.UInt64>"),
|
||||
].into_iter(),
|
||||
ReprLeaf::from_view(dst_digits_port)
|
||||
);
|
||||
src_rt.attach_leaf_to(
|
||||
Context::parse(&ctx, "
|
||||
<PosInt DstRadix LittleEndian>
|
||||
~ <Seq <Digit DstRadix> ~ ℤ_2^64 ~ machine.UInt64>
|
||||
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||
dst_digits_port
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use {
|
||||
r3vi::{
|
||||
view::{
|
||||
ViewPort,
|
||||
ViewPort, port::UpdateTask,
|
||||
OuterViewPort, Observer,
|
||||
singleton::*,
|
||||
list::*
|
||||
|
@ -32,33 +32,34 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
ctx.write().unwrap().morphisms.add_morphism(mt, {
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let list_port = src_rt.read().unwrap().get_port::<dyn ListView<char>>().clone();
|
||||
let list_port = src_rt.descend(Context::parse(&ctx, "<List Char>")).expect("descend").get_port::<dyn ListView<char>>().clone();
|
||||
if let Some(list_port) = list_port {
|
||||
|
||||
// for each char, create EditTree
|
||||
let edit_tree_list =
|
||||
list_port
|
||||
// for each char, create and EditTree
|
||||
.map({
|
||||
let ctx = ctx.clone();
|
||||
move |c| {
|
||||
let item_rt = ReprTree::from_char(&ctx, *c);
|
||||
|
||||
ctx.read().unwrap().setup_edittree(
|
||||
item_rt.clone(),
|
||||
SingletonBuffer::new(0).get_port()
|
||||
);
|
||||
|
||||
let et = item_rt
|
||||
.descend(Context::parse(&ctx, "EditTree")).unwrap()
|
||||
.read().unwrap()
|
||||
.get_port::< dyn SingletonView<Item = EditTree> >()
|
||||
.expect("cant get view port (EditTree)")
|
||||
.descend(Context::parse(&ctx, "Char ~ EditTree")).expect("cant descend repr tree")
|
||||
.get_port::< dyn SingletonView<Item = EditTree> >().expect("cant get view port (EditTree)")
|
||||
.get_view().unwrap()
|
||||
.get();
|
||||
Arc::new(RwLock::new(et))
|
||||
}
|
||||
});
|
||||
|
||||
src_rt.write().unwrap().insert_leaf(
|
||||
Context::parse(&ctx, "<List EditTree>").get_lnf_vec().into_iter(),
|
||||
ReprLeaf::from_view( edit_tree_list )
|
||||
src_rt.attach_leaf_to(
|
||||
Context::parse(&ctx, "<List Char>~<List EditTree>"),
|
||||
edit_tree_list
|
||||
);
|
||||
} else {
|
||||
eprintln!("morphism missing view port");
|
||||
|
@ -70,44 +71,29 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
src_type: Context::parse(&ctx, "<List Item>~<List EditTree>~<Vec EditTree>"),
|
||||
dst_type: Context::parse(&ctx, "<List Item>~EditTree")
|
||||
};
|
||||
|
||||
ctx.write().unwrap().morphisms.add_morphism(mt, {
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let item_id = laddertypes::TypeID::Var( ctx.read().unwrap().get_var_typeid("Item").unwrap() );
|
||||
if let Some( item_type ) = σ.get( &item_id ) {
|
||||
/*
|
||||
let mut item_vec_buffer = VecBuffer::new();
|
||||
|
||||
eprintln!("try attach to data port");
|
||||
if let Some( list_port ) =
|
||||
src_rt
|
||||
.descend(Context::parse(&ctx, "<List EditTree>")).expect("")
|
||||
.read().unwrap()
|
||||
.get_port::< dyn ListView< Arc<RwLock<EditTree>> > >()
|
||||
{
|
||||
eprintln!("get list<edittree> port");
|
||||
item_vec_buffer.attach_to( list_port );
|
||||
}*/
|
||||
|
||||
let mut item_vec_rt = src_rt
|
||||
.descend(Context::parse(&ctx, "<List EditTree>~<Vec EditTree>"))
|
||||
.descend(
|
||||
Context::parse(&ctx, "<List Item~EditTree>~<Vec EditTree>")
|
||||
.apply_substitution(&|id| σ.get(id).cloned()).clone()
|
||||
)
|
||||
.expect("cant descend src repr");
|
||||
|
||||
let item_vec_buffer = item_vec_rt
|
||||
.write().unwrap()
|
||||
.vec_buffer::< Arc<RwLock<EditTree>> >().expect("cant get vec buffer");
|
||||
let item_vec_buffer = item_vec_rt.vec_buffer::< Arc<RwLock<EditTree>> >();
|
||||
|
||||
// eprintln!("create ListEditor");
|
||||
let mut list_editor = ListEditor::with_data(ctx.clone(), item_type.clone(), item_vec_buffer);
|
||||
|
||||
let edittree_list = list_editor.into_node(
|
||||
SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
// eprintln!("make edittree");
|
||||
src_rt.write().unwrap().insert_branch(
|
||||
ReprTree::from_singleton_buffer(
|
||||
Context::parse(&ctx, "EditTree"),
|
||||
src_rt.insert_leaf(
|
||||
Context::parse(&ctx, "<List Item> ~ EditTree")
|
||||
.apply_substitution(&|id| σ.get(id).cloned()).clone(),
|
||||
ReprLeaf::from_singleton_buffer(
|
||||
SingletonBuffer::new(edittree_list)
|
||||
)
|
||||
);
|
||||
|
@ -128,64 +114,31 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
move |src_rt, σ| {
|
||||
let edittree =
|
||||
src_rt
|
||||
.descend(Context::parse(&ctx, "EditTree")).unwrap()
|
||||
.descend(Context::parse(&ctx, "<List Char>~EditTree")).unwrap()
|
||||
.singleton_buffer::<EditTree>();
|
||||
|
||||
let list_edit = edittree.get().get_edit::< ListEditor >().unwrap();
|
||||
let edittree_items = list_edit.read().unwrap().data.get_port().to_list();
|
||||
src_rt.write().unwrap().insert_leaf(
|
||||
vec![].into_iter(),
|
||||
ReprLeaf::from_view(
|
||||
edittree_items
|
||||
.map(
|
||||
|edittree_char|
|
||||
edittree_char
|
||||
.read().unwrap()
|
||||
.get_edit::<CharEditor>().unwrap()
|
||||
.read().unwrap()
|
||||
.get()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
let mt = crate::repr_tree::MorphismType {
|
||||
src_type: Context::parse(&ctx, "<List <Digit Radix>>~EditTree"),
|
||||
dst_type: Context::parse(&ctx, "<List <Digit Radix>~Char>")
|
||||
};
|
||||
ctx.write().unwrap().morphisms.add_morphism(
|
||||
mt,
|
||||
{
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let edittree =
|
||||
src_rt
|
||||
.descend(Context::parse(&ctx, "EditTree")).unwrap()
|
||||
.singleton_buffer::<EditTree>();
|
||||
|
||||
let list_edit = edittree.get().get_edit::< ListEditor >().unwrap();
|
||||
let edittree_items = list_edit.read().unwrap().data.get_port().to_list();
|
||||
src_rt.write().unwrap().insert_leaf(
|
||||
vec![ Context::parse(&ctx, "<List Char>") ].into_iter(),
|
||||
src_rt.insert_leaf(
|
||||
Context::parse(&ctx, "<List Char>"),
|
||||
ReprLeaf::from_view(
|
||||
edittree_items
|
||||
.map(
|
||||
|edittree_char|
|
||||
edittree_char
|
||||
.read().unwrap()
|
||||
.get_edit::<crate::editors::digit::editor::DigitEditor>().unwrap()
|
||||
.read().unwrap()
|
||||
.get_char()
|
||||
)
|
||||
)
|
||||
edittree_items
|
||||
.map(|edittree_char|
|
||||
edittree_char
|
||||
.read().unwrap()
|
||||
.get_edit::<CharEditor>().unwrap()
|
||||
.read().unwrap()
|
||||
.get()
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/* todo : unify the following two morphims with generic item parameter ?
|
||||
*/
|
||||
let mt = crate::repr_tree::MorphismType {
|
||||
src_type: Context::parse(&ctx, "<List Char>"),
|
||||
dst_type: Context::parse(&ctx, "<List Char>~<Vec Char>")
|
||||
|
@ -195,17 +148,30 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
{
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let buf = VecBuffer::<char>::new();
|
||||
let mut leaf = ReprLeaf::from_vec_buffer(buf);
|
||||
leaf.attach_to(
|
||||
src_rt.read().unwrap()
|
||||
.get_port::<dyn ListView<char>>()
|
||||
.unwrap()
|
||||
);
|
||||
src_rt.write().unwrap().insert_leaf(
|
||||
vec![ Context::parse(&ctx, "<Vec Char>") ].into_iter(),
|
||||
leaf
|
||||
);
|
||||
src_rt
|
||||
.attach_leaf_to(
|
||||
Context::parse(&ctx, "<List Char>~<Vec Char>"),
|
||||
src_rt
|
||||
.descend(Context::parse(&ctx, "<List Char>"))
|
||||
.expect("descend")
|
||||
.view_list::<char>()
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
let mt = crate::repr_tree::MorphismType {
|
||||
src_type: Context::parse(&ctx, "<List Char>~<Vec Char>"),
|
||||
dst_type: Context::parse(&ctx, "<List Char>")
|
||||
};
|
||||
ctx.write().unwrap().morphisms.add_morphism(
|
||||
mt,
|
||||
{
|
||||
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() );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -219,16 +185,14 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
{
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let buf = VecBuffer::<Arc<RwLock<EditTree>>>::new();
|
||||
let mut leaf = ReprLeaf::from_vec_buffer(buf);
|
||||
leaf.attach_to(
|
||||
src_rt.read().unwrap()
|
||||
.get_port::<dyn ListView< Arc<RwLock<EditTree>> >>()
|
||||
.unwrap()
|
||||
);
|
||||
src_rt.write().unwrap().insert_leaf(
|
||||
vec![ Context::parse(&ctx, "<Vec EditTree>") ].into_iter(),
|
||||
leaf
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -319,12 +319,14 @@ impl ListEditor {
|
|||
let mut b = item.ctrl.spillbuf.write().unwrap();
|
||||
|
||||
let rt = ReprTree::new_arc(self.typ.clone());
|
||||
let edittree = self.ctx.read().unwrap()
|
||||
let mut et = self.ctx.read().unwrap()
|
||||
.setup_edittree(
|
||||
rt,
|
||||
self.depth.map(|d| d+1)
|
||||
);
|
||||
|
||||
if let Some(edittree) = et.as_mut(){
|
||||
|
||||
let mut tail_node = edittree.get_mut();
|
||||
tail_node.goto(TreeCursor::home());
|
||||
|
||||
|
@ -354,6 +356,8 @@ impl ListEditor {
|
|||
edittree.value.clone()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
self.up();
|
||||
self.listlist_split();
|
||||
|
|
|
@ -179,7 +179,7 @@ impl Context {
|
|||
&self,
|
||||
rt: Arc<RwLock<ReprTree>>,
|
||||
depth: OuterViewPort<dyn SingletonView<Item = usize>>
|
||||
) -> SingletonBuffer<EditTree> {
|
||||
) -> Option<SingletonBuffer<EditTree>> {
|
||||
let ladder = TypeTerm::Ladder(vec![
|
||||
rt.read().unwrap().get_type().clone(),
|
||||
self.type_term_from_str("EditTree").expect("")
|
||||
|
@ -194,14 +194,19 @@ impl Context {
|
|||
if let Some(new_edittree) =
|
||||
rt.descend(self.type_term_from_str("EditTree").unwrap())
|
||||
{
|
||||
let typ = rt.read().unwrap().get_type().clone();
|
||||
let buf = new_edittree.singleton_buffer::<EditTree>();
|
||||
(*self.edittree_hook)(
|
||||
&mut *buf.get_mut(),
|
||||
rt.read().unwrap().get_type().clone()
|
||||
typ
|
||||
);
|
||||
buf
|
||||
Some(buf)
|
||||
} else {
|
||||
unreachable!();
|
||||
eprintln!("cant find edit tree repr {} ~Ψ~ {}",
|
||||
self.type_term_to_str(rt.read().unwrap().get_halo_type()),
|
||||
self.type_term_to_str(rt.read().unwrap().get_type())
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use {
|
|||
ViewPort, OuterViewPort,
|
||||
AnyViewPort, AnyInnerViewPort, AnyOuterViewPort,
|
||||
port::UpdateTask,
|
||||
View,
|
||||
View, Observer,
|
||||
singleton::*,
|
||||
sequence::*,
|
||||
list::*
|
||||
|
@ -40,6 +40,7 @@ pub struct ReprLeaf {
|
|||
|
||||
/// keepalive for the observer that updates the buffer from in_port
|
||||
keepalive: Option<Arc<dyn Any + Send + Sync>>,
|
||||
in_keepalive: Option<Arc<dyn Any + Send + Sync>>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -72,26 +73,73 @@ impl ReprLeaf {
|
|||
V::Msg: Clone
|
||||
{
|
||||
let mut in_port = ViewPort::<V>::new();
|
||||
in_port.attach_to(src_port);
|
||||
let in_keepalive = in_port.attach_to(src_port);
|
||||
|
||||
let mut buf_port = ViewPort::<V>::new();
|
||||
buf_port.attach_to(in_port.outer());
|
||||
let mut out_port = ViewPort::<V>::new();
|
||||
let out_keepalive = out_port.attach_to(in_port.outer());
|
||||
|
||||
ReprLeaf {
|
||||
keepalive: None,
|
||||
keepalive: Some(out_keepalive),
|
||||
in_keepalive: Some(in_keepalive),
|
||||
in_port: in_port.inner().into(),
|
||||
out_port: buf_port.into(),
|
||||
out_port: out_port.into(),
|
||||
data: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn detach<V>(&mut self)
|
||||
where V: View + ?Sized + 'static,
|
||||
V::Msg: Clone
|
||||
{
|
||||
self.keepalive = None;
|
||||
self.in_keepalive = None;
|
||||
|
||||
let ip = self.in_port.clone()
|
||||
.downcast::<V>().ok()
|
||||
.unwrap();
|
||||
ip.0.detach();
|
||||
|
||||
if self.data.is_none() {
|
||||
let mut op = self.out_port.clone()
|
||||
.downcast::<V>().ok()
|
||||
.unwrap();
|
||||
|
||||
op.detach();
|
||||
self.keepalive = Some(op.attach_to(ip.0.outer()));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn detach_vec<Item>(&mut self)
|
||||
where Item: Clone + Send + Sync + 'static
|
||||
{
|
||||
self.keepalive = None;
|
||||
self.in_keepalive = None;
|
||||
|
||||
let ip = self.in_port.clone()
|
||||
.downcast::<dyn ListView<Item>>().ok()
|
||||
.unwrap();
|
||||
|
||||
ip.0.detach();
|
||||
|
||||
if let Some(data) = self.data.as_mut() {
|
||||
let mut op = self.out_port.clone()
|
||||
.downcast::<RwLock<Vec<Item>>>().ok()
|
||||
.unwrap();
|
||||
op.detach();
|
||||
|
||||
let data = data.clone().downcast::< RwLock<Vec<Item>> >().ok().unwrap();
|
||||
let buffer = VecBuffer::with_data_arc_port(data, op.inner());
|
||||
self.keepalive = Some(buffer.attach_to(ip.0.outer()))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn attach_to<V>(&mut self, src_port: OuterViewPort<V>)
|
||||
where V: View + ?Sized + 'static,
|
||||
V::Msg: Clone
|
||||
{
|
||||
self.in_port.clone()
|
||||
self.in_keepalive = Some(self.in_port.clone()
|
||||
.downcast::<V>().ok().unwrap()
|
||||
.0.attach_to( src_port );
|
||||
.0.attach_to( src_port ));
|
||||
}
|
||||
|
||||
pub fn from_singleton_buffer<T>( buffer: SingletonBuffer<T> ) -> Self
|
||||
|
@ -99,6 +147,7 @@ impl ReprLeaf {
|
|||
{
|
||||
let in_port = ViewPort::<dyn SingletonView<Item = T>>::new();
|
||||
ReprLeaf {
|
||||
in_keepalive: None,
|
||||
keepalive: Some(buffer.attach_to(in_port.outer())),
|
||||
in_port: in_port.inner().into(),
|
||||
out_port: buffer.get_port().0.into(),
|
||||
|
@ -109,9 +158,9 @@ impl ReprLeaf {
|
|||
pub fn from_vec_buffer<T>( buffer: VecBuffer<T> ) -> Self
|
||||
where T: Clone + Send + Sync + 'static
|
||||
{
|
||||
eprintln!("ReprLeaf from vec buffer (LEN ={})", buffer.len());
|
||||
let in_port = ViewPort::< dyn ListView<T> >::new();
|
||||
ReprLeaf {
|
||||
in_keepalive: None,
|
||||
keepalive: Some(buffer.attach_to(in_port.outer())),
|
||||
in_port: in_port.inner().into(),
|
||||
out_port: buffer.get_port().0.into(),
|
||||
|
@ -159,7 +208,6 @@ impl ReprLeaf {
|
|||
|
||||
let data_arc =
|
||||
if let Some(data) = self.data.as_ref() {
|
||||
eprintln!("downcast existing vec-data");
|
||||
data.clone().downcast::<RwLock<Vec<T>>>().ok()
|
||||
} else {
|
||||
vec_port.update();
|
||||
|
@ -175,14 +223,8 @@ impl ReprLeaf {
|
|||
};
|
||||
|
||||
if let Some(data_arc) = data_arc {
|
||||
eprintln!("ReprLeaf: have Vec-like data-arc");
|
||||
eprintln!("LEN = {}", data_arc.read().unwrap().len());
|
||||
|
||||
self.data = Some(data_arc.clone() as Arc<dyn Any + Send + Sync>);
|
||||
let buf = VecBuffer {
|
||||
data: data_arc,
|
||||
port: vec_port.inner()
|
||||
};
|
||||
let buf = VecBuffer::with_data_arc_port(data_arc, vec_port.inner());
|
||||
self.keepalive = Some(buf.attach_to(
|
||||
self.in_port.0.clone()
|
||||
.downcast::< dyn ListView<T> >()
|
||||
|
@ -195,7 +237,6 @@ impl ReprLeaf {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_port<V>(&self) -> Option<OuterViewPort<V>>
|
||||
where V: View + ?Sized + 'static,
|
||||
V::Msg: Clone
|
||||
|
@ -243,6 +284,22 @@ impl ReprTree {
|
|||
&self.halo
|
||||
}
|
||||
|
||||
pub fn get_leaf_types(&self) -> Vec< TypeTerm > {
|
||||
let mut leaf_types = Vec::new();
|
||||
if self.leaf.is_some() {
|
||||
leaf_types.push( self.get_type().clone() );
|
||||
}
|
||||
for (branch_type, branch) in self.branches.iter() {
|
||||
for t in branch.read().unwrap().get_leaf_types() {
|
||||
leaf_types.push(TypeTerm::Ladder(vec![
|
||||
self.get_type().clone(),
|
||||
t
|
||||
]).normalize())
|
||||
}
|
||||
}
|
||||
leaf_types
|
||||
}
|
||||
|
||||
pub fn insert_branch(&mut self, repr: Arc<RwLock<ReprTree>>) {
|
||||
let branch_type = repr.read().unwrap().get_type().clone();
|
||||
|
||||
|
@ -252,6 +309,7 @@ impl ReprTree {
|
|||
self.halo.clone(),
|
||||
self.type_tag.clone()
|
||||
]).normalize() );
|
||||
|
||||
self.branches.insert(branch_type, repr.clone());
|
||||
}
|
||||
|
||||
|
@ -298,12 +356,20 @@ impl ReprTree {
|
|||
V::Msg: Clone
|
||||
{
|
||||
if let Some(rung_type) = type_ladder.next() {
|
||||
if let Some(next_repr) = self.branches.get(&rung_type) {
|
||||
next_repr.write().unwrap().attach_leaf_to(type_ladder, src_port);
|
||||
if &rung_type == self.get_type() {
|
||||
if let Some(leaf) = self.leaf.as_mut() {
|
||||
leaf.attach_to(src_port);
|
||||
} else {
|
||||
self.leaf = Some(ReprLeaf::from_view(src_port));
|
||||
}
|
||||
} else {
|
||||
let mut next_repr = ReprTree::new(rung_type.clone());
|
||||
next_repr.attach_leaf_to(type_ladder, src_port);
|
||||
self.insert_branch(Arc::new(RwLock::new(next_repr)));
|
||||
if let Some(next_repr) = self.branches.get(&rung_type) {
|
||||
next_repr.write().unwrap().attach_leaf_to(type_ladder, src_port);
|
||||
} else {
|
||||
let mut next_repr = ReprTree::new(rung_type.clone());
|
||||
next_repr.attach_leaf_to(type_ladder, src_port);
|
||||
self.insert_branch(Arc::new(RwLock::new(next_repr)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let Some(leaf) = self.leaf.as_mut() {
|
||||
|
@ -314,6 +380,38 @@ impl ReprTree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn attach_to<V>(
|
||||
&mut self,
|
||||
src_port: OuterViewPort<V>
|
||||
)
|
||||
where V: View + ?Sized + 'static,
|
||||
V::Msg: Clone
|
||||
{
|
||||
if let Some(leaf) = self.leaf.as_mut() {
|
||||
leaf.attach_to(src_port);
|
||||
} else {
|
||||
eprintln!("cant attach branch without leaf");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn detach(&mut self, ctx: &Arc<RwLock<Context>>) {
|
||||
if let Some(leaf) = self.leaf.as_mut() {
|
||||
if self.type_tag == Context::parse(&ctx, "Char") {
|
||||
leaf.detach::<dyn SingletonView<Item = char>>();
|
||||
}
|
||||
if self.type_tag == Context::parse(&ctx, "<Vec Char>") {
|
||||
leaf.detach_vec::<char>();
|
||||
}
|
||||
if self.type_tag == Context::parse(&ctx, "<List Char>") {
|
||||
leaf.detach::<dyn ListView<char>>();
|
||||
}
|
||||
}
|
||||
|
||||
for (t,b) in self.branches.iter_mut() {
|
||||
b.write().unwrap().detach(&ctx);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert_leaf(
|
||||
&mut self,
|
||||
mut type_ladder: impl Iterator<Item = TypeTerm>,
|
||||
|
@ -352,7 +450,15 @@ impl ReprTree {
|
|||
}
|
||||
|
||||
pub fn descend(rt: &Arc<RwLock<Self>>, dst_type: impl Into<TypeTerm>) -> Option<Arc<RwLock<ReprTree>>> {
|
||||
ReprTree::descend_ladder(rt, dst_type.into().get_lnf_vec().into_iter())
|
||||
let mut lnf = dst_type.into().get_lnf_vec();
|
||||
if lnf.len() > 0 {
|
||||
if lnf[0] == rt.get_type() {
|
||||
lnf.remove(0);
|
||||
}
|
||||
ReprTree::descend_ladder(rt, lnf.into_iter())
|
||||
} else {
|
||||
Some(rt.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ascend(rt: &Arc<RwLock<Self>>, type_term: impl Into<TypeTerm>) -> Arc<RwLock<ReprTree>> {
|
||||
|
@ -413,6 +519,10 @@ impl ReprTree {
|
|||
self.get_port::<dyn SequenceView<Item = T>>().expect("no sequence-view available")
|
||||
}
|
||||
|
||||
pub fn view_list<T: Clone + Send + Sync + 'static>(&self) -> OuterViewPort<dyn ListView<T>> {
|
||||
self.get_port::<dyn ListView<T>>().expect("no list-view available")
|
||||
}
|
||||
|
||||
pub fn view_char(&self) -> OuterViewPort<dyn SingletonView<Item = char>> {
|
||||
self.get_port::<dyn SingletonView<Item = char>>().expect("no char-view available")
|
||||
}
|
||||
|
@ -442,11 +552,17 @@ pub trait ReprTreeExt {
|
|||
fn create_branch(&mut self, rung: impl Into<TypeTerm>);
|
||||
fn descend(&self, target_type: impl Into<TypeTerm>) -> Option<Arc<RwLock<ReprTree>>>;
|
||||
|
||||
fn attach_leaf_to<V: View + ?Sized + 'static>(&self, t: impl Into<TypeTerm>, v: OuterViewPort<V>) where V::Msg: Clone;
|
||||
fn get_port<V: View + ?Sized + 'static>(&self) -> Option<OuterViewPort<V>> where V::Msg: Clone;
|
||||
|
||||
fn view_char(&self) -> OuterViewPort<dyn SingletonView<Item = char>>;
|
||||
fn view_u8(&self) -> OuterViewPort<dyn SingletonView<Item = u8>>;
|
||||
fn view_u64(&self) -> OuterViewPort<dyn SingletonView<Item = u64>>;
|
||||
fn view_usize(&self) -> OuterViewPort<dyn SingletonView<Item = usize>>;
|
||||
|
||||
fn view_seq<T: Send + Sync + 'static>(&self) -> OuterViewPort<dyn SequenceView<Item = T>>;
|
||||
fn view_list<T: Clone + Send + Sync + 'static>(&self) -> OuterViewPort<dyn ListView<T>>;
|
||||
|
||||
fn singleton_buffer<T: Clone + Send + Sync + 'static>(&self) -> SingletonBuffer<T>;
|
||||
fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> VecBuffer<T>;
|
||||
}
|
||||
|
@ -478,6 +594,14 @@ impl ReprTreeExt for Arc<RwLock<ReprTree>> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_port<V: View + ?Sized + 'static>(&self) -> Option<OuterViewPort<V>> where V::Msg: Clone {
|
||||
self.read().unwrap().get_port::<V>()
|
||||
}
|
||||
|
||||
fn attach_leaf_to<V: View + ?Sized + 'static>(&self, type_ladder: impl Into<TypeTerm>, v: OuterViewPort<V>) where V::Msg: Clone {
|
||||
self.write().unwrap().attach_leaf_to::<V>(type_ladder.into().get_lnf_vec().into_iter(), v)
|
||||
}
|
||||
|
||||
fn descend(&self, target_type: impl Into<TypeTerm>) -> Option<Arc<RwLock<ReprTree>>> {
|
||||
ReprTree::descend( self, target_type )
|
||||
}
|
||||
|
@ -498,6 +622,14 @@ impl ReprTreeExt for Arc<RwLock<ReprTree>> {
|
|||
self.read().unwrap().view_usize()
|
||||
}
|
||||
|
||||
fn view_seq<T: Send + Sync + 'static>(&self) -> OuterViewPort<dyn SequenceView<Item = T>> {
|
||||
self.read().unwrap().view_seq::<T>()
|
||||
}
|
||||
|
||||
fn view_list<T: Clone + Send + Sync + 'static>(&self) -> OuterViewPort<dyn ListView<T>> {
|
||||
self.read().unwrap().view_list::<T>()
|
||||
}
|
||||
|
||||
fn singleton_buffer<T: Clone + Send + Sync + 'static>(&self) -> SingletonBuffer<T> {
|
||||
self.write().unwrap().singleton_buffer::<T>().expect("")
|
||||
}
|
||||
|
|
|
@ -52,7 +52,10 @@ impl MorphismBase {
|
|||
) {
|
||||
self.morphisms.push(
|
||||
GenericReprTreeMorphism {
|
||||
morph_type,
|
||||
morph_type: MorphismType {
|
||||
src_type: morph_type.src_type.normalize(),
|
||||
dst_type: morph_type.dst_type.normalize()
|
||||
},
|
||||
setup_projection: Arc::new(setup_projection)
|
||||
}
|
||||
);
|
||||
|
@ -67,12 +70,13 @@ impl MorphismBase {
|
|||
|
||||
let unification_problem = laddertypes::UnificationProblem::new(
|
||||
vec![
|
||||
( src_type.clone(), m.morph_type.src_type.clone() ),
|
||||
( dst_type.clone(), m.morph_type.dst_type.clone() )
|
||||
( src_type.clone().normalize(), m.morph_type.src_type.clone() ),
|
||||
( dst_type.clone().normalize(), m.morph_type.dst_type.clone() )
|
||||
]
|
||||
);
|
||||
|
||||
if let Ok(σ) = unification_problem.solve() {
|
||||
let unification_result = unification_problem.solve();
|
||||
if let Ok(σ) = unification_result {
|
||||
return Some((m, σ));
|
||||
}
|
||||
}
|
||||
|
@ -80,19 +84,70 @@ impl MorphismBase {
|
|||
None
|
||||
}
|
||||
|
||||
|
||||
pub fn find_morphism_ladder(
|
||||
&self,
|
||||
src_type: &TypeTerm,
|
||||
dst_type: &TypeTerm,
|
||||
) -> Option<(
|
||||
&GenericReprTreeMorphism,
|
||||
TypeTerm,
|
||||
HashMap<TypeID, TypeTerm>
|
||||
)> {
|
||||
let mut src_lnf = src_type.clone().get_lnf_vec();
|
||||
let mut dst_lnf = dst_type.clone().get_lnf_vec();
|
||||
let mut halo = vec![];
|
||||
|
||||
while src_lnf.len() > 0 && dst_lnf.len() > 0 {
|
||||
if let Some((m, σ)) = self.find_morphism( &TypeTerm::Ladder(src_lnf.clone()), &TypeTerm::Ladder(dst_lnf.clone()) ) {
|
||||
return Some((m, TypeTerm::Ladder(halo), σ));
|
||||
} else {
|
||||
if src_lnf[0] == dst_lnf[0] {
|
||||
src_lnf.remove(0);
|
||||
halo.push(dst_lnf.remove(0));
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn apply_morphism(
|
||||
&self,
|
||||
mut repr_tree: Arc<RwLock<ReprTree>>,
|
||||
repr_tree: Arc<RwLock<ReprTree>>,
|
||||
src_type: &TypeTerm,
|
||||
dst_type: &TypeTerm
|
||||
) {
|
||||
// let t = repr_tree.read().unwrap().get_type().clone();
|
||||
if let Some((m, σ)) = self.find_morphism( &src_type, dst_type ) {
|
||||
(m.setup_projection)( &mut repr_tree, &σ );
|
||||
if let Some((m, s, σ)) = self.find_morphism_ladder( &src_type, dst_type ) {
|
||||
//eprintln!("apply morphism on subtree {:?}", s);
|
||||
let mut rt = repr_tree.descend( s ).expect("descend");
|
||||
(m.setup_projection)( &mut rt, &σ );
|
||||
} else {
|
||||
eprintln!("could not find morphism");
|
||||
eprintln!("could not find morphism\n {:?}\n ====>\n {:?}", src_type, dst_type);
|
||||
}
|
||||
}
|
||||
/*
|
||||
pub fn apply_seq_map_morphism<SrcItem, DstItem>(
|
||||
&self,
|
||||
mut repr_tree: Arc<RwLock<ReprTree>>,
|
||||
src_item_type: &TypeTerm,
|
||||
dst_item_type: &TypeTerm
|
||||
) {
|
||||
if let Some((item_morphism, σ)) = self.find_morphism( &src_item_type, dst_item_type ) {
|
||||
|
||||
let src_port = repr_tree.read().unwrap().get_port::<dyn SequenceView<Item = Arc<RwLock<ReprTree>> >>().unwrap();
|
||||
src_port.map(
|
||||
m.setup_projection
|
||||
)
|
||||
|
||||
(m.setup_projection)( &mut repr_tree, &σ );
|
||||
} else {
|
||||
eprintln!("could not find item morphism");
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
|
|
@ -7,6 +7,7 @@ use {
|
|||
repr_tree::{Context, ReprTree},
|
||||
editors::list::*,
|
||||
edit_tree::{TreeCursor, TreeNav, TreeNavResult, EditTree},
|
||||
repr_tree::{ReprTreeExt, ReprLeaf}
|
||||
},
|
||||
crate::{
|
||||
DisplaySegment,
|
||||
|
@ -80,10 +81,12 @@ impl PTYListStyle {
|
|||
editor.get_cursor_port(),
|
||||
editor.get_data_port()
|
||||
);
|
||||
let seg_seq = seg_seq.read().unwrap();
|
||||
|
||||
let seg_seq0 = seg_seq.read().unwrap();
|
||||
let seg_seq = seg_seq0.get_view();
|
||||
drop(seg_seq0);
|
||||
|
||||
seg_seq
|
||||
.get_view()
|
||||
.map(move |segment| segment.display_view())
|
||||
.separate(make_label(&self.style.1))
|
||||
.wrap(make_label(&self.style.0), make_label(&self.style.2))
|
||||
|
@ -92,15 +95,14 @@ impl PTYListStyle {
|
|||
}
|
||||
|
||||
pub fn for_node(node: &mut EditTree, style: (&str, &str, &str)) {
|
||||
let editor = node.get_edit::<ListEditor>().unwrap();
|
||||
let editor = editor.read().unwrap();
|
||||
let pty_view = Self::new(style).pty_view(&editor);
|
||||
node.disp.view
|
||||
.write().unwrap()
|
||||
.insert_branch(ReprTree::from_view(
|
||||
.attach_leaf_to(
|
||||
Context::parse(&node.ctx, "TerminalView"),
|
||||
Self::new(style)
|
||||
.pty_view(
|
||||
&node.get_edit::<ListEditor>().unwrap().read().unwrap()
|
||||
)
|
||||
));
|
||||
pty_view
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,6 +228,8 @@ impl PTYListController {
|
|||
self.depth.map(|d| d+1)
|
||||
);
|
||||
|
||||
if let Some(new_edittree) = new_edittree {
|
||||
|
||||
let mut ne = new_edittree.get();
|
||||
match ne.send_cmd_obj(cmd_obj.clone()) {
|
||||
TreeNavResult::Continue => {
|
||||
|
@ -237,6 +241,12 @@ impl PTYListController {
|
|||
TreeNavResult::Exit
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
panic!("cant get edit tree");
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
},
|
||||
ListCursorMode::Select => {
|
||||
if let Some(item) = e.get_item_mut() {
|
||||
|
|
|
@ -17,7 +17,6 @@ use {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
pub fn edittree_make_char_view(
|
||||
node: EditTree
|
||||
) -> EditTree {
|
||||
|
|
Loading…
Reference in a new issue