Compare commits
2 commits
8d637a6f32
...
7762fa4b12
Author | SHA1 | Date | |
---|---|---|---|
7762fa4b12 | |||
786866746c |
2 changed files with 29 additions and 28 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,9 +113,13 @@ impl RadixProjection {
|
|||
|
||||
if let Some(src) = self.src.as_ref() {
|
||||
let mut val = src.get_value();
|
||||
while val > 0 {
|
||||
self.dst_digits.push(val % self.dst_radix);
|
||||
val /= self.dst_radix;
|
||||
if val == 0 {
|
||||
self.dst_digits.push(0);
|
||||
} else {
|
||||
while val > 0 {
|
||||
self.dst_digits.push(val % self.dst_radix);
|
||||
val /= self.dst_radix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue