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},
|
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_std::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
/* setup context
|
/* 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")
|
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()
|
let edittree_hex_be_list = ctx.read().unwrap()
|
||||||
.setup_edittree(
|
.setup_edittree(
|
||||||
|
@ -174,14 +161,24 @@ async fn main() {
|
||||||
0 => {
|
0 => {
|
||||||
let mut li = last_idx.write().unwrap();
|
let mut li = last_idx.write().unwrap();
|
||||||
if *li != 0 {
|
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;
|
*li = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
let mut li = last_idx.write().unwrap();
|
let mut li = last_idx.write().unwrap();
|
||||||
if *li != 1 {
|
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;
|
*li = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,11 +113,15 @@ impl RadixProjection {
|
||||||
|
|
||||||
if let Some(src) = self.src.as_ref() {
|
if let Some(src) = self.src.as_ref() {
|
||||||
let mut val = src.get_value();
|
let mut val = src.get_value();
|
||||||
|
if val == 0 {
|
||||||
|
self.dst_digits.push(0);
|
||||||
|
} else {
|
||||||
while val > 0 {
|
while val > 0 {
|
||||||
self.dst_digits.push(val % self.dst_radix);
|
self.dst_digits.push(val % self.dst_radix);
|
||||||
val /= self.dst_radix;
|
val /= self.dst_radix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let new_len = self.dst_digits.len();
|
let new_len = self.dst_digits.len();
|
||||||
for i in 0 .. usize::max(old_len, new_len) {
|
for i in 0 .. usize::max(old_len, new_len) {
|
||||||
|
|
Loading…
Reference in a new issue