|
|
|
@ -15,6 +15,7 @@ pub const T_WRITE: u8 = 0x06;
|
|
|
|
|
pub const T_LABEL: u8 = 0x07;
|
|
|
|
|
pub const T_GOTO: u8 = 0x08;
|
|
|
|
|
pub const T_DEBUG: u8 = 0x09;
|
|
|
|
|
pub const T_PRINT: u8 = 0x0A;
|
|
|
|
|
pub const T_ADD: u8 = 0x10;
|
|
|
|
|
pub const T_SUB: u8 = 0x11;
|
|
|
|
|
pub const T_MUL: u8 = 0x12;
|
|
|
|
@ -311,9 +312,36 @@ impl Token for DebugToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for GotoToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct PrintToken {
|
|
|
|
|
pub register: u8,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Token for PrintToken {
|
|
|
|
|
fn to_bytecode(&self) -> Vec<u8> {
|
|
|
|
|
vec![T_PRINT, self.register]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn invoke(&self, runtime: &mut Runtime) -> io::Result<()> {
|
|
|
|
|
let mut value = if let Some(rg) = runtime.get_1byte_register(self.register) {
|
|
|
|
|
rg.get() as u32
|
|
|
|
|
} else if let Some(rg) = runtime.get_4byte_register(self.register) {
|
|
|
|
|
rg.get()
|
|
|
|
|
} else if self.register == RCS {
|
|
|
|
|
runtime.rcs.get() as u32
|
|
|
|
|
} else {
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
println!("{}", value);
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for PrintToken {
|
|
|
|
|
fn from_bytecode(code: &[&u8]) -> Self {
|
|
|
|
|
Self { register: *code[1] }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -331,13 +359,6 @@ impl Token for AddToken {
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for AddToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct SubToken;
|
|
|
|
|
|
|
|
|
@ -353,12 +374,6 @@ impl Token for SubToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for SubToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct MulToken;
|
|
|
|
|
|
|
|
|
@ -374,12 +389,6 @@ impl Token for MulToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for MulToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct DivToken;
|
|
|
|
|
|
|
|
|
@ -395,12 +404,6 @@ impl Token for DivToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for DivToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct ModToken;
|
|
|
|
|
|
|
|
|
@ -416,12 +419,6 @@ impl Token for ModToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for ModToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct LshToken;
|
|
|
|
|
|
|
|
|
@ -437,12 +434,6 @@ impl Token for LshToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for LshToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct RshToken;
|
|
|
|
|
|
|
|
|
@ -458,12 +449,6 @@ impl Token for RshToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for RshToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct JgToken;
|
|
|
|
|
|
|
|
|
@ -481,12 +466,6 @@ impl Token for JgToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for JgToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct JlToken;
|
|
|
|
|
|
|
|
|
@ -504,12 +483,6 @@ impl Token for JlToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for JlToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct JeToken;
|
|
|
|
|
|
|
|
|
@ -527,12 +500,6 @@ impl Token for JeToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for JeToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct PauseToken;
|
|
|
|
|
|
|
|
|
@ -548,12 +515,6 @@ impl Token for PauseToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for PauseToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct CmdToken;
|
|
|
|
|
|
|
|
|
@ -569,12 +530,6 @@ impl Token for CmdToken {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromBytecode for CmdToken {
|
|
|
|
|
fn from_bytecode(_: &[&u8]) -> Self {
|
|
|
|
|
Self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct SendToken;
|
|
|
|
|
|
|
|
|
|
impl Token for SendToken {
|
|
|
|
|