simplify posint example
remove setup_hex_master() / setup_dec_master() functions and instead directly call apply_morphism()
This commit is contained in:
parent
786866746c
commit
7762fa4b12
1 changed files with 22 additions and 25 deletions
|
@ -32,28 +32,6 @@ use {
|
|||
std::sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
fn setup_hex_master(ctx: &Arc<RwLock<Context>>, rt_int: &Arc<RwLock<ReprTree>>) {
|
||||
rt_int.write().unwrap().detach( ctx );
|
||||
ctx.read().unwrap().apply_morphism(
|
||||
rt_int,
|
||||
&laddertypes::MorphismType {
|
||||
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree"),
|
||||
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char> ~ EditTree")
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
fn setup_dec_master(ctx: &Arc<RwLock<Context>>, rt_int: &Arc<RwLock<ReprTree>>) {
|
||||
rt_int.write().unwrap().detach( ctx );
|
||||
ctx.read().unwrap().apply_morphism(
|
||||
rt_int,
|
||||
&laddertypes::MorphismType {
|
||||
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char> ~ EditTree"),
|
||||
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree")
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
/* setup context
|
||||
|
@ -92,7 +70,16 @@ async fn main() {
|
|||
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree")
|
||||
});
|
||||
|
||||
setup_hex_master(&ctx, &rt_int);
|
||||
/* set Hex-editor to be master
|
||||
*/
|
||||
rt_int.write().unwrap().detach( &ctx );
|
||||
ctx.read().unwrap().apply_morphism(
|
||||
&rt_int,
|
||||
&laddertypes::MorphismType {
|
||||
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree"),
|
||||
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char> ~ EditTree")
|
||||
}
|
||||
);
|
||||
|
||||
let edittree_hex_be_list = ctx.read().unwrap()
|
||||
.setup_edittree(
|
||||
|
@ -174,14 +161,24 @@ async fn main() {
|
|||
0 => {
|
||||
let mut li = last_idx.write().unwrap();
|
||||
if *li != 0 {
|
||||
setup_hex_master(&ctx, &rt_int);
|
||||
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;
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
let mut li = last_idx.write().unwrap();
|
||||
if *li != 1 {
|
||||
setup_dec_master(&ctx, &rt_int);
|
||||
rt_int.write().unwrap().detach( &ctx );
|
||||
ctx.read().unwrap().apply_morphism(&rt_int, &laddertypes::MorphismType {
|
||||
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10> ~ Char> ~ EditTree"),
|
||||
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char> ~ EditTree")
|
||||
});
|
||||
|
||||
*li = 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue