use min_infmachine_lltk::builder::*;
use min_infmachine_lltk::handler::*;
use min_infmachine_lltk::*;
fn create_table(f: impl Fn(MISimpleBuilder) -> MISimpleBuilder) -> Vec<usize> {
let builder = MISimpleBuilder::new();
let builder = f(builder);
let code = builder.try_to_code().unwrap().0;
to_table(code)
}
fn gen_return_handler_code(
return_bits: usize,
number: usize,
temp_buffer: bool,
forward: bool,
) -> Vec<usize> {
create_table(|mut builder| {
let mut ret_handler = RoutineHandler::<String>::new("routine0", temp_buffer, forward);
builder.l("routine0");
for i in 0..number {
let cslabel = format!("code{}s", i);
let cretlabel = format!("code{}_ret", i);
ret_handler.add_label(&cslabel, cretlabel);
}
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_return())));
for i in 0..number {
let clabel = format!("code{}", i);
let cslabel = format!("code{}s", i);
let cretlabel = format!("code{}_ret", i);
builder.l(clabel.clone());
builder.i(MINF_MR);
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_call(&cslabel))));
builder.l(cretlabel.clone());
builder.i(MINF_MR);
}
ret_handler.install(Some(return_bits), &mut builder);
builder
})
}
#[test]
fn test_routine_handler() {
assert_eq!(
gen_return_handler_code(3, 8, false, false),
vec![
181, 130, 153, 132, 133, 155, 135, 136, 157, 138, 139, 159, 141, 142, 161, 144, 145,
163, 147, 148, 165, 150, 151, 167, 153, 794, 553, 924, 553, 798, 555, 928, 555, 802,
557, 932, 557, 806, 559, 936, 559, 810, 561, 940, 561, 814, 563, 944, 563, 818, 512,
948, 512, 54, 823, 56, 825, 60, 827, 64, 829, 131, 831, 137, 833, 143, 835, 149, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
181, 130, 153, 132, 133, 155, 135, 136, 157, 138, 139, 159, 141, 142, 161, 144, 145,
163, 147, 148, 165, 150, 151, 167, 153, 794, 553, 924, 553, 798, 555, 928, 555, 802,
557, 932, 557, 806, 559, 936, 559, 810, 561, 940, 561, 814, 563, 944, 563, 818, 512,
948, 512, 54, 823, 58, 825, 62, 827, 66, 829, 134, 831, 140, 833, 146, 835, 152, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
);
assert_eq!(
gen_return_handler_code(3, 7, false, false),
vec![
112, 66, 86, 68, 69, 88, 71, 72, 90, 74, 75, 92, 77, 78, 94, 80, 81, 96, 83, 84, 98,
86, 407, 292, 473, 292, 411, 294, 477, 294, 415, 296, 481, 296, 419, 298, 421, 300,
487, 300, 425, 302, 491, 302, 429, 256, 495, 256, 49, 434, 51, 436, 55, 438, 59, 440,
67, 442, 73, 444, 79, 446, 85, 0, 112, 66, 86, 68, 69, 88, 71, 72, 90, 74, 75, 92, 77,
78, 94, 80, 81, 96, 83, 84, 98, 86, 407, 292, 473, 292, 411, 294, 477, 294, 415, 296,
481, 296, 419, 298, 421, 300, 487, 300, 425, 302, 491, 302, 429, 256, 495, 256, 49,
434, 53, 436, 57, 438, 61, 440, 70, 442, 76, 444, 82, 446, 85, 0
]
);
assert_eq!(
gen_return_handler_code(3, 8, false, true),
vec![
181, 130, 153, 132, 133, 155, 135, 136, 157, 138, 139, 159, 141, 142, 161, 144, 145,
163, 147, 148, 165, 150, 151, 167, 153, 794, 41, 924, 41, 798, 43, 928, 43, 802, 45,
932, 45, 806, 47, 936, 47, 810, 49, 940, 49, 814, 51, 944, 51, 818, 0, 948, 0, 566,
823, 568, 825, 572, 827, 576, 829, 131, 831, 137, 833, 143, 835, 149, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 181, 130,
153, 132, 133, 155, 135, 136, 157, 138, 139, 159, 141, 142, 161, 144, 145, 163, 147,
148, 165, 150, 151, 167, 153, 794, 41, 924, 41, 798, 43, 928, 43, 802, 45, 932, 45,
806, 47, 936, 47, 810, 49, 940, 49, 814, 51, 944, 51, 818, 0, 948, 0, 566, 823, 570,
825, 574, 827, 578, 829, 134, 831, 140, 833, 146, 835, 152, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
);
assert_eq!(
gen_return_handler_code(3, 7, false, true),
vec![
112, 66, 86, 68, 69, 88, 71, 72, 90, 74, 75, 92, 77, 78, 94, 80, 81, 96, 83, 84, 98,
86, 407, 36, 473, 36, 411, 38, 477, 38, 415, 40, 481, 40, 419, 42, 421, 44, 487, 44,
425, 46, 491, 46, 429, 0, 495, 0, 305, 434, 307, 436, 311, 438, 315, 440, 67, 442, 73,
444, 79, 446, 85, 0, 112, 66, 86, 68, 69, 88, 71, 72, 90, 74, 75, 92, 77, 78, 94, 80,
81, 96, 83, 84, 98, 86, 407, 36, 473, 36, 411, 38, 477, 38, 415, 40, 481, 40, 419, 42,
421, 44, 487, 44, 425, 46, 491, 46, 429, 0, 495, 0, 305, 434, 309, 436, 313, 438, 317,
440, 70, 442, 76, 444, 82, 446, 85, 0
]
);
assert_eq!(
gen_return_handler_code(3, 8, true, false),
vec![
181, 130, 153, 132, 133, 155, 135, 136, 157, 138, 139, 159, 141, 142, 161, 144, 145,
163, 147, 148, 165, 150, 151, 167, 153, 1306, 1577, 1436, 1577, 1310, 1579, 1440, 1579,
1314, 1581, 1444, 1581, 1318, 1583, 1448, 1583, 1322, 1585, 1452, 1585, 1326, 1587,
1456, 1587, 1330, 1536, 1460, 1536, 1078, 1335, 1080, 1337, 1084, 1339, 1088, 1341,
131, 1343, 137, 1345, 143, 1347, 149, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 181, 130, 153, 132, 133, 155, 135, 136,
157, 138, 139, 159, 141, 142, 161, 144, 145, 163, 147, 148, 165, 150, 151, 167, 153,
1306, 1577, 1436, 1577, 1310, 1579, 1440, 1579, 1314, 1581, 1444, 1581, 1318, 1583,
1448, 1583, 1322, 1585, 1452, 1585, 1326, 1587, 1456, 1587, 1330, 1536, 1460, 1536,
1078, 1335, 1082, 1337, 1086, 1339, 1090, 1341, 134, 1343, 140, 1345, 146, 1347, 152,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
]
);
assert_eq!(
gen_return_handler_code(3, 7, true, false),
vec![
112, 66, 86, 68, 69, 88, 71, 72, 90, 74, 75, 92, 77, 78, 94, 80, 81, 96, 83, 84, 98,
86, 663, 804, 729, 804, 667, 806, 733, 806, 671, 808, 737, 808, 675, 810, 677, 812,
743, 812, 681, 814, 747, 814, 685, 768, 751, 768, 561, 690, 563, 692, 567, 694, 571,
696, 67, 698, 73, 700, 79, 702, 85, 0, 112, 66, 86, 68, 69, 88, 71, 72, 90, 74, 75, 92,
77, 78, 94, 80, 81, 96, 83, 84, 98, 86, 663, 804, 729, 804, 667, 806, 733, 806, 671,
808, 737, 808, 675, 810, 677, 812, 743, 812, 681, 814, 747, 814, 685, 768, 751, 768,
561, 690, 565, 692, 569, 694, 573, 696, 70, 698, 76, 700, 82, 702, 85, 0
]
);
assert_eq!(
gen_return_handler_code(3, 8, true, true),
vec![
181, 130, 153, 132, 133, 155, 135, 136, 157, 138, 139, 159, 141, 142, 161, 144, 145,
163, 147, 148, 165, 150, 151, 167, 153, 1306, 1065, 1436, 1065, 1310, 1067, 1440, 1067,
1314, 1069, 1444, 1069, 1318, 1071, 1448, 1071, 1322, 1073, 1452, 1073, 1326, 1075,
1456, 1075, 1330, 1024, 1460, 1024, 1590, 1335, 1592, 1337, 1596, 1339, 1600, 1341,
131, 1343, 137, 1345, 143, 1347, 149, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 181, 130, 153, 132, 133, 155, 135, 136,
157, 138, 139, 159, 141, 142, 161, 144, 145, 163, 147, 148, 165, 150, 151, 167, 153,
1306, 1065, 1436, 1065, 1310, 1067, 1440, 1067, 1314, 1069, 1444, 1069, 1318, 1071,
1448, 1071, 1322, 1073, 1452, 1073, 1326, 1075, 1456, 1075, 1330, 1024, 1460, 1024,
1590, 1335, 1594, 1337, 1598, 1339, 1602, 1341, 134, 1343, 140, 1345, 146, 1347, 152,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
]
);
assert_eq!(
gen_return_handler_code(3, 7, true, true),
vec![
112, 66, 86, 68, 69, 88, 71, 72, 90, 74, 75, 92, 77, 78, 94, 80, 81, 96, 83, 84, 98,
86, 663, 548, 729, 548, 667, 550, 733, 550, 671, 552, 737, 552, 675, 554, 677, 556,
743, 556, 681, 558, 747, 558, 685, 512, 751, 512, 817, 690, 819, 692, 823, 694, 827,
696, 67, 698, 73, 700, 79, 702, 85, 0, 112, 66, 86, 68, 69, 88, 71, 72, 90, 74, 75, 92,
77, 78, 94, 80, 81, 96, 83, 84, 98, 86, 663, 548, 729, 548, 667, 550, 733, 550, 671,
552, 737, 552, 675, 554, 677, 556, 743, 556, 681, 558, 747, 558, 685, 512, 751, 512,
817, 690, 821, 692, 825, 694, 829, 696, 70, 698, 76, 700, 82, 702, 85, 0
]
);
}
fn gen_return_handler_code_rcall(
return_bits: usize,
number: usize,
temp_buffer: bool,
forward: bool,
) -> Vec<usize> {
create_table(|mut builder| {
let mut ret_handler = RoutineHandler::<String>::new("routine0", temp_buffer, forward);
builder.l("routine0");
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_return())));
for i in 0..number {
let clabel = format!("code{}", i);
builder.l(clabel.clone());
builder.i(MINF_MR);
routine_call_01(&mut ret_handler, &mut builder, MINF_MR);
builder.i(MINF_MR);
}
ret_handler.install(Some(return_bits), &mut builder);
builder
})
}
#[test]
fn test_routine_handler_rcall() {
assert_eq!(
gen_return_handler_code_rcall(3, 8, false, false),
vec![
181, 130, 153, 132, 133, 155, 135, 136, 157, 138, 139, 159, 141, 142, 161, 144, 145,
163, 147, 148, 165, 150, 151, 167, 153, 794, 553, 924, 553, 798, 555, 928, 555, 802,
557, 932, 557, 806, 559, 936, 559, 810, 561, 940, 561, 814, 563, 944, 563, 818, 512,
948, 512, 54, 823, 56, 825, 60, 827, 64, 829, 131, 831, 137, 833, 143, 835, 149, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
181, 130, 153, 132, 133, 155, 135, 136, 157, 138, 139, 159, 141, 142, 161, 144, 145,
163, 147, 148, 165, 150, 151, 167, 153, 794, 553, 924, 553, 798, 555, 928, 555, 802,
557, 932, 557, 806, 559, 936, 559, 810, 561, 940, 561, 814, 563, 944, 563, 818, 512,
948, 512, 54, 823, 58, 825, 62, 827, 66, 829, 134, 831, 140, 833, 146, 835, 152, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
);
assert_eq!(
gen_return_handler_code_rcall(3, 8, false, true),
vec![
181, 130, 153, 132, 133, 155, 135, 136, 157, 138, 139, 159, 141, 142, 161, 144, 145,
163, 147, 148, 165, 150, 151, 167, 153, 794, 41, 924, 41, 798, 43, 928, 43, 802, 45,
932, 45, 806, 47, 936, 47, 810, 49, 940, 49, 814, 51, 944, 51, 818, 0, 948, 0, 566,
823, 568, 825, 572, 827, 576, 829, 131, 831, 137, 833, 143, 835, 149, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 181, 130,
153, 132, 133, 155, 135, 136, 157, 138, 139, 159, 141, 142, 161, 144, 145, 163, 147,
148, 165, 150, 151, 167, 153, 794, 41, 924, 41, 798, 43, 928, 43, 802, 45, 932, 45,
806, 47, 936, 47, 810, 49, 940, 49, 814, 51, 944, 51, 818, 0, 948, 0, 566, 823, 570,
825, 574, 827, 578, 829, 134, 831, 140, 833, 146, 835, 152, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
);
}
#[test]
fn test_routine_handler_multiple_entries() {
let number = 5;
let mut builder = MISimpleBuilder::new();
let mut ret_handler = RoutineHandler::<String>::new_with_labels_l(
"routine0",
["routine0_a", "routine0_b", "routine0_c"],
true,
true,
);
builder.l("routine0");
for i in 0..number {
let cslabel = format!("code{}s", i);
let cretlabel = format!("code{}_ret", i);
ret_handler.add_label(&cslabel, cretlabel);
}
builder.l("routine0_a");
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_return())));
builder.l("routine0_b");
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_return())));
builder.l("routine0_c");
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_return())));
for i in 0..number {
let cslabel = format!("code{}s", i);
let cretlabel = format!("code{}_ret", i);
for j in 0..3 {
let clabel = format!("code{}_{}", i, j);
builder.l(clabel.clone());
builder.i(MINF_MR);
builder.i((
MINF_MR,
MinInfRel::from(ret_handler.jump_to_call_rl(&cslabel, j)),
));
}
builder.l(cretlabel.clone());
builder.i(MINF_MR);
}
ret_handler.install(Some(3), &mut builder);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MR, MINF_MR, 98, 98),
(MINF_MR, MINF_MR, 98, 98).into(),
(MINF_MR, MINF_MR, 98, 98).into(),
(MINF_MR, MINF_MR, 4, 4).into(),
(MINF_MR, MINF_MR, 38, 38).into(),
(MINF_MR, MINF_MR, 6, 6).into(),
(MINF_MR, MINF_MR, 58, 58).into(),
(MINF_MR, MINF_MR, 8, 8).into(),
(MINF_MR, MINF_MR, 78, 78).into(),
(MINF_MR, MINF_MR, 10, 10).into(),
(MINF_MR, MINF_MR, 11, 11).into(),
(MINF_MR, MINF_MR, 40, 40).into(),
(MINF_MR, MINF_MR, 13, 13).into(),
(MINF_MR, MINF_MR, 60, 60).into(),
(MINF_MR, MINF_MR, 15, 15).into(),
(MINF_MR, MINF_MR, 80, 80).into(),
(MINF_MR, MINF_MR, 17, 17).into(),
(MINF_MR, MINF_MR, 18, 18).into(),
(MINF_MR, MINF_MR, 42, 42).into(),
(MINF_MR, MINF_MR, 20, 20).into(),
(MINF_MR, MINF_MR, 62, 62).into(),
(MINF_MR, MINF_MR, 22, 22).into(),
(MINF_MR, MINF_MR, 82, 82).into(),
(MINF_MR, MINF_MR, 24, 24).into(),
(MINF_MR, MINF_MR, 25, 25).into(),
(MINF_MR, MINF_MR, 44, 44).into(),
(MINF_MR, MINF_MR, 27, 27).into(),
(MINF_MR, MINF_MR, 64, 64).into(),
(MINF_MR, MINF_MR, 29, 29).into(),
(MINF_MR, MINF_MR, 84, 84).into(),
(MINF_MR, MINF_MR, 31, 31).into(),
(MINF_MR, MINF_MR, 32, 32).into(),
(MINF_MR, MINF_MR, 46, 46).into(),
(MINF_MR, MINF_MR, 34, 34).into(),
(MINF_MR, MINF_MR, 66, 66).into(),
(MINF_MR, MINF_MR, 36, 36).into(),
(MINF_MR, MINF_MR, 86, 86).into(),
(MINF_MR, MINF_MR, 38, 38).into(),
(MINF_TBRW0, MINF_TBRW0, 39, 39).into(),
(MINF_TBRF, MINF_TBRF, 48, 48).into(),
(MINF_TBRW1, MINF_TBRW1, 41, 41).into(),
(MINF_TBRF, MINF_TBRF, 48, 48).into(),
(MINF_TBRW0, MINF_TBRW0, 43, 43).into(),
(MINF_TBRF, MINF_TBRF, 50, 50).into(),
(MINF_TBRW1, MINF_TBRW1, 45, 45).into(),
(MINF_TBRF, MINF_TBRF, 50, 50).into(),
(MINF_TBRW0, MINF_TBRW0, 47, 47).into(),
(MINF_TBRF, MINF_TBRF, 52, 52).into(),
(MINF_TBRW0, MINF_TBRW0, 49, 49).into(),
(MINF_TBRF, MINF_TBRF, 54, 54).into(),
(MINF_TBRW1, MINF_TBRW1, 51, 51).into(),
(MINF_TBRF, MINF_TBRF, 54, 54).into(),
(MINF_TBRW0, MINF_TBRW0, 53, 53).into(),
(MINF_TBRF, MINF_TBRF, 56, 56).into(),
(MINF_TBRW0, MINF_TBRW0, 55, 55).into(),
(MINF_TBRF, MINF_TBRF, 0, 0).into(),
(MINF_TBRW1, MINF_TBRW1, 57, 57).into(),
(MINF_TBRF, MINF_TBRF, 0, 0).into(),
(MINF_TBRW0, MINF_TBRW0, 59, 59).into(),
(MINF_TBRF, MINF_TBRF, 68, 68).into(),
(MINF_TBRW1, MINF_TBRW1, 61, 61).into(),
(MINF_TBRF, MINF_TBRF, 68, 68).into(),
(MINF_TBRW0, MINF_TBRW0, 63, 63).into(),
(MINF_TBRF, MINF_TBRF, 70, 70).into(),
(MINF_TBRW1, MINF_TBRW1, 65, 65).into(),
(MINF_TBRF, MINF_TBRF, 70, 70).into(),
(MINF_TBRW0, MINF_TBRW0, 67, 67).into(),
(MINF_TBRF, MINF_TBRF, 72, 72).into(),
(MINF_TBRW0, MINF_TBRW0, 69, 69).into(),
(MINF_TBRF, MINF_TBRF, 74, 74).into(),
(MINF_TBRW1, MINF_TBRW1, 71, 71).into(),
(MINF_TBRF, MINF_TBRF, 74, 74).into(),
(MINF_TBRW0, MINF_TBRW0, 73, 73).into(),
(MINF_TBRF, MINF_TBRF, 76, 76).into(),
(MINF_TBRW0, MINF_TBRW0, 75, 75).into(),
(MINF_TBRF, MINF_TBRF, 1, 1).into(),
(MINF_TBRW1, MINF_TBRW1, 77, 77).into(),
(MINF_TBRF, MINF_TBRF, 1, 1).into(),
(MINF_TBRW0, MINF_TBRW0, 79, 79).into(),
(MINF_TBRF, MINF_TBRF, 88, 88).into(),
(MINF_TBRW1, MINF_TBRW1, 81, 81).into(),
(MINF_TBRF, MINF_TBRF, 88, 88).into(),
(MINF_TBRW0, MINF_TBRW0, 83, 83).into(),
(MINF_TBRF, MINF_TBRF, 90, 90).into(),
(MINF_TBRW1, MINF_TBRW1, 85, 85).into(),
(MINF_TBRF, MINF_TBRF, 90, 90).into(),
(MINF_TBRW0, MINF_TBRW0, 87, 87).into(),
(MINF_TBRF, MINF_TBRF, 92, 92).into(),
(MINF_TBRW0, MINF_TBRW0, 89, 89).into(),
(MINF_TBRF, MINF_TBRF, 94, 94).into(),
(MINF_TBRW1, MINF_TBRW1, 91, 91).into(),
(MINF_TBRF, MINF_TBRF, 94, 94).into(),
(MINF_TBRW0, MINF_TBRW0, 93, 93).into(),
(MINF_TBRF, MINF_TBRF, 96, 96).into(),
(MINF_TBRW0, MINF_TBRW0, 95, 95).into(),
(MINF_TBRF, MINF_TBRF, 2, 2).into(),
(MINF_TBRW1, MINF_TBRW1, 97, 97).into(),
(MINF_TBRF, MINF_TBRF, 2, 2).into(),
(MINF_TBB, MINF_TBB, 99, 99).into(),
(MINF_TBRW0, MINF_TBRW0, 100, 100).into(),
(MINF_TBB, MINF_TBB, 101, 103).into(),
(MINF_TBRW0, MINF_TBRW0, 102, 102).into(),
(MINF_TBB, MINF_TBB, 105, 107).into(),
(MINF_TBRW0, MINF_TBRW0, 104, 104).into(),
(MINF_TBB, MINF_TBB, 109, 109).into(),
(MINF_TBRW0, MINF_TBRW0, 106, 106).into(),
(MINF_MR, MINF_MR, 9, 16).into(),
(MINF_TBRW0, MINF_TBRW0, 108, 108).into(),
(MINF_MR, MINF_MR, 23, 30).into(),
(MINF_TBRW0, MINF_TBRW0, 110, 110).into(),
(MINF_MR, MINF_MR, 37, 37).into(),
],
vec![
("code0_0".to_string(), 3),
("code0_1".to_string(), 5),
("code0_2".to_string(), 7),
("code0_ret".to_string(), 9),
("code1_0".to_string(), 10),
("code1_1".to_string(), 12),
("code1_2".to_string(), 14),
("code1_ret".to_string(), 16),
("code2_0".to_string(), 17),
("code2_1".to_string(), 19),
("code2_2".to_string(), 21),
("code2_ret".to_string(), 23),
("code3_0".to_string(), 24),
("code3_1".to_string(), 26),
("code3_2".to_string(), 28),
("code3_ret".to_string(), 30),
("code4_0".to_string(), 31),
("code4_1".to_string(), 33),
("code4_2".to_string(), 35),
("code4_ret".to_string(), 37),
("routine0".to_string(), 0),
("routine0_0_putret_1_0".to_string(), 54),
("routine0_0_putret_1_1".to_string(), 56),
("routine0_0_putret_2_00".to_string(), 48),
("routine0_0_putret_2_01".to_string(), 50),
("routine0_0_putret_2_10".to_string(), 52),
("routine0_0_putret_x_0".to_string(), 38),
("routine0_0_putret_x_1".to_string(), 40),
("routine0_0_putret_x_10".to_string(), 42),
("routine0_0_putret_x_100".to_string(), 46),
("routine0_0_putret_x_11".to_string(), 44),
("routine0_1_putret_1_0".to_string(), 74),
("routine0_1_putret_1_1".to_string(), 76),
("routine0_1_putret_2_00".to_string(), 68),
("routine0_1_putret_2_01".to_string(), 70),
("routine0_1_putret_2_10".to_string(), 72),
("routine0_1_putret_x_0".to_string(), 58),
("routine0_1_putret_x_1".to_string(), 60),
("routine0_1_putret_x_10".to_string(), 62),
("routine0_1_putret_x_100".to_string(), 66),
("routine0_1_putret_x_11".to_string(), 64),
("routine0_2_putret_1_0".to_string(), 94),
("routine0_2_putret_1_1".to_string(), 96),
("routine0_2_putret_2_00".to_string(), 88),
("routine0_2_putret_2_01".to_string(), 90),
("routine0_2_putret_2_10".to_string(), 92),
("routine0_2_putret_x_0".to_string(), 78),
("routine0_2_putret_x_1".to_string(), 80),
("routine0_2_putret_x_10".to_string(), 82),
("routine0_2_putret_x_100".to_string(), 86),
("routine0_2_putret_x_11".to_string(), 84),
("routine0_a".to_string(), 0),
("routine0_b".to_string(), 1),
("routine0_c".to_string(), 2),
("routine0_return".to_string(), 98),
("routine0_return_id_0_0".to_string(), 99),
("routine0_return_id_1_0".to_string(), 101),
("routine0_return_id_1_1".to_string(), 103),
("routine0_return_id_2_00".to_string(), 105),
("routine0_return_id_2_01".to_string(), 107),
("routine0_return_id_2_10".to_string(), 109),
]
),
builder.to_code()
);
}
#[test]
fn test_routine_handler_multiple_entries_one_ret() {
let number = 1;
let mut builder = MISimpleBuilder::new();
let mut ret_handler = RoutineHandler::<String>::new_with_labels_l(
"routine0",
["routine0_a", "routine0_b", "routine0_c"],
true,
true,
);
builder.l("routine0");
for i in 0..number {
let cslabel = format!("code{}s", i);
let cretlabel = format!("code{}_ret", i);
ret_handler.add_label(&cslabel, cretlabel);
}
builder.l("routine0_a");
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_return())));
builder.l("routine0_b");
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_return())));
builder.l("routine0_c");
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_return())));
for i in 0..number {
let cslabel = format!("code{}s", i);
let cretlabel = format!("code{}_ret", i);
for j in 0..3 {
let clabel = format!("code{}_{}", i, j);
builder.l(clabel.clone());
builder.i(MINF_MR);
builder.i((
MINF_MR,
MinInfRel::from(ret_handler.jump_to_call_rl(&cslabel, j)),
));
}
builder.l(cretlabel.clone());
builder.i(MINF_MR);
}
ret_handler.install(None, &mut builder);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MR, MINF_MR, 13, 13),
(MINF_MR, MINF_MR, 13, 13).into(),
(MINF_MR, MINF_MR, 13, 13).into(),
(MINF_MR, MINF_MR, 4, 4).into(),
(MINF_MR, MINF_MR, 10, 10).into(),
(MINF_MR, MINF_MR, 6, 6).into(),
(MINF_MR, MINF_MR, 11, 11).into(),
(MINF_MR, MINF_MR, 8, 8).into(),
(MINF_MR, MINF_MR, 12, 12).into(),
(MINF_MR, MINF_MR, 10, 10).into(),
(MINF_MR, MINF_MR, 0, 0).into(),
(MINF_MR, MINF_MR, 1, 1).into(),
(MINF_MR, MINF_MR, 2, 2).into(),
(MINF_MR, MINF_MR, 9, 9).into(),
],
vec![
("code0_0".to_string(), 3),
("code0_1".to_string(), 5),
("code0_2".to_string(), 7),
("code0_ret".to_string(), 9),
("routine0".to_string(), 0),
("routine0_0_putret_x_0".to_string(), 10),
("routine0_1_putret_x_0".to_string(), 11),
("routine0_2_putret_x_0".to_string(), 12),
("routine0_a".to_string(), 0),
("routine0_b".to_string(), 1),
("routine0_c".to_string(), 2),
("routine0_return".to_string(), 13),
]
),
builder.to_code()
);
}
use min_infmachine::MinInfMachine;
fn gen_return_handler_run_test(
return_bits: usize,
number: usize,
temp_buffer: bool,
forward: bool,
start: usize,
) -> (MinInfMachine<usize>, usize) {
let mut builder = MISimpleBuilder::new();
let start_label = format!("code{}", start);
for _ in 0..10 {
builder.i(MINF_TBRF);
builder.i(MINF_MARF);
}
builder.i((MINF_MR, start_label.clone()));
let mut ret_handler = RoutineHandler::<String>::new("routine0", temp_buffer, forward);
builder.l("routine0");
for i in 0..number {
let cslabel = format!("code{}s", i);
let cretlabel = format!("code{}_ret", i);
ret_handler.add_label(&cslabel, cretlabel);
}
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_return())));
for i in 0..number {
let clabel = format!("code{}", i);
let cslabel = format!("code{}s", i);
let cretlabel = format!("code{}_ret", i);
builder.l(&clabel);
builder.i(MINF_MR);
builder.i((MINF_MR, MinInfRel::from(ret_handler.jump_to_call(&cslabel))));
builder.l(&cretlabel);
builder.i(MINF_STOP);
if i == start {
builder.l("stop_step");
}
}
ret_handler.install(Some(return_bits), &mut builder);
if number == 0 {
builder.l(&start_label);
}
builder.i(MINF_STOP);
let (code, labels) = builder.try_to_code().unwrap();
eprintln!("CodeLen: {:?}", code.len());
let tbl = to_table(code);
let stop_step = if number != 0 {
labels[labels
.binary_search_by_key(&"stop_step".to_string(), |(l, _)| l.clone())
.unwrap()]
.1
} else {
0
};
(MinInfMachine::new_with_table(tbl).unwrap(), stop_step)
}
#[test]
fn test_return_handler_run() {
for temp_buffer in [false, true] {
for forward in [false, true] {
for return_bits in 0..6 {
{
let number = 0;
gen_return_handler_run_test(return_bits, number, temp_buffer, forward, 0);
}
for number in 1..=1 << return_bits {
for start in 0..number {
eprintln!(
"SSX {} {} {} {} {}",
temp_buffer, forward, return_bits, number, start
);
let (mut machine, stop_step) = gen_return_handler_run_test(
return_bits,
number,
temp_buffer,
forward,
start,
);
machine.execute();
let state = machine
.state()
.into_iter()
.enumerate()
.fold(0, |a, (b, v)| a | (usize::from(*v) << b));
if temp_buffer {
assert_eq!(
10, machine.temp_buffer_pos,
"{} {} {} {} {}",
temp_buffer, forward, return_bits, number, start
);
assert!(
(machine.temp_buffer.iter().all(|x| *x == 0)),
"{} {} {} {} {}",
temp_buffer,
forward,
return_bits,
number,
start
);
} else {
assert_eq!(
10, machine.mem_address_pos,
"{} {} {} {} {}",
temp_buffer, forward, return_bits, number, start
);
assert!(
(machine.mem_address.iter().all(|x| *x == 0)),
"{} {} {} {} {}",
temp_buffer,
forward,
return_bits,
number,
start
);
}
eprintln!(
"SS {} {} {} {} {}: {} {}",
temp_buffer, forward, return_bits, number, start, state, stop_step
);
assert_eq!(
state, stop_step,
"{} {} {} {} {}",
temp_buffer, forward, return_bits, number, start
);
}
}
}
}
}
}
fn gen_data_handler_code(
data_bits: usize,
per_bits: usize,
values: &[usize],
temp_buffer: bool,
) -> Vec<usize> {
create_table(|mut builder| {
let mut dh = DataHandler::new("data0", data_bits, per_bits, "end".into(), temp_buffer);
for v in values {
dh.put_data(*v);
}
dh.install(&mut builder);
builder.l("end");
builder.i(MINF_STOP);
builder
})
}
#[test]
fn test_data_handler() {
assert_eq!(
gen_data_handler_code(4, 1, &[2, 5, 6, 7, 10, 13], false),
vec![
385, 12, 451, 14, 389, 16, 455, 16, 393, 18, 459, 20, 461, 22, 399, 24, 465, 24, 467,
26, 405, 28, 407, 30, 473, 30, 411, 32, 477, 32, 415, 34, 481, 34, 960, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 385, 12, 451,
14, 389, 16, 455, 16, 393, 18, 459, 20, 461, 22, 399, 24, 465, 24, 467, 26, 405, 28,
407, 30, 473, 30, 411, 32, 477, 32, 415, 34, 481, 34, 960, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
);
assert_eq!(
gen_data_handler_code(4, 1, &[2, 5, 6, 7, 10, 13], true),
vec![
641, 524, 707, 526, 645, 528, 711, 528, 649, 530, 715, 532, 717, 534, 655, 536, 721,
536, 723, 538, 661, 540, 663, 542, 729, 542, 667, 544, 733, 544, 671, 546, 737, 546,
960, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 641, 524, 707, 526, 645, 528, 711, 528, 649, 530, 715, 532, 717, 534, 655, 536,
721, 536, 723, 538, 661, 540, 663, 542, 729, 542, 667, 544, 733, 544, 671, 546, 737,
546, 960, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0
]
);
assert_eq!(
gen_data_handler_code(4, 2, &[2, 5, 6, 7, 10, 13], false),
vec![
385, 2, 18, 452, 5, 21, 391, 8, 24, 458, 11, 24, 397, 14, 27, 464, 17, 30, 467, 20, 33,
406, 23, 36, 473, 26, 36, 476, 29, 39, 415, 32, 42, 418, 35, 45, 485, 38, 45, 424, 41,
48, 491, 44, 48, 430, 47, 51, 497, 50, 51, 960, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
385, 2, 18, 452, 5, 21, 391, 8, 24, 458, 11, 24, 397, 14, 27, 464, 17, 30, 467, 20, 33,
406, 23, 36, 473, 26, 36, 476, 29, 39, 415, 32, 42, 418, 35, 45, 485, 38, 45, 424, 41,
48, 491, 44, 48, 430, 47, 51, 497, 50, 51, 960, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
);
assert_eq!(
gen_data_handler_code(4, 2, &[2, 5, 6, 7, 10, 13], true),
vec![
641, 514, 530, 708, 517, 533, 647, 520, 536, 714, 523, 536, 653, 526, 539, 720, 529,
542, 723, 532, 545, 662, 535, 548, 729, 538, 548, 732, 541, 551, 671, 544, 554, 674,
547, 557, 741, 550, 557, 680, 553, 560, 747, 556, 560, 686, 559, 563, 753, 562, 563,
960, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 641, 514, 530, 708, 517, 533, 647, 520, 536,
714, 523, 536, 653, 526, 539, 720, 529, 542, 723, 532, 545, 662, 535, 548, 729, 538,
548, 732, 541, 551, 671, 544, 554, 674, 547, 557, 741, 550, 557, 680, 553, 560, 747,
556, 560, 686, 559, 563, 753, 562, 563, 960, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
);
assert_eq!(
gen_data_handler_code(4, 3, &[2, 5, 6, 7, 10, 13], false),
vec![
769, 2, 3, 24, 901, 6, 7, 28, 777, 10, 11, 32, 909, 14, 15, 32, 785, 18, 19, 36, 917,
22, 23, 40, 921, 26, 27, 44, 797, 30, 31, 48, 929, 34, 35, 48, 933, 38, 39, 52, 809,
42, 43, 56, 813, 46, 47, 60, 945, 50, 51, 60, 821, 54, 55, 64, 953, 58, 59, 64, 829,
62, 63, 68, 961, 66, 67, 68, 1920, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 769, 2, 3, 24, 901, 6, 7, 28, 777, 10, 11, 32,
909, 14, 15, 32, 785, 18, 19, 36, 917, 22, 23, 40, 921, 26, 27, 44, 797, 30, 31, 48,
929, 34, 35, 48, 933, 38, 39, 52, 809, 42, 43, 56, 813, 46, 47, 60, 945, 50, 51, 60,
821, 54, 55, 64, 953, 58, 59, 64, 829, 62, 63, 68, 961, 66, 67, 68, 1920, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
);
assert_eq!(
gen_data_handler_code(4, 3, &[2, 5, 6, 7, 10, 13], true),
vec![
1281, 1026, 1027, 1048, 1413, 1030, 1031, 1052, 1289, 1034, 1035, 1056, 1421, 1038,
1039, 1056, 1297, 1042, 1043, 1060, 1429, 1046, 1047, 1064, 1433, 1050, 1051, 1068,
1309, 1054, 1055, 1072, 1441, 1058, 1059, 1072, 1445, 1062, 1063, 1076, 1321, 1066,
1067, 1080, 1325, 1070, 1071, 1084, 1457, 1074, 1075, 1084, 1333, 1078, 1079, 1088,
1465, 1082, 1083, 1088, 1341, 1086, 1087, 1092, 1473, 1090, 1091, 1092, 1920, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1281,
1026, 1027, 1048, 1413, 1030, 1031, 1052, 1289, 1034, 1035, 1056, 1421, 1038, 1039,
1056, 1297, 1042, 1043, 1060, 1429, 1046, 1047, 1064, 1433, 1050, 1051, 1068, 1309,
1054, 1055, 1072, 1441, 1058, 1059, 1072, 1445, 1062, 1063, 1076, 1321, 1066, 1067,
1080, 1325, 1070, 1071, 1084, 1457, 1074, 1075, 1084, 1333, 1078, 1079, 1088, 1465,
1082, 1083, 1088, 1341, 1086, 1087, 1092, 1473, 1090, 1091, 1092, 1920, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
);
}
fn gen_indirect_jump_handler_run_test(
jump_bits: usize,
number: usize,
temp_buffer: bool,
reuse: bool,
start: usize,
) -> (MinInfMachine<usize>, usize) {
let mut builder = MISimpleBuilder::new();
for _ in 0..10 {
builder.i(MINF_TBRF);
builder.i(MINF_MARF);
}
let jump_handler = IndirectJumpHandler::<String>::new(
"myind0",
(0..number).map(|x| format!("target{}", x)),
temp_buffer,
reuse,
);
for i in 0..jump_bits {
let bit = ((start >> i) & 1) != 0;
if temp_buffer {
builder.i(if bit { MINF_TBRW1 } else { MINF_TBRW0 });
builder.i(MINF_TBRF);
} else {
builder.i(if bit { MINF_MARW1 } else { MINF_MARW0 });
builder.i(MINF_MARF);
}
}
builder.i((MINF_MR, jump_handler.ind_jump()));
for i in 0..number {
let tlabel = format!("target{}", i);
builder.l(&tlabel);
builder.i(MINF_MR);
builder.i(MINF_STOP);
if i == start {
builder.l("stop_step");
}
}
jump_handler.install(Some(jump_bits), &mut builder);
builder.i(MINF_STOP);
let (code, labels) = builder.try_to_code().unwrap();
let tbl = to_table(code);
let stop_step = labels[labels
.binary_search_by_key(&"stop_step".to_string(), |(l, _)| l.clone())
.unwrap()]
.1;
(MinInfMachine::new_with_table(tbl).unwrap(), stop_step)
}
#[test]
fn test_indirect_jump_handler_run() {
for temp_buffer in [false, true] {
for jump_bits in 0..6 {
for number in 1..=1 << jump_bits {
for start in 0..number {
eprintln!("SSX {} {} {} {}", temp_buffer, jump_bits, number, start);
let (mut machine, stop_step) = gen_indirect_jump_handler_run_test(
jump_bits,
number,
temp_buffer,
false,
start,
);
machine.execute();
let state = machine
.state()
.into_iter()
.enumerate()
.fold(0, |a, (b, v)| a | (usize::from(*v) << b));
if temp_buffer {
assert_eq!(
10, machine.temp_buffer_pos,
"{} {} {} {}",
temp_buffer, jump_bits, number, start
);
assert!(
(machine.temp_buffer.iter().all(|x| *x == 0)),
"{} {} {} {}",
temp_buffer,
jump_bits,
number,
start
);
} else {
assert_eq!(
10, machine.mem_address_pos,
"{} {} {} {}",
temp_buffer, jump_bits, number, start
);
assert!(
(machine.mem_address.iter().all(|x| *x == 0)),
"{} {} {} {}",
temp_buffer,
jump_bits,
number,
start
);
}
eprintln!(
"SS {} {} {} {}: {} {}",
temp_buffer, jump_bits, number, start, state, stop_step
);
assert_eq!(
state, stop_step,
"{} {} {} {}",
temp_buffer, jump_bits, number, start
);
}
}
}
}
}
#[test]
fn test_indirect_jump_handler_run_reuse() {
for temp_buffer in [false, true] {
for jump_bits in 0..6 {
for number in 1..=1 << jump_bits {
for start in 0..number {
eprintln!("SSX {} {} {} {}", temp_buffer, jump_bits, number, start);
let (mut machine, stop_step) = gen_indirect_jump_handler_run_test(
jump_bits,
number,
temp_buffer,
true,
start,
);
machine.execute();
let state = machine
.state()
.into_iter()
.enumerate()
.fold(0, |a, (b, v)| a | (usize::from(*v) << b));
if temp_buffer {
assert_eq!(
u64::try_from(10 + jump_bits).unwrap(),
machine.temp_buffer_pos,
"{} {} {} {}",
temp_buffer,
jump_bits,
number,
start
);
assert!(
*machine.temp_buffer.get(0).unwrap_or(&0)
== u32::try_from(start << 10).unwrap(),
"{} {} {} {}",
temp_buffer,
jump_bits,
number,
start
);
} else {
assert_eq!(
u64::try_from(10 + jump_bits).unwrap(),
machine.mem_address_pos,
"{} {} {} {}",
temp_buffer,
jump_bits,
number,
start
);
assert!(
*machine.mem_address.get(0).unwrap_or(&0)
== u32::try_from(start << 10).unwrap(),
"{} {} {} {}",
temp_buffer,
jump_bits,
number,
start
);
}
eprintln!(
"SS {} {} {} {}: {} {}",
temp_buffer, jump_bits, number, start, state, stop_step
);
assert_eq!(
state, stop_step,
"{} {} {} {}",
temp_buffer, jump_bits, number, start
);
}
}
}
}
}
fn gen_long_data_handler_run_test(
temp_buffer: bool,
per_bits: usize,
data: (&[u8], u8, u8),
) -> MinInfMachine<usize> {
let mut builder = MISimpleBuilder::new();
let mut ldh = LongDataHandler::new("test1", temp_buffer, per_bits);
let start = ldh.add_data(data, "next_step");
builder.i((MINF_MR, start));
builder.l("next_step");
builder.i(MINF_STOP);
ldh.install(&mut builder);
let (code, _) = builder.try_to_code().unwrap();
let tbl = to_table(code);
MinInfMachine::new_with_table(tbl).unwrap()
}
fn run_long_data_handler_run_test(temp_buffer: bool, per_bits: usize, data: (&[u8], u8, u8)) {
println!("Test: {} {} {:x?}", temp_buffer, per_bits, data);
let mut machine = gen_long_data_handler_run_test(temp_buffer, per_bits, data);
machine.execute();
let data_len = 8 * data.0.len() + data.2 as usize;
let (res_data_pos, res_data, stack_pos, stack) = if temp_buffer {
(
machine.temp_buffer_pos,
&machine.temp_buffer,
machine.mem_address_pos,
&machine.mem_address,
)
} else {
(
machine.mem_address_pos,
&machine.mem_address,
machine.temp_buffer_pos,
&machine.temp_buffer,
)
};
assert_eq!(
stack_pos, 0,
"{} {} ({:?}, {}, {})",
temp_buffer, per_bits, data.0, data.1, data.2
);
assert!(
stack.into_iter().all(|x| *x == 0),
"{} {} ({:?}, {}, {})",
temp_buffer,
per_bits,
data.0,
data.1,
data.2
);
assert_eq!(
res_data_pos,
u64::try_from(per_bits * data_len).unwrap(),
"{} {} ({:?}, {}, {})",
temp_buffer,
per_bits,
data.0,
data.1,
data.2
);
for i in 0..data_len {
let expv = if i < (data_len & !7) {
((data.0[i >> 3] >> (i & 7)) & 1) != 0
} else {
((data.1 >> (i & 7)) & 1) != 0
};
let bit = i * per_bits;
assert_eq!(
expv,
((res_data.get(bit >> 5).unwrap_or(&0) >> (bit & 31)) & 1) != 0,
"{} {} ({:?}, {}, {})",
temp_buffer,
per_bits,
data.0,
data.1,
data.2
);
for j in 1..per_bits {
let bit = i * per_bits + j;
assert_eq!(
false,
((res_data.get(bit >> 5).unwrap_or(&0) >> (bit & 31)) & 1) != 0,
"{} {} ({:?}, {}, {})",
temp_buffer,
per_bits,
data.0,
data.1,
data.2
);
}
}
}
#[test]
fn test_long_data_handler_run() {
for temp_buffer in [false, true] {
for per_bits in 1..=5 {
for data in [
(&[0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef][..], 0, 0),
(&[0x8c, 0x04, 0x9d, 0x15, 0xae, 0x26, 0xbf, 0x37][..], 0, 0),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 0, 0),
(&[0x21, 0x63, 0x72, 0x63, 0x21, 0x63, 0x72, 0x63][..], 0, 0),
(&[0x22, 0x53, 0x44, 0x2a, 0x3b, 0x51, 0x55, 0x66][..], 0, 0),
(&[0x22, 0x53, 0x44, 0x3b, 0x3b, 0x51, 0x22, 0x53][..], 0, 0),
(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..], 0, 0),
(&[0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44][..], 0, 0),
(
&[
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78,
0x9a, 0xbc, 0xde, 0xf0,
][..],
0,
0,
),
(
&[
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab, 0xcd, 0xef,
][..],
0,
0,
),
(
&[
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
][..],
0,
0,
),
(
&[
0x8c, 0x04, 0x9d, 0x15, 0xae, 0x26, 0xbf, 0x37, 0x21, 0x53, 0xca, 0x2a,
0x3b, 0x51, 0xb1, 0xc3,
][..],
0,
0,
),
(
&[
0x22, 0x53, 0x44, 0x3b, 0x3b, 0x51, 0x22, 0x53, 0x8c, 0x04, 0x9d, 0x15,
0xae, 0x26, 0xbf, 0x37, 0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3,
][..],
0,
0,
),
(&[0x01, 0x23, 0x45, 0x67][..], 0, 0),
(&[0x75, 0x75, 0x57, 0x27][..], 0, 0),
(&[0x39, 0xca][..], 0, 0),
(&[0x41, 0x14][..], 0, 0),
(&[0x22, 0x22][..], 0, 0),
(&[0x38][..], 0, 0),
(&[0x55][..], 0, 0),
(&[][..], 0, 0),
(&[][..], 0xd, 4),
(&[0x01, 0x23, 0x45, 0x67, 0x89, 0xab][..], 0, 0),
(&[0x01, 0x23, 0x89, 0xab, 0x89, 0xab][..], 0, 0),
(&[0x89, 0xab, 0x89, 0xab, 0x89, 0xab][..], 0, 0),
(&[0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd][..], 0, 0),
(&[0x01, 0x23, 0x45][..], 0, 0),
(&[0x45, 0x45, 0x45][..], 0, 0),
(&[0x01, 0x23, 0x45, 0x67, 0x89][..], 0, 0),
(&[0x89, 0x23, 0x45, 0x89, 0x89][..], 0, 0),
(&[0x89, 0x23, 0x89, 0x89, 0x89][..], 0, 0),
(&[0x89, 0x89, 0x89, 0x89, 0x89][..], 0, 0),
(&[0xad, 0x23, 0xad][..], 0, 0),
(&[0x01, 0x23, 0x45, 0x67, 0x89, 0xab][..], 0xd, 4),
(&[0x01, 0x23, 0x45][..], 0xe, 4),
(&[0xa7, 0x23, 0x45, 0x67, 0x89, 0xab][..], 0xd, 4),
(&[0xa7, 0x23, 0x45, 0x67, 0x89, 0xab][..], 0xa, 4),
(&[0x61, 0x63, 0x45, 0x67, 0x89, 0x6b, 0xcd][..], 0x6, 4),
(&[0x61, 0x66, 0x45, 0x67, 0x89, 0x66, 0xcd][..], 0x6, 4),
(&[0xe0, 0x23, 0x45][..], 0xe, 4),
(&[0x0e, 0x23, 0x45][..], 0xe, 4),
(&[0xee, 0xee, 0xee][..], 0xe, 4),
(&[0xe2, 0xe4, 0x1e][..], 0xe, 4),
(&[0x2a, 0xb4][..], 0xe, 4),
(&[0x0e, 0x23][..], 0xe, 4),
(&[0x01, 0x23, 0x45, 0x67][..], 5, 3),
(&[0x01, 0x23, 0x45, 0x67][..], 6, 3),
(&[0x01, 0x23, 0x45, 0x67][..], 3, 3),
(&[0x01, 0x23, 0x45, 0x67][..], 1, 2),
(&[0x01, 0x23, 0x45, 0x67][..], 2, 2),
(&[0x01, 0x23, 0x45, 0x67][..], 1, 1),
(&[0x01, 0x23, 0x45, 0x67][..], 0, 1),
(&[0x01, 0x23, 0x45, 0x67][..], 0x6c, 7),
(&[0x01, 0x23, 0x45, 0x67][..], 0x2c, 6),
(&[0x01, 0x23, 0x45, 0x67, 0x89, 0xab][..], 5, 3),
(&[0x01, 0x23, 0x89, 0xab, 0x89, 0xab][..], 3, 3),
(&[0x89, 0xab, 0x89, 0xab, 0x89, 0xab][..], 5, 3),
(&[0x01, 0x23, 0x45, 0x67, 0x89, 0xab][..], 0x59, 7),
(&[0x01, 0x23, 0x89, 0xab, 0x89, 0xab][..], 0x39, 7),
(&[0x89, 0xab, 0x89, 0xab, 0x89, 0xab][..], 0x59, 7),
(&[0x01, 0x23, 0x45, 0x67, 0x89][..], 5, 3),
(&[0x89, 0x23, 0x45, 0x89, 0x89][..], 6, 3),
(&[0x89, 0x23, 0x89, 0x89, 0x89][..], 6, 3),
(&[0x89, 0x89, 0x89, 0x89, 0x89][..], 6, 3),
(&[0x01, 0x23, 0x45, 0x67, 0x89][..], 0x56, 7),
(&[0x89, 0x23, 0x45, 0x89, 0x89][..], 0x66, 7),
(&[0x01, 0x23, 0x45, 0x67, 0x89][..], 0x58, 7),
(&[0x89, 0x23, 0x45, 0x89, 0x89][..], 0x68, 7),
(&[0x89, 0x23, 0x89, 0x89, 0x89][..], 0x68, 7),
(&[0x89, 0x89, 0x89, 0x89, 0x89][..], 0x68, 7),
(&[0x71, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd][..], 7, 3),
(&[0x71, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd][..], 6, 3),
(&[0x91, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd][..], 0x79, 7),
(&[0x91, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd][..], 0x69, 7),
(&[0x01, 0x23, 0x45, 0x67][..], 6, 3),
(&[0x75, 0x75, 0x57, 0x27][..], 6, 3),
(&[0x01, 0x23, 0x45, 0x67][..], 0x63, 7),
(&[0x75, 0x75, 0x57, 0x27][..], 0x63, 7),
(&[0x41, 0x23, 0x45][..], 4, 3),
(&[0x41, 0x23, 0x45][..], 6, 3),
(&[0x41, 0x23, 0x45][..], 1, 1),
(&[0x41, 0x23, 0x45][..], 0x4b, 7),
(&[0x41, 0xb3, 0x45][..], 0x4b, 7),
(&[0x41, 0x23, 0xb5][..], 0x6b, 7),
(&[0x4b, 0x23, 0x45][..], 0x1b, 5),
(&[0x2a, 0xb4][..], 2, 2),
(&[0x0e, 0x23][..], 1, 2),
(&[0x2a, 0xb4][..], 0x2e, 6),
(&[0x0e, 0x23][..], 0x1e, 6),
(&[0x2a][..], 2, 2),
(&[0x2a][..], 0x24, 6),
(&[0x2a][..], 0x2a, 6),
(&[][..], 0x5d, 7),
(&[][..], 0x6d, 7),
(&[][..], 6, 3),
(&[][..], 5, 3),
(&[][..], 4, 3),
(&[][..], 3, 3),
(&[][..], 3, 2),
(&[][..], 2, 2),
(&[][..], 1, 2),
(&[][..], 1, 1),
(&[][..], 0, 1),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x6d, 0x41, 0x45, 0x67,
][..],
0,
0,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x6d, 0x41][..],
0,
0,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x3b, 0x41][..],
0,
0,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xca, 0x2a][..],
0,
0,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x31][..],
0,
0,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xca][..],
0,
0,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..],
0x5,
4,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..],
0x7,
4,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab, 0xcd,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x21, 0x53, 0xca, 0x2a,
0x89, 0xab, 0xcd,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab, 0xb1,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x89, 0x23, 0x45, 0x89,
0x89,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x89, 0x23, 0x89, 0x89,
0x89,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xe0, 0x23, 0x45,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab,
][..],
0xb,
4,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab, 0xcd,
][..],
0xe,
4,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab, 0xcd,
][..],
0x6,
4,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x6d, 0x41, 0x45, 0x67,
][..],
0x6,
4,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xe0, 0x23, 0x45,
][..],
5,
4,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xe0, 0x23, 0x45,
][..],
6,
4,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xca, 0x2a][..],
0x7,
4,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xbb, 0xda][..],
0x7,
4,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xbb][..],
0xb,
4,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x6d, 0x41, 0x45, 0x67,
][..],
3,
2,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x6d, 0x41, 0x45, 0x67,
][..],
6,
3,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x3b, 0x41][..],
5,
3,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xca, 0x2a][..],
6,
3,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xca][..],
4,
3,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..],
0x45,
7,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab,
][..],
6,
3,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab, 0xcd,
][..],
6,
3,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x89, 0x23, 0x89, 0x89,
0x89,
][..],
4,
3,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xe0, 0x23, 0x45,
][..],
4,
3,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x6d, 0x41, 0x45, 0x67,
][..],
0x3d,
6,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x6d, 0x41, 0x45, 0x67,
][..],
0x5a,
7,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xbb, 0xda][..],
0x67,
7,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0xbb][..],
0x3b,
7,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab,
][..],
0x6e,
7,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab, 0xcd,
][..],
0x6c,
7,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x89, 0x23, 0x89, 0x89,
0x89,
][..],
0x42,
7,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..],
0x42,
7,
),
(
&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..],
0x62,
7,
),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 6, 3),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 5, 3),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 3, 3),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 3, 2),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 2, 2),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 0, 2),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 1, 1),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x0a, 0xb2, 0x5d, 0x4e,
0xf4, 0xba, 0x39, 0x2a, 0x6d, 0x41, 0x45, 0x67,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x0a, 0xb2, 0x5d, 0x4e,
0xf4, 0xba, 0x39, 0x2a, 0x6d, 0x41,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x0a, 0xb2, 0x5d, 0x4e,
0xf4, 0xba, 0x39, 0x2a, 0x6d, 0x41, 0x45,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x0a, 0xb2, 0x5d, 0x4e,
0xf4, 0xba, 0x39, 0x2a, 0x6d,
][..],
0,
0,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x0a, 0xb2, 0x5d, 0x4e,
0xf4, 0xba, 0x39, 0x2a, 0x6d, 0x41, 0x45,
][..],
7,
4,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x0a, 0xb2, 0x5d, 0x4e,
0xf4, 0xba, 0x39, 0x2a, 0x6d,
][..],
8,
4,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x0a, 0xb2, 0x5d, 0x4e,
0xf4, 0xba, 0x39, 0x2a, 0x6d,
][..],
0x38,
6,
),
(
&[
0x0a, 0xb2, 0x5d, 0x4e, 0xf4, 0xba, 0x39, 0x2a, 0x0a, 0xb2, 0x5d, 0x4e,
0xf4, 0xba, 0x39, 0x2a, 0x6d,
][..],
0x38,
6,
),
(
&[
0x0a, 0xb2, 0x5d, 0x4e, 0xf4, 0xba, 0x39, 0x2a, 0x0a, 0xb2, 0x5d, 0x4e,
0xf4, 0xba, 0x39, 0x2a, 0x0a, 0xb2, 0x5d, 0x4e, 0xf4, 0xba, 0x39, 0x2a,
0x6d,
][..],
0x38,
6,
),
(
&[
0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3, 0x0a, 0xb2, 0x5d, 0x4e,
0xf4, 0xba, 0x39, 0x2a,
][..],
6,
3,
),
("Alice and cat. Where is my cat?".as_bytes(), 0, 0),
(
"Ben and dog. Where is my dog? Can you find my dog?".as_bytes(),
0,
0,
),
] {
run_long_data_handler_run_test(temp_buffer, per_bits, data);
}
}
}
}
const BIT_GAP: usize = 10;
fn gen_multi_long_data_handler_run_test(
temp_buffer: bool,
per_bits: usize,
datas: &[(&[u8], u8, u8)],
) -> (MinInfMachine<usize>, usize) {
let mut builder = MISimpleBuilder::new();
let mut ldh = LongDataHandler::new("test1", temp_buffer, per_bits);
for (i, data) in datas.into_iter().enumerate() {
let label = format!("next_step_{}", i);
let start = ldh.add_data(*data, label.clone());
builder.i((MINF_MR, start));
builder.l(label);
for _ in 0..BIT_GAP {
if temp_buffer {
builder.i(MINF_TBRF);
} else {
builder.i(MINF_MARF);
}
}
}
builder.i(MINF_STOP);
let max_ret_bits = ldh.install(&mut builder);
let (code, _) = builder.try_to_code().unwrap();
let tbl = to_table(code);
(MinInfMachine::new_with_table(tbl).unwrap(), max_ret_bits)
}
fn run_multi_long_data_handler_run_test(
temp_buffer: bool,
per_bits: usize,
datas: Vec<(&[u8], u8, u8)>,
) {
println!("Test: {} {} {:x?}", temp_buffer, per_bits, &datas);
let mut machine = gen_multi_long_data_handler_run_test(temp_buffer, per_bits, &datas).0;
machine.execute();
let (res_data_pos, res_data, stack_pos, stack) = if temp_buffer {
(
machine.temp_buffer_pos,
&machine.temp_buffer,
machine.mem_address_pos,
&machine.mem_address,
)
} else {
(
machine.mem_address_pos,
&machine.mem_address,
machine.temp_buffer_pos,
&machine.temp_buffer,
)
};
assert_eq!(stack_pos, 0, "{} {} {:?}", temp_buffer, per_bits, datas);
assert!(
stack.into_iter().all(|x| *x == 0),
"{} {} {:?}",
temp_buffer,
per_bits,
datas
);
let mut start = 0;
for (it, data) in datas.clone().into_iter().enumerate() {
let data_len = 8 * data.0.len() + data.2 as usize;
for i in 0..data_len {
let expv = if i < (data_len & !7) {
((data.0[i >> 3] >> (i & 7)) & 1) != 0
} else {
((data.1 >> (i & 7)) & 1) != 0
};
let bit = start + i * per_bits;
assert_eq!(
expv,
((res_data.get(bit >> 5).unwrap_or(&0) >> (bit & 31)) & 1) != 0,
"{} {} {:?}: {}",
temp_buffer,
per_bits,
datas,
it
);
for j in 1..per_bits {
let bit = start + i * per_bits + j;
assert_eq!(
false,
((res_data.get(bit >> 5).unwrap_or(&0) >> (bit & 31)) & 1) != 0,
"{} {} {:?}: {}",
temp_buffer,
per_bits,
datas,
it
);
}
}
for i in 0..BIT_GAP {
let bit = start + data_len * per_bits + i;
assert_eq!(
false,
((res_data.get(bit >> 5).unwrap_or(&0) >> (bit & 31)) & 1) != 0,
"{} {} {:?}: {}",
temp_buffer,
per_bits,
datas,
it
);
}
start += data_len * per_bits + BIT_GAP;
}
assert_eq!(
res_data_pos,
u64::try_from(start).unwrap(),
"{} {} {:?}",
temp_buffer,
per_bits,
datas
);
}
#[test]
fn test_multi_long_data_handler_run() {
for temp_buffer in [false, true] {
for per_bits in 1..=5 {
for datas in [
vec![(&[0xda][..], 0, 0), (&[0xdc][..], 0, 0)],
vec![(&[0xda][..], 0, 0), (&[0xda][..], 0, 0)],
vec![
(&[0xda, 0x1e, 0x41, 0x3f][..], 0, 0),
(&[0xdb, 0x7e, 0x42, 0x3f][..], 0, 0),
],
vec![
(&[0xda, 0x1e, 0x41, 0x3f][..], 0, 0),
(&[0xda, 0x1e, 0x41, 0x3f][..], 0, 0),
],
vec![(&[][..], 14, 4), (&[][..], 10, 4)],
vec![(&[][..], 6, 3), (&[][..], 5, 3)],
vec![(&[][..], 6, 3), (&[][..], 3, 3), (&[][..], 6, 3)],
vec![
(&[0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef][..], 0, 0),
(&[0x8c, 0x04, 0x9d, 0x15, 0xae, 0x26, 0xbf, 0x37][..], 0, 0),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 0, 0),
],
vec![
(&[0x21, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef][..], 0, 0),
(&[0x21, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef][..], 0, 0),
],
vec![
(&[0x21, 0x23, 0x45, 0x67, 0x21, 0x23, 0x45, 0x67][..], 0, 0),
(&[0x21, 0x23, 0x45, 0x67, 0x21, 0x23, 0x45, 0x67][..], 0, 0),
],
vec![
(
&[
0x21, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x21, 0x23, 0x45, 0x67,
0x89, 0xab, 0xcd, 0xef,
][..],
0,
0,
),
(
&[
0x21, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x21, 0x23, 0x45, 0x67,
0x89, 0xab, 0xcd, 0xef,
][..],
0,
0,
),
],
vec![
(&[0x61, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef][..], 0, 0),
(&[0x61, 0x23, 0x67, 0x45, 0x89, 0xbb, 0xcd, 0xff][..], 0, 0),
(&[0xda, 0xca, 0xff, 0xeb, 0xda, 0xdb, 0x89, 0xc3][..], 0, 0),
],
vec![
(&[0x61, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef][..], 6, 3),
(&[0x61, 0x23, 0x67, 0x45, 0x89, 0xbb, 0xcd, 0xff][..], 6, 3),
(&[0xda, 0xca, 0xff, 0xeb, 0xda, 0xdb, 0x89, 0xc3][..], 6, 3),
],
vec![
(&[0x61, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef][..], 6, 3),
(&[0x61, 0x23, 0x67, 0x45, 0x89, 0xbb, 0xcd, 0xff][..], 5, 3),
(&[0xda, 0xca, 0xff, 0xeb, 0xda, 0xdb, 0x89, 0xc3][..], 2, 3),
],
vec![
(
&[0x61, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xa2, 0xb6][..],
6,
3,
),
(
&[0x61, 0x23, 0x67, 0x45, 0x89, 0xbb, 0xcd, 0xff, 0xa2, 0xb6][..],
6,
3,
),
(
&[0xda, 0xca, 0xff, 0xeb, 0xda, 0xdb, 0x89, 0xc3, 0xa2, 0xb6][..],
6,
3,
),
],
vec![
(
&[0x61, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xa1, 0xb6][..],
1,
3,
),
(
&[0x61, 0x23, 0x67, 0x45, 0x89, 0xbb, 0xcd, 0xff, 0x23, 0xb5][..],
7,
3,
),
(
&[0xda, 0xca, 0xff, 0xeb, 0xda, 0xdb, 0x89, 0xc3, 0xa2, 0xab][..],
5,
3,
),
],
vec![
(
&[0x61, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xa2, 0xb6][..],
0x6d,
7,
),
(
&[0x61, 0x23, 0x67, 0x45, 0x89, 0xbb, 0xcd, 0xff, 0xa2, 0xb6][..],
0x6d,
7,
),
(
&[0xda, 0xca, 0xff, 0xeb, 0xda, 0xdb, 0x89, 0xc3, 0xa2, 0xb6][..],
0x6d,
7,
),
],
vec![
(
&[0x61, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xa1, 0xb6][..],
0x1e,
7,
),
(
&[0x61, 0x23, 0x67, 0x45, 0x89, 0xbb, 0xcd, 0xff, 0x23, 0xb5][..],
0x7a,
7,
),
(
&[0xda, 0xca, 0xff, 0xeb, 0xda, 0xdb, 0x89, 0xc3, 0xa2, 0xab][..],
0x5c,
7,
),
],
vec![
(&[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xbb][..], 0x0a, 4),
(
&[0xab, 0xba, 0xab, 0xbb, 0xca, 0x3b, 0x3a, 0xda][..],
0x1a,
5,
),
(&[0x00, 0x00, 0x23, 0x34, 0xad, 0x33, 0xba][..], 0x4b, 6),
],
] {
run_multi_long_data_handler_run_test(temp_buffer, per_bits, datas);
}
}
}
}
#[test]
fn test_multi_long_data_handler_max_ret_bits() {
for temp_buffer in [false, true] {
for per_bits in 1..=5 {
for (datas, exp_max_ret_bits) in [
(vec![(&[0xda][..], 0, 0), (&[0xdc][..], 0, 0)], 1),
(vec![(&[0xda][..], 0, 0), (&[0xda][..], 0, 0)], 1),
(
vec![
(&[0xda, 0x1e, 0x41, 0x3f][..], 0, 0),
(&[0xdb, 0x7e, 0x42, 0x3f][..], 0, 0),
],
1,
),
(
vec![
(&[0xda, 0x1e, 0x41, 0x3f][..], 0, 0),
(&[0xda, 0x1e, 0x41, 0x3f][..], 0, 0),
],
2,
),
(vec![(&[][..], 14, 4), (&[][..], 10, 4)], 0),
(vec![(&[][..], 6, 3), (&[][..], 5, 3)], 0),
(vec![(&[][..], 6, 3), (&[][..], 3, 3), (&[][..], 6, 3)], 0),
(
vec![
(&[0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef][..], 0, 0),
(&[0x8c, 0x04, 0x9d, 0x15, 0xae, 0x26, 0xbf, 0x37][..], 0, 0),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 0, 0),
],
3,
),
(
vec![
(&[0x01, 0x23, 0x3b, 0x51, 0x89, 0xab, 0xcd, 0xef][..], 0, 0),
(&[0x8c, 0x04, 0x9d, 0x15, 0xae, 0x26, 0xbf, 0x37][..], 0, 0),
(&[0x21, 0x53, 0xca, 0x2a, 0x3b, 0x51, 0xb1, 0xc3][..], 0, 0),
],
4,
),
(
vec![
(
&[0x61, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xa1, 0xb6][..],
0x1e,
7,
),
(
&[0x61, 0x23, 0x67, 0x45, 0x89, 0xbb, 0xcd, 0xff, 0x23, 0xb5][..],
0x7a,
7,
),
(
&[0xda, 0xca, 0xff, 0xeb, 0xda, 0xdb, 0x89, 0xc3, 0xa2, 0xab][..],
0x5c,
7,
),
],
4,
),
(
vec![
(&[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xbb][..], 0x0a, 4),
(
&[0xab, 0xba, 0xab, 0xbb, 0xca, 0x3b, 0x3a, 0xda][..],
0x1a,
5,
),
(&[0x00, 0x00, 0x23, 0x34, 0xad, 0x33, 0xba][..], 0x4b, 6),
],
7,
),
] {
assert_eq!(
exp_max_ret_bits,
gen_multi_long_data_handler_run_test(temp_buffer, per_bits, &datas).1,
"{} {}: {}",
temp_buffer,
per_bits,
datas
.into_iter()
.map(|x| format!("({:x?}, {:x?}, {})", x.0, x.1, x.2))
.collect::<Vec<_>>()
.join(",")
);
}
}
}
}
#[test]
fn test_long_data_handler_calls() {
let mut builder = MISimpleBuilder::new();
let mut ldhm = LongDataHandler::<String>::new("md", false, 2);
let mut ldh = LongDataHandler::<String>::new("td", true, 1);
ldh.call_01(&mut builder, (&[], 12, 4), MINF_MR);
ldh.call(&mut builder, (&[], 12, 4), MINF_TBR, MINF_MAR);
ldh.call_fr0_01(&mut builder, (&[], 13, 4), MINF_MARF, "stop");
ldh.call_fr0(&mut builder, (&[], 11, 4), MINF_TBRW0, MINF_MARW1, "stop");
ldh.call_fr1_01(&mut builder, (&[], 2, 4), MINF_MARW1, "stop2");
ldh.call_fr1(&mut builder, (&[], 7, 4), MINF_TBRF, MINF_MAB, "stop2");
ldh.call_2_01(&mut builder, (&[], 9, 4), (&[], 5, 4), MINF_MARW0);
ldh.call_2(
&mut builder,
(&[], 8, 4),
(&[], 6, 4),
MINF_TBRW0,
MINF_TBRF,
);
ldh.call_2x_01(
&mut ldhm,
&mut builder,
(&[], 7, 4),
(&[], 10, 4),
MINF_MARW0,
);
ldhm.call_2x(
&mut ldh,
&mut builder,
(&[], 9, 4),
(&[], 5, 4),
MINF_TBRW0,
MINF_MARW1,
);
builder.l("stop");
builder.i(MINF_STOP);
builder.l("stop2");
builder.i(MINF_STOP);
ldhm.install(&mut builder);
ldh.install(&mut builder);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MR, MINF_MR, 128, 128),
(MINF_TBR, MINF_MAR, 130, 130).into(),
(MINF_MARF, MINF_MARF, 143, 10).into(),
(MINF_TBRW0, MINF_MARW1, 118, 10).into(),
(MINF_MARW1, MINF_MARW1, 11, 48).into(),
(MINF_TBRF, MINF_MAB, 11, 83).into(),
(MINF_MARW0, MINF_MARW0, 108, 58).into(),
(MINF_TBRW0, MINF_TBRF, 98, 73).into(),
(MINF_MARW0, MINF_MARW0, 85, 38).into(),
(MINF_TBRW0, MINF_MARW1, 24, 60).into(),
(MINF_STOP, MINF_STOP, 11, 11).into(),
(MINF_STOP, MINF_STOP, 12, 12).into(),
(MINF_MARW1, MINF_MARW1, 13, 13).into(),
(MINF_MARF, MINF_MARF, 14, 14).into(),
(MINF_MARF, MINF_MARF, 15, 15).into(),
(MINF_MARW0, MINF_MARW0, 16, 16).into(),
(MINF_MARF, MINF_MARF, 17, 17).into(),
(MINF_MARF, MINF_MARF, 18, 18).into(),
(MINF_MARW0, MINF_MARW0, 19, 19).into(),
(MINF_MARF, MINF_MARF, 20, 20).into(),
(MINF_MARF, MINF_MARF, 21, 21).into(),
(MINF_MARW1, MINF_MARW1, 22, 22).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MARF, MINF_MARF, 25, 25).into(),
(MINF_MR, MINF_MR, 12, 12).into(),
(MINF_MR, MINF_MR, 10, 10).into(),
(MINF_MARW0, MINF_MARW0, 27, 27).into(),
(MINF_MARF, MINF_MARF, 28, 28).into(),
(MINF_MARF, MINF_MARF, 29, 29).into(),
(MINF_MARW1, MINF_MARW1, 30, 30).into(),
(MINF_MARF, MINF_MARF, 31, 31).into(),
(MINF_MARF, MINF_MARF, 32, 32).into(),
(MINF_MARW0, MINF_MARW0, 33, 33).into(),
(MINF_MARF, MINF_MARF, 34, 34).into(),
(MINF_MARF, MINF_MARF, 35, 35).into(),
(MINF_MARW1, MINF_MARW1, 36, 36).into(),
(MINF_MARF, MINF_MARF, 37, 37).into(),
(MINF_MARF, MINF_MARF, 39, 39).into(),
(MINF_MR, MINF_MR, 26, 26).into(),
(MINF_MR, MINF_MR, 9, 9).into(),
(MINF_TBRW0, MINF_TBRW0, 41, 41).into(),
(MINF_TBRF, MINF_TBRF, 42, 42).into(),
(MINF_TBRW1, MINF_TBRW1, 43, 43).into(),
(MINF_TBRF, MINF_TBRF, 44, 44).into(),
(MINF_TBRW0, MINF_TBRW0, 45, 45).into(),
(MINF_TBRF, MINF_TBRF, 46, 46).into(),
(MINF_TBRW0, MINF_TBRW0, 47, 47).into(),
(MINF_TBRF, MINF_TBRF, 49, 49).into(),
(MINF_MR, MINF_MR, 40, 40).into(),
(MINF_MR, MINF_MR, 5, 5).into(),
(MINF_TBRW1, MINF_TBRW1, 51, 51).into(),
(MINF_TBRF, MINF_TBRF, 52, 52).into(),
(MINF_TBRW0, MINF_TBRW0, 53, 53).into(),
(MINF_TBRF, MINF_TBRF, 54, 54).into(),
(MINF_TBRW1, MINF_TBRW1, 55, 55).into(),
(MINF_TBRF, MINF_TBRF, 56, 56).into(),
(MINF_TBRW0, MINF_TBRW0, 57, 57).into(),
(MINF_TBRF, MINF_TBRF, 62, 62).into(),
(MINF_MARW0, MINF_MARW0, 59, 59).into(),
(MINF_MARF, MINF_MARF, 50, 50).into(),
(MINF_MARW1, MINF_MARW1, 61, 61).into(),
(MINF_MARF, MINF_MARF, 50, 50).into(),
(MINF_MAB, MINF_MAB, 63, 63).into(),
(MINF_MARW0, MINF_MARW0, 64, 64).into(),
(MINF_MR, MINF_MR, 7, 10).into(),
(MINF_TBRW0, MINF_TBRW0, 66, 66).into(),
(MINF_TBRF, MINF_TBRF, 67, 67).into(),
(MINF_TBRW1, MINF_TBRW1, 68, 68).into(),
(MINF_TBRF, MINF_TBRF, 69, 69).into(),
(MINF_TBRW1, MINF_TBRW1, 70, 70).into(),
(MINF_TBRF, MINF_TBRF, 71, 71).into(),
(MINF_TBRW0, MINF_TBRW0, 72, 72).into(),
(MINF_TBRF, MINF_TBRF, 74, 74).into(),
(MINF_MR, MINF_MR, 65, 65).into(),
(MINF_MR, MINF_MR, 8, 8).into(),
(MINF_TBRW1, MINF_TBRW1, 76, 76).into(),
(MINF_TBRF, MINF_TBRF, 77, 77).into(),
(MINF_TBRW1, MINF_TBRW1, 78, 78).into(),
(MINF_TBRF, MINF_TBRF, 79, 79).into(),
(MINF_TBRW1, MINF_TBRW1, 80, 80).into(),
(MINF_TBRF, MINF_TBRF, 81, 81).into(),
(MINF_TBRW0, MINF_TBRW0, 82, 82).into(),
(MINF_TBRF, MINF_TBRF, 87, 87).into(),
(MINF_MARW0, MINF_MARW0, 84, 84).into(),
(MINF_MARF, MINF_MARF, 75, 75).into(),
(MINF_MARW1, MINF_MARW1, 86, 86).into(),
(MINF_MARF, MINF_MARF, 75, 75).into(),
(MINF_MAB, MINF_MAB, 88, 88).into(),
(MINF_MARW0, MINF_MARW0, 89, 89).into(),
(MINF_MR, MINF_MR, 6, 9).into(),
(MINF_TBRW0, MINF_TBRW0, 91, 91).into(),
(MINF_TBRF, MINF_TBRF, 92, 92).into(),
(MINF_TBRW0, MINF_TBRW0, 93, 93).into(),
(MINF_TBRF, MINF_TBRF, 94, 94).into(),
(MINF_TBRW0, MINF_TBRW0, 95, 95).into(),
(MINF_TBRF, MINF_TBRF, 96, 96).into(),
(MINF_TBRW1, MINF_TBRW1, 97, 97).into(),
(MINF_TBRF, MINF_TBRF, 99, 99).into(),
(MINF_MR, MINF_MR, 90, 90).into(),
(MINF_MR, MINF_MR, 8, 8).into(),
(MINF_TBRW1, MINF_TBRW1, 101, 101).into(),
(MINF_TBRF, MINF_TBRF, 102, 102).into(),
(MINF_TBRW0, MINF_TBRW0, 103, 103).into(),
(MINF_TBRF, MINF_TBRF, 104, 104).into(),
(MINF_TBRW0, MINF_TBRW0, 105, 105).into(),
(MINF_TBRF, MINF_TBRF, 106, 106).into(),
(MINF_TBRW1, MINF_TBRW1, 107, 107).into(),
(MINF_TBRF, MINF_TBRF, 109, 109).into(),
(MINF_MR, MINF_MR, 100, 100).into(),
(MINF_MR, MINF_MR, 7, 7).into(),
(MINF_TBRW1, MINF_TBRW1, 111, 111).into(),
(MINF_TBRF, MINF_TBRF, 112, 112).into(),
(MINF_TBRW1, MINF_TBRW1, 113, 113).into(),
(MINF_TBRF, MINF_TBRF, 114, 114).into(),
(MINF_TBRW0, MINF_TBRW0, 115, 115).into(),
(MINF_TBRF, MINF_TBRF, 116, 116).into(),
(MINF_TBRW1, MINF_TBRW1, 117, 117).into(),
(MINF_TBRF, MINF_TBRF, 119, 119).into(),
(MINF_MR, MINF_MR, 110, 110).into(),
(MINF_MR, MINF_MR, 4, 4).into(),
(MINF_TBRW0, MINF_TBRW0, 121, 121).into(),
(MINF_TBRF, MINF_TBRF, 122, 122).into(),
(MINF_TBRW0, MINF_TBRW0, 123, 123).into(),
(MINF_TBRF, MINF_TBRF, 124, 124).into(),
(MINF_TBRW1, MINF_TBRW1, 125, 125).into(),
(MINF_TBRF, MINF_TBRF, 126, 126).into(),
(MINF_TBRW1, MINF_TBRW1, 127, 127).into(),
(MINF_TBRF, MINF_TBRF, 132, 132).into(),
(MINF_MARW0, MINF_MARW0, 129, 129).into(),
(MINF_MARF, MINF_MARF, 120, 120).into(),
(MINF_MARW1, MINF_MARW1, 131, 131).into(),
(MINF_MARF, MINF_MARF, 120, 120).into(),
(MINF_MAB, MINF_MAB, 133, 133).into(),
(MINF_MARW0, MINF_MARW0, 134, 134).into(),
(MINF_MR, MINF_MR, 1, 2).into(),
(MINF_TBRW1, MINF_TBRW1, 136, 136).into(),
(MINF_TBRF, MINF_TBRF, 137, 137).into(),
(MINF_TBRW0, MINF_TBRW0, 138, 138).into(),
(MINF_TBRF, MINF_TBRF, 139, 139).into(),
(MINF_TBRW1, MINF_TBRW1, 140, 140).into(),
(MINF_TBRF, MINF_TBRF, 141, 141).into(),
(MINF_TBRW1, MINF_TBRW1, 142, 142).into(),
(MINF_TBRF, MINF_TBRF, 144, 144).into(),
(MINF_MR, MINF_MR, 135, 135).into(),
(MINF_MR, MINF_MR, 3, 3).into(),
],
vec![
("md_chunk_9_4".to_string(), 12),
("md_chunk_9_4_0_putret_x_0".to_string(), 24),
("md_chunk_9_4_return".to_string(), 25),
("md_chunk_a_4".to_string(), 26),
("md_chunk_a_4_0_putret_x_0".to_string(), 38),
("md_chunk_a_4_return".to_string(), 39),
("md_next_0".to_string(), 10),
("stop".to_string(), 10),
("stop2".to_string(), 11),
("td_chunk_2_4".to_string(), 40),
("td_chunk_2_4_0_putret_x_0".to_string(), 48),
("td_chunk_2_4_return".to_string(), 49),
("td_chunk_5_4".to_string(), 50),
("td_chunk_5_4_0_putret_x_0".to_string(), 58),
("td_chunk_5_4_0_putret_x_1".to_string(), 60),
("td_chunk_5_4_return".to_string(), 62),
("td_chunk_5_4_return_id_0_0".to_string(), 63),
("td_chunk_6_4".to_string(), 65),
("td_chunk_6_4_0_putret_x_0".to_string(), 73),
("td_chunk_6_4_return".to_string(), 74),
("td_chunk_7_4".to_string(), 75),
("td_chunk_7_4_0_putret_x_0".to_string(), 83),
("td_chunk_7_4_0_putret_x_1".to_string(), 85),
("td_chunk_7_4_return".to_string(), 87),
("td_chunk_7_4_return_id_0_0".to_string(), 88),
("td_chunk_8_4".to_string(), 90),
("td_chunk_8_4_0_putret_x_0".to_string(), 98),
("td_chunk_8_4_return".to_string(), 99),
("td_chunk_9_4".to_string(), 100),
("td_chunk_9_4_0_putret_x_0".to_string(), 108),
("td_chunk_9_4_return".to_string(), 109),
("td_chunk_b_4".to_string(), 110),
("td_chunk_b_4_0_putret_x_0".to_string(), 118),
("td_chunk_b_4_return".to_string(), 119),
("td_chunk_c_4".to_string(), 120),
("td_chunk_c_4_0_putret_x_0".to_string(), 128),
("td_chunk_c_4_0_putret_x_1".to_string(), 130),
("td_chunk_c_4_return".to_string(), 132),
("td_chunk_c_4_return_id_0_0".to_string(), 133),
("td_chunk_d_4".to_string(), 135),
("td_chunk_d_4_0_putret_x_0".to_string(), 143),
("td_chunk_d_4_return".to_string(), 144),
("td_next_0".to_string(), 1),
("td_next_1".to_string(), 2),
("td_next_2".to_string(), 3),
("td_next_3".to_string(), 4),
("td_next_4".to_string(), 5),
("td_next_5".to_string(), 6),
("td_next_6".to_string(), 7),
("td_next_7".to_string(), 8),
("td_next_8".to_string(), 9),
]
),
builder.to_code()
);
}
#[test]
fn test_vecu32_to_longdata() {
assert_eq!((vec![], 0, 0), vecu32_to_longdata(vec![0], 0));
assert_eq!(
(vec![0x34, 0xaa, 0xff], 0, 0),
vecu32_to_longdata(vec![0xffaa34], 24)
);
assert_eq!(
(vec![0x34, 0xaa], 15, 4),
vecu32_to_longdata(vec![0xffaa34], 20)
);
assert_eq!(
(
vec![0x01, 0x9a, 0x84, 0x03, 0x9e, 0xa8, 0x93, 0x5f, 0x82, 0x27],
1,
2
),
vecu32_to_longdata(vec![0x3849a01, 0x5f93a89e, 0x52782], 82)
);
assert_eq!(
(vec![0x01, 0x9a, 0x84, 0x03, 0x9e, 0xa8, 0x93, 0x5f], 0, 0),
vecu32_to_longdata(vec![0x3849a01, 0x5f93a89e, 0x52782], 64)
);
assert_eq!(
(vec![0x01, 0x9a, 0x84, 0x03, 0x9e, 0xa8, 0x93, 0x5f], 0, 0),
vecu32_to_longdata(vec![0x3849a01, 0x5f93a89e], 64)
);
}