Skip to content

Commit 840f916

Browse files
committed
apply clippy suggestions
1 parent 253cded commit 840f916

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

‎src/jit.rs‎

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ impl JIT {
4545
parser::function(&input).map_err(|e| e.to_string())?;
4646

4747
// Then, translate the AST nodes into Cranelift IR.
48-
self.translate(params, the_return, stmts)
49-
.map_err(|e| e.to_string())?;
48+
self.translate(params, the_return, stmts)?;
5049

5150
// Next, declare the function to simplejit. Functions must be declared
5251
// before they can be called, or defined.
@@ -215,53 +214,53 @@ impl<'a> FunctionTranslator<'a> {
215214
self.builder.ins().udiv(lhs, rhs)
216215
}
217216

218-
Expr::Eq(lhs, rhs) => self.translate_icmp(IntCC::Equal, lhs, rhs),
219-
Expr::Ne(lhs, rhs) => self.translate_icmp(IntCC::NotEqual, lhs, rhs),
220-
Expr::Lt(lhs, rhs) => self.translate_icmp(IntCC::SignedLessThan, lhs, rhs),
221-
Expr::Le(lhs, rhs) => self.translate_icmp(IntCC::SignedLessThanOrEqual, lhs, rhs),
222-
Expr::Gt(lhs, rhs) => self.translate_icmp(IntCC::SignedGreaterThan, lhs, rhs),
223-
Expr::Ge(lhs, rhs) => self.translate_icmp(IntCC::SignedGreaterThanOrEqual, lhs, rhs),
217+
Expr::Eq(lhs, rhs) => self.translate_icmp(IntCC::Equal, *lhs, *rhs),
218+
Expr::Ne(lhs, rhs) => self.translate_icmp(IntCC::NotEqual, *lhs, *rhs),
219+
Expr::Lt(lhs, rhs) => self.translate_icmp(IntCC::SignedLessThan, *lhs, *rhs),
220+
Expr::Le(lhs, rhs) => self.translate_icmp(IntCC::SignedLessThanOrEqual, *lhs, *rhs),
221+
Expr::Gt(lhs, rhs) => self.translate_icmp(IntCC::SignedGreaterThan, *lhs, *rhs),
222+
Expr::Ge(lhs, rhs) => self.translate_icmp(IntCC::SignedGreaterThanOrEqual, *lhs, *rhs),
224223
Expr::Call(name, args) => self.translate_call(name, args),
225224
Expr::GlobalDataAddr(name) => self.translate_global_data_addr(name),
226225
Expr::Identifier(name) => {
227226
// `use_var` is used to read the value of a variable.
228227
let variable = self.variables.get(&name).expect("variable not defined");
229228
self.builder.use_var(*variable)
230229
}
231-
Expr::Assign(name, expr) => self.translate_assign(name, expr),
230+
Expr::Assign(name, expr) => self.translate_assign(name, *expr),
232231
Expr::IfElse(condition, then_body, else_body) => {
233-
self.translate_if_else(condition, then_body, else_body)
232+
self.translate_if_else(*condition, then_body, else_body)
234233
}
235234
Expr::WhileLoop(condition, loop_body) => {
236-
self.translate_while_loop(condition, loop_body)
235+
self.translate_while_loop(*condition, loop_body)
237236
}
238237
}
239238
}
240239

241-
fn translate_assign(&mut self, name: String, expr: Box<Expr>) -> Value {
240+
fn translate_assign(&mut self, name: String, expr: Expr) -> Value {
242241
// `def_var` is used to write the value of a variable. Note that
243242
// variables can have multiple definitions. Cranelift will
244243
// convert them into SSA form for itself automatically.
245-
let new_value = self.translate_expr(*expr);
244+
let new_value = self.translate_expr(expr);
246245
let variable = self.variables.get(&name).unwrap();
247246
self.builder.def_var(*variable, new_value);
248247
new_value
249248
}
250249

251-
fn translate_icmp(&mut self, cmp: IntCC, lhs: Box<Expr>, rhs: Box<Expr>) -> Value {
252-
let lhs = self.translate_expr(*lhs);
253-
let rhs = self.translate_expr(*rhs);
250+
fn translate_icmp(&mut self, cmp: IntCC, lhs: Expr, rhs: Expr) -> Value {
251+
let lhs = self.translate_expr(lhs);
252+
let rhs = self.translate_expr(rhs);
254253
let c = self.builder.ins().icmp(cmp, lhs, rhs);
255254
self.builder.ins().bint(self.int, c)
256255
}
257256

258257
fn translate_if_else(
259258
&mut self,
260-
condition: Box<Expr>,
259+
condition: Expr,
261260
then_body: Vec<Expr>,
262261
else_body: Vec<Expr>,
263262
) -> Value {
264-
let condition_value = self.translate_expr(*condition);
263+
let condition_value = self.translate_expr(condition);
265264

266265
let then_block = self.builder.create_block();
267266
let else_block = self.builder.create_block();
@@ -312,15 +311,15 @@ impl<'a> FunctionTranslator<'a> {
312311
phi
313312
}
314313

315-
fn translate_while_loop(&mut self, condition: Box<Expr>, loop_body: Vec<Expr>) -> Value {
314+
fn translate_while_loop(&mut self, condition: Expr, loop_body: Vec<Expr>) -> Value {
316315
let header_block = self.builder.create_block();
317316
let body_block = self.builder.create_block();
318317
let exit_block = self.builder.create_block();
319318

320319
self.builder.ins().jump(header_block, &[]);
321320
self.builder.switch_to_block(header_block);
322321

323-
let condition_value = self.translate_expr(*condition);
322+
let condition_value = self.translate_expr(condition);
324323
self.builder.ins().brz(condition_value, exit_block, &[]);
325324
self.builder.ins().jump(body_block, &[]);
326325

0 commit comments

Comments
 (0)