summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2024-10-28 19:52:29 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2024-10-28 19:52:47 +1300
commitf4027cae775e3c9c237675f9df35a744d54f3f2e (patch)
tree733fa3af9e1bd44d61dd83983a2da86cb75c53e9 /src/main.rs
parent16ee0e9e8dce2c88acc88ba5ffd97e013624fa5e (diff)
downloadbedrock-asm-f4027cae775e3c9c237675f9df35a744d54f3f2e.zip
Rewrite assembler
This is an almost complete rewrite of the entire assembler from the ground up, with a different parsing strategy and a whole new symbol resolution mechanism for automatically including library files. The assembly syntax has also been slightly modified, with padding tokens now being prefixed with '#' instead of '$', and a block-style anonymous-label syntax which uses the '{' and '}' characters.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs43
1 files changed, 0 insertions, 43 deletions
diff --git a/src/main.rs b/src/main.rs
deleted file mode 100644
index 11ce42b..0000000
--- a/src/main.rs
+++ /dev/null
@@ -1,43 +0,0 @@
-use std::io::{Read, Write};
-use bedrock_asm::*;
-
-fn main() {
- // Read source code from standard input
- let mut source_code = String::new();
- if let Err(err) = std::io::stdin().read_to_string(&mut source_code) {
- eprintln!("Could not read from standard input, quitting.");
- eprintln!("({err:?})");
- std::process::exit(1);
- };
-
- let (bytecode, tokens) = assemble(&source_code);
- let mut is_error = false;
- for token in &tokens {
- if token.print_error(&source_code) { is_error = true };
- }
- if !is_error {
- for token in &tokens {
- if let SemanticTokenType::LabelDefinition(def) = &token.r#type {
- if def.references.is_empty() {
- eprintln!("Unused label definition: {}", def.name);
- }
- }
- }
- eprintln!();
- }
-
- let byte_count = bytecode.len();
- let byte_percentage = (byte_count as f32 / 65536.0 * 100.0).round() as u16;
- eprintln!("Assembled program in {byte_count} bytes ({byte_percentage}% of maximum).");
-
- if is_error {
- std::process::exit(1)
- }
-
- // Write bytecode to standard output
- if let Err(_) = std::io::stdout().write_all(&bytecode) {
- eprintln!("Could not write to standard output, quitting.");
- std::process::exit(1);
- }
-}
-