assembler: enhance error handling and tokenization logic

This commit is contained in:
2025-06-26 17:00:14 +01:00
parent 40f8b1d57b
commit ed4fcc8495
11 changed files with 514 additions and 98 deletions
+5 -9
View File
@@ -5,10 +5,9 @@
use common::prelude::*;
use crate::source::{
opcode::Opcode,
source_info::SourceInfo,
token_info::{
DirectiveToken, InstructionToken, LabelToken, RegisterToken, SymbolToken,
},
token_info::{DirectiveToken, LabelToken, RegisterToken, SymbolToken},
};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -22,7 +21,7 @@ pub enum TokenType {
/// String literal (e.g., `"hello world"`).
String(String),
/// Assembly instruction (e.g., `add`, `jmp`, `nop`).
Instruction(InstructionToken),
Instruction(Opcode),
/// Label definition (e.g., `loop_start:`).
Label(LabelToken),
/// Assembler directive (e.g., `.global`, `.section`, `.dw`, `.resb`).
@@ -65,11 +64,8 @@ impl Token {
}
#[must_use]
pub const fn instruction(mnemonic: String, source_info: SourceInfo) -> Self {
Self::new(
TokenType::Instruction(InstructionToken { mnemonic }),
source_info,
)
pub const fn instruction(op: Opcode, source_info: SourceInfo) -> Self {
Self::new(TokenType::Instruction(op), source_info)
}
#[must_use]