-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some error checking and move some of the returned items into a ho…
…lding struct instead, to keep things cleaner.
- Loading branch information
1 parent
58a2954
commit ca23d53
Showing
4 changed files
with
74 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#[derive(Debug, Clone)] | ||
pub struct DataDeclaration { | ||
/// The [`DataDeclarationType`]. | ||
pub declaration_type: DataDeclarationType, | ||
/// The label associated with the statement. | ||
pub label: String, | ||
/// The stored bytes. | ||
pub bytes: Vec<u8>, | ||
} | ||
|
||
impl DataDeclaration { | ||
pub fn new(declaration_type: DataDeclarationType, label: String, bytes: Vec<u8>) -> Self { | ||
Self { | ||
declaration_type, | ||
label, | ||
bytes, | ||
} | ||
} | ||
} | ||
|
||
/// The supported data declaration statement types. | ||
#[derive(Debug, Clone)] | ||
pub enum DataDeclarationType { | ||
/// Declare a byte storage block. | ||
DB, | ||
} | ||
|
||
impl TryFrom<&str> for DataDeclarationType { | ||
type Error = (); | ||
|
||
fn try_from(string: &str) -> Result<Self, Self::Error> { | ||
match string.to_lowercase().as_str() { | ||
"db" => Ok(DataDeclarationType::DB), | ||
_ => { | ||
panic!("invalid syntax - an unrecognized data declaration {string}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod asm_parser; | ||
mod data_declaration; | ||
mod type_hints; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters