diff --git a/src/binread.rs b/src/binread.rs index 0ca536d..7315169 100644 --- a/src/binread.rs +++ b/src/binread.rs @@ -2,6 +2,7 @@ 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; fn cur(&self) -> usize; diff --git a/src/block.rs b/src/block.rs index f0fcb1c..d30e166 100644 --- a/src/block.rs +++ b/src/block.rs @@ -51,7 +51,7 @@ impl ops::Index for Block { type Output = u8; fn index(&self, index: usize) -> &>::Output { - return &self.source[index]; + &self.source[index] } } diff --git a/src/lib.rs b/src/lib.rs index 9217059..00e5d8a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,8 +6,9 @@ pub mod machine; pub mod stack; pub mod pool; pub mod frame; -pub mod netstack; +#[cfg(feature = "bonus:network")] +pub mod netstack; #[cfg(feature = "bonus:heap")] pub mod heap; diff --git a/src/machine.rs b/src/machine.rs index c236929..ccef42d 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1,5 +1,8 @@ use std::io::{Read, Write}; +use std::sync::Mutex; +use std::rc::Rc; +use Result; use block::Block; use ops::Operation; use ijvmreader::IJVMReader; @@ -7,11 +10,9 @@ use binread::{BinRead, BinReadable}; use frame::Frame; use stack::Stack; 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")] use heap::Heap; @@ -24,8 +25,9 @@ pub struct Machine { pub pool: Pool, pub block: Block, pub frame: Vec, - pub net: NetStack, + #[cfg(feature = "bonus:network")] + pub net: NetStack, #[cfg(feature = "bonus:heap")] pub heap: Heap, @@ -45,6 +47,7 @@ impl Machine { stream_in: Box::new(::std::io::stdin()), stream_out: Rc::new(Mutex::new(::std::io::stdout())), + #[cfg(feature = "bonus:network")] net: NetStack::new(), #[cfg(feature = "bonus:heap")] diff --git a/src/netstack.rs b/src/netstack.rs index e13ad06..cc1a1cf 100644 --- a/src/netstack.rs +++ b/src/netstack.rs @@ -1,10 +1,7 @@ use std::net::TcpStream; -#[cfg(feature = "bonus:network")] use Result; -#[cfg(feature = "bonus:network")] use std::io::{Read, Write}; -#[cfg(feature = "bonus:network")] use std::net::TcpListener; #[derive(Debug)] @@ -19,7 +16,6 @@ impl NetStack { } } - #[cfg(feature = "bonus:network")] pub fn bind(&mut self, port: u16) -> Result<()> { let listener = match TcpListener::bind(format!("0.0.0.0:{}", port)) { Ok(a) => a, @@ -35,7 +31,6 @@ impl NetStack { } } - #[cfg(feature = "bonus:network")] pub fn connect(&mut self, host: u32, port: u16) -> Result<()> { let h1 = (host & (0xFF << 24)) >> 24 as u8; let h2 = (host & (0xFF << 16)) >> 16 as u8; @@ -50,7 +45,6 @@ impl NetStack { Err("Could not connect to address") } - #[cfg(feature = "bonus:network")] pub fn close(&mut self) -> Result<()> { if self.stream.is_none() { return Err("Cannot close a nonexistent socket") @@ -60,7 +54,6 @@ impl NetStack { Ok(()) } - #[cfg(feature = "bonus:network")] pub fn read_byte(&mut self) -> Result { match self.stream { Some(ref mut stream) => { diff --git a/src/stack.rs b/src/stack.rs index 2a1f118..c94e182 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -1,6 +1,6 @@ use Result; -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Stack { pub data: Vec } @@ -16,6 +16,10 @@ impl Stack { self.data.len() } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn get(&self, i: usize) -> i32 { self.data[i] }