Fixed module system

This commit is contained in:
2026-07-02 21:24:13 +02:00
parent 28e9fb664c
commit f3046e3442
3 changed files with 33 additions and 7 deletions
+3 -1
View File
@@ -76,7 +76,9 @@ pub class Module
pub PathBuf output_path(&self, PathBuf& parent_dir, Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>& curr_mod_decl) 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 { let name = if self.path.is_dir() || self.is_package() {
&self.name
} else if let Some((_, name)) = curr_mod_decl {
&name.0 &name.0
} else { } else {
&self.name &self.name
+27 -2
View File
@@ -136,12 +136,37 @@ impl modules::Module
} }
(bool, String) write_transpile(&self, String output, PathBuf& parent_dir, bool child_changed) (bool, String) write_transpile(&self, String output, PathBuf& parent_dir, bool child_changed)
{ {
if self.path.is_dir() { if self.path.is_dir() || self.is_package() {
let output_file = self.output_path(parent_dir, &None); let output_file = self.output_path(parent_dir, &None);
let final_output = if self.is_package() {
let source = match fs::read_to_string(&self.path) {
Ok(s) => s,
Err(e) => {
eprintln!("error: failed to read file {}\n {}", self.path.display(), e);
process::exit(1);
}
};
let curr_mod_decl = mist_parser::parse_module(&source).expect("Failed parsing module");
let (result_path, gc, rust_code) = match transpile_code(&self.path, &source, output_file.clone(), &output, &curr_mod_decl) {
Ok(v) => v,
Err(e) => {
decode_err(&e, &self.path);
process::exit(1);
}
};
let map_path = result_path.with_extension("map.json");
if let Some(parent) = map_path.parent() {
let _ = fs::create_dir_all(parent);
}
fs::write(&map_path, serde_json::to_string(&gc.mapping).unwrap()).expect("Failed to write map file");
rust_code
} else {
if output.len() == 0 { if output.len() == 0 {
return (true, String::new()); return (true, String::new());
} }
let res = fs::write(&output_file, output); output
};
let res = fs::write(&output_file, final_output);
if res.is_err() { if res.is_err() {
eprintln!("error: failed to write output {}\n {}", eprintln!("error: failed to write output {}\n {}",
output_file.display(), output_file.display(),
-1
View File
@@ -1,4 +1,3 @@
pub module main;
void main() void main()
{ {
println!("running common tests..."); println!("running common tests...");