Fixed module system

This commit is contained in:
2026-06-03 16:00:23 +02:00
parent e0b52a0216
commit 71e4f74c24
9 changed files with 19 additions and 304 deletions
+13 -44
View File
@@ -9,27 +9,27 @@ pub class Module {
pub PathBuf path;
pub Vec<Self> children;
pub constructor(String name, PathBuf mist_path, PathBuf rust_path) {
pub constructor(PathBuf mist_path) {
self.children = new Vec();
self.name = name;
self.name = mist_path.file_stem()
.and_then(|var s| s.to_str())
.expect("Failed to get module name")
.to_string();
self.path = mist_path;
if (self.path.is_dir()) {
PathBuf dir = self.path.clone();
// Behavior 2: It's a directory node. Check for gateway package.mist first.
PathBuf pkg_gate = self.path.join("package.mist");
if (pkg_gate.exists()) {
self.path = pkg_gate;
}
self.scan_directory(&dir, &rust_path);
self.scan_directory(&dir);
}
}
void scan_directory(self mut*, Path* search_dir, Path* rust_path) {
fs::create_dir_all(rust_path).expect("Failed to create dir");
void scan_directory(self mut*, Path* search_dir) {
var entries = match (fs::read_dir(search_dir)) {
Ok[entries] => entries;
Err[e] => {
@@ -53,28 +53,7 @@ pub class Module {
continue;
}
if (!child_path.is_dir() && child_path.extension().and_then(|var v| v.to_str()) != Some("mist")) {
var file_name = child_path.file_name()
.and_then(|var s| s.to_str())
.expect("Failed to get file name");
fs::copy(&child_path, rust_path.join(&file_name)).expect("Failed to copy SideFile");
continue;
}
String child_name = child_path.file_stem()
.and_then(|var s| s.to_str())
.expect("Failed to get module name")
.to_string();
PathBuf child_output = rust_path.join(&child_name).with_extension("rs");
if (should_skip(&child_path, &child_output)) {
continue;
}
self.children.push(new Module(child_name, child_path, child_output));
self.children.push(new Module(child_path));
}
}
@@ -95,23 +74,13 @@ pub class Module {
}
}
pub Module master_package(PathBuf mist_path, PathBuf rust_path) {
String name = mist_path.file_stem()
.and_then(|var s| s.to_str())
.expect("Failed to get module name")
.to_string();
pub Module master_package(PathBuf mist_path) {
var mut root_mod = new Module(mist_path.clone());
var mut root_mod = new Module(name, mist_path.clone(), rust_path.clone());
Path* parent_dir = mist_path.parent()
.expect("Failed to get parent directory of root file");
if (!mist_path.is_dir()) {
Path* parent_dir = mist_path.parent()
.expect("Failed to get parent directory of root file");
Path* rust_path = rust_path.parent()
.expect("Failed to get parent directory of rust path");
root_mod.scan_directory(parent_dir, rust_path);
}
root_mod.scan_directory(parent_dir);
root_mod
}
+1 -1
View File
@@ -15,7 +15,7 @@ pub PathBuf transpile() {
PathBuf src = root.join("src");
PathBuf out = root.join(".mist/src");
var master = modules::master_package(src.join("main.mist"), out.join("main.rs"));
var master = modules::master_package(src.join("main.mist"));
master.transpile(&out);