|
|
@ -5,10 +5,10 @@ use crate::registers::{
|
|
|
|
use crate::tokens::{
|
|
|
|
use crate::tokens::{
|
|
|
|
AddToken, AndToken, ClearToken, CmdToken, CopyToken, DebugToken, DivToken, ExitToken,
|
|
|
|
AddToken, AndToken, ClearToken, CmdToken, CopyToken, DebugToken, DivToken, ExitToken,
|
|
|
|
FromBytecode, GotoToken, JeToken, JgToken, JlToken, LabelToken, LoadToken, LshToken, ModToken,
|
|
|
|
FromBytecode, GotoToken, JeToken, JgToken, JlToken, LabelToken, LoadToken, LshToken, ModToken,
|
|
|
|
MulToken, NopToken, NotToken, NrtToken, OrToken, PauseToken, PowToken, PrintToken, RshToken,
|
|
|
|
MulToken, NotToken, NrtToken, OrToken, PauseToken, PowToken, PrintToken, RshToken, SendToken,
|
|
|
|
SendToken, SetToken, SubToken, Token, WriteToken, XorToken, T_ADD, T_AND, T_CLEAR, T_CMD,
|
|
|
|
SetToken, SubToken, Token, WriteToken, XorToken, T_ADD, T_AND, T_CLEAR, T_CMD, T_COPY, T_DEBUG,
|
|
|
|
T_COPY, T_DEBUG, T_DIV, T_EXIT, T_GOTO, T_JE, T_JG, T_JL, T_LABEL, T_LOAD, T_LSH, T_MOD, T_MUL,
|
|
|
|
T_DIV, T_EXIT, T_GOTO, T_JE, T_JG, T_JL, T_LABEL, T_LOAD, T_LSH, T_MOD, T_MUL, T_NOT, T_NRT,
|
|
|
|
T_NOT, T_NRT, T_OR, T_PAUSE, T_POW, T_PRINT, T_RSH, T_SEND, T_SET, T_SUB, T_WRITE, T_XOR,
|
|
|
|
T_OR, T_PAUSE, T_POW, T_PRINT, T_RSH, T_SEND, T_SET, T_SUB, T_WRITE, T_XOR,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashMap;
|
|
|
@ -32,6 +32,7 @@ pub struct Runtime {
|
|
|
|
pub strip_controller: Rc<RefCell<LedStripController>>,
|
|
|
|
pub strip_controller: Rc<RefCell<LedStripController>>,
|
|
|
|
exit: Option<u8>,
|
|
|
|
exit: Option<u8>,
|
|
|
|
current_index: usize,
|
|
|
|
current_index: usize,
|
|
|
|
|
|
|
|
debug: bool,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Runtime {
|
|
|
|
impl Runtime {
|
|
|
@ -56,9 +57,15 @@ impl Runtime {
|
|
|
|
strip_controller: controller,
|
|
|
|
strip_controller: controller,
|
|
|
|
exit: None,
|
|
|
|
exit: None,
|
|
|
|
current_index: 0,
|
|
|
|
current_index: 0,
|
|
|
|
|
|
|
|
debug: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Sets debug to the specified value
|
|
|
|
|
|
|
|
pub fn set_debug(&mut self, debug: bool) {
|
|
|
|
|
|
|
|
self.debug = debug;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Parses a vector containing the bytecode into a vector of tokens
|
|
|
|
/// Parses a vector containing the bytecode into a vector of tokens
|
|
|
|
/// that can be executed
|
|
|
|
/// that can be executed
|
|
|
|
pub fn parse_bytecode(&mut self, bytecode: Vec<u8>) {
|
|
|
|
pub fn parse_bytecode(&mut self, bytecode: Vec<u8>) {
|
|
|
@ -137,6 +144,9 @@ impl Runtime {
|
|
|
|
while self.current_index < text.len() {
|
|
|
|
while self.current_index < text.len() {
|
|
|
|
let token = text.get(self.current_index).unwrap();
|
|
|
|
let token = text.get(self.current_index).unwrap();
|
|
|
|
token.invoke(self)?;
|
|
|
|
token.invoke(self)?;
|
|
|
|
|
|
|
|
if self.debug {
|
|
|
|
|
|
|
|
println!("{:?}", token);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(code) = self.exit {
|
|
|
|
if let Some(code) = self.exit {
|
|
|
|
self.strip_controller
|
|
|
|
self.strip_controller
|
|
|
|