diff --git a/crates/mist-api/src/builder.mist b/crates/mist-api/src/builder.mist index 4a055aa..27aa308 100644 --- a/crates/mist-api/src/builder.mist +++ b/crates/mist-api/src/builder.mist @@ -11,11 +11,11 @@ use mist_parser::rev_mapper; #[derive(Debug, Clone)] pub struct MistDiagnosticMessage { - pub message String, - pub file_path PathBuf, - pub file_name String , - pub line usize, - pub column usize, + pub String message, + pub PathBuf file_path, + pub String file_name, + pub usize line, + pub usize column, } #[derive(Debug, Clone)] @@ -25,7 +25,7 @@ pub enum MistDiagnostic { Rust(CompilerMessage), } -pub fn bool build(mut args Vec, root PathBuf) { +pub bool build(Vec mut args, PathBuf root) { args.remove(0); args.insert(1, "--message-format=json".to_string()); @@ -123,7 +123,7 @@ pub fn bool build(mut args Vec, root PathBuf) { false } -pub fn void print_diagnostics(diagnostics *Vec) { +pub void print_diagnostics(Vec& diagnostics) { let mut files = HashMap::new(); for diag in diagnostics { @@ -159,9 +159,9 @@ pub fn void print_diagnostics(diagnostics *Vec) { } } -pub fn Option get_line( - files *mut HashMap>, - msg *MistDiagnosticMessage, +pub Option get_line( + HashMap> mut& files, + MistDiagnosticMessage& msg, ) { let src_path = msg.file_path.clone(); diff --git a/crates/mist-api/src/modules.mist b/crates/mist-api/src/modules.mist index 6754844..4b5dc80 100644 --- a/crates/mist-api/src/modules.mist +++ b/crates/mist-api/src/modules.mist @@ -9,11 +9,11 @@ use crate::transpiler::MistConfig; #[derive(Debug)] pub class Module { - pub name String; - pub path PathBuf; - pub children Vec; + pub String name; + pub PathBuf path; + pub Vec children; - pub constructor(mist_path PathBuf, config *MistConfig) { + pub constructor(PathBuf mist_path, MistConfig& config) { self.children = Vec::new(); self.name = mist_path.file_stem() .and_then(fn(s) -> s.to_str()) @@ -37,7 +37,7 @@ pub class Module { } } - fn void scan_directory(*mut self, search_dir *Path, config *MistConfig) { + void scan_directory(&mut self, Path& search_dir, MistConfig& config) { let entries = match fs::read_dir(search_dir) { Ok(entries) => entries; Err(e) => { @@ -65,11 +65,11 @@ pub class Module { } } - pub fn bool is_package(*self) { + pub bool is_package(&self) { self.path.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() == Some("package.mist") } - pub fn PathBuf output_dir(*self, parent_dir *PathBuf) { + pub PathBuf output_dir(&self, PathBuf& parent_dir) { if self.path.is_dir() || self.is_package() { parent_dir.join(&self.name) } else { @@ -77,7 +77,13 @@ pub class Module { } } - pub fn PathBuf output_path(*self, parent_dir *PathBuf, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) { + pub PathBuf output_path(&self, + PathBuf& parent_dir, + Option<( + mist_parser::ast::Visibility, + mist_parser::ast::Identifier + )>& curr_mod_decl + ) { let name = if let Some((_, name)) = curr_mod_decl { &name.0 } else { diff --git a/crates/mist-api/src/transpiler.mist b/crates/mist-api/src/transpiler.mist index 83ea5ed..406284e 100644 --- a/crates/mist-api/src/transpiler.mist +++ b/crates/mist-api/src/transpiler.mist @@ -16,13 +16,13 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] #[serde(default)] pub struct MistConfig { - pub package PathBuf, - pub packages Vec, - pub main_mods String + pub PathBuf package, + pub Vec packages, + pub String main_mods } impl MistConfig { - pub fn bool should_ignore(*self, path *Path) { + pub bool should_ignore(&self, Path& path) { if path == self.package { return true; } @@ -37,7 +37,7 @@ impl MistConfig { } } impl Default for MistConfig { - fn Self default() { + Self default() { Self { package: PathBuf::from("main.mist"), packages: Vec::new(), @@ -46,7 +46,7 @@ impl Default for MistConfig { } } -pub fn PathBuf transpile() { +pub PathBuf transpile() { let start = time::Instant::now(); let root = env::current_dir().expect("Unable to find project root"); @@ -58,7 +58,7 @@ pub fn PathBuf transpile() { let toml_content = fs::read_to_string(&toml_path) .unwrap_or_else(fn(_) -> panic!("Could not read file at {:?}", toml_path)); - let mut config MistConfig = toml::from_str(&toml_content) + MistConfig mut config = toml::from_str(&toml_content) .unwrap_or_else(fn(_) -> panic!("Failed to parse Mist.toml from {:?}", toml_path)); for pkg in &mut config.packages { @@ -85,7 +85,7 @@ pub fn PathBuf transpile() { } impl modules::Module { - fn (bool, String) transpile(*self, parent_dir *PathBuf, config *mut MistConfig) { + (bool, String) transpile(&self, PathBuf& parent_dir, MistConfig mut& config) { if !self.path.is_dir() && self.path.extension().and_then(fn(v) -> v.to_str()) != Some("mist") { let file_name = self.path.file_name() .and_then(fn(s) -> s.to_str()) @@ -124,7 +124,7 @@ impl modules::Module { self.write_transpile(output, parent_dir, child_changed) } - fn (bool, String) write_transpile(*self, output String, parent_dir *PathBuf, child_changed bool) { + (bool, String) write_transpile(&self, String output, PathBuf& parent_dir, bool child_changed) { if self.path.is_dir() { let output_file = self.output_path(parent_dir, &None); @@ -174,7 +174,7 @@ impl modules::Module { } } -fn std::io::Result is_source_newer(source *Path, output *Path) { +std::io::Result is_source_newer(Path& source, Path& output) { if !output.exists() { return Ok(true); } @@ -190,8 +190,14 @@ pub enum TranspileError<'a> { Semantic(Vec) } -pub fn Result<(PathBuf, mist_codegen::RustCodegen, String), TranspileError<'a>> - transpile_code<'a>(path *PathBuf, source *'a str, mut output_file PathBuf, mod_decl *str, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) { +pub Result<(PathBuf, mist_codegen::RustCodegen, String), TranspileError<'a>> + transpile_code<'a>( + PathBuf& path, + str 'a& source, + PathBuf mut output_file, + str& mod_decl, + Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>& curr_mod_decl + ) { if let Some((_, name)) = &curr_mod_decl { if output_file.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() != Some("mod.rs") { @@ -225,7 +231,14 @@ pub fn Result<(PathBuf, mist_codegen::RustCodegen, String), TranspileError<'a>> Ok((output_file, gc, output)) } -pub fn void transpile_file(path *PathBuf, source *str, output_file PathBuf, mod_decl *str, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) { +pub void transpile_file( + PathBuf& path, + str& source, + PathBuf output_file, + str& mod_decl, + Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>& curr_mod_decl + ) { + let (output_file, gc, output) = match transpile_code(path, source, output_file, mod_decl, curr_mod_decl) { Ok(output) => output; Err(e) => { @@ -261,7 +274,7 @@ pub fn void transpile_file(path *PathBuf, source *str, output_file PathBuf, mod_ } } -pub fn void decode_err<'a>(err *TranspileError<'a>, path *PathBuf) { +pub void decode_err<'a>(TranspileError<'a>& err, PathBuf& path) { let curr_dir = std::env::current_dir().unwrap(); match err {