2021-11-19 12:19:52 +01:00
|
|
|
|
use nested::{
|
|
|
|
|
core::{TypeDict, ViewPort},
|
|
|
|
|
integer::RadixProjection,
|
|
|
|
|
vec::VecBuffer,
|
2021-04-29 01:32:59 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[async_std::main]
|
|
|
|
|
async fn main() {
|
2021-04-30 03:49:53 +02:00
|
|
|
|
let mut td = TypeDict::new();
|
|
|
|
|
for tn in vec![
|
2021-11-19 12:19:52 +01:00
|
|
|
|
"MachineWord",
|
|
|
|
|
"MachineInt",
|
|
|
|
|
"MachineSyllab",
|
|
|
|
|
"Vec",
|
|
|
|
|
"Stream",
|
|
|
|
|
"Json",
|
|
|
|
|
"Sequence",
|
|
|
|
|
"UTF-8-Char",
|
|
|
|
|
"PositionalInt",
|
|
|
|
|
"Digit",
|
|
|
|
|
"LittleEndian",
|
|
|
|
|
"BigEndian",
|
|
|
|
|
"DiffStream",
|
|
|
|
|
"ℕ",
|
|
|
|
|
"$src_radix",
|
|
|
|
|
"$dst_radix",
|
|
|
|
|
] {
|
|
|
|
|
td.add_typename(tn.into());
|
|
|
|
|
}
|
2021-04-30 03:49:53 +02:00
|
|
|
|
|
|
|
|
|
let radix_types = vec![
|
|
|
|
|
td.type_term_from_str("( ℕ )").unwrap(),
|
2021-11-19 12:19:52 +01:00
|
|
|
|
td.type_term_from_str("( PositionalInt 10 LittleEndian )")
|
|
|
|
|
.unwrap(),
|
2021-04-30 03:49:53 +02:00
|
|
|
|
td.type_term_from_str("( Sequence ( Digit 10 ) )").unwrap(),
|
2021-05-03 19:55:29 +02:00
|
|
|
|
td.type_term_from_str("( Sequence UTF-8-Char )").unwrap(),
|
2021-11-19 12:19:52 +01:00
|
|
|
|
td.type_term_from_str("( Sequence MachineSyllab )").unwrap(),
|
2021-05-03 19:55:29 +02:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let src_types = vec![
|
|
|
|
|
td.type_term_from_str("( ℕ )").unwrap(),
|
2021-11-19 12:19:52 +01:00
|
|
|
|
td.type_term_from_str("( PositionalInt $src_radix LittleEndian )")
|
|
|
|
|
.unwrap(),
|
|
|
|
|
td.type_term_from_str("( Sequence ( Digit $src_radix ) )")
|
|
|
|
|
.unwrap(),
|
2021-05-03 19:55:29 +02:00
|
|
|
|
td.type_term_from_str("( Sequence MachineInt )").unwrap(),
|
2021-11-19 12:19:52 +01:00
|
|
|
|
td.type_term_from_str("( DiffStream ( Vec MachineInt ) )")
|
|
|
|
|
.unwrap(),
|
2021-05-03 19:55:29 +02:00
|
|
|
|
td.type_term_from_str("( Json )").unwrap(),
|
|
|
|
|
td.type_term_from_str("( Stream UTF-8-Char )").unwrap(),
|
2021-11-19 12:19:52 +01:00
|
|
|
|
td.type_term_from_str("( Stream MachineSyllab )").unwrap(),
|
2021-05-03 19:55:29 +02:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let dst_types = vec![
|
|
|
|
|
td.type_term_from_str("( ℕ )").unwrap(),
|
2021-11-19 12:19:52 +01:00
|
|
|
|
td.type_term_from_str("( PositionalInt $dst_radix LittleEndian )")
|
|
|
|
|
.unwrap(),
|
|
|
|
|
td.type_term_from_str("( Sequence ( Digit $dst_radix ) )")
|
|
|
|
|
.unwrap(),
|
2021-05-03 19:55:29 +02:00
|
|
|
|
td.type_term_from_str("( Sequence MachineInt )").unwrap(),
|
2021-11-19 12:19:52 +01:00
|
|
|
|
td.type_term_from_str("( DiffStream ( Vec MachineInt ) )")
|
|
|
|
|
.unwrap(),
|
2021-05-03 19:55:29 +02:00
|
|
|
|
td.type_term_from_str("( Json )").unwrap(),
|
|
|
|
|
td.type_term_from_str("( Stream UTF-8-Char )").unwrap(),
|
2021-11-19 12:19:52 +01:00
|
|
|
|
td.type_term_from_str("( Stream MachineSyllab )").unwrap(),
|
2021-04-30 03:49:53 +02:00
|
|
|
|
];
|
|
|
|
|
|
2021-04-29 01:32:59 +02:00
|
|
|
|
nested::magic_header();
|
|
|
|
|
eprintln!(" Convert Radix of Positional Integer");
|
|
|
|
|
nested::magic_header();
|
|
|
|
|
|
2021-04-30 03:49:53 +02:00
|
|
|
|
eprintln!("\n$1: src_radix");
|
|
|
|
|
for t in radix_types.iter() {
|
|
|
|
|
eprintln!(" {}", td.type_term_to_str(t));
|
|
|
|
|
}
|
2021-04-29 01:32:59 +02:00
|
|
|
|
|
2021-04-30 03:49:53 +02:00
|
|
|
|
eprintln!("\n$2: dst_radix");
|
|
|
|
|
for t in radix_types.iter() {
|
|
|
|
|
eprintln!(" {}", td.type_term_to_str(t));
|
|
|
|
|
}
|
2021-04-29 01:32:59 +02:00
|
|
|
|
|
2021-04-30 03:49:53 +02:00
|
|
|
|
eprintln!("\n>0: n");
|
2021-05-03 19:55:29 +02:00
|
|
|
|
for t in src_types.iter() {
|
2021-04-30 03:49:53 +02:00
|
|
|
|
eprintln!(" {}", td.type_term_to_str(t));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eprintln!("\n<1: n");
|
2021-05-03 19:55:29 +02:00
|
|
|
|
for t in dst_types.iter() {
|
2021-04-30 03:49:53 +02:00
|
|
|
|
eprintln!(" {}", td.type_term_to_str(t));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nested::magic_header();
|
|
|
|
|
|
2021-05-03 19:55:29 +02:00
|
|
|
|
let mut args = std::env::args();
|
|
|
|
|
args.next().expect("Arg $0 missing!");
|
2021-05-22 01:39:08 +02:00
|
|
|
|
|
2021-05-03 19:55:29 +02:00
|
|
|
|
let src_radix_str = args.next().expect("Arg $1 required!");
|
|
|
|
|
let dst_radix_str = args.next().expect("Arg $2 required!");
|
|
|
|
|
|
|
|
|
|
let src_radix = usize::from_str_radix(&src_radix_str, 10).expect("could not parse src_radix");
|
|
|
|
|
let dst_radix = usize::from_str_radix(&dst_radix_str, 10).expect("could not parse dst_radix");
|
|
|
|
|
|
|
|
|
|
assert!(src_radix > 1);
|
|
|
|
|
assert!(dst_radix > 1);
|
|
|
|
|
|
2021-04-29 01:32:59 +02:00
|
|
|
|
let src_digits_port = ViewPort::new();
|
|
|
|
|
let dst_digits_port = ViewPort::new();
|
|
|
|
|
|
|
|
|
|
let mut src_digits = VecBuffer::<usize>::new(src_digits_port.inner());
|
|
|
|
|
|
2021-05-13 16:22:30 +02:00
|
|
|
|
let _proj = RadixProjection::new(
|
2021-04-29 01:32:59 +02:00
|
|
|
|
src_radix,
|
|
|
|
|
dst_radix,
|
|
|
|
|
src_digits_port.outer().to_sequence(),
|
2021-11-19 12:19:52 +01:00
|
|
|
|
dst_digits_port.inner(),
|
2021-04-29 01:32:59 +02:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// output dst digits
|
2021-05-22 01:39:08 +02:00
|
|
|
|
let writer = {
|
2021-11-19 12:19:52 +01:00
|
|
|
|
use std::os::unix::io::FromRawFd;
|
2021-04-29 01:32:59 +02:00
|
|
|
|
|
2021-11-19 12:19:52 +01:00
|
|
|
|
dst_digits_port
|
|
|
|
|
.outer()
|
|
|
|
|
.serialize_json(unsafe { std::fs::File::from_raw_fd(1) })
|
2021-04-29 01:32:59 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// start reading src digits
|
|
|
|
|
{
|
2021-11-19 12:19:52 +01:00
|
|
|
|
use async_std::os::unix::io::FromRawFd;
|
2021-04-29 01:32:59 +02:00
|
|
|
|
|
2021-11-19 12:19:52 +01:00
|
|
|
|
src_digits
|
|
|
|
|
.from_json(unsafe { async_std::fs::File::from_raw_fd(0) })
|
|
|
|
|
.await;
|
2021-04-29 01:32:59 +02:00
|
|
|
|
}
|
2021-05-22 01:39:08 +02:00
|
|
|
|
|
|
|
|
|
drop(writer);
|
2021-04-29 01:32:59 +02:00
|
|
|
|
}
|