Please lord clippy
This commit is contained in:
@@ -2,6 +2,7 @@ use Result;
|
|||||||
use block::Block;
|
use block::Block;
|
||||||
use ops::{Operation,num_to_op};
|
use ops::{Operation,num_to_op};
|
||||||
|
|
||||||
|
#[allow(unknown_lints,len_without_is_empty)]
|
||||||
pub trait BinReadable {
|
pub trait BinReadable {
|
||||||
fn get(&mut self) -> Result<u8>;
|
fn get(&mut self) -> Result<u8>;
|
||||||
fn cur(&self) -> usize;
|
fn cur(&self) -> usize;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ impl ops::Index<usize> for Block {
|
|||||||
type Output = u8;
|
type Output = u8;
|
||||||
|
|
||||||
fn index(&self, index: usize) -> &<Self as ops::Index<usize>>::Output {
|
fn index(&self, index: usize) -> &<Self as ops::Index<usize>>::Output {
|
||||||
return &self.source[index];
|
&self.source[index]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ pub mod machine;
|
|||||||
pub mod stack;
|
pub mod stack;
|
||||||
pub mod pool;
|
pub mod pool;
|
||||||
pub mod frame;
|
pub mod frame;
|
||||||
pub mod netstack;
|
|
||||||
|
|
||||||
|
#[cfg(feature = "bonus:network")]
|
||||||
|
pub mod netstack;
|
||||||
#[cfg(feature = "bonus:heap")]
|
#[cfg(feature = "bonus:heap")]
|
||||||
pub mod heap;
|
pub mod heap;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
use std::sync::Mutex;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use Result;
|
||||||
use block::Block;
|
use block::Block;
|
||||||
use ops::Operation;
|
use ops::Operation;
|
||||||
use ijvmreader::IJVMReader;
|
use ijvmreader::IJVMReader;
|
||||||
@@ -7,11 +10,9 @@ use binread::{BinRead, BinReadable};
|
|||||||
use frame::Frame;
|
use frame::Frame;
|
||||||
use stack::Stack;
|
use stack::Stack;
|
||||||
use pool::Pool;
|
use pool::Pool;
|
||||||
use netstack::NetStack;
|
|
||||||
use Result;
|
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
|
#[cfg(feature = "bonus:network")]
|
||||||
|
use netstack::NetStack;
|
||||||
#[cfg(feature = "bonus:heap")]
|
#[cfg(feature = "bonus:heap")]
|
||||||
use heap::Heap;
|
use heap::Heap;
|
||||||
|
|
||||||
@@ -24,8 +25,9 @@ pub struct Machine {
|
|||||||
pub pool: Pool,
|
pub pool: Pool,
|
||||||
pub block: Block,
|
pub block: Block,
|
||||||
pub frame: Vec<Frame>,
|
pub frame: Vec<Frame>,
|
||||||
pub net: NetStack,
|
|
||||||
|
|
||||||
|
#[cfg(feature = "bonus:network")]
|
||||||
|
pub net: NetStack,
|
||||||
#[cfg(feature = "bonus:heap")]
|
#[cfg(feature = "bonus:heap")]
|
||||||
pub heap: Heap,
|
pub heap: Heap,
|
||||||
|
|
||||||
@@ -45,6 +47,7 @@ impl Machine {
|
|||||||
stream_in: Box::new(::std::io::stdin()),
|
stream_in: Box::new(::std::io::stdin()),
|
||||||
stream_out: Rc::new(Mutex::new(::std::io::stdout())),
|
stream_out: Rc::new(Mutex::new(::std::io::stdout())),
|
||||||
|
|
||||||
|
#[cfg(feature = "bonus:network")]
|
||||||
net: NetStack::new(),
|
net: NetStack::new(),
|
||||||
|
|
||||||
#[cfg(feature = "bonus:heap")]
|
#[cfg(feature = "bonus:heap")]
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
|
|
||||||
#[cfg(feature = "bonus:network")]
|
|
||||||
use Result;
|
use Result;
|
||||||
#[cfg(feature = "bonus:network")]
|
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
#[cfg(feature = "bonus:network")]
|
|
||||||
use std::net::TcpListener;
|
use std::net::TcpListener;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -19,7 +16,6 @@ impl NetStack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "bonus:network")]
|
|
||||||
pub fn bind(&mut self, port: u16) -> Result<()> {
|
pub fn bind(&mut self, port: u16) -> Result<()> {
|
||||||
let listener = match TcpListener::bind(format!("0.0.0.0:{}", port)) {
|
let listener = match TcpListener::bind(format!("0.0.0.0:{}", port)) {
|
||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
@@ -35,7 +31,6 @@ impl NetStack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "bonus:network")]
|
|
||||||
pub fn connect(&mut self, host: u32, port: u16) -> Result<()> {
|
pub fn connect(&mut self, host: u32, port: u16) -> Result<()> {
|
||||||
let h1 = (host & (0xFF << 24)) >> 24 as u8;
|
let h1 = (host & (0xFF << 24)) >> 24 as u8;
|
||||||
let h2 = (host & (0xFF << 16)) >> 16 as u8;
|
let h2 = (host & (0xFF << 16)) >> 16 as u8;
|
||||||
@@ -50,7 +45,6 @@ impl NetStack {
|
|||||||
Err("Could not connect to address")
|
Err("Could not connect to address")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "bonus:network")]
|
|
||||||
pub fn close(&mut self) -> Result<()> {
|
pub fn close(&mut self) -> Result<()> {
|
||||||
if self.stream.is_none() {
|
if self.stream.is_none() {
|
||||||
return Err("Cannot close a nonexistent socket")
|
return Err("Cannot close a nonexistent socket")
|
||||||
@@ -60,7 +54,6 @@ impl NetStack {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "bonus:network")]
|
|
||||||
pub fn read_byte(&mut self) -> Result<i8> {
|
pub fn read_byte(&mut self) -> Result<i8> {
|
||||||
match self.stream {
|
match self.stream {
|
||||||
Some(ref mut stream) => {
|
Some(ref mut stream) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use Result;
|
use Result;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Stack {
|
pub struct Stack {
|
||||||
pub data: Vec<i32>
|
pub data: Vec<i32>
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,10 @@ impl Stack {
|
|||||||
self.data.len()
|
self.data.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.len() == 0
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get(&self, i: usize) -> i32 {
|
pub fn get(&self, i: usize) -> i32 {
|
||||||
self.data[i]
|
self.data[i]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user