Browse Source

Clippy fixes

Update .gitignore
pull/6/head
Ehsan M. Kermani 3 years ago
parent
commit
e1cbe596bb
  1. 1
      .gitignore
  2. 6
      calculator/src/compiler/interpreter.rs
  3. 6
      calculator/src/compiler/jit.rs
  4. 2
      calculator/src/main.rs
  5. 4
      calculator/src/parser.rs

1
.gitignore

@ -1,3 +1,4 @@
.vscode
/target
Cargo.lock
book/book

6
calculator/src/compiler/interpreter.rs

@ -29,15 +29,15 @@ impl Eval {
match node {
Node::Int(n) => *n,
Node::UnaryExpr { op, child } => {
let child = self.eval(&child);
let child = self.eval(child);
match op {
Operator::Plus => child,
Operator::Minus => -child,
}
}
Node::BinaryExpr { op, lhs, rhs } => {
let lhs_ret = self.eval(&lhs);
let rhs_ret = self.eval(&rhs);
let lhs_ret = self.eval(lhs);
let rhs_ret = self.eval(rhs);
match op {
Operator::Plus => lhs_ret + rhs_ret,

6
calculator/src/compiler/jit.rs

@ -64,15 +64,15 @@ impl<'a> RecursiveBuilder<'a> {
match ast {
Node::Int(n) => self.i32_type.const_int(*n as u64, true),
Node::UnaryExpr { op, child } => {
let child = self.build(&child);
let child = self.build(child);
match op {
Operator::Minus => child.const_neg(),
Operator::Plus => child,
}
}
Node::BinaryExpr { op, lhs, rhs } => {
let left = self.build(&lhs);
let right = self.build(&rhs);
let left = self.build(lhs);
let right = self.build(rhs);
match op {
Operator::Plus => self.builder.build_int_add(left, right, "plus_temp"),

2
calculator/src/main.rs

@ -13,7 +13,7 @@ cfg_if! {
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() < 2 {
eprintln!("Not input file was provided");
eprintln!("No input file was provided");
std::process::exit(-1);
}
println!(

4
calculator/src/parser.rs

@ -1,3 +1,5 @@
#![allow(clippy::upper_case_acronyms)]
use pest::{self, Parser};
use crate::ast::{Node, Operator};
@ -50,7 +52,7 @@ fn build_ast_from_term(pair: pest::iterators::Pair<Rule>) -> Node {
let istr = pair.as_str();
let (sign, istr) = match &istr[..1] {
"-" => (-1, &istr[1..]),
_ => (1, &istr[..]),
_ => (1, istr),
};
let int: i32 = istr.parse().unwrap();
Node::Int(sign * int)

Loading…
Cancel
Save