diff --git a/src/Rust/vvs_cli/src/main.rs b/src/Rust/vvs_cli/src/main.rs index 11349fa8e3355e230d09b5ee2cb29cba4a084a3c..a47c618a58fb7789c7ef48db9d21f9e0164b1bfd 100644 --- a/src/Rust/vvs_cli/src/main.rs +++ b/src/Rust/vvs_cli/src/main.rs @@ -3,24 +3,23 @@ //! The VivyScript cli use anyhow::{Context as _, Result}; -use clap::CommandFactory as _; +use clap::{CommandFactory as _, Parser as _}; use std::{fs, io, path::Path}; use vvs_cli::{ args::Args, config::{Config, ConfigFile}, }; -use vvs_font::{embeded_fonts, Font}; use vvs_lang::*; use vvs_xdg::{file::TempFile, XDGConfig, XDGConfigMergedSilent}; -fn print_font(name: impl AsRef<Path>, font: &[u8]) -> Result<()> { - let font = Font::try_from(font).with_context(|| format!("failed to parse font {}", name.as_ref().display()))?; - let types = Vec::from_iter(font.font_types().into_iter().map(|ty| ty.to_string())); +fn print_font(n: impl AsRef<Path>, f: &[u8]) -> Result<()> { + let f = vvs_font::Font::try_from(f).with_context(|| format!("failed to parse font {}", n.as_ref().display()))?; + let ts = Vec::from_iter(f.font_types().into_iter().map(|ty| ty.to_string())); println!("###"); - println!("# Family Name: {}", font.name().context("failed to get the font name")?); - println!("# Name(s): {}", font.family_names().join(", ")); - println!("# Font Type(s): {}", types.join(", ")); - println!("# Number of glyph(s): {}", font.number_of_glyphs()); + println!("# Family Name: {}", f.name().context("failed to get the font name")?); + println!("# Name(s): {}", f.family_names().join(", ")); + println!("# Font Type(s): {}", ts.join(", ")); + println!("# Number of glyph(s): {}", f.number_of_glyphs()); Ok(()) } @@ -33,7 +32,7 @@ fn main() -> Result<()> { .file("vvcc.toml") .read_or_default(), ) - .with_args(<Args as clap::Parser>::parse()) + .with_args(Args::parse()) .apply_logger(); // Handle auxiliary stuff @@ -47,7 +46,7 @@ fn main() -> Result<()> { } else if let Some(font_info) = font_info { return match font_info { Some(p) => print_font(&p, &fs::read(&p).with_context(|| format!("failed to read font: {}", p.display()))?), - None => embeded_fonts().try_for_each(|(n, f)| print_font(n, f)), + None => vvs_font::embeded_fonts().try_for_each(|(n, f)| print_font(n, f)), }; } @@ -76,11 +75,11 @@ fn main() -> Result<()> { Some(path) => println!("options file ....... {}", path.display()), None => println!("options file ....... ø"), } - println!("{output}"); + print!("{output}"); } - let jit = vvs_runtime::JIT::new()?; let mut file = TempFile::new("vvcc")?; + let jit = vvs_runtime::JIT::new()?; jit.with_module( vvs_codegen::lowerer::Lowerer::new(&jit.ctx(), &output.main.name)? .declare_globals(output.declared_functions())? diff --git a/src/Rust/vvs_lang/src/frontend_pipeline.rs b/src/Rust/vvs_lang/src/frontend_pipeline.rs index 7bff195057ca397c42fc1f7608849435f63f8fba..420739ad26ce82b00caff73df53de579c93f92d8 100644 --- a/src/Rust/vvs_lang/src/frontend_pipeline.rs +++ b/src/Rust/vvs_lang/src/frontend_pipeline.rs @@ -157,9 +157,8 @@ impl fmt::Display for FrontendOutput { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { imports, main, options, .. } = self; writeln!(f, "imported modules:")?; - imports.keys().try_for_each(|module| writeln!(f, " - {module}"))?; - writeln!(f, "{options}")?; - writeln!(f, "{main:#?}") + imports.keys().try_for_each(|module| writeln!(f, "\t- {module}"))?; + writeln!(f, "{options}\n{main}") } } diff --git a/src/Rust/vvs_lang/src/main_program.rs b/src/Rust/vvs_lang/src/main_program.rs index c8d532750f23df529042ad846157431b71206a2a..0a0bac77190a12cb2b08be1ee13f6b46aecf9fbe 100644 --- a/src/Rust/vvs_lang/src/main_program.rs +++ b/src/Rust/vvs_lang/src/main_program.rs @@ -1,6 +1,6 @@ //! Main program and utilities to be able to complete the work. -use derive_more::{IntoIterator, IsVariant}; +use derive_more::{Display, IntoIterator, IsVariant}; use vvs_parser::prelude::ast::Expression; use vvs_shortstring::ShortString; @@ -53,6 +53,16 @@ impl MainProgram { } } +impl Display for MainProgram { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { name, initial, steps, returns } = self; + writeln!(f, "program {name} ({initial}) {{")?; + steps.iter().try_for_each(|step| writeln!(f, "{step}"))?; + writeln!(f, "\t{returns}")?; + write!(f, "}}") + } +} + /// The returned variables from the main program. #[derive(Debug, Default, IntoIterator)] pub struct MainProgramReturns { @@ -66,6 +76,21 @@ impl FromIterator<ShortString> for MainProgramReturns { } } +impl Display for MainProgramReturns { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "return {{")?; + match &self.variables[..] { + [] => write!(f, " }}"), + [item] => write!(f, " {item} }}"), + [head, tail @ ..] => { + write!(f, " {head}")?; + tail.iter().try_for_each(|item| write!(f, ", {item}"))?; + write!(f, " }}") + } + } + } +} + /// A step to do for the main program. #[derive(Debug)] pub struct MainProgramStep { @@ -111,13 +136,31 @@ impl MainProgramStep { } } +impl Display for MainProgramStep { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { destination, job: (module, job), .. } = self; + write!(f, "{destination} = {module}:{job}")?; + match &self.call_list[..] { + [] => write!(f, " {{ }}"), + [item] => write!(f, " {{ {item} }}"), + [head, tail @ ..] => { + write!(f, " {{ {head}")?; + tail.iter().try_for_each(|item| write!(f, ", {item}"))?; + write!(f, " }}") + } + } + } +} + /// An item to pass to a job when we call it. -#[derive(Debug, IsVariant)] +#[derive(Debug, IsVariant, Display)] pub enum MainProgramCallListItem { /// We add a variable to process. + #[display("{_0}")] Variable(ShortString), /// We set a parameter for the job. + #[display("{_0} = {_1}")] Parameter(ShortString, Expression), } diff --git a/src/Rust/vvs_xdg/src/file/lock.rs b/src/Rust/vvs_xdg/src/file/lock.rs index 4c0fe27fb022f5d5507c0e8f5a528aebd084be42..54f80997df672b237845c0cb114d35dda4539b6b 100644 --- a/src/Rust/vvs_xdg/src/file/lock.rs +++ b/src/Rust/vvs_xdg/src/file/lock.rs @@ -1,7 +1,7 @@ use crate::*; use std::{ collections::hash_map::DefaultHasher, - fs::{self, File, OpenOptions}, + fs, hash::{Hash, Hasher}, io::Error as IoError, path::Path, @@ -55,7 +55,7 @@ impl LockFile { MaybeFolderList::Empty => unreachable!("failed to find the runtime dir..."), MaybeFolderList::Folder(path) | MaybeFolderList::Many(path, _) => { log::debug!("create lock file at: {}", path.display()); - let _ = OpenOptions::new() + let _ = fs::OpenOptions::new() .create_new(true) .open(&path) .map_err(Self::handle_io_error)?;