@@ -62,114 +62,114 @@ impl Command {
6262 pub fn apply ( & self , ip : & mut Interpreter , value : isize ) -> Result < ( ) , Box < dyn Error > > {
6363 assert ! ( value > 0 ) ;
6464 let stack = & mut ip. stack ;
65- match ( self ) {
65+ match self {
6666 Command :: Push => {
6767 stack. push ( value) ;
6868 }
6969 Command :: Pop => {
7070 stack. pop ( ) ;
7171 }
7272 Command :: Add => {
73- if ( stack. len ( ) >= 2 ) {
73+ if stack. len ( ) >= 2 {
7474 let x = stack. pop ( ) . unwrap ( ) ;
7575 let y = stack. pop ( ) . unwrap ( ) ;
7676 stack. push ( x + y) ;
7777 }
7878 }
7979 Command :: Subtract => {
80- if ( stack. len ( ) >= 2 ) {
80+ if stack. len ( ) >= 2 {
8181 let x = stack. pop ( ) . unwrap ( ) ;
8282 let y = stack. pop ( ) . unwrap ( ) ;
8383 stack. push ( y - x) ;
8484 }
8585 }
8686 Command :: Multiply => {
87- if ( stack. len ( ) >= 2 ) {
87+ if stack. len ( ) >= 2 {
8888 let x = stack. pop ( ) . unwrap ( ) ;
8989 let y = stack. pop ( ) . unwrap ( ) ;
9090 stack. push ( x * y) ;
9191 }
9292 }
9393 Command :: Divide => {
94- if ( stack. len ( ) >= 2 ) {
94+ if stack. len ( ) >= 2 {
9595 let x = stack. pop ( ) . unwrap ( ) ;
9696 let y = stack. pop ( ) . unwrap ( ) ;
97- if ( x == 0 ) {
97+ if x == 0 {
9898 return Err ( format ! ( "zero-division at {:?}" , value) . into ( ) ) ;
9999 }
100100 stack. push ( y / x) ;
101101 }
102102 }
103103 Command :: Mod => {
104- if ( stack. len ( ) >= 2 ) {
104+ if stack. len ( ) >= 2 {
105105 let x = stack. pop ( ) . unwrap ( ) ;
106106 let y = stack. pop ( ) . unwrap ( ) ;
107- if ( x == 0 ) {
107+ if x == 0 {
108108 return Err ( format ! ( "zero-division at {:?}" , value) . into ( ) ) ;
109109 }
110110 #[ allow( unstable_name_collisions) ]
111111 stack. push ( y - ( y. div_floor ( & x) * x) ) ; //Python-style mod
112112 }
113113 }
114114 Command :: Not => {
115- if ( !stack. is_empty ( ) ) {
115+ if !stack. is_empty ( ) {
116116 let x = stack. pop ( ) . unwrap ( ) ;
117- if ( x == 0 ) {
117+ if x == 0 {
118118 stack. push ( 1 ) ;
119119 } else {
120120 stack. push ( 0 ) ;
121121 }
122122 }
123123 }
124124 Command :: Greater => {
125- if ( stack. len ( ) >= 2 ) {
125+ if stack. len ( ) >= 2 {
126126 let x = stack. pop ( ) . unwrap ( ) ;
127127 let y = stack. pop ( ) . unwrap ( ) ;
128- if ( y > x) {
128+ if y > x {
129129 stack. push ( 1 ) ;
130130 } else {
131131 stack. push ( 0 ) ;
132132 }
133133 }
134134 }
135135 Command :: Pointer => {
136- if ( !stack. is_empty ( ) ) {
136+ if !stack. is_empty ( ) {
137137 let x = stack. pop ( ) . unwrap ( ) ;
138138 ip. dp = ip. dp . rotate_by ( x) ;
139139 }
140140 }
141141 Command :: Switch => {
142- if ( !stack. is_empty ( ) ) {
142+ if !stack. is_empty ( ) {
143143 let x = stack. pop ( ) . unwrap ( ) ;
144- if ( x. abs ( ) % 2 == 1 ) {
144+ if x. abs ( ) % 2 == 1 {
145145 ip. cc = ip. cc . flip ( ) ;
146146 }
147147 }
148148 }
149149 Command :: Duplicate => {
150- if ( !stack. is_empty ( ) ) {
150+ if !stack. is_empty ( ) {
151151 stack. push ( * stack. last ( ) . unwrap ( ) ) ;
152152 }
153153 }
154154 Command :: Roll => {
155- if ( stack. len ( ) >= 2 ) {
155+ if stack. len ( ) >= 2 {
156156 let num_roll = stack[ stack. len ( ) - 1 ] ;
157157 let depth = stack[ stack. len ( ) - 2 ] ;
158158 //if operation cannoe be done
159- if ( ( depth < 0 ) || ( stack. len ( ) - 2 < depth as usize ) ) {
159+ if ( depth < 0 ) || ( stack. len ( ) - 2 < depth as usize ) {
160160 return Ok ( ( ) ) ;
161161 }
162162 for _ in 0 ..2 {
163163 stack. pop ( ) . unwrap ( ) ;
164164 }
165165 //if operation can be done but virtually nothing happens
166- if ( ( depth <= 1 ) || ( num_roll == 0 ) ) {
166+ if ( depth <= 1 ) || ( num_roll == 0 ) {
167167 return Ok ( ( ) ) ;
168168 }
169169
170170 //rotates the indices `[0, 1, 2, ..., depth - 1]`
171171 let mut position = VecDeque :: from_iter ( 0 ..( depth as usize ) ) ;
172- if ( num_roll > 0 ) {
172+ if num_roll > 0 {
173173 position. rotate_right ( ( num_roll % depth) as usize ) ;
174174 } else {
175175 position. rotate_left ( ( num_roll. abs ( ) % depth) as usize ) ;
@@ -187,28 +187,28 @@ impl Command {
187187 }
188188 Command :: ReadNumber => {
189189 let n = ip. stdin . read_integer ( ) ;
190- if ( n. is_none ( ) ) {
190+ if n. is_none ( ) {
191191 return Ok ( ( ) ) ;
192192 }
193193 stack. push ( n. unwrap ( ) ) ;
194194 }
195195 Command :: ReadChar => {
196196 let c = ip. stdin . read_char ( ) ;
197- if ( c. is_none ( ) ) {
197+ if c. is_none ( ) {
198198 return Ok ( ( ) ) ;
199199 }
200200 stack. push ( c. unwrap ( ) as isize ) ;
201201 }
202202 Command :: WriteNumber => {
203- if ( !stack. is_empty ( ) ) {
203+ if !stack. is_empty ( ) {
204204 let x = stack. pop ( ) . unwrap ( ) ;
205205 ip. output ( & format ! ( "{}\n " , x) ) ;
206206 }
207207 }
208208 Command :: WriteChar => {
209- if ( !stack. is_empty ( ) ) {
209+ if !stack. is_empty ( ) {
210210 let x = * stack. last ( ) . unwrap ( ) ;
211- if ( ( 0 <= x) && ( x <= char:: MAX as isize ) ) {
211+ if ( 0 <= x) && ( x <= char:: MAX as isize ) {
212212 stack. pop ( ) . unwrap ( ) ;
213213 ip. output ( & format ! ( "{}" , char :: from_u32( x as u32 ) . unwrap( ) ) ) ;
214214 }
0 commit comments