diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-07-04 21:17:30 +1200 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-07-04 21:17:30 +1200 |
commit | 99ad972395af9953e433b4a7c11bcfd6c4daad3f (patch) | |
tree | 78e6b2c8f3dcc4acc0a3d7bc3e22fbfbc2d973ad /src | |
parent | f454238e433792fda0f66f807f7ec12d3e560fa2 (diff) | |
download | bedrock-asm-99ad972395af9953e433b4a7c11bcfd6c4daad3f.zip |
Fix sort order of generated symbols file
The symbols file was not being generated in ascending address order.
This was because the assembler was using unordered HashMaps, which have
now been replaced with ordered IndexMaps.
Diffstat (limited to 'src')
-rw-r--r-- | src/stages/bytecode.rs | 10 | ||||
-rw-r--r-- | src/stages/semantic.rs | 6 | ||||
-rw-r--r-- | src/stages/semantic_tokens.rs | 6 |
3 files changed, 11 insertions, 11 deletions
diff --git a/src/stages/bytecode.rs b/src/stages/bytecode.rs index f0b99df..02cc739 100644 --- a/src/stages/bytecode.rs +++ b/src/stages/bytecode.rs @@ -1,6 +1,6 @@ use crate::*; -use std::collections::HashMap; +use indexmap::IndexMap; /// Doesn't truncate trailing null bytes. @@ -22,8 +22,8 @@ pub fn generate_bytecode(semantic: &Program) -> Result<AssembledProgram, Vec<Tra pub struct BytecodeGenerator<'a> { - definitions: &'a HashMap<String, Tracked<Definition>>, - labels: HashMap<String, LabelInformation>, + definitions: &'a IndexMap<String, Tracked<Definition>>, + labels: IndexMap<String, LabelInformation>, stack: Vec<usize>, bytecode: Vec<u8>, errors: Vec<Tracked<BytecodeError>>, @@ -35,8 +35,8 @@ struct LabelInformation { } impl<'a> BytecodeGenerator<'a> { - pub fn new(definitions: &'a HashMap<String, Tracked<Definition>>) -> Self { - let mut labels = HashMap::new(); + pub fn new(definitions: &'a IndexMap<String, Tracked<Definition>>) -> Self { + let mut labels = IndexMap::new(); for (name, definition) in definitions { if let DefinitionVariant::LabelDefinition = definition.variant { // Use fake address for now. diff --git a/src/stages/semantic.rs b/src/stages/semantic.rs index f2774a4..909659d 100644 --- a/src/stages/semantic.rs +++ b/src/stages/semantic.rs @@ -1,12 +1,12 @@ use crate::*; -use std::collections::{HashMap, HashSet}; +use indexmap::{IndexMap, IndexSet}; pub fn parse_semantic(syntactic: Vec<Tracked<SyntacticToken>>) -> Result<Program, Vec<Tracked<SemanticError>>> { // Record all label definitions and macro names up front. - let mut definitions = HashMap::new(); - let mut macro_names = HashSet::new(); + let mut definitions = IndexMap::new(); + let mut macro_names = IndexSet::new(); for token in &syntactic { match &token.value { SyntacticToken::LabelDefinition(name) => { diff --git a/src/stages/semantic_tokens.rs b/src/stages/semantic_tokens.rs index fe49c26..fc454be 100644 --- a/src/stages/semantic_tokens.rs +++ b/src/stages/semantic_tokens.rs @@ -1,10 +1,10 @@ use crate::*; -use std::collections::HashMap; +use indexmap::IndexMap; pub struct Program { - pub definitions: HashMap<String, Tracked<Definition>>, + pub definitions: IndexMap<String, Tracked<Definition>>, pub tokens: Vec<Tracked<SemanticToken>>, } @@ -69,7 +69,7 @@ fn report_semantic_error(error: &Tracked<SemanticError>, source_code: &str) { } -pub fn print_semantic_token(i: usize, token: &SemanticToken, definitions: &HashMap<String, Tracked<Definition>>) { +pub fn print_semantic_token(i: usize, token: &SemanticToken, definitions: &IndexMap<String, Tracked<Definition>>) { match token { SemanticToken::Literal(value) => indent!(i, "Literal({value})"), SemanticToken::Pad(value) => indent!(i, "Pad({value})"), |