summaryrefslogtreecommitdiff
path: root/src/stages/bytecode_tokens.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2025-07-03 14:56:25 +1200
committerBen Bridle <ben@derelict.engineering>2025-07-03 21:22:31 +1200
commit21101c197643836184e754c60d5075ee5a2d3cdf (patch)
treecc4533251bfce394e913009473b7dd49b3bbb1ac /src/stages/bytecode_tokens.rs
downloadbedrock-asm-21101c197643836184e754c60d5075ee5a2d3cdf.zip
Initial commit
Diffstat (limited to 'src/stages/bytecode_tokens.rs')
-rw-r--r--src/stages/bytecode_tokens.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/stages/bytecode_tokens.rs b/src/stages/bytecode_tokens.rs
new file mode 100644
index 0000000..902fcd7
--- /dev/null
+++ b/src/stages/bytecode_tokens.rs
@@ -0,0 +1,37 @@
+use crate::*;
+
+
+pub struct AssembledProgram {
+ pub bytecode: Vec<u8>,
+ pub symbols: Vec<AssembledSymbol>,
+}
+
+pub struct AssembledSymbol {
+ pub name: String,
+ pub address: usize,
+ pub source: SourceSpan,
+}
+
+pub enum BytecodeError {
+ InvalidLabelAddress(usize),
+ InvalidBlockAddress(usize),
+}
+
+
+pub fn report_bytecode_errors(errors: &[Tracked<BytecodeError>], source_code: &str) {
+ for error in errors {
+ report_bytecode_error(error, source_code);
+ }
+}
+
+
+fn report_bytecode_error(error: &Tracked<BytecodeError>, source_code: &str) {
+ let context = Context { source_code: &source_code, source: &error.source };
+ let message = match &error.value {
+ BytecodeError::InvalidLabelAddress(address) =>
+ &format!("The label address exceeds 0xFFFF: 0x{address:X}"),
+ BytecodeError::InvalidBlockAddress(address) =>
+ &format!("The block address exceeds 0xFFFF: 0x{address:X}"),
+ };
+ report_source_issue(LogLevel::Error, &context, message);
+}