assembler shenanigans. shiny ahh code.

This commit is contained in:
2025-06-16 03:48:31 +01:00
parent 2b5ad0885b
commit 7f834adbce
5 changed files with 679 additions and 0 deletions
+24
View File
@@ -1,5 +1,12 @@
use core::fmt;
use common::prelude::Instruction;
use crate::{lexer::Token, parser::TokenType};
pub mod lexer;
pub mod parser;
pub fn assemble(src: &str) -> Vec<Instruction> {
todo!()
}
@@ -12,3 +19,20 @@ pub fn disassemble(binary: Vec<Instruction>) -> String {
// sequences that are expansions of pseduo-instructions and reversing this to produce near enough the original source code.
todo!()
}
#[derive(Debug)]
pub enum AssembleError {
Generic,
UnexpectedToken(Token, TokenType),
}
impl fmt::Display for AssembleError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AssembleError::Generic => write!(f, "Generic error"),
AssembleError::UnexpectedToken(tok, expected) => {
write!(f, "Unexpected token {:?}, expected {:?}", tok, expected)
}
}
}
}