Some small fixes and compile flaggery

This commit is contained in:
2017-06-06 21:24:57 +02:00
parent e23a9e8fb8
commit d4f851e81b
2 changed files with 13 additions and 4 deletions

View File

@@ -66,7 +66,7 @@ impl Machine {
} }
}, },
Ok(Operation::Invalid(a)) => { Ok(Operation::Invalid(a)) => {
println!("OP: {}", a); println!("UNDEFINED OP: 0x{:X}", a);
Err("Invalid op") Err("Invalid op")
}, },
Err(str) => Err(str) Err(str) => Err(str)

View File

@@ -1,7 +1,11 @@
use ijvm::Result; use std::net::TcpStream;
use std::io::{Read, Write};
use std::net::{TcpListener, TcpStream};
#[cfg(feature = "bonus:network")]
use ijvm::Result;
#[cfg(feature = "bonus:network")]
use std::io::{Read, Write};
#[cfg(feature = "bonus:network")]
use std::net::TcpListener;
#[derive(Debug)] #[derive(Debug)]
pub struct NetStack { pub struct NetStack {
@@ -15,6 +19,7 @@ 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,
@@ -30,6 +35,7 @@ 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;
@@ -44,6 +50,7 @@ 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 let None = self.stream { if let None = self.stream {
return Err("Cannot close a nonexistent socket") return Err("Cannot close a nonexistent socket")
@@ -53,6 +60,7 @@ impl NetStack {
Ok(()) Ok(())
} }
#[cfg(feature = "bonus:network")]
pub fn read_byte(&mut self) -> Result<i8> { pub fn read_byte(&mut self) -> Result<i8> {
return match self.stream { return match self.stream {
Some(ref mut stream) => { Some(ref mut stream) => {
@@ -65,6 +73,7 @@ impl NetStack {
} }
} }
#[cfg(feature = "bonus:network")]
pub fn write_byte(&mut self, byte: u8) -> Result<()> { pub fn write_byte(&mut self, byte: u8) -> Result<()> {
return match self.stream { return match self.stream {
Some(ref mut stream) => { Some(ref mut stream) => {