diff --git a/crates/mist-api/src/modules.mist b/crates/mist-api/src/modules.mist index 536f0e8..6a7b1b1 100644 --- a/crates/mist-api/src/modules.mist +++ b/crates/mist-api/src/modules.mist @@ -9,27 +9,27 @@ pub class Module { pub PathBuf path; pub Vec 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 } diff --git a/crates/mist-api/src/transpiler.mist b/crates/mist-api/src/transpiler.mist index 330ee6e..39b8240 100644 --- a/crates/mist-api/src/transpiler.mist +++ b/crates/mist-api/src/transpiler.mist @@ -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); diff --git a/mist-test/src/app.mist b/mist-test/src/app.mist deleted file mode 100644 index 9e68eb4..0000000 --- a/mist-test/src/app.mist +++ /dev/null @@ -1,123 +0,0 @@ -use ; -use ; -use ; - -pub class Application { - String name; - - Vec tasks; - Vec plugins; - - logger::Logger logger; - - bool running; - i32 ticks; - - pub constructor(str* name) { - self.name = name.to_string(); - self.tasks = new Vec(); - self.plugins = new Vec(); - - self.logger = new logger::Logger("app"); - - self.running = false; - self.ticks = 0; - } - - pub void boot(self mut*) { - self.logger.info("booting application"); - - self.running = true; - - self.emit(event::Event::Startup); - } - - pub void run(self mut*) { - while(self.running) { - self.tick(); - - if(self.ticks >= 5) { - self.shutdown(); - } - } - } - - void tick(self mut*) { - self.logger.info("tick"); - - self.ticks++; - - var task = task::create_task("background-job"); - - self.tasks.push(task); - - println!("tasks: {}", self.tasks.len()); - } - - pub void shutdown(self mut*) { - self.emit(event::Event::Shutdown); - - self.logger.warning("shutdown"); - - self.running = false; - } - - pub void register_plugin(self mut*, String name) { - self.plugins.push(name.clone()); - - self.emit(event::Event::PluginLoaded(name)); - } - - void emit(self*, event::Event event) { - match(event) { - event::Event::Startup => { - self.logger.info("startup event"); - } - - event::Event::Shutdown => { - self.logger.info("shutdown event"); - } - - event::Event::PluginLoaded[name] => { - println!("plugin loaded: {}", name); - } - - event::Event::TaskExecuted[name] => { - println!("task executed: {}", name); - } - - event::Event::Error[message] => { - self.logger.error(&message); - } - } - } -} - -i32 test_stmt() { - if (0 == 0) { - 0 - } - else { - 1 - } -} - -void loops_test() { - for (x : 0..10) { - println!("{x}"); - } - - for (var mut i = 0; i < 10; i++) { - println!("{i}"); - } - - var i = 0; - - while (i == 1) { - println!("hi"); - } - - loop { - println!("loop!"); - } -} diff --git a/mist-test/src/event.mist b/mist-test/src/event.mist deleted file mode 100644 index 61a1292..0000000 --- a/mist-test/src/event.mist +++ /dev/null @@ -1,7 +0,0 @@ -pub enum Event { - Startup, - Shutdown, - TaskExecuted[String], - PluginLoaded[String], - Error[String], -} \ No newline at end of file diff --git a/mist-test/src/logger.mist b/mist-test/src/logger.mist deleted file mode 100644 index fab6cea..0000000 --- a/mist-test/src/logger.mist +++ /dev/null @@ -1,72 +0,0 @@ -use ; -use ; - -pub trait TestLogging: fmt::Display { - String get(self*); -} - -pub enum LogLevel { - Info, - Warning, - Error, -} - -impl fmt::Display for LogLevel { - fmt::Result fmt(self*, Formatter<'_> mut* f) { - match (self) { - LogLevel::Info => write!(f, "[INFO]"); - - LogLevel::Warning => write!(f, "[WARN]"); - - LogLevel::Error => write!(f, "[ERROR]"); - } - } -} - -impl TestLogging for LogLevel { - String get(self*) { - return format!("{self}"); - } -} - -pub class Logger { - String prefix; - - pub constructor(str* prefix) { - self.prefix = prefix.to_string(); - } - - pub void info(self*, str* message) { - self.log(LogLevel::Info, message); - } - - pub void warning(self*, str* message) { - self.log(LogLevel::Warning, message); - } - - pub void error(self*, str* message) { - self.log(LogLevel::Error, message); - } - - void log(self*, LogLevel level, str* message) { - match(level) { - LogLevel::Info => { - println!("{level} {} {}", self.prefix, message); - } - - LogLevel::Warning => { - println!("{} {} {}", level.get(), self.prefix, message); - } - - LogLevel::Error => { - println!("{level} {} {}", self.prefix, message); - } - } - } - - impl fmt::Display { - fmt::Result fmt(self*, Formatter<'_> mut* f) { - write!(f, "logger ({})", self.prefix) - } - } -} \ No newline at end of file diff --git a/mist-test/src/main.mist b/mist-test/src/main.mist index 317b44f..a6546d1 100644 --- a/mist-test/src/main.mist +++ b/mist-test/src/main.mist @@ -1,22 +1,3 @@ void main() { - var mut app_instance = new app::Application("mist-app"); - - app_instance.boot(); - app_instance.run(); -} - -void do_stuff() { - vec!(1, 2, 3).into_iter().map(Option |var v| {Some(v)}).collect::>(); - - if (43==69) testing1(); -} - -i32 testing1() { - - i32 v = if (0 == 0) { - 0 - } else { - 1 - }; - v -} + test_package::hello(); +} \ No newline at end of file diff --git a/mist-test/src/plugin.mist b/mist-test/src/plugin.mist deleted file mode 100644 index a3d16ba..0000000 --- a/mist-test/src/plugin.mist +++ /dev/null @@ -1,16 +0,0 @@ -pub struct PluginInfo { - pub String name, - pub String version, -} - -pub class PluginRegistry { - T plugins; - - pub constructor(T plugins) { - self.plugins = plugins; - } - - pub T plugins(self) { - return self.plugins; - } -} \ No newline at end of file diff --git a/mist-test/src/task.mist b/mist-test/src/task.mist deleted file mode 100644 index a90f9e3..0000000 --- a/mist-test/src/task.mist +++ /dev/null @@ -1,20 +0,0 @@ -pub enum TaskState { - Pending, - Running, - Finished, - Failed, -} - -pub struct Task { - pub String name, - pub TaskState state, - pub i32 executions, -} - -pub Task create_task(str* name) { - Task { - name: name.to_string(), - state: TaskState::Pending, - executions: 0, - } -} \ No newline at end of file diff --git a/mist-test/src/test_package.mist b/mist-test/src/test_package.mist new file mode 100644 index 0000000..c35a53e --- /dev/null +++ b/mist-test/src/test_package.mist @@ -0,0 +1,3 @@ +pub void hello() { + println!("Hello") +} \ No newline at end of file