diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 37 |
1 files changed, 26 insertions, 11 deletions
@@ -20,7 +20,26 @@ pub const WIDE_MODE: u8 = 0x40; pub const IMMEDIATE_MODE: u8 = 0x20; -pub fn assemble(mut args: Switchboard, invocation: &str) { +pub fn assemble(mut args: Switchboard, invocation: &str) -> ! { + args.named("help").short('h'); + args.named("version"); + args.named("verbose").short('v'); + + if args.get("help").as_bool() { + print_help(invocation); + std::process::exit(0); + } + if args.get("version").as_bool() { + let name = env!("CARGO_PKG_NAME"); + let version = env!("CARGO_PKG_VERSION"); + eprintln!("{name} v{version}"); + eprintln!("Written by Ben Bridle."); + std::process::exit(0); + } + if args.get("verbose").as_bool() { + log::set_log_level(log::LogLevel::Info); + } + args.positional("source"); args.positional("destination"); args.named("extension").default("brc"); @@ -34,14 +53,8 @@ pub fn assemble(mut args: Switchboard, invocation: &str) { args.named("dry-run").short('n'); args.named("tree"); args.named("with-symbols"); - args.named("help").short('h'); args.raise_errors(); - if args.get("help").as_bool() { - print_help(invocation); - std::process::exit(0); - } - let source_path = args.get("source").as_path_opt().map( |p| p.canonicalize().unwrap_or_else(|e| fatal!("{p:?}: {e:?}"))); let destination_path = args.get("destination").as_path_opt(); @@ -135,9 +148,10 @@ pub fn assemble(mut args: Switchboard, invocation: &str) { while let Some(0) = bytecode.last() { bytecode.pop(); } - let difference = length - bytecode.len(); + let new_length = bytecode.len(); + let difference = length - new_length; if difference > 0 { - info!("Truncated program to {length} bytes (saved {difference} bytes)"); + info!("Truncated program to {new_length} bytes (saved {difference} bytes)"); } } @@ -169,6 +183,7 @@ pub fn assemble(mut args: Switchboard, invocation: &str) { }; write_bytes_and_exit(&bytes, destination_path.as_ref()); } + std::process::exit(0); } @@ -191,7 +206,7 @@ fn print_help(invocation: &str) { eprintln!("\ Usage: {invocation} [source] [destination] -Convert Bedrock source code into an assembled Bedrock program. +Assembler for the Bedrock computer system. Usage: To assemble a Bedrock program from a source file and write to an output @@ -204,7 +219,7 @@ Usage: Environment variables: BEDROCK_LIBS - A list of colon-separated paths which will be searched to find Bedrock + A list of colon-separated paths that will be searched to find Bedrock source code files to use as libraries when assembling a Bedrock program. If a library file resolves an unresolved symbol in the program being assembled, the library file will be merged into the program. |
