From 10a061c41b9a9a566dbe2d8822d0806226e92f74 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Sun, 9 Jul 2023 15:29:26 +0200 Subject: [PATCH] automatic add Process to DCEHack --- src/kernel/DCEHack.hx | 23 ++------------------ src/kernel/ps/Process.hx | 1 + src/macros/DCEHack.hx | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 src/macros/DCEHack.hx diff --git a/src/kernel/DCEHack.hx b/src/kernel/DCEHack.hx index 94a67c4..339d794 100644 --- a/src/kernel/DCEHack.hx +++ b/src/kernel/DCEHack.hx @@ -3,26 +3,7 @@ package kernel; @:keep class DCEHack { // Dont actually call this - public static function load() { - return [ - new bin.Disk(), - new bin.GPS(), - new bin.HelloWorld(), - new bin.KernelLog(), - new bin.LSPS(), - new bin.Net(), - new bin.Redstone(), - new bin.Service(), - new bin.Terminal(), - new bin.Turtle(), - new bin.HelloWorldService(), - new bin.srsc.SiteRessourceController(), - new bin.srsc.CLI(), - new bin.Perf(), - new bin.KSettings(), - new bin.exporter.ResManager(), - new bin.exporter.Res(), - new bin.ID(), - ]; + public static function load():Array{ + macros.DCEHack.dceGenerateCreate(); } } diff --git a/src/kernel/ps/Process.hx b/src/kernel/ps/Process.hx index 555cf84..efa4f77 100644 --- a/src/kernel/ps/Process.hx +++ b/src/kernel/ps/Process.hx @@ -3,6 +3,7 @@ package kernel.ps; /** Defines an independent process that can be run by the kernel. **/ +@:autoBuild(macros.DCEHack.DCEHack.dceInclude()) interface Process { public function run(handle: ProcessHandle): Void; } diff --git a/src/macros/DCEHack.hx b/src/macros/DCEHack.hx new file mode 100644 index 0000000..5d1bf5c --- /dev/null +++ b/src/macros/DCEHack.hx @@ -0,0 +1,45 @@ +package macros; + +import haxe.macro.Context; +import haxe.macro.Expr; +using Lambda; + + +class DCEHack { + + public static final classes: Array = []; + + macro static public function dceInclude(): Array { + #if !display + var localClass = Context.getLocalClass(); + + if (localClass == null){ + return Context.getBuildFields(); + } + + // Ignore abstract classes + if (localClass.get().isAbstract){ + return Context.getBuildFields(); + } + + classes.push(Context.getLocalType()); + #end + return Context.getBuildFields(); + } + + macro static public function dceGenerateCreate(){ + var exprs = []; + + for (c in classes){ + switch (c){ + case TInst(_.get() => t, _): + var path: TypePath = {pack: t.pack, name: t.name}; + exprs.push(macro new $path()); + default: + Context.error("Unknown type: " + c, Context.currentPos()); + } + } + + return macro return $a{exprs}; + } +}