From 184c39579227c0add80a61d489c242120001d6b6 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 26 Sep 2024 15:53:57 +0200 Subject: Re-work the parser from scratch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The initial implementation was incredibly naive on how complex an assembler can actually be. Because of this, it never bothered to define and produce a proper AST, and hence it was overall extremely fragile on (not so) corner cases. This commit re-writes everything from scratch for the parser, and it should really be the last fundamental change to the parser other than minor additions/features here and there. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/opcodes.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/xixanta/src/opcodes.rs') diff --git a/lib/xixanta/src/opcodes.rs b/lib/xixanta/src/opcodes.rs index a716545..e849126 100644 --- a/lib/xixanta/src/opcodes.rs +++ b/lib/xixanta/src/opcodes.rs @@ -19,6 +19,12 @@ pub struct Entry { pub affected_on_page: bool, } +#[derive(Debug)] +pub struct Control { + pub has_identifier: bool, + pub required_args: Option, +} + lazy_static! { pub static ref INSTRUCTIONS: HashMap> = { let mut instrs = HashMap::new(); @@ -669,4 +675,25 @@ lazy_static! { opcodes }; + + pub static ref CONTROL_FUNCTIONS: HashMap = { + let mut functions = HashMap::new(); + + functions.insert(String::from(".hibyte"), Control { has_identifier: false, required_args: Some(1) }); + functions.insert(String::from(".lobyte"), Control { has_identifier: false, required_args: Some(1) }); + functions.insert(String::from(".macro"), Control { has_identifier: true, required_args: None }); + functions.insert(String::from(".proc"), Control { has_identifier: true, required_args: Some(0) }); + functions.insert(String::from(".scope"), Control { has_identifier: true, required_args: Some(0) }); + functions.insert(String::from(".end"), Control { has_identifier: false, required_args: Some(0) }); + functions.insert(String::from(".endscope"), Control { has_identifier: false, required_args: Some(0) }); + functions.insert(String::from(".endproc"), Control { has_identifier: false, required_args: Some(0) }); + functions.insert(String::from(".endmacro"), Control { has_identifier: false, required_args: Some(0) }); + functions.insert(String::from(".segment"), Control { has_identifier: false, required_args: Some(1) }); + functions.insert(String::from(".byte"), Control { has_identifier: false, required_args: None }); + functions.insert(String::from(".db"), Control { has_identifier: false, required_args: None }); + functions.insert(String::from(".word"), Control { has_identifier: false, required_args: None }); + functions.insert(String::from(".dw"), Control { has_identifier: false, required_args: None }); + + functions + }; } -- cgit v1.2.3