diff options
-rw-r--r-- | Cargo.lock | 23 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-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 |
5 files changed, 36 insertions, 11 deletions
@@ -17,11 +17,34 @@ name = "bedrock-asm" version = "1.0.0" dependencies = [ "assembler", + "indexmap", "log 2.0.0", "switchboard", ] [[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "hashbrown" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" + +[[package]] +name = "indexmap" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] name = "inked" version = "1.0.0" source = "git+git://benbridle.com/inked?tag=v1.0.0#2954d37b638fa2c1dd3d51ff53f08f475aea6ea3" @@ -10,6 +10,8 @@ assembler = { git = "git://benbridle.com/assembler", tag = "v2.3.0" } log = { git = "git://benbridle.com/log", tag = "v2.0.0" } switchboard = { git = "git://benbridle.com/switchboard", tag = "v2.1.0" } +indexmap = "2.7.1" + [profile.release] lto=true opt-level="s" 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})"), |