|
|
@@ -198,41 +198,6 @@ pub enum Token { |
|
|
|
} |
|
|
|
|
|
|
|
impl Token { |
|
|
|
// returns the token as a str |
|
|
|
fn as_str(&self) -> String { |
|
|
|
match self { |
|
|
|
// general stuff |
|
|
|
Self::Comment => "a comment".to_owned(), |
|
|
|
Self::Newline => "\\n".to_owned(), |
|
|
|
// registers |
|
|
|
Self::ZeroRegister => "$z0".to_owned(), |
|
|
|
Self::ProgramCounter => "$pc".to_owned(), |
|
|
|
Self::StackPointer => "$sp".to_owned(), |
|
|
|
Self::ReturnAddress => "$ra".to_owned(), |
|
|
|
Self::ArgumentZero => "$a0".to_owned(), |
|
|
|
Self::ArgumentOne => "$z1".to_owned(), |
|
|
|
Self::ArgumentTwo => "$a2".to_owned(), |
|
|
|
Self::ReturnZero => "$v0".to_owned(), |
|
|
|
Self::ReturnOne => "$v1".to_owned(), |
|
|
|
Self::TemporaryRegister(idx) => format!("$t{}", idx), |
|
|
|
Self::RegisterIndex(idx) => format!("${}", idx), |
|
|
|
// types |
|
|
|
Self::Immediate => "immd".to_owned(), |
|
|
|
Self::VideoMemory => "vram".to_owned(), |
|
|
|
Self::CartMemory => "cram".to_owned(), |
|
|
|
// literals |
|
|
|
Self::HexLiteral(_) => "hex lit".to_owned(), |
|
|
|
Self::BinaryLiteral(_) => "bin lit".to_owned(), |
|
|
|
Self::DecimalLiteral(_) => "dec lit".to_owned(), |
|
|
|
// instructions |
|
|
|
Self::Load => "ld:".to_owned(), |
|
|
|
Self::Add => "add".to_owned(), |
|
|
|
Self::Sub => "sub".to_owned(), |
|
|
|
// errors |
|
|
|
Self::Error => "ERR".to_owned(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// returns the index of a register |
|
|
|
fn register_index(&self) -> Result<u8> { |
|
|
|
match self { |
|
|
|