automatic add Process to DCEHack

This commit is contained in:
Djeeberjr 2023-07-09 15:29:26 +02:00
parent c390519393
commit 10a061c41b
3 changed files with 48 additions and 21 deletions

View File

@ -3,26 +3,7 @@ package kernel;
@:keep @:keep
class DCEHack { class DCEHack {
// Dont actually call this // Dont actually call this
public static function load() { public static function load():Array<kernel.ps.Process>{
return [ macros.DCEHack.dceGenerateCreate();
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(),
];
} }
} }

View File

@ -3,6 +3,7 @@ package kernel.ps;
/** /**
Defines an independent process that can be run by the kernel. Defines an independent process that can be run by the kernel.
**/ **/
@:autoBuild(macros.DCEHack.DCEHack.dceInclude())
interface Process { interface Process {
public function run(handle: ProcessHandle): Void; public function run(handle: ProcessHandle): Void;
} }

45
src/macros/DCEHack.hx Normal file
View File

@ -0,0 +1,45 @@
package macros;
import haxe.macro.Context;
import haxe.macro.Expr;
using Lambda;
class DCEHack {
public static final classes: Array<haxe.macro.Type> = [];
macro static public function dceInclude(): Array<Field> {
#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};
}
}