This commit is contained in:
2026-05-10 03:35:13 +02:00
parent 0c2746eefc
commit 5a475f3b8a
7 changed files with 193 additions and 15 deletions
+90
View File
@@ -0,0 +1,90 @@
use <collections::list>;
list::List<task::Task> tasks;
list::List<String> plugins;
logger::Logger logger;
bool running;
i32 ticks;
public constructor(String name) {
self.name = name;
self.tasks = new list::List<task::Task>();
self.plugins = new list::List<String>();
self.logger = new logger::Logger("app");
self.running = false;
self.ticks = 0;
}
public void boot(self mut*) {
self.logger.info("booting application");
self.running = true;
self.emit(event::Event::Startup);
}
public 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 = self.ticks + 1;
var task = task::create_task("background-job");
self.tasks.push(task);
println!("tasks: {}", self.tasks.len());
}
public void shutdown(self mut*) {
self.emit(event::Event::Shutdown);
self.logger.warning("shutdown");
self.running = false;
}
public void register_plugin(self mut*, String name) {
self.plugins.push(name);
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);
}
}
}
}
+7
View File
@@ -0,0 +1,7 @@
public enum Event {
Startup,
Shutdown,
TaskExecuted(String),
PluginLoaded(String),
Error(String),
}
+41
View File
@@ -0,0 +1,41 @@
public enum LogLevel {
Info,
Warning,
Error,
}
public class Logger {
String prefix;
public constructor(String prefix) {
self.prefix = prefix;
}
public void info(self*, String message) {
self.log(LogLevel::Info, message);
}
public void warning(self*, String message) {
self.log(LogLevel::Warning, message);
}
public void error(self*, String message) {
self.log(LogLevel::Error, message);
}
void log(self*, LogLevel level, String message) {
match(level) {
LogLevel::Info => {
println!("[INFO] {} {}", self.prefix, message);
}
LogLevel::Warning => {
println!("[WARN] {} {}", self.prefix, message);
}
LogLevel::Error => {
println!("[ERROR] {} {}", self.prefix, message);
}
}
}
}
+5
View File
@@ -0,0 +1,5 @@
mod app;
mod task;
mod plugin;
mod logger;
mod event;
+16
View File
@@ -0,0 +1,16 @@
public struct PluginInfo {
public String name,
public String version,
}
public class PluginRegistry<T> {
T plugins;
public constructor(T plugins) {
self.plugins = plugins;
}
public T plugins(self) {
return self.plugins;
}
}
+20
View File
@@ -0,0 +1,20 @@
public enum TaskState {
Pending,
Running,
Finished,
Failed,
}
public struct Task {
public String name,
public TaskState state,
public i32 executions,
}
public Task create_task(String name) {
return Task {
name: name,
state: TaskState::Pending,
executions: 0,
};
}
+14 -15
View File
@@ -1,18 +1,17 @@
mod my_class;
use <my_class::MyClass>;
use <my_class::MyEnum>;
mod core;
void main() {
var my_class = new MyClass("World");
my_class.greet();
use <core::app>;
use <plugins::greeting>;
use <plugins::statistics>;
match (MyEnum::Tuple(10, String::new())) {
MyEnum::Tuple(i, _) => {
println!("{i}");
}
MyEnum::Named => {
i32 main() {
var app = new app::Application("mist-app");
}
_ => {}
}
}
greeting::register(&mut app);
statistics::register(&mut app);
app.boot();
app.run();
return 0;
}