From d9e0c4895608cdcb04b868222b49b3f117766ed0 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 14 Oct 2025 21:33:30 +1300 Subject: Implement new bytecode stage This completes the Torque version 3 rewrite, other than some extensive testing that is yet to be done. --- src/bin/tq.rs | 58 +++++++++++++++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) (limited to 'src/bin') diff --git a/src/bin/tq.rs b/src/bin/tq.rs index 2afe8ec..4e1065a 100644 --- a/src/bin/tq.rs +++ b/src/bin/tq.rs @@ -31,7 +31,7 @@ fn main() { let no_libs = args.get("no-libs").as_bool(); let no_project_libs = args.get("no-project-libs").as_bool(); let no_env_libs = args.get("no-env-libs").as_bool(); - // let format = Format::from_str(args.get("format").as_str()); + let format = Format::from_str(args.get("format").as_str()); let width = args.get("width").as_u32_opt(); let dry_run = args.get("dry-run").as_bool(); let print_tree = args.get("tree").as_bool(); @@ -138,9 +138,9 @@ Output formats: std::process::exit(1); }); - // if !dry_run && format == Format::Source { - // write_bytes_and_exit(merged_source.as_bytes(), destination.as_ref()); - // } + if !dry_run && format == Format::Source { + write_bytes_and_exit(merged_source.as_bytes(), destination.as_ref()); + } // ----------------------------------------------------------------------- @@ -169,36 +169,28 @@ Output formats: } }; - // TODO - println!("INTERMEDIATE:"); - for token in &intermediate { - print_intermediate_token(1, token); + let segments = match parse_bytecode(intermediate, width) { + Ok(segments) => segments, + Err(errors) => { + report_bytecode_errors(&errors, &merged_source); + std::process::exit(1); + } + }; + + if !dry_run { + let result = match format { + Format::Cmd => format_cmd(&segments), + Format::Debug => format_debug(&segments), + Format::Inhx => format_inhx(&segments), + Format::Inhx32 => format_inhx32(&segments), + Format::Raw => format_raw(&segments, width), + Format::Source => unreachable!("Source output is handled before full assembly"), + }; + match result { + Ok(bytes) => write_bytes_and_exit(&bytes, destination.as_ref()), + Err(error) => report_format_error(&error, format, &merged_source), + } } - println!(); - - // let segments = match parse_bytecode(intermediate, width) { - // Ok(segments) => segments, - // Err(errors) => { - // report_bytecode_errors(&errors, &merged_source); - // std::process::exit(1); - // } - // }; - - - // if !dry_run { - // let result = match format { - // Format::Cmd => format_cmd(&segments), - // Format::Debug => format_debug(&segments), - // Format::Inhx => format_inhx(&segments), - // Format::Inhx32 => format_inhx32(&segments), - // Format::Raw => format_raw(&segments, width), - // Format::Source => unreachable!("Source output is handled before full assembly"), - // }; - // match result { - // Ok(bytes) => write_bytes_and_exit(&bytes, destination.as_ref()), - // Err(error) => report_format_error(&error, format, &merged_source), - // } - // } } -- cgit v1.2.3-70-g09d2