summaryrefslogtreecommitdiff
path: root/src/bin/br/main.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2025-02-14 09:37:11 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2025-02-14 09:37:18 +1300
commit76ebb9cb80eadab97e12bfbbd66a99b2e585d3b1 (patch)
tree85480e59cf2cedfa94b48d457c9a48eef0705bd6 /src/bin/br/main.rs
parent07ae3438917fd854a46924a410f6890cd0651f1b (diff)
downloadbedrock-pc-76ebb9cb80eadab97e12bfbbd66a99b2e585d3b1.zip
Checkpoint
Diffstat (limited to 'src/bin/br/main.rs')
-rw-r--r--src/bin/br/main.rs101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/bin/br/main.rs b/src/bin/br/main.rs
new file mode 100644
index 0000000..4df8c67
--- /dev/null
+++ b/src/bin/br/main.rs
@@ -0,0 +1,101 @@
+mod asm;
+mod run;
+
+use switchboard::{Switchboard, SwitchQuery};
+
+
+fn main() {
+ let mut args = Switchboard::from_env();
+ if args.named("help").short('h').as_bool() {
+ print_help();
+ }
+ if args.named("version").as_bool() {
+ print_version();
+ }
+ if args.named("verbose").short('v').as_bool() {
+ log::set_log_level(log::LogLevel::Info);
+ }
+ match args.peek() {
+ Some("run") => { args.pop(); run::main(args) },
+ Some("asm") => { args.pop(); asm::main(args) },
+ _ => run::main(args),
+ }
+}
+
+
+fn print_help() -> ! {
+ println!("\
+Usage: br [source]
+ br asm [source] [destination] [extension]
+
+Integrated Bedrock assembler and emulator.
+
+Usage:
+ To load a Bedrock program from a file, run `br <path>`, where
+ <path> is the path to an assembled Bedrock program.
+
+ To load a Bedrock program from piped input, run `<command> | br`,
+ where <command> is a command that generates Bedrock bytecode.
+
+ To assemble a Bedrock program from a source file and write to an
+ output file, run `br asm <source> <output>`, where <source> is the
+ path of the source file and <output> is the path to write to.
+
+ To assemble and run a Bedrock program without saving to a file,
+ run `br asm <source> | br`, where <source> is the path of the
+ source file.
+
+Environment variables:
+ BEDROCK_PATH
+ A list of colon-separated paths which will be searched to find
+ a Bedrock program when the program doesn't exist in the current
+ directory. This allows the user to run frequently-used programs
+ from any directory.
+ BEDROCK_LIBS
+ A list of colon-separated paths which 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.
+
+Arguments:
+ [program] Path to a Bedrock program to run
+
+Switches:
+ --verbose, (-v) Print additional debug information
+ --version Print the assembler version and exit
+ --help (-h) Prints help
+ --debug, (-d) Show debug information while the program is running
+ --fullscreen (-f) Start the program in fullscreen mode (toggle with F11)
+ --size=<dim> (-s) Set the initial window size in the format <width>x<height>
+ --zoom=<scale> (-z) Set the pixel size for the screen (change with F5/F6)
+ --palette=<pal> Set a debug colour palette in the format <rgb>,... (toggle with F2)
+ --show-cursor (-c) Show the operating system cursor over the window
+ --decode-stdin (-i) Decode standard input
+ --encode-stdout (-o) Encode standard output
+
+Arguments (asm mode):
+ [source] Bedrock source code file to assemble.
+ [destination] Destination path for assembler output.
+ [extension] File extension to identify source files.
+
+Switches (asm mode):
+ --no-libs Don't include libraries or resolve references.
+ --no-project-libs Don't include project libraries
+ --no-env-libs Don't include environment libraries.
+ --tree Show the resolved source file heirarchy
+ --check Assemble the program without saving any output
+ --resolve Only return resolved source code.
+ --symbols Generate debug symbols with file extension '.br.sym'
+");
+ std::process::exit(0);
+}
+
+
+fn print_version() -> ! {
+ 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);
+}