Compare commits
10 commits
2749e41fce
...
ff80a0cba0
Author | SHA1 | Date | |
---|---|---|---|
ff80a0cba0 | |||
3ec8164202 | |||
b9e73584c5 | |||
7268ed9bc9 | |||
f60f8b2ac8 | |||
2afe027abe | |||
12e50d132e | |||
7a8a37d334 | |||
ca5ba52e53 | |||
fea21dbda1 |
14 changed files with 422 additions and 218 deletions
|
@ -47,7 +47,7 @@ async fn main() {
|
||||||
* / | \
|
* / | \
|
||||||
* / | \
|
* / | \
|
||||||
* / | \
|
* / | \
|
||||||
* u32 EditTree Char
|
* u64 EditTree Char
|
||||||
* - Editor \
|
* - Editor \
|
||||||
* - Display EditTree
|
* - Display EditTree
|
||||||
* / | \ - Editor
|
* / | \ - Editor
|
||||||
|
|
|
@ -63,76 +63,66 @@ async fn main() {
|
||||||
|
|
||||||
/* initially copy values from Vec to EditTree...
|
/* initially copy values from Vec to EditTree...
|
||||||
*/
|
*/
|
||||||
ctx.read().unwrap().apply_morphism(
|
ctx.read().unwrap().build_repr_tree(
|
||||||
&rt_int,
|
&rt_int,
|
||||||
&nested::repr_tree::morphism::MorphismType {
|
Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>~Char> ~ <Vec Char>"),
|
||||||
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ <Vec Char>"),
|
vec![
|
||||||
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree")
|
Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>> ~ EditTree"),
|
||||||
});
|
Context::parse(&ctx, "ℕ ~ <PosInt 16 LittleEndian> ~ <Seq~List <Digit 16>> ~ EditTree"),
|
||||||
|
]);
|
||||||
|
|
||||||
/* set Hex-editor to be master
|
fn set_master(
|
||||||
*/
|
ctx: &Arc<RwLock<Context>>,
|
||||||
rt_int.write().unwrap().detach( &ctx );
|
rt: &Arc<RwLock<ReprTree>>,
|
||||||
ctx.read().unwrap().apply_morphism(
|
mut leaves: Vec< laddertypes::TypeTerm >,
|
||||||
&rt_int,
|
master_idx: usize
|
||||||
&laddertypes::MorphismType {
|
) {
|
||||||
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree"),
|
eprintln!("set master to {}", master_idx);
|
||||||
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char> ~ EditTree")
|
if master_idx < leaves.len() {
|
||||||
}
|
let master = leaves.remove( master_idx );
|
||||||
|
rt.write().unwrap().detach( &ctx );
|
||||||
|
ctx.read().unwrap().build_repr_tree(
|
||||||
|
rt,
|
||||||
|
master,
|
||||||
|
leaves
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let edittree_hex_be_list =
|
let editor_types = vec![
|
||||||
rt_int
|
Context::parse(&ctx,
|
||||||
.descend(Context::parse(&ctx, "
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>> ~ EditTree"),
|
||||||
<PosInt 16 BigEndian>
|
Context::parse(&ctx,
|
||||||
~ <Seq~List <Digit 16>~Char>
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq~List <Digit 16>> ~ EditTree"),
|
||||||
")).unwrap()
|
Context::parse(&ctx,
|
||||||
.edittree( &ctx );
|
"ℕ ~ <PosInt 16 BigEndian> ~ EditTree"),
|
||||||
|
Context::parse(&ctx,
|
||||||
|
"ℕ ~ <PosInt 8 BigEndian> ~ EditTree"),
|
||||||
|
Context::parse(&ctx,
|
||||||
|
"ℕ ~ <PosInt 2 BigEndian> ~ EditTree"),
|
||||||
|
];
|
||||||
|
|
||||||
let edittree_dec_be_list =
|
set_master(&ctx, &rt_int, editor_types.clone(), 0);
|
||||||
rt_int
|
|
||||||
.descend(Context::parse(&ctx, "
|
|
||||||
<PosInt 10 BigEndian>
|
|
||||||
~ <Seq~List <Digit 10>~Char>
|
|
||||||
")).unwrap()
|
|
||||||
.edittree( &ctx );
|
|
||||||
|
|
||||||
let hex_digits_view = rt_int.descend(Context::parse(&ctx, "
|
/* list of editors
|
||||||
<PosInt 16 LittleEndian>
|
|
||||||
~ <Seq <Digit 16> >
|
|
||||||
~ <List <Digit 16>
|
|
||||||
~ ℤ_2^64
|
|
||||||
~ machine.UInt64 >
|
|
||||||
")).expect("descend")
|
|
||||||
.view_list::<u64>()
|
|
||||||
.map(|v| TerminalAtom::from(char::from_digit(*v as u32, 16)))
|
|
||||||
.to_sequence()
|
|
||||||
.to_grid_horizontal();
|
|
||||||
|
|
||||||
let dec_digits_view = rt_int.descend(Context::parse(&ctx, "
|
|
||||||
<PosInt 10 LittleEndian>
|
|
||||||
~ <Seq <Digit 10>>
|
|
||||||
~ <List <Digit 10>
|
|
||||||
~ ℤ_2^64
|
|
||||||
~ machine.UInt64 >
|
|
||||||
")).expect("descend")
|
|
||||||
.view_list::<u64>()
|
|
||||||
.map(|v| TerminalAtom::from(char::from_digit(*v as u32, 10)))
|
|
||||||
.to_sequence()
|
|
||||||
.to_grid_horizontal();
|
|
||||||
|
|
||||||
/* list of both editors
|
|
||||||
*/
|
*/
|
||||||
let mut list_editor = nested::editors::list::ListEditor::new(ctx.clone(), Context::parse(&ctx, "<Seq Char>"));
|
let mut list_editor = nested::editors::list::ListEditor::new(ctx.clone(), Context::parse(&ctx, "<Seq Char>"));
|
||||||
list_editor.data.push( edittree_hex_be_list.get() );
|
|
||||||
list_editor.data.push( edittree_dec_be_list.get() );
|
// add all desired editors to the list
|
||||||
|
for leaf in editor_types.iter() {
|
||||||
|
let et =
|
||||||
|
rt_int
|
||||||
|
.descend(leaf.clone()).unwrap()
|
||||||
|
.edittree(&ctx).get();
|
||||||
|
et.write().unwrap().goto(TreeCursor::none());
|
||||||
|
list_editor.data.push(et);
|
||||||
|
}
|
||||||
|
|
||||||
let mut edittree = list_editor.into_node(SingletonBuffer::new(0).get_port());
|
let mut edittree = list_editor.into_node(SingletonBuffer::new(0).get_port());
|
||||||
|
|
||||||
/* cursors are a bit screwed initially so fix them up
|
/* cursors are a bit screwed initially so fix them up
|
||||||
* TODO: how to fix this generally?
|
* TODO: how to fix this generally?
|
||||||
*/
|
*/
|
||||||
edittree_hex_be_list.get().write().unwrap().goto(TreeCursor::none());
|
|
||||||
edittree_dec_be_list.get().write().unwrap().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![0,0]
|
||||||
|
@ -146,37 +136,23 @@ async fn main() {
|
||||||
*/
|
*/
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
let rt_int = rt_int.clone();
|
let rt_int = rt_int.clone();
|
||||||
let last_idx = RwLock::new(1);
|
let last_idx = RwLock::new(0);
|
||||||
|
let editor_types = editor_types.clone();
|
||||||
move |ev| {
|
move |ev| {
|
||||||
|
|
||||||
let cur = edittree.read().unwrap().get_cursor();
|
let cur = edittree.read().unwrap().get_cursor();
|
||||||
if cur.tree_addr.len() > 0 {
|
if cur.tree_addr.len() > 0 {
|
||||||
match cur.tree_addr[0] {
|
|
||||||
0 => {
|
|
||||||
let mut li = last_idx.write().unwrap();
|
let mut li = last_idx.write().unwrap();
|
||||||
if *li != 0 {
|
let ci = cur.tree_addr[0];
|
||||||
rt_int.write().unwrap().detach( &ctx );
|
|
||||||
ctx.read().unwrap().apply_morphism(&rt_int, &laddertypes::MorphismType {
|
|
||||||
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char> ~ EditTree"),
|
|
||||||
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10> ~ Char> ~ EditTree")
|
|
||||||
});
|
|
||||||
|
|
||||||
*li = 0;
|
if *li != ci {
|
||||||
}
|
eprintln!("----------------------------------");
|
||||||
}
|
set_master(
|
||||||
1 => {
|
&ctx,
|
||||||
let mut li = last_idx.write().unwrap();
|
&rt_int,
|
||||||
if *li != 1 {
|
editor_types.clone(),
|
||||||
rt_int.write().unwrap().detach( &ctx );
|
ci as usize
|
||||||
ctx.read().unwrap().apply_morphism(&rt_int, &laddertypes::MorphismType {
|
);
|
||||||
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10> ~ Char> ~ EditTree"),
|
*li = ci;
|
||||||
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char> ~ EditTree")
|
|
||||||
});
|
|
||||||
|
|
||||||
*li = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_=>{}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,30 +175,21 @@ async fn main() {
|
||||||
{
|
{
|
||||||
let rt_edittree = rt.descend(Context::parse(&ctx, "EditTree")).expect("descend");
|
let rt_edittree = rt.descend(Context::parse(&ctx, "EditTree")).expect("descend");
|
||||||
let halo_type = rt_edittree.read().unwrap().get_halo_type().clone();
|
let halo_type = rt_edittree.read().unwrap().get_halo_type().clone();
|
||||||
let edittree = rt_edittree.read().unwrap().get_view::<dyn r3vi::view::singleton::SingletonView<Item = Arc<RwLock<EditTree>>>>().unwrap().get().read().unwrap().clone();
|
let edittree = rt_edittree.edittree( &ctx );
|
||||||
|
|
||||||
comp.push( nested_tty::make_label( &ctx.read().unwrap().type_term_to_str(&halo_type) )
|
comp.push( nested_tty::make_label( &ctx.read().unwrap().type_term_to_str(&halo_type) )
|
||||||
.map_item(|_pt, atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90))))
|
.map_item(|_pt, atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90))))
|
||||||
.offset(Vector2::new(1,y)));
|
.offset(Vector2::new(1,y)));
|
||||||
|
|
||||||
comp.push( edittree.display_view()
|
comp.push( edittree.get().read().unwrap().display_view()
|
||||||
.offset(Vector2::new(1,y+1)));
|
.offset(Vector2::new(1,y+1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
show_edit_tree(&ctx, &mut comp, &rt_int.descend(Context::parse(&ctx, "<PosInt 16 BigEndian> ~ <Seq~List <Digit 16>~Char>")).expect(""), 1);
|
let mut y = 1;
|
||||||
show_edit_tree(&ctx, &mut comp, &rt_int.descend(Context::parse(&ctx, "<PosInt 10 BigEndian> ~ <Seq~List <Digit 10>~Char>")).expect(""), 4);
|
for t in editor_types.iter() {
|
||||||
|
show_edit_tree(&ctx, &mut comp, &rt_int.descend(t.clone()).expect(""), y);
|
||||||
/* project the seq of u64 representations to a view
|
y += 3;
|
||||||
*/
|
}
|
||||||
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
|
/* write the changes in the view of `term_port` to the terminal
|
||||||
|
|
|
@ -25,7 +25,6 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
||||||
{
|
{
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
move |rt, σ| {
|
move |rt, σ| {
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut b = rt.write().unwrap().singleton_buffer::<char>();
|
let mut b = rt.write().unwrap().singleton_buffer::<char>();
|
||||||
if let Some(buf) = b {
|
if let Some(buf) = b {
|
||||||
|
@ -34,15 +33,12 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
||||||
// create char buffer
|
// create char buffer
|
||||||
rt.write().unwrap().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')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let char_buf = rt.singleton_buffer::<char>();
|
let char_buf = rt.singleton_buffer::<char>();
|
||||||
|
|
||||||
let mut edittree = CharEditor::new_edit_tree(
|
let mut edittree = CharEditor::new_edit_tree(
|
||||||
ctx.clone(),
|
ctx.clone(),
|
||||||
char_buf,
|
char_buf,
|
||||||
|
@ -58,16 +54,34 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.read().unwrap().setup_edittree(
|
ctx.read().unwrap().setup_edittree(rt);
|
||||||
rt.clone(),
|
|
||||||
SingletonBuffer::new(0).get_port()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let char_morph_from_edittree = GenericReprTreeMorphism::new(
|
||||||
|
Context::parse(&ctx, "Char~EditTree"),
|
||||||
|
Context::parse(&ctx, "Char"),
|
||||||
|
{
|
||||||
|
let ctx = ctx.clone();
|
||||||
|
move |rt, σ|
|
||||||
|
{
|
||||||
|
let mut b = rt
|
||||||
|
.descend(Context::parse(&ctx, "EditTree")).unwrap()
|
||||||
|
.view_singleton::<Arc<RwLock<EditTree>>>();
|
||||||
|
|
||||||
|
rt.attach_leaf_to(
|
||||||
|
Context::parse(&ctx, "Char"),
|
||||||
|
b.map(|x|
|
||||||
|
x.read().unwrap()
|
||||||
|
.get_edit::<CharEditor>().unwrap()
|
||||||
|
.read().unwrap()
|
||||||
|
.get())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
ctx.write().unwrap().morphisms.add_morphism( char_morph_to_edittree );
|
ctx.write().unwrap().morphisms.add_morphism( char_morph_to_edittree );
|
||||||
|
ctx.write().unwrap().morphisms.add_morphism( char_morph_from_edittree );
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CharEditor {
|
pub struct CharEditor {
|
||||||
|
|
|
@ -19,6 +19,43 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
||||||
// todo: proper scoping of Radix variable
|
// todo: proper scoping of Radix variable
|
||||||
ctx.write().unwrap().add_varname("Radix");
|
ctx.write().unwrap().add_varname("Radix");
|
||||||
|
|
||||||
|
let digit_make_edittree = GenericReprTreeMorphism::new(
|
||||||
|
Context::parse(&ctx, "<Digit Radix>"),
|
||||||
|
Context::parse(&ctx, "<Digit Radix>~EditTree"),
|
||||||
|
{
|
||||||
|
let ctx = ctx.clone();
|
||||||
|
move |src_rt, σ| {
|
||||||
|
let radix =
|
||||||
|
match σ.get( &laddertypes::TypeID::Var(ctx.read().unwrap().get_var_typeid("Radix").unwrap()) ) {
|
||||||
|
Some(TypeTerm::Num(n)) => *n as u32,
|
||||||
|
_ => 0
|
||||||
|
};
|
||||||
|
|
||||||
|
let char_buf = SingletonBuffer::<char>::new('?');
|
||||||
|
|
||||||
|
/* Create EditTree object
|
||||||
|
*/
|
||||||
|
let mut edittree = DigitEditor::new(
|
||||||
|
ctx.clone(),
|
||||||
|
radix,
|
||||||
|
char_buf
|
||||||
|
).into_node(
|
||||||
|
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
|
||||||
|
);
|
||||||
|
|
||||||
|
src_rt.write().unwrap()
|
||||||
|
.insert_branch(
|
||||||
|
ReprTree::from_singleton_buffer(
|
||||||
|
Context::parse(&ctx, "EditTree"),
|
||||||
|
SingletonBuffer::new(Arc::new(RwLock::new(edittree)))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.read().unwrap().setup_edittree( src_rt );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
let digit_morph_char_to_edittree = GenericReprTreeMorphism::new(
|
let digit_morph_char_to_edittree = GenericReprTreeMorphism::new(
|
||||||
Context::parse(&ctx, "<Digit Radix>~Char"),
|
Context::parse(&ctx, "<Digit Radix>~Char"),
|
||||||
Context::parse(&ctx, "<Digit Radix>~EditTree"),
|
Context::parse(&ctx, "<Digit Radix>~EditTree"),
|
||||||
|
@ -57,6 +94,30 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let digit_morph_char_from_edittree = GenericReprTreeMorphism::new(
|
||||||
|
Context::parse(&ctx, "<Digit Radix>~EditTree"),
|
||||||
|
Context::parse(&ctx, "<Digit Radix>~Char"),
|
||||||
|
|
||||||
|
{
|
||||||
|
let ctx = ctx.clone();
|
||||||
|
move |src_rt, σ| {
|
||||||
|
let edittree = src_rt.edittree( &ctx );
|
||||||
|
let port =
|
||||||
|
edittree
|
||||||
|
.get()
|
||||||
|
.read().unwrap()
|
||||||
|
.get_edit::<DigitEditor>().unwrap()
|
||||||
|
.read().unwrap()
|
||||||
|
.get_char_port();
|
||||||
|
|
||||||
|
src_rt.insert_leaf(
|
||||||
|
Context::parse(&ctx, "Char"),
|
||||||
|
ReprLeaf::from_view( port )
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
let digit_morph_char_to_u64 = GenericReprTreeMorphism::new(
|
let digit_morph_char_to_u64 = GenericReprTreeMorphism::new(
|
||||||
Context::parse(&ctx, "<Digit Radix>~Char"),
|
Context::parse(&ctx, "<Digit Radix>~Char"),
|
||||||
Context::parse(&ctx, "<Digit Radix>~ℤ_2^64~machine.UInt64"),
|
Context::parse(&ctx, "<Digit Radix>~ℤ_2^64~machine.UInt64"),
|
||||||
|
@ -134,7 +195,9 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
ctx.write().unwrap().morphisms.add_morphism( digit_make_edittree );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_to_edittree );
|
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_to_edittree );
|
||||||
|
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_from_edittree );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_to_u64 );
|
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_to_u64 );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( digit_morph_u64_to_char );
|
ctx.write().unwrap().morphisms.add_morphism( digit_morph_u64_to_char );
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,10 @@ impl DigitEditor {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_char_port(&self) -> OuterViewPort<dyn SingletonView<Item = char>> {
|
||||||
|
self.data.get_port()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_data_port(&self) -> OuterViewPort<dyn SingletonView<Item = Result<u32, char>>> {
|
pub fn get_data_port(&self) -> OuterViewPort<dyn SingletonView<Item = Result<u32, char>>> {
|
||||||
let radix = self.radix;
|
let radix = self.radix;
|
||||||
self.data.get_port().map(move |c|
|
self.data.get_port().map(move |c|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
|
||||||
use {
|
use {
|
||||||
r3vi::{
|
r3vi::{
|
||||||
view::{OuterViewPort, singleton::*, list::*}
|
view::{OuterViewPort, singleton::*, list::*},
|
||||||
|
buffer::singleton::SingletonBuffer
|
||||||
},
|
},
|
||||||
laddertypes::{TypeTerm, MorphismType},
|
laddertypes::{TypeTerm, MorphismType},
|
||||||
crate::{
|
crate::{
|
||||||
|
@ -170,9 +171,132 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let posint_list_morph_from_u64 = GenericReprTreeMorphism::new(
|
||||||
|
Context::parse(&ctx, "ℕ ~ machine.UInt64"),
|
||||||
|
Context::parse(&ctx, "ℕ ~ <PosInt 0 LittleEndian> ~ <Seq~List <Digit 0>~ℤ_2^64~machine.UInt64>"),
|
||||||
|
{
|
||||||
|
let ctx = ctx.clone();
|
||||||
|
move |rt, σ| {
|
||||||
|
let digits = rt
|
||||||
|
.descend(Context::parse(&ctx, "ℕ ~ machine.UInt64")).unwrap()
|
||||||
|
.view_u64()
|
||||||
|
.to_sequence()
|
||||||
|
.to_list();
|
||||||
|
|
||||||
|
rt.attach_leaf_to(
|
||||||
|
Context::parse(&ctx, "ℕ ~ <PosInt 0 LittleEndian> ~ <Seq~List <Digit 0>~ℤ_2^64~machine.UInt64>"),
|
||||||
|
digits
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
let posint_list_morph_to_u64 = GenericReprTreeMorphism::new(
|
||||||
|
Context::parse(&ctx, "ℕ ~ <PosInt 0 LittleEndian> ~ <Seq~List <Digit 0>~ℤ_2^64~machine.UInt64> ~ <Vec machine.UInt64>"),
|
||||||
|
Context::parse(&ctx, "ℕ ~ machine.UInt64"),
|
||||||
|
{
|
||||||
|
let ctx = ctx.clone();
|
||||||
|
move |rt, σ| {
|
||||||
|
let u64_view = rt
|
||||||
|
.descend(Context::parse(&ctx, "ℕ ~ <PosInt 0 LittleEndian> ~ <Seq~List <Digit 0>~ℤ_2^64~machine.UInt64> ~ <Vec machine.UInt64>")).unwrap()
|
||||||
|
.get_port::< RwLock<Vec< u64 >> >().unwrap()
|
||||||
|
.to_singleton()
|
||||||
|
.map(|digits| {
|
||||||
|
digits.get(0).cloned().unwrap_or(0)
|
||||||
|
});
|
||||||
|
|
||||||
|
rt.attach_leaf_to(
|
||||||
|
Context::parse(&ctx, "ℕ ~ machine.UInt64"),
|
||||||
|
u64_view
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let posint_make_edittree = GenericReprTreeMorphism::new(
|
||||||
|
Context::parse(&ctx, "ℕ ~ <PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>> ~ EditTree"),
|
||||||
|
Context::parse(&ctx, "ℕ ~ <PosInt Radix BigEndian> ~ EditTree"),
|
||||||
|
{
|
||||||
|
let ctx = ctx.clone();
|
||||||
|
move |src_rt, σ| {
|
||||||
|
let mut list_edittree = src_rt.descend(
|
||||||
|
Context::parse(&ctx, "ℕ ~ <PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>>")
|
||||||
|
.apply_substitution(&|x| σ.get(x).cloned()).clone()
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.edittree( &ctx )
|
||||||
|
.get().clone()
|
||||||
|
.read().unwrap()
|
||||||
|
.clone();
|
||||||
|
|
||||||
|
// clear display
|
||||||
|
list_edittree.disp.view = ReprTree::new_arc(Context::parse(&ctx, "Display"));
|
||||||
|
|
||||||
|
src_rt.insert_leaf(
|
||||||
|
Context::parse(&ctx, "<PosInt Radix BigEndian> ~ EditTree")
|
||||||
|
.apply_substitution(&|x| σ.get(x).cloned()).clone(),
|
||||||
|
ReprLeaf::from_singleton_buffer(
|
||||||
|
SingletonBuffer::new(
|
||||||
|
Arc::new(RwLock::new(list_edittree))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.read().unwrap().setup_edittree(
|
||||||
|
&src_rt.descend(
|
||||||
|
Context::parse(&ctx, "<PosInt Radix BigEndian>")
|
||||||
|
.apply_substitution(&|x| σ.get(x).cloned()).clone()
|
||||||
|
).unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let posint_edittree_to_list = GenericReprTreeMorphism::new(
|
||||||
|
Context::parse(&ctx, "ℕ ~ <PosInt Radix BigEndian> ~ EditTree"),
|
||||||
|
Context::parse(&ctx, "ℕ ~ <PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>> ~ EditTree"),
|
||||||
|
{
|
||||||
|
let ctx = ctx.clone();
|
||||||
|
move |src_rt, σ| {
|
||||||
|
let mut list_edittree = src_rt.descend(
|
||||||
|
Context::parse(&ctx, "ℕ ~ <PosInt Radix BigEndian>")
|
||||||
|
.apply_substitution(&|x| σ.get(x).cloned()).clone())
|
||||||
|
.unwrap()
|
||||||
|
.edittree( &ctx )
|
||||||
|
.get().clone()
|
||||||
|
.read().unwrap()
|
||||||
|
.clone();
|
||||||
|
|
||||||
|
// clear display
|
||||||
|
list_edittree.disp.view = ReprTree::new_arc(Context::parse(&ctx, "Display"));
|
||||||
|
|
||||||
|
src_rt.insert_leaf(
|
||||||
|
Context::parse(&ctx, "<PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>>~EditTree")
|
||||||
|
.apply_substitution(&|x| σ.get(x).cloned()).clone(),
|
||||||
|
ReprLeaf::from_singleton_buffer(
|
||||||
|
SingletonBuffer::new(
|
||||||
|
Arc::new(RwLock::new(list_edittree))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.read().unwrap().setup_edittree(
|
||||||
|
&src_rt.descend(
|
||||||
|
Context::parse(&ctx, "<PosInt Radix BigEndian> ~ <Seq~List <Digit Radix>>")
|
||||||
|
.apply_substitution(&|x| σ.get(x).cloned()).clone()
|
||||||
|
).unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.write().unwrap().morphisms.add_morphism( posint_make_edittree );
|
||||||
|
ctx.write().unwrap().morphisms.add_morphism( posint_edittree_to_list );
|
||||||
|
|
||||||
ctx.write().unwrap().morphisms.add_morphism( posint_seq_morph_big_to_little );
|
ctx.write().unwrap().morphisms.add_morphism( posint_seq_morph_big_to_little );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_big_to_little );
|
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_big_to_little );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_little_to_big );
|
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_little_to_big );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_radix );
|
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_radix );
|
||||||
|
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_from_u64 );
|
||||||
|
ctx.write().unwrap().morphisms.add_morphism( posint_list_morph_to_u64 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,11 @@ pub trait PositionalUInt : SequenceView<Item = u64> {
|
||||||
let mut val = 0;
|
let mut val = 0;
|
||||||
let mut r = 1;
|
let mut r = 1;
|
||||||
for i in 0..self.len().unwrap_or(0) {
|
for i in 0..self.len().unwrap_or(0) {
|
||||||
val += r * self.get(&i).unwrap();
|
if let Some(digit_val) = self.get(&i) {
|
||||||
|
val += r * digit_val;
|
||||||
r *= self.get_radix();
|
r *= self.get_radix();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val
|
val
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,36 +63,24 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let list_morph_editsetup3 = GenericReprTreeMorphism::new(
|
||||||
let list_morph_editsetup2 = GenericReprTreeMorphism::new(
|
Context::parse(&ctx, "<List Item> ~ EditTree"),
|
||||||
Context::parse(&ctx, "<List Char>~EditTree"),
|
Context::parse(&ctx, "<List Item> ~ <List EditTree>"),
|
||||||
Context::parse(&ctx, "<List Char>"),
|
|
||||||
{
|
{
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
move |src_rt, σ| {
|
move |src_rt, σ| {
|
||||||
let edittree =
|
let edittree = src_rt.edittree( &ctx );
|
||||||
src_rt
|
|
||||||
.descend(Context::parse(&ctx, "<List Char>~EditTree")).unwrap()
|
|
||||||
.singleton_buffer::<Arc<RwLock<EditTree>>>();
|
|
||||||
|
|
||||||
let list_edit = edittree.get().read().unwrap().get_edit::< ListEditor >().unwrap();
|
let list_edit = edittree.get().read().unwrap().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.insert_leaf(
|
eprintln!("edittree_items.len() = {:?}", edittree_items.get_view().unwrap().len());
|
||||||
Context::parse(&ctx, "<List Char>"),
|
|
||||||
ReprLeaf::from_view(
|
src_rt.attach_leaf_to(
|
||||||
|
Context::parse(&ctx, "<List Item> ~ <List EditTree>")
|
||||||
|
.apply_substitution(&|x| σ.get(x).cloned()).clone(),
|
||||||
edittree_items
|
edittree_items
|
||||||
.map(|edittree_char|
|
|
||||||
edittree_char
|
|
||||||
.read().unwrap()
|
|
||||||
.get_edit::<CharEditor>().unwrap()
|
|
||||||
.read().unwrap()
|
|
||||||
.get()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -132,21 +120,14 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
{
|
{
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
move |src_rt, σ| {
|
move |src_rt, σ| {
|
||||||
let p =
|
let list_port = src_rt.get_port::<dyn ListView< Arc<RwLock<EditTree>> >>().unwrap();
|
||||||
src_rt
|
src_rt.attach_leaf_to( Context::parse(&ctx, "<Vec EditTree>"), list_port );
|
||||||
.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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup1 );
|
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup1 );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup2 );
|
ctx.write().unwrap().morphisms.add_morphism( list_morph_editsetup3 );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_from_vec_char );
|
ctx.write().unwrap().morphisms.add_morphism( list_morph_from_vec_char );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_char );
|
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_char );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_edittree );
|
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_edittree );
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use {
|
use {
|
||||||
r3vi::{
|
r3vi::{
|
||||||
view::{OuterViewPort, singleton::*, sequence::*},
|
view::{OuterViewPort, singleton::*, sequence::*},
|
||||||
buffer::{singleton::*, vec::*}
|
buffer::{singleton::*, vec::*},
|
||||||
|
projection::*
|
||||||
},
|
},
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
|
@ -123,23 +124,18 @@ impl ListEditor {
|
||||||
.set_editor(editor.clone())
|
.set_editor(editor.clone())
|
||||||
.set_nav(editor.clone())
|
.set_nav(editor.clone())
|
||||||
.set_cmd(editor.clone())
|
.set_cmd(editor.clone())
|
||||||
.set_diag(e
|
.set_diag(e.get_data_port()
|
||||||
.get_data_port()
|
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, item_editor)| {
|
.map(|(idx, item_editor)| {
|
||||||
let idx = *idx;
|
let idx = *idx;
|
||||||
item_editor
|
item_editor.get_msg_port()
|
||||||
.get_msg_port()
|
.map(move |msg| {
|
||||||
.map(
|
|
||||||
move |msg| {
|
|
||||||
let mut msg = msg.clone();
|
let mut msg = msg.clone();
|
||||||
msg.addr.insert(0, idx);
|
msg.addr.insert(0, idx);
|
||||||
msg
|
msg
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.flatten()
|
})
|
||||||
);
|
.flatten());
|
||||||
|
|
||||||
node.ctrl.spillbuf = e.spillbuf.clone();
|
node.ctrl.spillbuf = e.spillbuf.clone();
|
||||||
node
|
node
|
||||||
|
@ -161,9 +157,9 @@ impl ListEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
|
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
|
||||||
self.data.get_port().to_sequence().map(
|
self.data.get_port().to_list().map(
|
||||||
|x| x.read().unwrap().clone()
|
|x| x.read().unwrap().clone()
|
||||||
)
|
).to_sequence()
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
pub fn get_data(&self) -> Arc<RwLock<ReprTree>> {
|
pub fn get_data(&self) -> Arc<RwLock<ReprTree>> {
|
||||||
|
@ -319,11 +315,7 @@ 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 mut et = self.ctx.read().unwrap()
|
let mut et = self.ctx.read().unwrap().setup_edittree(&rt);
|
||||||
.setup_edittree(
|
|
||||||
&rt
|
|
||||||
// , self.depth.map(|d| d+1)
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(edittree) = et.as_mut(){
|
if let Some(edittree) = et.as_mut(){
|
||||||
|
|
||||||
|
|
|
@ -42,11 +42,12 @@ impl SequenceView for ListSegmentSequence {
|
||||||
type Item = ListSegment;
|
type Item = ListSegment;
|
||||||
|
|
||||||
fn len(&self) -> Option<usize> {
|
fn len(&self) -> Option<usize> {
|
||||||
|
let l = self.data.len()?;
|
||||||
match self.cur_cursor.mode {
|
match self.cur_cursor.mode {
|
||||||
ListCursorMode::Insert => {
|
ListCursorMode::Insert => {
|
||||||
Some(self.data.len()? + if self.cur_cursor.idx.is_some() { 1 } else { 0 })
|
Some(l + if self.cur_cursor.idx.is_some() { 1 } else { 0 })
|
||||||
}
|
}
|
||||||
_ => self.data.len(),
|
_ => Some(l),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,32 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn build_repr_tree(
|
||||||
|
&self,
|
||||||
|
rt: &Arc<RwLock<ReprTree>>,
|
||||||
|
root: TypeTerm,
|
||||||
|
leaves: Vec< TypeTerm >
|
||||||
|
) {
|
||||||
|
let mut st_problem = laddertypes::steiner_tree::PathApproxSteinerTreeSolver::new(
|
||||||
|
root,
|
||||||
|
leaves
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Some( steiner_tree ) = st_problem.solve( &self.morphisms ) {
|
||||||
|
for morphism_type in steiner_tree.into_edges() {
|
||||||
|
eprintln!("--> apply morph to {}", self.type_term_to_str(&morphism_type.dst_type));
|
||||||
|
if let Some(( morphism, mut τ, σ )) =
|
||||||
|
self.morphisms.find_morphism_with_subtyping( &morphism_type )
|
||||||
|
{
|
||||||
|
let mut rt = rt.descend( τ ).expect("descend src repr");
|
||||||
|
(morphism.setup_projection)( &mut rt, &σ );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("could not find steiner tree to build the requested repr tree");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn make_repr(ctx: &Arc<RwLock<Self>>, t: &TypeTerm) -> Arc<RwLock<ReprTree>> {
|
pub fn make_repr(ctx: &Arc<RwLock<Self>>, t: &TypeTerm) -> Arc<RwLock<ReprTree>> {
|
||||||
let rt = Arc::new(RwLock::new(ReprTree::new( TypeTerm::unit() )));
|
let rt = Arc::new(RwLock::new(ReprTree::new( TypeTerm::unit() )));
|
||||||
ctx.read().unwrap().apply_morphism( &rt, &MorphismType{ src_type: TypeTerm::unit(), dst_type: t.clone() } );
|
ctx.read().unwrap().apply_morphism( &rt, &MorphismType{ src_type: TypeTerm::unit(), dst_type: t.clone() } );
|
||||||
|
@ -223,7 +249,6 @@ impl Context {
|
||||||
pub fn setup_edittree(
|
pub fn setup_edittree(
|
||||||
&self,
|
&self,
|
||||||
rt: &Arc<RwLock<ReprTree>>
|
rt: &Arc<RwLock<ReprTree>>
|
||||||
// depth: OuterViewPort<dyn SingletonView<Item = usize>>
|
|
||||||
) -> Option<SingletonBuffer<Arc<RwLock<EditTree>>>> {
|
) -> Option<SingletonBuffer<Arc<RwLock<EditTree>>>> {
|
||||||
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())
|
||||||
|
|
|
@ -19,7 +19,7 @@ use {
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
any::Any
|
any::Any
|
||||||
},
|
},
|
||||||
super::{Context, ReprLeaf, ReprTreeExt, context::{TYPEID_vec, TYPEID_char, TYPEID_u64, TYPEID_edittree}}
|
super::{Context, ReprLeaf, ReprTreeExt, context::{TYPEID_list, TYPEID_vec, TYPEID_char, TYPEID_u64, TYPEID_edittree}}
|
||||||
};
|
};
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
@ -285,8 +285,26 @@ impl ReprTree {
|
||||||
]) {
|
]) {
|
||||||
leaf.detach_vec::< u64 >();
|
leaf.detach_vec::< u64 >();
|
||||||
}
|
}
|
||||||
|
else if self.type_tag == TypeTerm::App(vec![
|
||||||
|
TypeTerm::TypeID(TYPEID_list),
|
||||||
|
TypeTerm::TypeID(TYPEID_edittree),
|
||||||
|
]) {
|
||||||
|
leaf.detach::< dyn ListView<Arc<RwLock<crate::edit_tree::EditTree>>> >();
|
||||||
|
}
|
||||||
|
else if self.type_tag == TypeTerm::App(vec![
|
||||||
|
TypeTerm::TypeID(TYPEID_list),
|
||||||
|
TypeTerm::TypeID(TYPEID_char),
|
||||||
|
]) {
|
||||||
|
leaf.detach::< dyn ListView<char> >();
|
||||||
|
}
|
||||||
|
else if self.type_tag == TypeTerm::App(vec![
|
||||||
|
TypeTerm::TypeID(TYPEID_list),
|
||||||
|
TypeTerm::TypeID(TYPEID_u64),
|
||||||
|
]) {
|
||||||
|
leaf.detach::< dyn ListView<u64> >();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
eprintln!("cant detach type");
|
eprintln!("cant detach type {}", ctx.read().unwrap().type_term_to_str(&self.type_tag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,22 +224,24 @@ impl PTYListController {
|
||||||
ListCursorMode::Insert => {
|
ListCursorMode::Insert => {
|
||||||
let rt = ReprTree::new_arc(e.typ.clone());
|
let rt = ReprTree::new_arc(e.typ.clone());
|
||||||
|
|
||||||
let ladder = laddertypes::TypeTerm::Ladder(vec![
|
let src_ladder = laddertypes::TypeTerm::Ladder(vec![
|
||||||
|
rt.read().unwrap().get_type().clone()
|
||||||
|
]);
|
||||||
|
let dst_ladder = laddertypes::TypeTerm::Ladder(vec![
|
||||||
rt.read().unwrap().get_type().clone(),
|
rt.read().unwrap().get_type().clone(),
|
||||||
ctx.type_term_from_str("EditTree").expect("")
|
ctx.type_term_from_str("EditTree").expect("")
|
||||||
]);
|
]);
|
||||||
ctx.apply_morphism(
|
ctx.apply_morphism(
|
||||||
&rt,
|
&rt,
|
||||||
&laddertypes::MorphismType {
|
&laddertypes::MorphismType {
|
||||||
src_type: rt.get_type(),
|
src_type: src_ladder,
|
||||||
dst_type: ladder
|
dst_type: dst_ladder
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let new_edittree = ctx.setup_edittree( &rt );
|
let new_edittree = ctx.setup_edittree( &rt );
|
||||||
|
|
||||||
if let Some(new_edittree) = new_edittree {
|
if let Some(new_edittree) = new_edittree {
|
||||||
|
|
||||||
let mut ne = new_edittree.get();
|
let mut ne = new_edittree.get();
|
||||||
let mut ne = ne.write().unwrap();
|
let mut ne = ne.write().unwrap();
|
||||||
match ne.send_cmd_obj(cmd_obj.clone()) {
|
match ne.send_cmd_obj(cmd_obj.clone()) {
|
||||||
|
@ -252,9 +254,7 @@ impl PTYListController {
|
||||||
TreeNavResult::Exit
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
panic!("cant get edit tree");
|
panic!("cant get edit tree");
|
||||||
TreeNavResult::Continue
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ impl ObjCommander for PTYListController {
|
||||||
let cmd_type = cmd_obj.read().unwrap().get_type().clone();
|
let cmd_type = cmd_obj.read().unwrap().get_type().clone();
|
||||||
|
|
||||||
if cmd_type == Context::parse(&e.ctx, "ListCmd").into()
|
if cmd_type == Context::parse(&e.ctx, "ListCmd").into()
|
||||||
|| cmd_type == Context::parse(&e.ctx, "NestedNode").into()
|
|| cmd_type == Context::parse(&e.ctx, "EditTree").into()
|
||||||
{
|
{
|
||||||
e.send_cmd_obj( cmd_obj )
|
e.send_cmd_obj( cmd_obj )
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,10 @@ pub fn setup_edittree_hook(ctx: &Arc<RwLock<Context>>) {
|
||||||
let char_type = Context::parse(&ctx, "Char");
|
let char_type = Context::parse(&ctx, "Char");
|
||||||
let digit_type = Context::parse(&ctx, "<Digit Radix>");
|
let digit_type = Context::parse(&ctx, "<Digit Radix>");
|
||||||
let list_type = Context::parse(&ctx, "<List Item>");
|
let list_type = Context::parse(&ctx, "<List Item>");
|
||||||
let posint_type = Context::parse(&ctx, "<PosInt Radix>");
|
let posint_bin_type = Context::parse(&ctx, "<PosInt 2 BigEndian>");
|
||||||
|
let posint_oct_type = Context::parse(&ctx, "<PosInt 8 BigEndian>");
|
||||||
|
let posint_dec_type = Context::parse(&ctx, "<PosInt 10 BigEndian>");
|
||||||
|
let posint_hex_type = Context::parse(&ctx, "<PosInt 16 BigEndian>");
|
||||||
let item_tyid = ctx.read().unwrap().get_var_typeid("Item").unwrap();
|
let item_tyid = ctx.read().unwrap().get_var_typeid("Item").unwrap();
|
||||||
|
|
||||||
ctx.write().unwrap().meta_chars.push(',');
|
ctx.write().unwrap().meta_chars.push(',');
|
||||||
|
@ -134,18 +137,28 @@ pub fn setup_edittree_hook(ctx: &Arc<RwLock<Context>>) {
|
||||||
ctx.write().unwrap().set_edittree_hook(
|
ctx.write().unwrap().set_edittree_hook(
|
||||||
Arc::new(
|
Arc::new(
|
||||||
move |et: &mut nested::edit_tree::EditTree, t: laddertypes::TypeTerm| {
|
move |et: &mut nested::edit_tree::EditTree, t: laddertypes::TypeTerm| {
|
||||||
// let mut et = et.write().unwrap();
|
|
||||||
|
|
||||||
if let Ok(σ) = laddertypes::unify(&t, &char_type.clone()) {
|
if let Ok(σ) = laddertypes::unify(&t, &char_type.clone()) {
|
||||||
*et = crate::editors::edittree_make_char_view(et.clone());
|
*et = crate::editors::edittree_make_char_view(et.clone());
|
||||||
}
|
}
|
||||||
else if let Ok(σ) = laddertypes::unify(&t, &digit_type) {
|
else if let Ok(σ) = laddertypes::unify(&t, &digit_type) {
|
||||||
*et = crate::editors::edittree_make_digit_view(et.clone());
|
*et = crate::editors::edittree_make_digit_view(et.clone());
|
||||||
}
|
}
|
||||||
else if let Ok(σ) = laddertypes::unify(&t, &posint_type) {
|
else if let Ok(σ) = laddertypes::unify(&t, &posint_bin_type) {
|
||||||
|
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0b", "", ""));
|
||||||
|
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
|
||||||
|
}
|
||||||
|
else if let Ok(σ) = laddertypes::unify(&t, &posint_oct_type) {
|
||||||
|
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0o", "", ""));
|
||||||
|
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
|
||||||
|
}
|
||||||
|
else if let Ok(σ) = laddertypes::unify(&t, &posint_dec_type) {
|
||||||
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0d", "", ""));
|
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0d", "", ""));
|
||||||
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
|
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
|
||||||
}
|
}
|
||||||
|
else if let Ok(σ) = laddertypes::unify(&t, &posint_hex_type) {
|
||||||
|
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0x", "", ""));
|
||||||
|
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
|
||||||
|
}
|
||||||
else if let Ok(σ) = laddertypes::unify(&t, &list_type) {
|
else if let Ok(σ) = laddertypes::unify(&t, &list_type) {
|
||||||
let item_type = σ.get( &laddertypes::TypeID::Var(item_tyid) ).unwrap();
|
let item_type = σ.get( &laddertypes::TypeID::Var(item_tyid) ).unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue