1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use *;
pub
// pub(crate) fn parse_advance_sp_combinator(input: &str) -> IResult<&str, String> {
// let (rest, (_, args)) = parse_mnemonic(input, "advance_sp", 1)?;
// // we should match args[0] as #(+-)decimal_integer
// let mut parser = nom::sequence::tuple((
// nom::bytes::complete::tag("#"),
// nom::multi::many0(nom::branch::alt((
// nom::bytes::complete::tag("-"),
// nom::bytes::complete::tag("+"),
// ))),
// nom::combinator::rest,
// ));
// use nom::Parser;
// let (_, result) = parser.parse(args[0])?;
// let sign_may_be = result.1;
// let abs = result.2;
// let mut sp_shift_is_positive = true;
// let sp_shift = if let Ok(sp_shift) = u64::from_str_radix(abs, 10) {
// sp_shift
// } else {
// return Err(nom::Err::Error(nom::error::Error::from_error_kind(
// abs,
// nom::error::ErrorKind::Digit,
// )));
// };
// if sp_shift == 0 {
// return Err(nom::Err::Error(nom::error::Error::from_error_kind(
// abs,
// nom::error::ErrorKind::Digit,
// )));
// }
// if sign_may_be.len() == 1 && sign_may_be[0] == "-" {
// sp_shift_is_positive = false;
// }
// // we also have to decide where to put it
// let canonical = if sp_shift_is_positive {
// // our convention
// let sp_shift = sp_shift - 1;
// // can only be done with dst
// format!("nop r0, r0, stack+=[#{}], r0", sp_shift)
// } else {
// // our convention
// let sp_shift = sp_shift - 1;
// // better to use src
// format!("nop stack-=[#{}], r0, r0, r0", sp_shift)
// };
// Ok((rest, canonical))
// }
pub
pub
// #[cfg(test)]
// mod test {
// use super::*;
// use crate::assembly::SimplifyNomError;
// #[test]
// fn test_parse_sp_manipulation() {
// let example = "advance_sp #42";
// let r = parse_advance_sp_combinator(example).simplify();
// dbg!(r);
// let example = "advance_sp #0";
// let r = parse_advance_sp_combinator(example).simplify();
// dbg!(r);
// let example = "advance_sp #-100";
// let r = parse_advance_sp_combinator(example).simplify();
// dbg!(r);
// let example = "advance_sp #+10";
// let r = parse_advance_sp_combinator(example).simplify();
// dbg!(r);
// }
// }