Compare commits

..

No commits in common. "e86070da500ca3a45ef55a14a82b3c03f0cbe03c" and "ab51ea5d3d8bcd0d83d7deb8e7be6088435df7b5" have entirely different histories.

10 changed files with 462 additions and 646 deletions

View file

@ -32,177 +32,6 @@ use {
std::sync::{Arc, RwLock},
};
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
);
}
}
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>"
),
// 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
* 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>
~ _2^64
~ machine.UInt64 >
"),
digits_view.clone()
);
//ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
//
*/
}
fn setup_be_master(ctx: &Arc<RwLock<Context>>, rt_int: &Arc<RwLock<ReprTree>>) {
rebuild_projections(
ctx.clone(),
rt_int.clone(),
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()
);
/*
/*
* 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>
~ _2^64
~ machine.UInt64 >
"),
digits_view.clone()
);
//ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
//
*/
}
#[async_std::main]
async fn main() {
/* setup context
@ -220,94 +49,263 @@ async fn main() {
/* 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() )
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>")
);
let mut digits_le = VecBuffer::with_data(vec!['3', '2', '1']);
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 LittleEndian>~<Seq <Digit 16>>~<List <Digit 16>>~<List Char>~<Vec Char>"),
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_le.clone() )
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 digits_le_editvec = VecBuffer::<Arc<RwLock<EditTree>>>::new();
let mut b_le = VecBuffer::with_data(vec!['3', '2', '1']);
rt_int.insert_leaf(
Context::parse(&ctx, "
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
~ EditTree>
~ <Vec EditTree>
"),
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_le_editvec.clone() )
~ <List <Digit 16>~Char>
")).expect("descend"),
&Context::parse(&ctx, "<List Char>~<List EditTree>~<Vec EditTree>"),
&Context::parse(&ctx, "<List Char>~EditTree")
);
let mut digits_be_editvec = VecBuffer::<Arc<RwLock<EditTree>>>::new();
rt_int.insert_leaf(
Context::parse(&ctx, "
<PosInt 16 BigEndian>
ctx.read().unwrap().morphisms.apply_morphism(
rt_int.descend(Context::parse(&ctx, "
<PosInt 16 LittleEndian>
~ <Seq <Digit 16>>
~ <List <Digit 16>
~ Char
~ EditTree>
~ <Vec EditTree>
"),
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_be_editvec.clone() )
~ <List <Digit 16>~Char >
")).expect("descend"),
&Context::parse(&ctx, "<List Char>~EditTree"),
&Context::parse(&ctx, "<List Char>")
);
/* initially copy values from Vec to EditTree...
*/
rebuild_projections(
ctx.clone(),
ctx.read().unwrap().morphisms.apply_morphism(
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()
&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>
")
);
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>
<PosInt 16 LittleEndian>
~ <Seq <Digit 16>>
~ <List <Digit 16>>
~ <List Char>
~ <List <Digit 16>~Char >
")).expect("descend"),
SingletonBuffer::new(0).get_port()
).unwrap();
);
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>")
);
/* 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("descend"),
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()
).unwrap();
);
/*
* 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.insert_leaf(Context::parse(&ctx, "
<PosInt 16 BigEndian>
~ <Seq <Digit 16>
~ _2^64
~ machine.UInt64 >
"),
nested::repr_tree::ReprLeaf::from_view( digits_view.clone() )
);
//ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
//
/* convert to little endian
*/
ctx.read().unwrap().morphisms.apply_morphism(
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 >
")
);
/* 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();
//ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
//
/* list of both editors
*/
@ -323,7 +321,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![1,0]
tree_addr: vec![0,0]
});
let edittree = Arc::new(RwLock::new(edittree));
@ -333,31 +331,7 @@ 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));
}
});
@ -367,7 +341,7 @@ async fn main() {
* so it will be displayed on TTY-output.
*/
let compositor = TerminalCompositor::new(app.port.inner());
/* Now add some views to our compositor
*/
{
@ -392,18 +366,15 @@ 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

View file

@ -32,17 +32,16 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
let ctx = ctx.clone();
move |rt, σ| {
{
let mut b = rt.write().unwrap().singleton_buffer::<char>();
if let Some(buf) = b {
let mut rt = rt.write().unwrap();
if let Some(buf) = rt.singleton_buffer::<char>() {
// buffer already exists
} else {
// create char buffer
rt.write().unwrap().insert_leaf(
rt.insert_leaf(
vec![].into_iter(),
ReprLeaf::from_singleton_buffer(
SingletonBuffer::new('\0')
)
);
SingletonBuffer::new('\0')
));
}
}
@ -54,10 +53,13 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
SingletonBuffer::<usize>::new(0).get_port()
);
rt.insert_leaf(
Context::parse(&ctx, "EditTree"),
ReprLeaf::from_singleton_buffer(SingletonBuffer::new(edittree))
);
rt.write().unwrap()
.insert_branch(
ReprTree::from_singleton_buffer(
Context::parse(&ctx, "EditTree"),
SingletonBuffer::new(edittree)
)
);
}
}
);

View file

@ -20,10 +20,6 @@ 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, "
@ -53,22 +49,21 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
.apply_substitution(&|k|σ.get(k).cloned())
.clone()
).expect("cant descend")
.view_seq::< u64 >();
.read().unwrap()
.view_seq::< u64 >();
src_rt.attach_leaf_to(Context::parse(&ctx, "
src_rt.insert_leaf(Context::parse(&ctx, "
<PosInt Radix LittleEndian>
~ <Seq <Digit Radix>
~ _2^64
~ machine.UInt64 >
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
src_digits.reverse()
ReprLeaf::from_view( src_digits.reverse() )
);
}
}
);
/* MACHINE INT, LIST
*/
let morphism_type = MorphismType {
src_type: Context::parse(&ctx, "
@ -100,15 +95,16 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
")
.apply_substitution(&|k|σ.get(k).cloned()).clone()
).expect("cant descend")
.get_port::< dyn ListView<u64> >().unwrap();
.read().unwrap()
.get_port::< dyn ListView<u64> >().unwrap();
src_rt.attach_leaf_to(
src_rt.insert_leaf(
Context::parse(&ctx, "
<PosInt Radix LittleEndian>
~ <Seq <Digit Radix>>
~ <List <Digit Radix> ~ _2^64 ~ machine.UInt64>
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
src_digits.reverse()
ReprLeaf::from_view( src_digits.reverse() )
);
}
}
@ -117,14 +113,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>>
@ -136,23 +132,22 @@ 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();
let rev_port = src_digits.reverse();
src_rt.attach_leaf_to(
src_rt.insert_leaf(
Context::parse(&ctx, "
< PosInt Radix LittleEndian >
< PosInt Radix LittleEndian >
~ < Seq <Digit Radix> >
~ < List <Digit Radix>~Char >
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
rev_port
ReprLeaf::from_view( src_digits.reverse() )
);
}
}
@ -181,14 +176,21 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
")
.apply_substitution(&|k|σ.get(k).cloned()).clone()
).expect("cant descend")
.view_seq::< u64 >();
.read().unwrap()
.view_seq::< u64 >();
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()
);
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() )
);
}
}
);
@ -217,29 +219,32 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
let ctx = ctx.clone();
move |src_rt, σ|
{
let src_digits = src_rt.descend(
Context::parse(&ctx, "
let src_digits = ReprTree::descend(
&src_rt,
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")
.view_list::<u64>();
")
.apply_substitution(&|k|σ.get(k).cloned()).clone()
).expect("cant descend")
.read().unwrap()
.get_port::< dyn ListView<u64> >().unwrap();
src_rt.attach_leaf_to(
src_rt.insert_leaf(
Context::parse(&ctx, "
<PosInt Radix BigEndian>
~ <Seq <Digit Radix>>
~ <List <Digit Radix>~_2^64~machine.UInt64 >
").apply_substitution(&|k|σ.get(k).cloned()).clone(),
src_digits.reverse()
);
"),
ReprLeaf::from_view( src_digits.reverse() )
);
}
}
);
let mt = MorphismType {
src_type: Context::parse(&ctx, "
@ -268,15 +273,16 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
~ <List <Digit Radix>~Char >
").apply_substitution(&|k|σ.get(k).cloned()).clone()
).expect("cant descend")
.view_list::<char>();
.read().unwrap()
.get_port::< dyn ListView<char> >().unwrap();
src_rt.attach_leaf_to(
src_rt.insert_leaf(
Context::parse(&ctx, "
< PosInt Radix BigEndian >
~ < Seq <Digit Radix> >
~ < List <Digit Radix>~Char >
").apply_substitution(&|k| σ.get(k).cloned()).clone(),
src_digits.reverse()
ReprLeaf::from_view( src_digits.reverse() )
);
}
}
@ -321,24 +327,30 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
_ => 0
};
let src_digits_rt = src_rt.descend(Context::parse(&ctx, "
let src_digits_rt = ReprTree::descend(
src_rt,
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.view_seq::<u64>()
src_digits_rt.read().unwrap()
.view_seq::<u64>()
.to_positional_uint( src_radix )
.transform_radix( dst_radix );
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
);
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)
);
}
}
);

View file

@ -1,7 +1,7 @@
use {
r3vi::{
view::{
ViewPort, port::UpdateTask,
ViewPort,
OuterViewPort, Observer,
singleton::*,
list::*
@ -32,34 +32,33 @@ 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.descend(Context::parse(&ctx, "<List Char>")).expect("descend").get_port::<dyn ListView<char>>().clone();
let list_port = src_rt.read().unwrap().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, "Char ~ EditTree")).expect("cant descend repr tree")
.get_port::< dyn SingletonView<Item = EditTree> >().expect("cant get view port (EditTree)")
.descend(Context::parse(&ctx, "EditTree")).unwrap()
.read().unwrap()
.get_port::< dyn SingletonView<Item = EditTree> >()
.expect("cant get view port (EditTree)")
.get_view().unwrap()
.get();
Arc::new(RwLock::new(et))
}
});
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List Char>~<List EditTree>"),
edit_tree_list
src_rt.write().unwrap().insert_leaf(
Context::parse(&ctx, "<List EditTree>").get_lnf_vec().into_iter(),
ReprLeaf::from_view( edit_tree_list )
);
} else {
eprintln!("morphism missing view port");
@ -71,29 +70,44 @@ 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 Item~EditTree>~<Vec EditTree>")
.apply_substitution(&|id| σ.get(id).cloned()).clone()
)
.descend(Context::parse(&ctx, "<List EditTree>~<Vec EditTree>"))
.expect("cant descend src repr");
let item_vec_buffer = item_vec_rt.vec_buffer::< Arc<RwLock<EditTree>> >();
let item_vec_buffer = item_vec_rt
.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 edittree_list = list_editor.into_node(
SingletonBuffer::<usize>::new(0).get_port()
);
src_rt.insert_leaf(
Context::parse(&ctx, "<List Item> ~ EditTree")
.apply_substitution(&|id| σ.get(id).cloned()).clone(),
ReprLeaf::from_singleton_buffer(
// eprintln!("make edittree");
src_rt.write().unwrap().insert_branch(
ReprTree::from_singleton_buffer(
Context::parse(&ctx, "EditTree"),
SingletonBuffer::new(edittree_list)
)
);
@ -114,31 +128,64 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
move |src_rt, σ| {
let edittree =
src_rt
.descend(Context::parse(&ctx, "<List Char>~EditTree")).unwrap()
.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.insert_leaf(
Context::parse(&ctx, "<List Char>"),
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()
))
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(),
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 {
src_type: Context::parse(&ctx, "<List Char>"),
dst_type: Context::parse(&ctx, "<List Char>~<Vec Char>")
@ -148,30 +195,17 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
{
let ctx = ctx.clone();
move |src_rt, σ| {
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() );
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
);
}
}
);
@ -185,14 +219,16 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
{
let ctx = ctx.clone();
move |src_rt, σ| {
let p =
src_rt
.descend(Context::parse(&ctx, "<List EditTree>")).expect("descend")
.get_port::<dyn ListView< Arc<RwLock<EditTree>> >>().unwrap();
src_rt.attach_leaf_to(
Context::parse(&ctx, "<List EditTree> ~ <Vec EditTree>"),
p
let 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
);
}
}

View file

@ -319,14 +319,12 @@ impl ListEditor {
let mut b = item.ctrl.spillbuf.write().unwrap();
let rt = ReprTree::new_arc(self.typ.clone());
let mut et = self.ctx.read().unwrap()
let edittree = 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());
@ -356,8 +354,6 @@ impl ListEditor {
edittree.value.clone()
);
}
} else {
self.up();
self.listlist_split();

View file

@ -179,7 +179,7 @@ impl Context {
&self,
rt: Arc<RwLock<ReprTree>>,
depth: OuterViewPort<dyn SingletonView<Item = usize>>
) -> Option<SingletonBuffer<EditTree>> {
) -> SingletonBuffer<EditTree> {
let ladder = TypeTerm::Ladder(vec![
rt.read().unwrap().get_type().clone(),
self.type_term_from_str("EditTree").expect("")
@ -194,19 +194,14 @@ 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(),
typ
rt.read().unwrap().get_type().clone()
);
Some(buf)
buf
} else {
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
unreachable!();
}
}
}

View file

@ -15,7 +15,7 @@ use {
ViewPort, OuterViewPort,
AnyViewPort, AnyInnerViewPort, AnyOuterViewPort,
port::UpdateTask,
View, Observer,
View,
singleton::*,
sequence::*,
list::*
@ -40,7 +40,6 @@ 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)]
@ -73,73 +72,26 @@ impl ReprLeaf {
V::Msg: Clone
{
let mut in_port = ViewPort::<V>::new();
let in_keepalive = in_port.attach_to(src_port);
in_port.attach_to(src_port);
let mut out_port = ViewPort::<V>::new();
let out_keepalive = out_port.attach_to(in_port.outer());
let mut buf_port = ViewPort::<V>::new();
buf_port.attach_to(in_port.outer());
ReprLeaf {
keepalive: Some(out_keepalive),
in_keepalive: Some(in_keepalive),
keepalive: None,
in_port: in_port.inner().into(),
out_port: out_port.into(),
out_port: buf_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_keepalive = Some(self.in_port.clone()
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
@ -147,7 +99,6 @@ 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(),
@ -158,9 +109,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(),
@ -208,6 +159,7 @@ 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();
@ -223,8 +175,14 @@ 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::with_data_arc_port(data_arc, vec_port.inner());
let buf = VecBuffer {
data: data_arc,
port: vec_port.inner()
};
self.keepalive = Some(buf.attach_to(
self.in_port.0.clone()
.downcast::< dyn ListView<T> >()
@ -237,6 +195,7 @@ impl ReprLeaf {
}
}
pub fn get_port<V>(&self) -> Option<OuterViewPort<V>>
where V: View + ?Sized + 'static,
V::Msg: Clone
@ -284,22 +243,6 @@ 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();
@ -309,7 +252,6 @@ impl ReprTree {
self.halo.clone(),
self.type_tag.clone()
]).normalize() );
self.branches.insert(branch_type, repr.clone());
}
@ -356,20 +298,12 @@ impl ReprTree {
V::Msg: Clone
{
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));
}
if let Some(next_repr) = self.branches.get(&rung_type) {
next_repr.write().unwrap().attach_leaf_to(type_ladder, src_port);
} else {
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)));
}
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() {
@ -380,38 +314,6 @@ 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>,
@ -450,15 +352,7 @@ impl ReprTree {
}
pub fn descend(rt: &Arc<RwLock<Self>>, dst_type: impl Into<TypeTerm>) -> Option<Arc<RwLock<ReprTree>>> {
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())
}
ReprTree::descend_ladder(rt, dst_type.into().get_lnf_vec().into_iter())
}
pub fn ascend(rt: &Arc<RwLock<Self>>, type_term: impl Into<TypeTerm>) -> Arc<RwLock<ReprTree>> {
@ -519,10 +413,6 @@ 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")
}
@ -552,17 +442,11 @@ 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>;
}
@ -594,14 +478,6 @@ 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 )
}
@ -622,14 +498,6 @@ 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("")
}

View file

@ -52,10 +52,7 @@ impl MorphismBase {
) {
self.morphisms.push(
GenericReprTreeMorphism {
morph_type: MorphismType {
src_type: morph_type.src_type.normalize(),
dst_type: morph_type.dst_type.normalize()
},
morph_type,
setup_projection: Arc::new(setup_projection)
}
);
@ -70,13 +67,12 @@ impl MorphismBase {
let unification_problem = laddertypes::UnificationProblem::new(
vec![
( src_type.clone().normalize(), m.morph_type.src_type.clone() ),
( dst_type.clone().normalize(), m.morph_type.dst_type.clone() )
( src_type.clone(), m.morph_type.src_type.clone() ),
( dst_type.clone(), m.morph_type.dst_type.clone() )
]
);
let unification_result = unification_problem.solve();
if let Ok(σ) = unification_result {
if let Ok(σ) = unification_problem.solve() {
return Some((m, σ));
}
}
@ -84,70 +80,19 @@ 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,
repr_tree: Arc<RwLock<ReprTree>>,
mut repr_tree: Arc<RwLock<ReprTree>>,
src_type: &TypeTerm,
dst_type: &TypeTerm
) {
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\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
)
// 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, &σ );
} else {
eprintln!("could not find item morphism");
eprintln!("could not find morphism");
}
}
*/
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>

View file

@ -7,7 +7,6 @@ use {
repr_tree::{Context, ReprTree},
editors::list::*,
edit_tree::{TreeCursor, TreeNav, TreeNavResult, EditTree},
repr_tree::{ReprTreeExt, ReprLeaf}
},
crate::{
DisplaySegment,
@ -81,12 +80,10 @@ impl PTYListStyle {
editor.get_cursor_port(),
editor.get_data_port()
);
let seg_seq0 = seg_seq.read().unwrap();
let seg_seq = seg_seq0.get_view();
drop(seg_seq0);
let seg_seq = seg_seq.read().unwrap();
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))
@ -95,14 +92,15 @@ 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
.attach_leaf_to(
.write().unwrap()
.insert_branch(ReprTree::from_view(
Context::parse(&node.ctx, "TerminalView"),
pty_view
);
Self::new(style)
.pty_view(
&node.get_edit::<ListEditor>().unwrap().read().unwrap()
)
));
}
}
@ -228,8 +226,6 @@ 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 => {
@ -241,12 +237,6 @@ impl PTYListController {
TreeNavResult::Exit
}
}
} else {
panic!("cant get edit tree");
TreeNavResult::Continue
}
},
ListCursorMode::Select => {
if let Some(item) = e.get_item_mut() {

View file

@ -17,6 +17,7 @@ use {
}
};
pub fn edittree_make_char_view(
node: EditTree
) -> EditTree {