From 0925bd156ae2e34ad259d40aaf870eb5f7cfcfb9 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 18 Mar 2025 12:06:17 +1300 Subject: Update assembler dependency torque-asm now uses the Compiler type provided by the assembler library. --- src/bin/tq.rs | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'src/bin/tq.rs') diff --git a/src/bin/tq.rs b/src/bin/tq.rs index ca8fc69..14459d6 100644 --- a/src/bin/tq.rs +++ b/src/bin/tq.rs @@ -1,11 +1,9 @@ use torque_asm::*; -use assembler::FileError; -use log::{info, fatal}; +use log::*; use switchboard::*; use std::io::{Read, Write}; -use std::path::Path; fn main() { @@ -29,6 +27,7 @@ fn main() { |p| p.canonicalize().unwrap_or_else(|e| fatal!("{p:?}: {e:?}"))); let destination = args.get("destination").as_path_opt(); let extension = args.get("extension").as_string(); + let opt_extension = Some(extension.as_str()); 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(); @@ -98,39 +97,28 @@ Created by Ben Bridle. // ----------------------------------------------------------------------- - let mut compiler = if let Some(path) = &source_path { + let mut compiler = new_compiler(); + + if let Some(path) = &source_path { info!("Reading program source from {path:?}"); - Compiler::from_path(path).unwrap_or_else(|err| match err { - FileError::InvalidExtension => fatal!( - "File {path:?} has invalid extension, must be '.{extension}'"), - FileError::NotFound => fatal!( - "File {path:?} was not found"), - FileError::InvalidUtf8 => fatal!( - "File {path:?} does not contain valid UTF-8 text"), - FileError::NotReadable => fatal!( - "File {path:?} is not readable"), - FileError::IsADirectory => fatal!( - "File {path:?} is a directory"), - FileError::Unknown => fatal!( - "Unknown error while attempting to read from {path:?}") - }) + compiler.root_from_path(path).unwrap_or_else(|err| fatal!("{err:?}: {path:?}")) } else { let mut source_code = String::new(); info!("Reading program source from standard input"); if let Err(err) = std::io::stdin().read_to_string(&mut source_code) { fatal!("Could not read from standard input\n{err:?}"); } - Compiler::from_string(source_code, "") + compiler.root_from_string(source_code, "") }; if compiler.error().is_some() && !no_libs && !no_project_libs { - compiler.include_libs_from_parent(&extension); + compiler.include_libs_from_parent(opt_extension); } if compiler.error().is_some() && !no_libs && !no_env_libs { - compiler.include_libs_from_path_variable("TORQUE_LIBS", &extension); + compiler.include_libs_from_path_variable("TORQUE_LIBS", opt_extension); } if print_tree { - compiler.resolver.hierarchy().report() + compiler.hierarchy().report() } if let Some(error) = compiler.error() { error.report(); -- cgit v1.2.3-70-g09d2