Make clippy happy
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -16,7 +16,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustijvm"
|
||||
version = "0.1.0"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"serde 1.0.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
@@ -2,12 +2,13 @@ use Result;
|
||||
use block::Block;
|
||||
use ops::{Operation,num_to_op};
|
||||
|
||||
#[allow(unknown_lints,len_without_is_empty)]
|
||||
pub trait BinReadable {
|
||||
fn get(&mut self) -> Result<u8>;
|
||||
fn cur(&self) -> usize;
|
||||
fn len(&self) -> usize;
|
||||
fn slice(&mut self, len: usize) -> &[u8];
|
||||
|
||||
fn is_empty(&self) -> bool;
|
||||
}
|
||||
|
||||
pub trait BinRead {
|
||||
|
||||
@@ -78,4 +78,8 @@ impl BinReadable for Block {
|
||||
self.pointer += len;
|
||||
slice
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.source.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ pub struct Instruction {
|
||||
impl fmt::Display for Instruction {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.label {
|
||||
write!(f, "\nLBL_{}:\n", self.pos)?;
|
||||
writeln!(f, "\nLBL_{}:", self.pos)?;
|
||||
}
|
||||
|
||||
if self.wide {
|
||||
write!(f, " WIDE\n")?;
|
||||
writeln!(f, " WIDE")?;
|
||||
}
|
||||
|
||||
write!(f, " {}", self.name)?;
|
||||
@@ -48,7 +48,7 @@ impl fmt::Display for Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
write!(f, "\n")?;
|
||||
writeln!(f)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -82,12 +82,12 @@ pub struct Method {
|
||||
|
||||
impl Method {
|
||||
pub fn new(i: i32, pos: usize, args: usize, vars: usize) -> Self {
|
||||
let name;
|
||||
if pos == 0 {
|
||||
name = "main".to_string();
|
||||
let name = if pos == 0 {
|
||||
"main".to_string()
|
||||
} else {
|
||||
name = format!("func_{}", i);
|
||||
}
|
||||
format!("func_{}", i)
|
||||
};
|
||||
|
||||
Self {
|
||||
name,
|
||||
pos,
|
||||
@@ -129,10 +129,9 @@ impl Method {
|
||||
|
||||
impl fmt::Display for Method {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut main_var_off = 0;
|
||||
if self.name == "main" {
|
||||
write!(f, ".main\n")?;
|
||||
main_var_off = 1;
|
||||
let main_var_off = if self.name == "main" {
|
||||
writeln!(f, ".main")?;
|
||||
1
|
||||
} else {
|
||||
write!(f, ".method {}(", self.name)?;
|
||||
let mut comma = "";
|
||||
@@ -140,18 +139,19 @@ impl fmt::Display for Method {
|
||||
write!(f, "{}var{}", comma, i)?;
|
||||
comma = ", ";
|
||||
}
|
||||
write!(f,")\n")?;
|
||||
}
|
||||
writeln!(f,")")?;
|
||||
0
|
||||
};
|
||||
|
||||
if self.vars > 0 {
|
||||
write!(f, "\n.var\n")?;
|
||||
writeln!(f, "\n.var")?;
|
||||
for i in 1..=self.vars {
|
||||
write!(f, " var{}\n", i + self.args - main_var_off)?;
|
||||
writeln!(f, " var{}", i + self.args - main_var_off)?;
|
||||
}
|
||||
write!(f, ".end-var\n")?;
|
||||
writeln!(f, ".end-var")?;
|
||||
}
|
||||
|
||||
write!(f, "\n")?;
|
||||
writeln!(f)?;
|
||||
|
||||
for inst in &self.instructions {
|
||||
write!(f, "{}", inst)?;
|
||||
@@ -159,9 +159,9 @@ impl fmt::Display for Method {
|
||||
|
||||
|
||||
if self.name == "main" {
|
||||
write!(f, "\n.end-main\n\n")?;
|
||||
writeln!(f, "\n.end-main\n")?;
|
||||
} else {
|
||||
write!(f, "\n.end-method\n\n")?;
|
||||
writeln!(f, "\n.end-method\n")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -214,25 +214,25 @@ impl Disassembler {
|
||||
|
||||
for arg in args.clone() {
|
||||
let v = match arg {
|
||||
ops::Args::Byte => self.text.read_i8()? as i32,
|
||||
ops::Args::Short => self.text.read_i16()? as i32,
|
||||
ops::Args::Byte => i32::from(self.text.read_i8()?),
|
||||
ops::Args::Short => i32::from(self.text.read_i16()?),
|
||||
ops::Args::Var => {
|
||||
if wide {
|
||||
self.text.read_u16()? as i32
|
||||
i32::from(self.text.read_u16()?)
|
||||
} else {
|
||||
self.text.read_u8()? as i32
|
||||
i32::from(self.text.read_u8()?)
|
||||
}
|
||||
},
|
||||
ops::Args::Label => {
|
||||
let offset = self.text.read_i16()?;
|
||||
let target = pos as i64 + offset as i64;
|
||||
let target = pos as i64 + i64::from(offset);
|
||||
if target < 0 {
|
||||
return Err("Invalid jump offset");
|
||||
}
|
||||
method.labels.push(target as usize);
|
||||
target as i32
|
||||
},
|
||||
ops::Args::Constant => self.text.read_u16()? as i32,
|
||||
ops::Args::Constant => i32::from(self.text.read_u16()?),
|
||||
};
|
||||
params.push(v);
|
||||
}
|
||||
@@ -372,14 +372,14 @@ impl Disassembly {
|
||||
|
||||
impl fmt::Display for Disassembly {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.constants.len() > 0 {
|
||||
write!(f, ".constant\n")?;
|
||||
if self.constants.is_empty() {
|
||||
writeln!(f, ".constant")?;
|
||||
for (i, c) in self.constants.iter().enumerate() {
|
||||
if !c.method {
|
||||
write!(f, " CONST_{:<6} {}\n", i, c.value)?;
|
||||
writeln!(f, " CONST_{:<6} {}", i, c.value)?;
|
||||
}
|
||||
}
|
||||
write!(f, ".end-constant\n\n")?;
|
||||
writeln!(f, ".end-constant\n")?;
|
||||
}
|
||||
|
||||
for method in &self.methods {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug,Default)]
|
||||
pub struct Heap {
|
||||
pub heaps: Vec<Vec<i32>>
|
||||
}
|
||||
@@ -22,4 +22,8 @@ impl Heap {
|
||||
self.heaps.push(vec![0; size]);
|
||||
self.len() - 1
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.heaps.is_empty()
|
||||
}
|
||||
}
|
||||
@@ -52,4 +52,8 @@ impl BinReadable for IJVMReader {
|
||||
self.pointer += len;
|
||||
slice
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.source.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,17 +155,17 @@ impl Machine {
|
||||
|
||||
for arg in &args {
|
||||
let v = match arg {
|
||||
Args::Byte => self.block.read_i8()? as i32,
|
||||
Args::Short => self.block.read_i16()? as i32,
|
||||
Args::Byte => i32::from(self.block.read_i8()?),
|
||||
Args::Short => i32::from(self.block.read_i16()?),
|
||||
Args::Var => {
|
||||
if wide {
|
||||
self.block.read_u16()? as i32
|
||||
i32::from(self.block.read_u16()?)
|
||||
} else {
|
||||
self.block.read_u8()? as i32
|
||||
i32::from(self.block.read_u8()?)
|
||||
}
|
||||
},
|
||||
Args::Label => self.block.read_i16()? as i32,
|
||||
Args::Constant => self.block.read_u16()? as i32,
|
||||
Args::Label => i32::from(self.block.read_i16()?),
|
||||
Args::Constant => i32::from(self.block.read_u16()?),
|
||||
};
|
||||
params.push(v);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use Result;
|
||||
use std::io::{Read, Write};
|
||||
use std::net::TcpListener;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct NetStack {
|
||||
pub stream: Option<TcpStream>
|
||||
}
|
||||
@@ -28,7 +28,7 @@ impl NetStack {
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err("Could not accept connection")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn connect(&mut self, host: u32, port: u16) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user