From cf1af202e01cdcbac437ac96f21c4437bf27bb0d Mon Sep 17 00:00:00 2001
From: Ben Bridle <ben@derelict.engineering>
Date: Tue, 4 Feb 2025 18:17:28 +1300
Subject: Use locator types from assembler crate

Work-in-progress commit while functionality is moved over to the
assembler crate. This commit doesn't compile.
---
 Cargo.lock               |  6 ++++
 Cargo.toml               |  1 +
 src/lib.rs               |  5 ++--
 src/locators.rs          |  5 ----
 src/locators/bytecode.rs | 39 -------------------------
 src/locators/source.rs   | 75 ------------------------------------------------
 6 files changed, 10 insertions(+), 121 deletions(-)
 delete mode 100644 src/locators.rs
 delete mode 100644 src/locators/bytecode.rs
 delete mode 100644 src/locators/source.rs

diff --git a/Cargo.lock b/Cargo.lock
index 37a16f3..acfec75 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2,10 +2,16 @@
 # It is not intended for manual editing.
 version = 4
 
+[[package]]
+name = "assembler"
+version = "1.0.0"
+source = "git+git://benbridle.com/assembler?tag=v1.0.0#93b2bc229a8347a925df819b2d6199a1a6066cf0"
+
 [[package]]
 name = "bedrock-asm"
 version = "4.0.6"
 dependencies = [
+ "assembler",
  "vagabond",
  "xflags",
 ]
diff --git a/Cargo.toml b/Cargo.toml
index 6dd908a..f5d7ef8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,7 @@ description = "Assembler program for the Bedrock assembly language"
 
 
 [dependencies]
+assembler = { git = "git://benbridle.com/assembler", tag = "v1.0.0" }
 vagabond = { git = "git://benbridle.com/vagabond", tag = "v1.0.1" }
 xflags = "0.4.0-pre"
 
diff --git a/src/lib.rs b/src/lib.rs
index 3470e6e..2108252 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,13 +9,14 @@ mod symbol_resolver;
 pub use gather_libraries::*;
 pub use symbol_resolver::*;
 
-mod locators;
 mod tokens;
 mod translators;
 
-pub use locators::*;
 pub use tokens::*;
 pub use translators::*;
 
 mod print;
 pub use print::*;
+
+
+pub use assembler::*;
diff --git a/src/locators.rs b/src/locators.rs
deleted file mode 100644
index b7db1ee..0000000
--- a/src/locators.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-mod bytecode;
-mod source;
-
-pub use bytecode::*;
-pub use source::*;
diff --git a/src/locators/bytecode.rs b/src/locators/bytecode.rs
deleted file mode 100644
index 500e9f0..0000000
--- a/src/locators/bytecode.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-pub struct BytecodeSpan {
-    /// The location of this span in the assembled bytecode.
-    pub location: BytecodeLocation,
-    /// The bytes which this span represents.
-    pub bytes: Vec<u8>,
-}
-
-
-impl Default for BytecodeSpan {
-    fn default() -> Self {
-        Self {
-            location: BytecodeLocation {
-                address: 0,
-                length: 0,
-            },
-            bytes: Vec::new(),
-        }
-    }
-}
-
-
-#[derive(Clone, Copy)]
-pub struct BytecodeLocation {
-    // Address of the first byte.
-    pub address: usize,
-    // Length as a number of bytes.
-    pub length: usize,
-}
-
-
-impl std::fmt::Display for BytecodeLocation {
-    fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
-        write!(f, "0x{:>04x}", self.address)?;
-        if self.length > 0 {
-            write!(f, "-0x{:>04x}", self.address + self.length)?;
-        }
-        Ok(())
-    }
-}
diff --git a/src/locators/source.rs b/src/locators/source.rs
deleted file mode 100644
index 20542e3..0000000
--- a/src/locators/source.rs
+++ /dev/null
@@ -1,75 +0,0 @@
-use std::path::PathBuf;
-
-
-#[derive(Clone)]
-pub struct SourceSpan {
-    /// The source characters which this span represents.
-    pub string: String,
-    /// The location of this span in the merged source file.
-    pub in_merged: SourceLocation,
-    /// The location of this span in the original source file.
-    pub in_source: Option<SourceLocation>,
-}
-
-impl SourceSpan {
-    pub fn location(&self) -> &SourceLocation {
-        self.in_source.as_ref().unwrap_or(&self.in_merged)
-    }
-}
-
-
-#[derive(Clone)]
-pub struct SourceLocation {
-    /// File path the source was loaded from.
-    pub path: Option<PathBuf>,
-    /// Position of the first character of the string.
-    pub start: Position,
-    /// Position of the final character of the string.
-    pub end: Position,
-}
-
-impl std::fmt::Display for SourceLocation {
-    fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
-        let y = self.start.line + 1;
-        let x = self.start.column + 1;
-        match &self.path {
-            Some(path) => write!(f, "{}:{y}:{x}", path.as_os_str().to_string_lossy()),
-            None => write!(f, "<unknown>:{y}:{x}"),
-        }
-    }
-}
-
-
-#[derive(Clone, Copy)]
-pub struct Position {
-    /// The number of lines that precede this line in the file.
-    pub line: usize,
-    /// The number of characters that precede this character in the line.
-    pub column: usize,
-}
-
-impl Position {
-    pub fn to_next_char(&mut self) {
-        self.column += 1;
-    }
-
-    pub fn to_next_line(&mut self) {
-        self.line += 1;
-        self.column = 0;
-    }
-
-    pub fn advance(&mut self, c: char) {
-        match c {
-            '\n' => self.to_next_line(),
-            _ => self.to_next_char(),
-        }
-    }
-}
-
-impl std::fmt::Display for Position {
-    fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
-        let y = self.line + 1;
-        let x = self.column + 1;
-        write!(f, "{y}:{x}")
-    }
-}
-- 
cgit v1.2.3-70-g09d2