fixes to make dual-editor with big/little endian projection work
This commit is contained in:
parent
bb846afc7c
commit
e86070da50
10 changed files with 578 additions and 450 deletions
|
@ -32,170 +32,56 @@ use {
|
||||||
std::sync::{Arc, RwLock},
|
std::sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_std::main]
|
fn rebuild_projections(
|
||||||
async fn main() {
|
ctx: Arc<RwLock<Context>>,
|
||||||
/* setup context
|
repr_tree: Arc<RwLock<ReprTree>>,
|
||||||
*/
|
morph_types: Vec< (laddertypes::TypeTerm, laddertypes::TypeTerm) >
|
||||||
let ctx = Arc::new(RwLock::new(Context::new()));
|
) {
|
||||||
nested::editors::char::init_ctx( ctx.clone() );
|
repr_tree.write().unwrap().detach(&ctx);
|
||||||
nested::editors::digit::init_ctx( ctx.clone() );
|
for (src_type, dst_type) in morph_types.iter() {
|
||||||
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(
|
ctx.read().unwrap().morphisms.apply_morphism(
|
||||||
rt_int.descend(Context::parse(&ctx, "
|
repr_tree.clone(),
|
||||||
<PosInt 16 LittleEndian>
|
&src_type,
|
||||||
~ <Seq <Digit 16>>
|
&dst_type
|
||||||
~ <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> >
|
fn setup_le_master(ctx: &Arc<RwLock<Context>>, rt_int: &Arc<RwLock<ReprTree>>) {
|
||||||
~ <List <Digit 16>~Char~EditTree >
|
rebuild_projections(
|
||||||
")).expect("descend"),
|
ctx.clone(),
|
||||||
&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(),
|
rt_int.clone(),
|
||||||
&Context::parse(&ctx, "
|
vec![
|
||||||
ℕ
|
// Little Endian Editor
|
||||||
~ <PosInt 16 LittleEndian>
|
(
|
||||||
~ <Seq <Digit 16>>
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree",
|
||||||
~ <List <Digit 16>>
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
||||||
~ <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()
|
// Convert Endianness
|
||||||
.setup_edittree(
|
(
|
||||||
rt_int.descend(Context::parse(&ctx,"
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
||||||
<PosInt 16 LittleEndian>
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
||||||
~ <Seq <Digit 16>>
|
),
|
||||||
~ <List <Digit 16>~Char >
|
|
||||||
")).expect("descend"),
|
|
||||||
SingletonBuffer::new(0).get_port()
|
|
||||||
);
|
|
||||||
|
|
||||||
ctx.read().unwrap().morphisms.apply_morphism(
|
// Big Endian Editor
|
||||||
rt_int.descend(Context::parse(&ctx, "
|
(
|
||||||
<PosInt 16 BigEndian>~<Seq <Digit 16>>~<List <Digit 16>~Char>
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
||||||
")).expect("descend"),
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree>"
|
||||||
&Context::parse(&ctx, "<List Char>"),
|
),
|
||||||
&Context::parse(&ctx, "<List Char~EditTree>")
|
(
|
||||||
);
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree>",
|
||||||
ctx.read().unwrap().morphisms.apply_morphism(
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree> ~ <Vec EditTree>"
|
||||||
rt_int.descend(Context::parse(&ctx, "
|
),
|
||||||
<PosInt 16 BigEndian>~<Seq <Digit 16>>~<List <Digit 16>~Char~EditTree>
|
(
|
||||||
")).expect("descend"),
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree> ~ <Vec EditTree>",
|
||||||
&Context::parse(&ctx, "<List EditTree>"),
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree"
|
||||||
&Context::parse(&ctx, "<List EditTree>~<Vec EditTree>")
|
),
|
||||||
);
|
].into_iter()
|
||||||
ctx.read().unwrap().morphisms.apply_morphism(
|
.map(|(s,d)| (Context::parse(&ctx, s), Context::parse(&ctx, d)))
|
||||||
rt_int.descend(Context::parse(&ctx, "
|
.collect()
|
||||||
<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>")
|
|
||||||
);
|
|
||||||
|
|
||||||
/* 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()
|
|
||||||
);
|
);
|
||||||
|
/*
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* map seq of chars to seq of u64 digits
|
* 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>
|
<PosInt 16 BigEndian>
|
||||||
~ <Seq <Digit 16>
|
~ <Seq <Digit 16>
|
||||||
~ ℤ_2^64
|
~ ℤ_2^64
|
||||||
~ machine.UInt64 >
|
~ 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(),
|
rt_int.clone(),
|
||||||
&Context::parse(&ctx, "
|
vec![
|
||||||
ℕ
|
// Big Endian Editor
|
||||||
~ <PosInt 16 BigEndian>
|
(
|
||||||
|
"ℕ ~ <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()
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
/*
|
||||||
|
* map seq of chars to seq of u64 digits
|
||||||
|
* and add this projection to the ReprTree
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
||||||
|
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()
|
||||||
|
.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>
|
~ <Seq <Digit 16>
|
||||||
~ ℤ_2^64
|
~ ℤ_2^64
|
||||||
~ machine.UInt64 >
|
~ machine.UInt64 >
|
||||||
"),
|
"),
|
||||||
&Context::parse(&ctx, "
|
digits_view.clone()
|
||||||
ℕ
|
|
||||||
~ <PosInt 16 LittleEndian>
|
|
||||||
~ <Seq <Digit 16>
|
|
||||||
~ ℤ_2^64
|
|
||||||
~ machine.UInt64 >
|
|
||||||
")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/* 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
|
|
||||||
* 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 >
|
|
||||||
")).expect("cant descend")
|
|
||||||
.read().unwrap()
|
|
||||||
.view_seq::< u64 >()
|
|
||||||
.map(|digit| TerminalAtom::from(char::from_digit(*digit as u32, 16)))
|
|
||||||
.to_grid_horizontal();
|
|
||||||
//ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
|
//ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
|
||||||
//
|
//
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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
|
/* list of both editors
|
||||||
*/
|
*/
|
||||||
|
@ -321,7 +323,7 @@ async fn main() {
|
||||||
edittree_hex_le_list.get().goto(TreeCursor::none());
|
edittree_hex_le_list.get().goto(TreeCursor::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![1,0]
|
||||||
});
|
});
|
||||||
let edittree = Arc::new(RwLock::new(edittree));
|
let edittree = Arc::new(RwLock::new(edittree));
|
||||||
|
|
||||||
|
@ -331,7 +333,31 @@ async fn main() {
|
||||||
/* event handler
|
/* event handler
|
||||||
*/
|
*/
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
|
let rt_int = rt_int.clone();
|
||||||
|
let last_idx = RwLock::new(1);
|
||||||
move |ev| {
|
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));
|
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
|
/* project the seq of u64 representations to a view
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
comp.push(nested_tty::make_label("dec: ").offset(Vector2::new(3,7)));
|
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| {
|
comp.push(dec_digits_view.offset(Vector2::new(8,7)).map_item(|_,a| {
|
||||||
a.add_style_back(TerminalStyle::fg_color((30,90,200)))
|
a.add_style_back(TerminalStyle::fg_color((30,90,200)))
|
||||||
}));
|
}));
|
||||||
|
*/
|
||||||
|
/*
|
||||||
comp.push(nested_tty::make_label("hex: ").offset(Vector2::new(3,8)));
|
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| {
|
comp.push(hex_digits_view.offset(Vector2::new(8,8)).map_item(|_,a| {
|
||||||
a.add_style_back(TerminalStyle::fg_color((200, 200, 30)))
|
a.add_style_back(TerminalStyle::fg_color((200, 200, 30)))
|
||||||
}));
|
}));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write the changes in the view of `term_port` to the terminal
|
/* 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();
|
let ctx = ctx.clone();
|
||||||
move |rt, σ| {
|
move |rt, σ| {
|
||||||
{
|
{
|
||||||
let mut rt = rt.write().unwrap();
|
let mut b = rt.write().unwrap().singleton_buffer::<char>();
|
||||||
if let Some(buf) = rt.singleton_buffer::<char>() {
|
if let Some(buf) = b {
|
||||||
// buffer already exists
|
// buffer already exists
|
||||||
} else {
|
} else {
|
||||||
// create char buffer
|
// create char buffer
|
||||||
rt.insert_leaf(
|
rt.write().unwrap().insert_leaf(
|
||||||
vec![].into_iter(),
|
vec![].into_iter(),
|
||||||
ReprLeaf::from_singleton_buffer(
|
ReprLeaf::from_singleton_buffer(
|
||||||
SingletonBuffer::new('\0')
|
SingletonBuffer::new('\0')
|
||||||
));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,12 +54,9 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
||||||
SingletonBuffer::<usize>::new(0).get_port()
|
SingletonBuffer::<usize>::new(0).get_port()
|
||||||
);
|
);
|
||||||
|
|
||||||
rt.write().unwrap()
|
rt.insert_leaf(
|
||||||
.insert_branch(
|
|
||||||
ReprTree::from_singleton_buffer(
|
|
||||||
Context::parse(&ctx, "EditTree"),
|
Context::parse(&ctx, "EditTree"),
|
||||||
SingletonBuffer::new(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("SrcRadix");
|
||||||
ctx.write().unwrap().add_varname("DstRadix");
|
ctx.write().unwrap().add_varname("DstRadix");
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MACHINE INT, SEQ
|
||||||
|
*/
|
||||||
let morphism_type =
|
let morphism_type =
|
||||||
MorphismType {
|
MorphismType {
|
||||||
src_type: Context::parse(&ctx, "
|
src_type: Context::parse(&ctx, "
|
||||||
|
@ -49,21 +53,22 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
.apply_substitution(&|k|σ.get(k).cloned())
|
.apply_substitution(&|k|σ.get(k).cloned())
|
||||||
.clone()
|
.clone()
|
||||||
).expect("cant descend")
|
).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>
|
<PosInt Radix LittleEndian>
|
||||||
~ <Seq <Digit Radix>
|
~ <Seq <Digit Radix>
|
||||||
~ ℤ_2^64
|
~ ℤ_2^64
|
||||||
~ machine.UInt64 >
|
~ machine.UInt64 >
|
||||||
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||||
ReprLeaf::from_view( src_digits.reverse() )
|
src_digits.reverse()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/* MACHINE INT, LIST
|
||||||
|
*/
|
||||||
let morphism_type = MorphismType {
|
let morphism_type = MorphismType {
|
||||||
src_type: Context::parse(&ctx, "
|
src_type: Context::parse(&ctx, "
|
||||||
ℕ
|
ℕ
|
||||||
|
@ -95,16 +100,15 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
")
|
")
|
||||||
.apply_substitution(&|k|σ.get(k).cloned()).clone()
|
.apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||||
).expect("cant descend")
|
).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, "
|
Context::parse(&ctx, "
|
||||||
<PosInt Radix LittleEndian>
|
<PosInt Radix LittleEndian>
|
||||||
~ <Seq <Digit Radix>>
|
~ <Seq <Digit Radix>>
|
||||||
~ <List <Digit Radix> ~ ℤ_2^64 ~ machine.UInt64>
|
~ <List <Digit Radix> ~ ℤ_2^64 ~ machine.UInt64>
|
||||||
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
|
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
|
||||||
ReprLeaf::from_view( src_digits.reverse() )
|
src_digits.reverse()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,22 +136,23 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
{
|
{
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
move |src_rt, σ| {
|
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, "
|
let src_digits = src_rt.descend(Context::parse(&ctx, "
|
||||||
<PosInt Radix BigEndian>
|
<PosInt Radix BigEndian>
|
||||||
~ <Seq <Digit Radix>>
|
~ <Seq <Digit Radix>>
|
||||||
~ <List <Digit Radix>~Char >
|
~ <List <Digit Radix>~Char >
|
||||||
").apply_substitution(&|k|σ.get(k).cloned()).clone()
|
").apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||||
).expect("cant descend")
|
).expect("cant descend")
|
||||||
.read().unwrap()
|
|
||||||
.get_port::< dyn ListView<char> >().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, "
|
Context::parse(&ctx, "
|
||||||
< PosInt Radix LittleEndian >
|
< PosInt Radix LittleEndian >
|
||||||
~ < Seq <Digit Radix> >
|
~ < Seq <Digit Radix> >
|
||||||
~ < List <Digit Radix>~Char >
|
~ < List <Digit Radix>~Char >
|
||||||
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
|
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
|
||||||
ReprLeaf::from_view( src_digits.reverse() )
|
rev_port
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,20 +181,13 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
")
|
")
|
||||||
.apply_substitution(&|k|σ.get(k).cloned()).clone()
|
.apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||||
).expect("cant descend")
|
).expect("cant descend")
|
||||||
.read().unwrap()
|
|
||||||
.view_seq::< u64 >();
|
.view_seq::< u64 >();
|
||||||
|
|
||||||
src_rt.write().unwrap().insert_leaf(
|
src_rt.attach_leaf_to(Context::parse(&ctx, "
|
||||||
vec![
|
<PosInt Radix BigEndian>
|
||||||
Context::parse(&ctx, "<PosInt Radix BigEndian>")
|
~ <Seq <Digit Radix> ~ ℤ_2^64 ~ machine.UInt64>
|
||||||
.apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||||
Context::parse(&ctx, "<Seq <Digit Radix>>")
|
src_digits.reverse()
|
||||||
.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() )
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,32 +217,29 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
move |src_rt, σ|
|
move |src_rt, σ|
|
||||||
{
|
{
|
||||||
let src_digits = ReprTree::descend(
|
let src_digits = src_rt.descend(
|
||||||
&src_rt,
|
|
||||||
Context::parse(&ctx, "
|
Context::parse(&ctx, "
|
||||||
<PosInt Radix LittleEndian>
|
<PosInt Radix LittleEndian>
|
||||||
~ <Seq <Digit Radix>>
|
~ <Seq <Digit Radix>>
|
||||||
~ <List <Digit Radix>~ℤ_2^64~machine.UInt64 >
|
~ <List <Digit Radix>~ℤ_2^64~machine.UInt64 >
|
||||||
")
|
").apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||||
.apply_substitution(&|k|σ.get(k).cloned()).clone()
|
)
|
||||||
).expect("cant descend")
|
.expect("cant descend")
|
||||||
.read().unwrap()
|
.view_list::<u64>();
|
||||||
.get_port::< dyn ListView<u64> >().unwrap();
|
|
||||||
|
|
||||||
src_rt.insert_leaf(
|
src_rt.attach_leaf_to(
|
||||||
Context::parse(&ctx, "
|
Context::parse(&ctx, "
|
||||||
<PosInt Radix BigEndian>
|
<PosInt Radix BigEndian>
|
||||||
~ <Seq <Digit Radix>>
|
~ <Seq <Digit Radix>>
|
||||||
~ <List <Digit Radix>~ℤ_2^64~machine.UInt64 >
|
~ <List <Digit Radix>~ℤ_2^64~machine.UInt64 >
|
||||||
"),
|
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||||
ReprLeaf::from_view( src_digits.reverse() )
|
src_digits.reverse()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mt = MorphismType {
|
let mt = MorphismType {
|
||||||
src_type: Context::parse(&ctx, "
|
src_type: Context::parse(&ctx, "
|
||||||
ℕ
|
ℕ
|
||||||
|
@ -273,16 +268,15 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
~ <List <Digit Radix>~Char >
|
~ <List <Digit Radix>~Char >
|
||||||
").apply_substitution(&|k|σ.get(k).cloned()).clone()
|
").apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||||
).expect("cant descend")
|
).expect("cant descend")
|
||||||
.read().unwrap()
|
.view_list::<char>();
|
||||||
.get_port::< dyn ListView<char> >().unwrap();
|
|
||||||
|
|
||||||
src_rt.insert_leaf(
|
src_rt.attach_leaf_to(
|
||||||
Context::parse(&ctx, "
|
Context::parse(&ctx, "
|
||||||
< PosInt Radix BigEndian >
|
< PosInt Radix BigEndian >
|
||||||
~ < Seq <Digit Radix> >
|
~ < Seq <Digit Radix> >
|
||||||
~ < List <Digit Radix>~Char >
|
~ < List <Digit Radix>~Char >
|
||||||
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
|
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
|
||||||
ReprLeaf::from_view( src_digits.reverse() )
|
src_digits.reverse()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,29 +321,23 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
_ => 0
|
_ => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
let src_digits_rt = ReprTree::descend(
|
let src_digits_rt = src_rt.descend(Context::parse(&ctx, "
|
||||||
src_rt,
|
|
||||||
Context::parse(&ctx, "
|
|
||||||
<PosInt SrcRadix LittleEndian>
|
<PosInt SrcRadix LittleEndian>
|
||||||
~ <Seq <Digit SrcRadix> ~ ℤ_2^64 ~ machine.UInt64 >"
|
~ <Seq <Digit SrcRadix> ~ ℤ_2^64 ~ machine.UInt64 >
|
||||||
).apply_substitution(&|k|σ.get(k).cloned()).clone()
|
").apply_substitution(&|k|σ.get(k).cloned()).clone()
|
||||||
).expect("cant descend repr tree");
|
).expect("cant descend repr tree");
|
||||||
|
|
||||||
let dst_digits_port =
|
let dst_digits_port =
|
||||||
src_digits_rt.read().unwrap()
|
src_digits_rt.view_seq::<u64>()
|
||||||
.view_seq::<u64>()
|
|
||||||
.to_positional_uint( src_radix )
|
.to_positional_uint( src_radix )
|
||||||
.transform_radix( dst_radix );
|
.transform_radix( dst_radix );
|
||||||
|
|
||||||
src_rt.write().unwrap()
|
src_rt.attach_leaf_to(
|
||||||
.insert_leaf(
|
Context::parse(&ctx, "
|
||||||
vec![
|
<PosInt DstRadix LittleEndian>
|
||||||
Context::parse(&ctx, "<PosInt DstRadix LittleEndian>").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
~ <Seq <Digit DstRadix> ~ ℤ_2^64 ~ machine.UInt64>
|
||||||
Context::parse(&ctx, "<Seq <Digit DstRadix>>").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
|
||||||
Context::parse(&ctx, "<Seq ℤ_2^64>"),
|
dst_digits_port
|
||||||
Context::parse(&ctx, "<Seq machine.UInt64>"),
|
|
||||||
].into_iter(),
|
|
||||||
ReprLeaf::from_view(dst_digits_port)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use {
|
use {
|
||||||
r3vi::{
|
r3vi::{
|
||||||
view::{
|
view::{
|
||||||
ViewPort,
|
ViewPort, port::UpdateTask,
|
||||||
OuterViewPort, Observer,
|
OuterViewPort, Observer,
|
||||||
singleton::*,
|
singleton::*,
|
||||||
list::*
|
list::*
|
||||||
|
@ -32,33 +32,34 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
ctx.write().unwrap().morphisms.add_morphism(mt, {
|
ctx.write().unwrap().morphisms.add_morphism(mt, {
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
move |src_rt, σ| {
|
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 {
|
if let Some(list_port) = list_port {
|
||||||
|
|
||||||
|
// for each char, create EditTree
|
||||||
let edit_tree_list =
|
let edit_tree_list =
|
||||||
list_port
|
list_port
|
||||||
// for each char, create and EditTree
|
|
||||||
.map({
|
.map({
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
move |c| {
|
move |c| {
|
||||||
let item_rt = ReprTree::from_char(&ctx, *c);
|
let item_rt = ReprTree::from_char(&ctx, *c);
|
||||||
|
|
||||||
ctx.read().unwrap().setup_edittree(
|
ctx.read().unwrap().setup_edittree(
|
||||||
item_rt.clone(),
|
item_rt.clone(),
|
||||||
SingletonBuffer::new(0).get_port()
|
SingletonBuffer::new(0).get_port()
|
||||||
);
|
);
|
||||||
|
|
||||||
let et = item_rt
|
let et = item_rt
|
||||||
.descend(Context::parse(&ctx, "EditTree")).unwrap()
|
.descend(Context::parse(&ctx, "Char ~ EditTree")).expect("cant descend repr tree")
|
||||||
.read().unwrap()
|
.get_port::< dyn SingletonView<Item = EditTree> >().expect("cant get view port (EditTree)")
|
||||||
.get_port::< dyn SingletonView<Item = EditTree> >()
|
|
||||||
.expect("cant get view port (EditTree)")
|
|
||||||
.get_view().unwrap()
|
.get_view().unwrap()
|
||||||
.get();
|
.get();
|
||||||
Arc::new(RwLock::new(et))
|
Arc::new(RwLock::new(et))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
src_rt.write().unwrap().insert_leaf(
|
src_rt.attach_leaf_to(
|
||||||
Context::parse(&ctx, "<List EditTree>").get_lnf_vec().into_iter(),
|
Context::parse(&ctx, "<List Char>~<List EditTree>"),
|
||||||
ReprLeaf::from_view( edit_tree_list )
|
edit_tree_list
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
eprintln!("morphism missing view port");
|
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>"),
|
src_type: Context::parse(&ctx, "<List Item>~<List EditTree>~<Vec EditTree>"),
|
||||||
dst_type: Context::parse(&ctx, "<List Item>~EditTree")
|
dst_type: Context::parse(&ctx, "<List Item>~EditTree")
|
||||||
};
|
};
|
||||||
|
|
||||||
ctx.write().unwrap().morphisms.add_morphism(mt, {
|
ctx.write().unwrap().morphisms.add_morphism(mt, {
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
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_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
|
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");
|
.expect("cant descend src repr");
|
||||||
|
|
||||||
let item_vec_buffer = item_vec_rt
|
let item_vec_buffer = item_vec_rt.vec_buffer::< Arc<RwLock<EditTree>> >();
|
||||||
.write().unwrap()
|
|
||||||
.vec_buffer::< Arc<RwLock<EditTree>> >().expect("cant get vec buffer");
|
|
||||||
|
|
||||||
// eprintln!("create ListEditor");
|
|
||||||
let mut list_editor = ListEditor::with_data(ctx.clone(), item_type.clone(), item_vec_buffer);
|
let mut list_editor = ListEditor::with_data(ctx.clone(), item_type.clone(), item_vec_buffer);
|
||||||
|
|
||||||
let edittree_list = list_editor.into_node(
|
let edittree_list = list_editor.into_node(
|
||||||
SingletonBuffer::<usize>::new(0).get_port()
|
SingletonBuffer::<usize>::new(0).get_port()
|
||||||
);
|
);
|
||||||
|
src_rt.insert_leaf(
|
||||||
// eprintln!("make edittree");
|
Context::parse(&ctx, "<List Item> ~ EditTree")
|
||||||
src_rt.write().unwrap().insert_branch(
|
.apply_substitution(&|id| σ.get(id).cloned()).clone(),
|
||||||
ReprTree::from_singleton_buffer(
|
ReprLeaf::from_singleton_buffer(
|
||||||
Context::parse(&ctx, "EditTree"),
|
|
||||||
SingletonBuffer::new(edittree_list)
|
SingletonBuffer::new(edittree_list)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -128,64 +114,31 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
move |src_rt, σ| {
|
move |src_rt, σ| {
|
||||||
let edittree =
|
let edittree =
|
||||||
src_rt
|
src_rt
|
||||||
.descend(Context::parse(&ctx, "EditTree")).unwrap()
|
.descend(Context::parse(&ctx, "<List Char>~EditTree")).unwrap()
|
||||||
.singleton_buffer::<EditTree>();
|
.singleton_buffer::<EditTree>();
|
||||||
|
|
||||||
let list_edit = edittree.get().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();
|
let edittree_items = list_edit.read().unwrap().data.get_port().to_list();
|
||||||
src_rt.write().unwrap().insert_leaf(
|
|
||||||
vec![].into_iter(),
|
src_rt.insert_leaf(
|
||||||
|
Context::parse(&ctx, "<List Char>"),
|
||||||
ReprLeaf::from_view(
|
ReprLeaf::from_view(
|
||||||
edittree_items
|
edittree_items
|
||||||
.map(
|
.map(|edittree_char|
|
||||||
|edittree_char|
|
|
||||||
edittree_char
|
edittree_char
|
||||||
.read().unwrap()
|
.read().unwrap()
|
||||||
.get_edit::<CharEditor>().unwrap()
|
.get_edit::<CharEditor>().unwrap()
|
||||||
.read().unwrap()
|
.read().unwrap()
|
||||||
.get()
|
.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(),
|
|
||||||
ReprLeaf::from_view(
|
|
||||||
edittree_items
|
|
||||||
.map(
|
|
||||||
|edittree_char|
|
|
||||||
edittree_char
|
|
||||||
.read().unwrap()
|
|
||||||
.get_edit::<crate::editors::digit::editor::DigitEditor>().unwrap()
|
|
||||||
.read().unwrap()
|
|
||||||
.get_char()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/* todo : unify the following two morphims with generic item parameter ?
|
||||||
|
*/
|
||||||
let mt = crate::repr_tree::MorphismType {
|
let mt = crate::repr_tree::MorphismType {
|
||||||
src_type: Context::parse(&ctx, "<List Char>"),
|
src_type: Context::parse(&ctx, "<List Char>"),
|
||||||
dst_type: Context::parse(&ctx, "<List Char>~<Vec 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();
|
let ctx = ctx.clone();
|
||||||
move |src_rt, σ| {
|
move |src_rt, σ| {
|
||||||
let buf = VecBuffer::<char>::new();
|
src_rt
|
||||||
let mut leaf = ReprLeaf::from_vec_buffer(buf);
|
.attach_leaf_to(
|
||||||
leaf.attach_to(
|
Context::parse(&ctx, "<List Char>~<Vec Char>"),
|
||||||
src_rt.read().unwrap()
|
src_rt
|
||||||
.get_port::<dyn ListView<char>>()
|
.descend(Context::parse(&ctx, "<List Char>"))
|
||||||
.unwrap()
|
.expect("descend")
|
||||||
|
.view_list::<char>()
|
||||||
);
|
);
|
||||||
src_rt.write().unwrap().insert_leaf(
|
}
|
||||||
vec![ Context::parse(&ctx, "<Vec Char>") ].into_iter(),
|
}
|
||||||
leaf
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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();
|
let ctx = ctx.clone();
|
||||||
move |src_rt, σ| {
|
move |src_rt, σ| {
|
||||||
let buf = VecBuffer::<Arc<RwLock<EditTree>>>::new();
|
let p =
|
||||||
let mut leaf = ReprLeaf::from_vec_buffer(buf);
|
src_rt
|
||||||
leaf.attach_to(
|
.descend(Context::parse(&ctx, "<List EditTree>")).expect("descend")
|
||||||
src_rt.read().unwrap()
|
.get_port::<dyn ListView< Arc<RwLock<EditTree>> >>().unwrap();
|
||||||
.get_port::<dyn ListView< Arc<RwLock<EditTree>> >>()
|
|
||||||
.unwrap()
|
src_rt.attach_leaf_to(
|
||||||
);
|
Context::parse(&ctx, "<List EditTree> ~ <Vec EditTree>"),
|
||||||
src_rt.write().unwrap().insert_leaf(
|
p
|
||||||
vec![ Context::parse(&ctx, "<Vec EditTree>") ].into_iter(),
|
|
||||||
leaf
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -319,12 +319,14 @@ impl ListEditor {
|
||||||
let mut b = item.ctrl.spillbuf.write().unwrap();
|
let mut b = item.ctrl.spillbuf.write().unwrap();
|
||||||
|
|
||||||
let rt = ReprTree::new_arc(self.typ.clone());
|
let rt = ReprTree::new_arc(self.typ.clone());
|
||||||
let edittree = self.ctx.read().unwrap()
|
let mut et = self.ctx.read().unwrap()
|
||||||
.setup_edittree(
|
.setup_edittree(
|
||||||
rt,
|
rt,
|
||||||
self.depth.map(|d| d+1)
|
self.depth.map(|d| d+1)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if let Some(edittree) = et.as_mut(){
|
||||||
|
|
||||||
let mut tail_node = edittree.get_mut();
|
let mut tail_node = edittree.get_mut();
|
||||||
tail_node.goto(TreeCursor::home());
|
tail_node.goto(TreeCursor::home());
|
||||||
|
|
||||||
|
@ -354,6 +356,8 @@ impl ListEditor {
|
||||||
edittree.value.clone()
|
edittree.value.clone()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
self.up();
|
self.up();
|
||||||
self.listlist_split();
|
self.listlist_split();
|
||||||
|
|
|
@ -179,7 +179,7 @@ impl Context {
|
||||||
&self,
|
&self,
|
||||||
rt: Arc<RwLock<ReprTree>>,
|
rt: Arc<RwLock<ReprTree>>,
|
||||||
depth: OuterViewPort<dyn SingletonView<Item = usize>>
|
depth: OuterViewPort<dyn SingletonView<Item = usize>>
|
||||||
) -> SingletonBuffer<EditTree> {
|
) -> Option<SingletonBuffer<EditTree>> {
|
||||||
let ladder = TypeTerm::Ladder(vec![
|
let ladder = TypeTerm::Ladder(vec![
|
||||||
rt.read().unwrap().get_type().clone(),
|
rt.read().unwrap().get_type().clone(),
|
||||||
self.type_term_from_str("EditTree").expect("")
|
self.type_term_from_str("EditTree").expect("")
|
||||||
|
@ -194,14 +194,19 @@ impl Context {
|
||||||
if let Some(new_edittree) =
|
if let Some(new_edittree) =
|
||||||
rt.descend(self.type_term_from_str("EditTree").unwrap())
|
rt.descend(self.type_term_from_str("EditTree").unwrap())
|
||||||
{
|
{
|
||||||
|
let typ = rt.read().unwrap().get_type().clone();
|
||||||
let buf = new_edittree.singleton_buffer::<EditTree>();
|
let buf = new_edittree.singleton_buffer::<EditTree>();
|
||||||
(*self.edittree_hook)(
|
(*self.edittree_hook)(
|
||||||
&mut *buf.get_mut(),
|
&mut *buf.get_mut(),
|
||||||
rt.read().unwrap().get_type().clone()
|
typ
|
||||||
);
|
);
|
||||||
buf
|
Some(buf)
|
||||||
} else {
|
} 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ pub struct ReprLeaf {
|
||||||
|
|
||||||
/// keepalive for the observer that updates the buffer from in_port
|
/// keepalive for the observer that updates the buffer from in_port
|
||||||
keepalive: Option<Arc<dyn Any + Send + Sync>>,
|
keepalive: Option<Arc<dyn Any + Send + Sync>>,
|
||||||
|
in_keepalive: Option<Arc<dyn Any + Send + Sync>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -72,15 +73,16 @@ impl ReprLeaf {
|
||||||
V::Msg: Clone
|
V::Msg: Clone
|
||||||
{
|
{
|
||||||
let mut in_port = ViewPort::<V>::new();
|
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();
|
let mut out_port = ViewPort::<V>::new();
|
||||||
buf_port.attach_to(in_port.outer());
|
let out_keepalive = out_port.attach_to(in_port.outer());
|
||||||
|
|
||||||
ReprLeaf {
|
ReprLeaf {
|
||||||
keepalive: None,
|
keepalive: Some(out_keepalive),
|
||||||
|
in_keepalive: Some(in_keepalive),
|
||||||
in_port: in_port.inner().into(),
|
in_port: in_port.inner().into(),
|
||||||
out_port: buf_port.into(),
|
out_port: out_port.into(),
|
||||||
data: None,
|
data: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,23 +91,55 @@ impl ReprLeaf {
|
||||||
where V: View + ?Sized + 'static,
|
where V: View + ?Sized + 'static,
|
||||||
V::Msg: Clone
|
V::Msg: Clone
|
||||||
{
|
{
|
||||||
|
self.keepalive = None;
|
||||||
|
self.in_keepalive = None;
|
||||||
|
|
||||||
let ip = self.in_port.clone()
|
let ip = self.in_port.clone()
|
||||||
.downcast::<V>().ok()
|
.downcast::<V>().ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
ip.0.detach();
|
||||||
|
|
||||||
ip.0.update_hooks.write().unwrap().clear();
|
if self.data.is_none() {
|
||||||
ip.set_view(None)
|
let mut op = self.out_port.clone()
|
||||||
.write().unwrap()
|
.downcast::<V>().ok()
|
||||||
.reset(None);
|
.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>)
|
pub fn attach_to<V>(&mut self, src_port: OuterViewPort<V>)
|
||||||
where V: View + ?Sized + 'static,
|
where V: View + ?Sized + 'static,
|
||||||
V::Msg: Clone
|
V::Msg: Clone
|
||||||
{
|
{
|
||||||
self.in_port.clone()
|
self.in_keepalive = Some(self.in_port.clone()
|
||||||
.downcast::<V>().ok().unwrap()
|
.downcast::<V>().ok().unwrap()
|
||||||
.0.attach_to( src_port );
|
.0.attach_to( src_port ));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_singleton_buffer<T>( buffer: SingletonBuffer<T> ) -> Self
|
pub fn from_singleton_buffer<T>( buffer: SingletonBuffer<T> ) -> Self
|
||||||
|
@ -113,6 +147,7 @@ impl ReprLeaf {
|
||||||
{
|
{
|
||||||
let in_port = ViewPort::<dyn SingletonView<Item = T>>::new();
|
let in_port = ViewPort::<dyn SingletonView<Item = T>>::new();
|
||||||
ReprLeaf {
|
ReprLeaf {
|
||||||
|
in_keepalive: None,
|
||||||
keepalive: Some(buffer.attach_to(in_port.outer())),
|
keepalive: Some(buffer.attach_to(in_port.outer())),
|
||||||
in_port: in_port.inner().into(),
|
in_port: in_port.inner().into(),
|
||||||
out_port: buffer.get_port().0.into(),
|
out_port: buffer.get_port().0.into(),
|
||||||
|
@ -125,6 +160,7 @@ impl ReprLeaf {
|
||||||
{
|
{
|
||||||
let in_port = ViewPort::< dyn ListView<T> >::new();
|
let in_port = ViewPort::< dyn ListView<T> >::new();
|
||||||
ReprLeaf {
|
ReprLeaf {
|
||||||
|
in_keepalive: None,
|
||||||
keepalive: Some(buffer.attach_to(in_port.outer())),
|
keepalive: Some(buffer.attach_to(in_port.outer())),
|
||||||
in_port: in_port.inner().into(),
|
in_port: in_port.inner().into(),
|
||||||
out_port: buffer.get_port().0.into(),
|
out_port: buffer.get_port().0.into(),
|
||||||
|
@ -172,7 +208,6 @@ impl ReprLeaf {
|
||||||
|
|
||||||
let data_arc =
|
let data_arc =
|
||||||
if let Some(data) = self.data.as_ref() {
|
if let Some(data) = self.data.as_ref() {
|
||||||
eprintln!("downcast existing vec-data");
|
|
||||||
data.clone().downcast::<RwLock<Vec<T>>>().ok()
|
data.clone().downcast::<RwLock<Vec<T>>>().ok()
|
||||||
} else {
|
} else {
|
||||||
vec_port.update();
|
vec_port.update();
|
||||||
|
@ -188,9 +223,6 @@ impl ReprLeaf {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(data_arc) = data_arc {
|
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>);
|
self.data = Some(data_arc.clone() as Arc<dyn Any + Send + Sync>);
|
||||||
let buf = VecBuffer::with_data_arc_port(data_arc, vec_port.inner());
|
let buf = VecBuffer::with_data_arc_port(data_arc, vec_port.inner());
|
||||||
self.keepalive = Some(buf.attach_to(
|
self.keepalive = Some(buf.attach_to(
|
||||||
|
@ -252,6 +284,22 @@ impl ReprTree {
|
||||||
&self.halo
|
&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>>) {
|
pub fn insert_branch(&mut self, repr: Arc<RwLock<ReprTree>>) {
|
||||||
let branch_type = repr.read().unwrap().get_type().clone();
|
let branch_type = repr.read().unwrap().get_type().clone();
|
||||||
|
|
||||||
|
@ -261,6 +309,7 @@ impl ReprTree {
|
||||||
self.halo.clone(),
|
self.halo.clone(),
|
||||||
self.type_tag.clone()
|
self.type_tag.clone()
|
||||||
]).normalize() );
|
]).normalize() );
|
||||||
|
|
||||||
self.branches.insert(branch_type, repr.clone());
|
self.branches.insert(branch_type, repr.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,6 +356,13 @@ impl ReprTree {
|
||||||
V::Msg: Clone
|
V::Msg: Clone
|
||||||
{
|
{
|
||||||
if let Some(rung_type) = type_ladder.next() {
|
if let Some(rung_type) = type_ladder.next() {
|
||||||
|
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 {
|
||||||
if let Some(next_repr) = self.branches.get(&rung_type) {
|
if let Some(next_repr) = self.branches.get(&rung_type) {
|
||||||
next_repr.write().unwrap().attach_leaf_to(type_ladder, src_port);
|
next_repr.write().unwrap().attach_leaf_to(type_ladder, src_port);
|
||||||
} else {
|
} else {
|
||||||
|
@ -314,6 +370,7 @@ impl ReprTree {
|
||||||
next_repr.attach_leaf_to(type_ladder, src_port);
|
next_repr.attach_leaf_to(type_ladder, src_port);
|
||||||
self.insert_branch(Arc::new(RwLock::new(next_repr)));
|
self.insert_branch(Arc::new(RwLock::new(next_repr)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Some(leaf) = self.leaf.as_mut() {
|
if let Some(leaf) = self.leaf.as_mut() {
|
||||||
leaf.attach_to(src_port);
|
leaf.attach_to(src_port);
|
||||||
|
@ -343,7 +400,7 @@ impl ReprTree {
|
||||||
leaf.detach::<dyn SingletonView<Item = char>>();
|
leaf.detach::<dyn SingletonView<Item = char>>();
|
||||||
}
|
}
|
||||||
if self.type_tag == Context::parse(&ctx, "<Vec Char>") {
|
if self.type_tag == Context::parse(&ctx, "<Vec Char>") {
|
||||||
leaf.detach::<dyn ListView<char>>();
|
leaf.detach_vec::<char>();
|
||||||
}
|
}
|
||||||
if self.type_tag == Context::parse(&ctx, "<List Char>") {
|
if self.type_tag == Context::parse(&ctx, "<List Char>") {
|
||||||
leaf.detach::<dyn ListView<char>>();
|
leaf.detach::<dyn ListView<char>>();
|
||||||
|
@ -393,7 +450,15 @@ impl ReprTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn descend(rt: &Arc<RwLock<Self>>, dst_type: impl Into<TypeTerm>) -> Option<Arc<RwLock<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>> {
|
pub fn ascend(rt: &Arc<RwLock<Self>>, type_term: impl Into<TypeTerm>) -> Arc<RwLock<ReprTree>> {
|
||||||
|
@ -487,14 +552,17 @@ pub trait ReprTreeExt {
|
||||||
fn create_branch(&mut self, rung: impl Into<TypeTerm>);
|
fn create_branch(&mut self, rung: impl Into<TypeTerm>);
|
||||||
fn descend(&self, target_type: impl Into<TypeTerm>) -> Option<Arc<RwLock<ReprTree>>>;
|
fn descend(&self, target_type: impl Into<TypeTerm>) -> Option<Arc<RwLock<ReprTree>>>;
|
||||||
|
|
||||||
fn get_port<V: View + ?Sized + 'static>(&self) -> Option<OuterViewPort<V>> where V::Msg: Clone;
|
|
||||||
fn attach_leaf_to<V: View + ?Sized + 'static>(&self, t: impl Into<TypeTerm>, v: OuterViewPort<V>) where V::Msg: Clone;
|
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_char(&self) -> OuterViewPort<dyn SingletonView<Item = char>>;
|
||||||
fn view_u8(&self) -> OuterViewPort<dyn SingletonView<Item = u8>>;
|
fn view_u8(&self) -> OuterViewPort<dyn SingletonView<Item = u8>>;
|
||||||
fn view_u64(&self) -> OuterViewPort<dyn SingletonView<Item = u64>>;
|
fn view_u64(&self) -> OuterViewPort<dyn SingletonView<Item = u64>>;
|
||||||
fn view_usize(&self) -> OuterViewPort<dyn SingletonView<Item = usize>>;
|
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 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>;
|
||||||
}
|
}
|
||||||
|
@ -554,6 +622,14 @@ impl ReprTreeExt for Arc<RwLock<ReprTree>> {
|
||||||
self.read().unwrap().view_usize()
|
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> {
|
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("")
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,10 @@ impl MorphismBase {
|
||||||
) {
|
) {
|
||||||
self.morphisms.push(
|
self.morphisms.push(
|
||||||
GenericReprTreeMorphism {
|
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)
|
setup_projection: Arc::new(setup_projection)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -67,12 +70,13 @@ impl MorphismBase {
|
||||||
|
|
||||||
let unification_problem = laddertypes::UnificationProblem::new(
|
let unification_problem = laddertypes::UnificationProblem::new(
|
||||||
vec![
|
vec![
|
||||||
( src_type.clone(), m.morph_type.src_type.clone() ),
|
( src_type.clone().normalize(), m.morph_type.src_type.clone() ),
|
||||||
( dst_type.clone(), m.morph_type.dst_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, σ));
|
return Some((m, σ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,19 +84,70 @@ impl MorphismBase {
|
||||||
None
|
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(
|
pub fn apply_morphism(
|
||||||
&self,
|
&self,
|
||||||
mut repr_tree: Arc<RwLock<ReprTree>>,
|
repr_tree: Arc<RwLock<ReprTree>>,
|
||||||
src_type: &TypeTerm,
|
src_type: &TypeTerm,
|
||||||
dst_type: &TypeTerm
|
dst_type: &TypeTerm
|
||||||
) {
|
) {
|
||||||
// let t = repr_tree.read().unwrap().get_type().clone();
|
if let Some((m, s, σ)) = self.find_morphism_ladder( &src_type, dst_type ) {
|
||||||
if let Some((m, σ)) = self.find_morphism( &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\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, &σ );
|
(m.setup_projection)( &mut repr_tree, &σ );
|
||||||
} else {
|
} else {
|
||||||
eprintln!("could not find morphism");
|
eprintln!("could not find item morphism");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
|
@ -7,6 +7,7 @@ use {
|
||||||
repr_tree::{Context, ReprTree},
|
repr_tree::{Context, ReprTree},
|
||||||
editors::list::*,
|
editors::list::*,
|
||||||
edit_tree::{TreeCursor, TreeNav, TreeNavResult, EditTree},
|
edit_tree::{TreeCursor, TreeNav, TreeNavResult, EditTree},
|
||||||
|
repr_tree::{ReprTreeExt, ReprLeaf}
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
DisplaySegment,
|
DisplaySegment,
|
||||||
|
@ -80,10 +81,12 @@ impl PTYListStyle {
|
||||||
editor.get_cursor_port(),
|
editor.get_cursor_port(),
|
||||||
editor.get_data_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
|
seg_seq
|
||||||
.get_view()
|
|
||||||
.map(move |segment| segment.display_view())
|
.map(move |segment| segment.display_view())
|
||||||
.separate(make_label(&self.style.1))
|
.separate(make_label(&self.style.1))
|
||||||
.wrap(make_label(&self.style.0), make_label(&self.style.2))
|
.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)) {
|
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
|
node.disp.view
|
||||||
.write().unwrap()
|
.attach_leaf_to(
|
||||||
.insert_branch(ReprTree::from_view(
|
|
||||||
Context::parse(&node.ctx, "TerminalView"),
|
Context::parse(&node.ctx, "TerminalView"),
|
||||||
Self::new(style)
|
pty_view
|
||||||
.pty_view(
|
);
|
||||||
&node.get_edit::<ListEditor>().unwrap().read().unwrap()
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,6 +228,8 @@ impl PTYListController {
|
||||||
self.depth.map(|d| d+1)
|
self.depth.map(|d| d+1)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if let Some(new_edittree) = new_edittree {
|
||||||
|
|
||||||
let mut ne = new_edittree.get();
|
let mut ne = new_edittree.get();
|
||||||
match ne.send_cmd_obj(cmd_obj.clone()) {
|
match ne.send_cmd_obj(cmd_obj.clone()) {
|
||||||
TreeNavResult::Continue => {
|
TreeNavResult::Continue => {
|
||||||
|
@ -237,6 +241,12 @@ impl PTYListController {
|
||||||
TreeNavResult::Exit
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
panic!("cant get edit tree");
|
||||||
|
TreeNavResult::Continue
|
||||||
|
}
|
||||||
},
|
},
|
||||||
ListCursorMode::Select => {
|
ListCursorMode::Select => {
|
||||||
if let Some(item) = e.get_item_mut() {
|
if let Some(item) = e.get_item_mut() {
|
||||||
|
|
|
@ -17,7 +17,6 @@ use {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
pub fn edittree_make_char_view(
|
pub fn edittree_make_char_view(
|
||||||
node: EditTree
|
node: EditTree
|
||||||
) -> EditTree {
|
) -> EditTree {
|
||||||
|
|
Loading…
Reference in a new issue