Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
3c1u committed Dec 14, 2019
1 parent 4c7963e commit 0624b93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ pub struct Codegen<'c> {
extern "C" fn bfrs_get_char() -> u8 {
let mut input = std::io::stdin();
let mut buf = [0u8];
input.read(&mut buf).unwrap();

if input.read(&mut buf).unwrap() == 0 {
return 0xFF; // EOF
}

buf[0]
}

extern "C" fn bfrs_print_char(c: u8) {
let mut out = std::io::stdout();
out.write(&[c]).unwrap();
out.write_all(&[c]).unwrap();
out.flush().unwrap();
}

Expand Down Expand Up @@ -167,7 +171,7 @@ impl<'c> Codegen<'c> {
match operation {
BfAST::LoopBlock(v) => {
// 特殊パターンの高速化
if v.len() == 0 {
if v.is_empty() {
return Ok(());
} else if v.len() == 1 {
if let BfAST::SubOp(k) = v[0] {
Expand All @@ -189,7 +193,7 @@ impl<'c> Codegen<'c> {
return Ok(());
}
} else if v.len() == 3 {
if let &[BfAST::AddPtr(j), BfAST::AddOp(k), BfAST::SubPtr(l)] = &v[0..3] {
if let [BfAST::AddPtr(j), BfAST::AddOp(k), BfAST::SubPtr(l)] = v[0..3] {
if j == l {
let rhs = self.get_current(value_table, counter);

Expand Down Expand Up @@ -221,8 +225,7 @@ impl<'c> Codegen<'c> {

return Ok(());
}
} else if let &[BfAST::SubPtr(j), BfAST::AddOp(k), BfAST::AddPtr(l)] = &v[0..3]
{
} else if let [BfAST::SubPtr(j), BfAST::AddOp(k), BfAST::AddPtr(l)] = v[0..3] {
if j == l {
let rhs = self.get_current(value_table, counter);

Expand Down
5 changes: 2 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ fn visit_program(p: Pair<'_, Rule>, v: &mut Vec<BfAST>) -> Result<()> {
}

pub fn parse<P: AsRef<str>>(program: P) -> Result<Vec<BfAST>> {
let pairs = BfParser::parse(Rule::program, program.as_ref())?;
let mut pairs = BfParser::parse(Rule::program, program.as_ref())?;
let program = pairs
.into_iter()
.next()
.ok_or(Error::ice("no matching program"))?;
.ok_or_else(|| Error::ice("no matching program"))?;

let mut program_out = vec![];
visit_program(program, &mut program_out)?;
Expand Down

0 comments on commit 0624b93

Please sign in to comment.