From 4cc350870d59518fec1cd259d84989d1a0f85572 Mon Sep 17 00:00:00 2001 From: Ryan Jones-Ward Date: Fri, 12 Jul 2024 14:31:19 +0100 Subject: [PATCH] More work on the byte data declaration statement. --- redox-core/src/parsing/asm_parser.rs | 35 +++++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/redox-core/src/parsing/asm_parser.rs b/redox-core/src/parsing/asm_parser.rs index c6e56be..b09dfe2 100644 --- a/redox-core/src/parsing/asm_parser.rs +++ b/redox-core/src/parsing/asm_parser.rs @@ -59,6 +59,7 @@ enum Argument { /// The supported data declaration command types. #[derive(Debug, Clone)] enum DataDeclarationType { + // Declare a byte storage block. DB, } @@ -448,10 +449,26 @@ impl<'a> AsmParser<'a> { } }); - let declarationType = DataDeclarationType::try_from(arguments[1].as_str()); - println!("{declarationType:?}"); + let label = &arguments[0]; + let declaration_args = &arguments[2..]; + let declaration_type = DataDeclarationType::try_from(arguments[1].as_str()) + .expect("invalid syntax - failed to identify data declaration type"); - println!("{arguments:?}"); + let mut storage = vec![]; + match declaration_type { + DataDeclarationType::DB => { + for arg in declaration_args { + AsmParser::try_parse_data_byte_declaration_args(arg, &mut storage); + } + } + } + + println!("label = {label}, declaration_type = {declaration_type:?}, storage = {storage:?}"); + } + + fn try_parse_data_byte_declaration_args(arg: &str, bytes: &mut Vec) { + println!("argument: {}", arg); + bytes.push(0); } /// Parse a section line of an ASM file. @@ -981,15 +998,15 @@ impl<'a> AsmParser<'a> { // I can't imagine these would be used much... but why not? if string.starts_with("0b") { // Binary. - let stripped = string.strip_prefix("0b").expect(""); + let stripped = string.strip_prefix("0b").unwrap(); u8::from_str_radix(stripped, 2) } else if string.starts_with("0o") { // Octal. - let stripped = string.strip_prefix("0o").expect(""); + let stripped = string.strip_prefix("0o").unwrap(); u8::from_str_radix(stripped, 8) } else if string.starts_with("0x") { // Hex. - let stripped = string.strip_prefix("0x").expect(""); + let stripped = string.strip_prefix("0x").unwrap(); u8::from_str_radix(stripped, 16) } else { string.parse::() @@ -1006,15 +1023,15 @@ impl<'a> AsmParser<'a> { // I can't imagine these would be used much... but why not? if string.starts_with("0b") { // Binary. - let stripped = string.strip_prefix("0b").expect(""); + let stripped = string.strip_prefix("0b").unwrap(); u32::from_str_radix(stripped, 2) } else if string.starts_with("0o") { // Octal. - let stripped = string.strip_prefix("0o").expect(""); + let stripped = string.strip_prefix("0o").unwrap(); u32::from_str_radix(stripped, 8) } else if string.starts_with("0x") { // Hex. - let stripped = string.strip_prefix("0x").expect(""); + let stripped = string.strip_prefix("0x").unwrap(); u32::from_str_radix(stripped, 16) } else { string.parse::()