update feature names
This commit is contained in:
20
Cargo.toml
20
Cargo.toml
@@ -11,15 +11,15 @@ lazy_static = "1.3.0"
|
||||
[features]
|
||||
default = ["bonus", "extra"]
|
||||
|
||||
bonus = ["bonus:network", "bonus:heap"]
|
||||
"bonus:network" = []
|
||||
"bonus:heap" = []
|
||||
bonus = ["bonus.network", "bonus.heap"]
|
||||
"bonus.network" = []
|
||||
"bonus.heap" = []
|
||||
|
||||
extra = ["extra:sleep", "extra:arithmetic"]
|
||||
"extra:sleep" = []
|
||||
"extra:arithmetic" = []
|
||||
extra = ["extra.sleep", "extra.arithmetic"]
|
||||
"extra.sleep" = []
|
||||
"extra.arithmetic" = []
|
||||
|
||||
debug = ["debug:instr", "debug:frame", "debug:gc"]
|
||||
"debug:instr" = []
|
||||
"debug:frame" = []
|
||||
"debug:gc" = []
|
||||
debug = ["debug.instr", "debug.frame", "debug.gc"]
|
||||
"debug.instr" = []
|
||||
"debug.frame" = []
|
||||
"debug.gc" = []
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct Frame {
|
||||
|
||||
impl Frame {
|
||||
pub fn new(num_locals: usize, base: usize) -> Frame {
|
||||
if cfg!(feature = "debug:frame") {
|
||||
if cfg!(feature = "debug.frame") {
|
||||
println!("Initializing frame of len {}", num_locals);
|
||||
}
|
||||
Frame {
|
||||
@@ -24,7 +24,7 @@ impl Frame {
|
||||
}
|
||||
|
||||
pub fn new_extendable(base: usize) -> Frame {
|
||||
if cfg!(feature = "debug:frame") {
|
||||
if cfg!(feature = "debug.frame") {
|
||||
println!("Initializing extendable frame");
|
||||
}
|
||||
Frame {
|
||||
|
||||
@@ -14,9 +14,9 @@ pub mod pool;
|
||||
pub mod frame;
|
||||
pub mod stubs;
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
pub mod netstack;
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
#[cfg(feature = "bonus.heap")]
|
||||
pub mod heap;
|
||||
|
||||
type Result<T> = ::std::result::Result<T, &'static str>;
|
||||
|
||||
@@ -10,9 +10,9 @@ use pool::Pool;
|
||||
use stack::Stack;
|
||||
use Result;
|
||||
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
#[cfg(feature = "bonus.heap")]
|
||||
use heap::Heaps;
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
use netstack::NetStack;
|
||||
use std::convert::TryInto;
|
||||
|
||||
@@ -25,9 +25,9 @@ pub struct Machine {
|
||||
pub block: Block,
|
||||
pub frame: Vec<Frame>,
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
pub net: NetStack,
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
#[cfg(feature = "bonus.heap")]
|
||||
pub heap: Heaps,
|
||||
|
||||
pub stream_in: Box<dyn Read + Send + Sync>,
|
||||
@@ -45,10 +45,10 @@ impl Machine {
|
||||
stream_in: Box::new(::std::io::stdin()),
|
||||
stream_out: Arc::new(Mutex::new(::std::io::stdout())),
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
net: NetStack::new(),
|
||||
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
#[cfg(feature = "bonus.heap")]
|
||||
heap: Heaps::new(),
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ impl Machine {
|
||||
pub fn step(&mut self) -> Result<()> {
|
||||
match self.block.read_op() {
|
||||
Ok(Operation::Op(a, func, _)) => {
|
||||
if cfg!(feature = "debug:instr") {
|
||||
if cfg!(feature = "debug.instr") {
|
||||
println!("{}", a);
|
||||
println!("Stack: {:?}", self.cur_frame().stack.data);
|
||||
let x = func(self);
|
||||
|
||||
@@ -66,7 +66,7 @@ impl NetStack {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
pub fn write_byte(&mut self, byte: u8) -> Result<()> {
|
||||
match self.stream {
|
||||
Some(ref mut stream) => {
|
||||
|
||||
36
src/ops.rs
36
src/ops.rs
@@ -45,7 +45,7 @@ lazy_static! {
|
||||
m[0x60] = Operation::Op("IADD", iadd, vec![]);
|
||||
m[0x64] = Operation::Op("ISUB", isub, vec![]);
|
||||
|
||||
#[cfg(feature = "extra:arithmetic")]
|
||||
#[cfg(feature = "extra.arithmetic")]
|
||||
{
|
||||
m[0x70] = Operation::Op("SHL", shl, vec![]);
|
||||
m[0x71] = Operation::Op("SHR", shr, vec![]);
|
||||
@@ -68,7 +68,7 @@ lazy_static! {
|
||||
|
||||
m[0xC4] = Operation::Op("WIDE", wide, vec![]);
|
||||
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
#[cfg(feature = "bonus.heap")]
|
||||
{
|
||||
m[0xD1] = Operation::Op("NEWARRAY", newarray, vec![]);
|
||||
m[0xD2] = Operation::Op("IALOAD", iaload, vec![]);
|
||||
@@ -76,7 +76,7 @@ lazy_static! {
|
||||
m[0xD4] = Operation::Op("GC", gc, vec![]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
{
|
||||
m[0xE1] = Operation::Op("NETBIND", netbind, vec![]);
|
||||
m[0xE2] = Operation::Op("NETCONNECT", netconnect, vec![]);
|
||||
@@ -85,7 +85,7 @@ lazy_static! {
|
||||
m[0xE5] = Operation::Op("NETCLOSE", netclose, vec![]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "extra:sleep")]
|
||||
#[cfg(feature = "extra.sleep")]
|
||||
{
|
||||
m[0xF0] = Operation::Op("SLP", slp, vec![Args::Byte]);
|
||||
}
|
||||
@@ -294,7 +294,7 @@ fn ireturn(machine: &mut Machine) -> Result<()> {
|
||||
machine.block.seek(return_addr as usize)
|
||||
}
|
||||
|
||||
#[cfg(feature = "extra:sleep")]
|
||||
#[cfg(feature = "extra.sleep")]
|
||||
fn slp(machine: &mut Machine) -> Result<()> {
|
||||
use std::thread;
|
||||
use std::time;
|
||||
@@ -307,7 +307,7 @@ fn slp(machine: &mut Machine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
fn netbind(machine: &mut Machine) -> Result<()> {
|
||||
let port: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
|
||||
@@ -319,7 +319,7 @@ fn netbind(machine: &mut Machine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
fn netconnect(machine: &mut Machine) -> Result<()> {
|
||||
let port: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let host: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
@@ -331,7 +331,7 @@ fn netconnect(machine: &mut Machine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
fn netin(machine: &mut Machine) -> Result<()> {
|
||||
let netref: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
if netref != 1 {
|
||||
@@ -343,7 +343,7 @@ fn netin(machine: &mut Machine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
fn netout(machine: &mut Machine) -> Result<()> {
|
||||
let netref: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
if netref != 1 {
|
||||
@@ -354,7 +354,7 @@ fn netout(machine: &mut Machine) -> Result<()> {
|
||||
machine.net.write_byte(val as u8)
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
#[cfg(feature = "bonus.network")]
|
||||
fn netclose(machine: &mut Machine) -> Result<()> {
|
||||
let netref: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
if netref != 1 {
|
||||
@@ -363,7 +363,7 @@ fn netclose(machine: &mut Machine) -> Result<()> {
|
||||
machine.net.close()
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
#[cfg(feature = "bonus.heap")]
|
||||
fn newarray(machine: &mut Machine) -> Result<()> {
|
||||
let size: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let heap = machine.heap.alloc(size as usize);
|
||||
@@ -371,7 +371,7 @@ fn newarray(machine: &mut Machine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
#[cfg(feature = "bonus.heap")]
|
||||
fn iastore(machine: &mut Machine) -> Result<()> {
|
||||
use std::cell::RefCell;
|
||||
|
||||
@@ -387,7 +387,7 @@ fn iastore(machine: &mut Machine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
#[cfg(feature = "bonus.heap")]
|
||||
fn iaload(machine: &mut Machine) -> Result<()> {
|
||||
let heap = match machine.cur_stack().pop()? {
|
||||
Value::HeapRef(a) => a,
|
||||
@@ -404,13 +404,13 @@ fn iaload(machine: &mut Machine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
#[cfg(feature = "bonus.heap")]
|
||||
fn gc(machine: &mut Machine) -> Result<()> {
|
||||
machine.heap.gc();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "extra:arithmetic")]
|
||||
#[cfg(feature = "extra.arithmetic")]
|
||||
fn shl(machine: &mut Machine) -> Result<()> {
|
||||
let shift: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let value: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
@@ -419,7 +419,7 @@ fn shl(machine: &mut Machine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "extra:arithmetic")]
|
||||
#[cfg(feature = "extra.arithmetic")]
|
||||
fn shr(machine: &mut Machine) -> Result<()> {
|
||||
let shift: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let value: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
@@ -429,7 +429,7 @@ fn shr(machine: &mut Machine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "extra:arithmetic")]
|
||||
#[cfg(feature = "extra.arithmetic")]
|
||||
fn imul(machine: &mut Machine) -> Result<()> {
|
||||
let a: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let b: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
@@ -438,7 +438,7 @@ fn imul(machine: &mut Machine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "extra:arithmetic")]
|
||||
#[cfg(feature = "extra.arithmetic")]
|
||||
fn idiv(machine: &mut Machine) -> Result<()> {
|
||||
let divisor: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let value: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
|
||||
Reference in New Issue
Block a user