construct list items from Void repr

This commit is contained in:
Michael Sippel 2025-01-22 23:36:43 +01:00
parent f88f4971af
commit 16a0381ada
Signed by: senvas
GPG key ID: F96CF119C34B64A6
5 changed files with 118 additions and 12 deletions

View file

@ -21,6 +21,46 @@ use {
}; };
pub fn init_ctx( ctx: Arc<RwLock<Context>> ) { pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
let char_void_to_edittree = GenericReprTreeMorphism::new(
Context::parse(&ctx, "Char~Void"),
Context::parse(&ctx, "Char~EditTree"),
{
let ctx = ctx.clone();
move |rt, σ| {
rt.write().unwrap().branches.remove(&Context::parse(&ctx, "Void"));
{
let mut b = rt.write().unwrap().singleton_buffer::<char>();
if let Some(buf) = b {
// buffer already exists
} else {
// create char buffer
rt.write().unwrap().insert_leaf(
vec![].into_iter(),
ReprLeaf::from_singleton_buffer(SingletonBuffer::new('\0'))
);
}
}
let char_buf = rt.singleton_buffer::<char>();
eprintln!("c = {}",char_buf.get());
let mut edittree = CharEditor::new_edit_tree(
ctx.clone(),
char_buf,
SingletonBuffer::<usize>::new(0).get_port()
);
rt.insert_leaf(
Context::parse(&ctx, "Char~EditTree"),
ReprLeaf::from_singleton_buffer(
SingletonBuffer::new(edittree)
)
);
ctx.read().unwrap().setup_edittree(rt);
}
}
);
let char_morph_to_edittree = GenericReprTreeMorphism::new( let char_morph_to_edittree = GenericReprTreeMorphism::new(
Context::parse(&ctx, "Char"), Context::parse(&ctx, "Char"),
@ -90,6 +130,8 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
); );
} }
}); });
ctx.write().unwrap().morphisms.add_morphism( char_void_to_edittree );
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 ); ctx.write().unwrap().morphisms.add_morphism( char_morph_from_edittree );
} }

View file

@ -38,7 +38,7 @@ impl ObjCommander for CharEditor {
TreeNavResult::Exit TreeNavResult::Exit
} else { } else {
self.data.set(value); self.data.set(value);
TreeNavResult::Continue TreeNavResult::Exit
} }
} else { } else {
TreeNavResult::Exit TreeNavResult::Exit

View file

@ -19,6 +19,63 @@ 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_from_void = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<Digit Radix>~Void"),
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_rt = src_rt.descend_create(Context::parse(&ctx, "Char")).unwrap();
let char_buf = {
let mut b = char_rt.write().unwrap().singleton_buffer::<char>();
if let Some(buf) = b {
// buffer already exists
eprintln!("take existing char buffer");
buf
} else {
// create char buffer
eprintln!("create char buffer");
let char_buf = SingletonBuffer::<char>::new('?');
src_rt.insert_leaf(
Context::parse(&ctx, "Char"),
ReprLeaf::from_singleton_buffer(char_buf.clone())
);
char_buf
}
};
/* Create EditTree object
*/
//if src_rt.descend(Context::parse(&ctx, "EditTree")).is_none() {
eprintln!("create Digit-Editor");
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(edittree)
)
);
ctx.read().unwrap().setup_edittree( src_rt );
//}
}
}
);
let digit_make_edittree = GenericReprTreeMorphism::new( let digit_make_edittree = GenericReprTreeMorphism::new(
Context::parse(&ctx, "<Digit Radix>"), Context::parse(&ctx, "<Digit Radix>"),
Context::parse(&ctx, "<Digit Radix>~EditTree"), Context::parse(&ctx, "<Digit Radix>~EditTree"),
@ -235,6 +292,7 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
ctx.write().unwrap().morphisms.add_morphism( digit_make_edittree ); ctx.write().unwrap().morphisms.add_morphism( digit_make_edittree );
ctx.write().unwrap().morphisms.add_morphism( digit_make_edittree_from_void );
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_from_edittree );
ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_to_u64 ); ctx.write().unwrap().morphisms.add_morphism( digit_morph_char_to_u64 );

View file

@ -31,7 +31,7 @@ use {
pub struct ReprTree { pub struct ReprTree {
halo: TypeTerm, halo: TypeTerm,
type_tag: TypeTerm, type_tag: TypeTerm,
branches: HashMap<TypeTerm, ReprTreeArc>, pub branches: HashMap<TypeTerm, ReprTreeArc>,
leaf: Option< ReprLeaf >, leaf: Option< ReprLeaf >,
} }

View file

@ -220,19 +220,25 @@ impl PTYListController {
match cur.mode { match cur.mode {
ListCursorMode::Insert => { ListCursorMode::Insert => {
let mut rt = ReprTree::new_arc(e.item_type.clone()); let mut rt = ReprTree::new_arc(Context::parse(&ctx, "Void"));
rt.write().unwrap().set_halo(e.item_type.clone());
rt = e.item_builder.build_from(rt).expect("cant creat EditTree for item"); rt = e.item_builder.build_from(rt).expect("cant creat EditTree for item");
let mut ne = rt.edittree(&ctx).get_mut(); let mut ne = rt.edittree(&ctx).get_mut();
ne.goto(TreeCursor::home());
match ne.send_cmd_obj(cmd_obj.clone()) { match ne.send_cmd_obj(cmd_obj.clone()) {
TreeNavResult::Continue => { TreeNavResult::Continue => {
drop(ne); e.insert(rt);
e.insert(rt); e.goto(TreeCursor{
TreeNavResult::Continue leaf_mode: ListCursorMode::Insert,
} tree_addr: vec![ cur.idx.unwrap() as isize, 1 ]
TreeNavResult::Exit => { });
TreeNavResult::Exit TreeNavResult::Continue
} }
TreeNavResult::Exit => {
e.insert(rt);
TreeNavResult::Continue
}
} }
}, },
ListCursorMode::Select => { ListCursorMode::Select => {