remove macro-fixer that is uhh made by yknoow
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
--macro macros.CustomFieldMacro.init()
|
||||
--macro macros.HashLinkFixer.init()
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"name": "custom-fields-macro",
|
||||
"url": "https://example.com/",
|
||||
"license": "Public",
|
||||
"description": "A fix",
|
||||
"version": "1.0.0",
|
||||
"releasenote": "NOTHING",
|
||||
"contributors": ["NeeEoo"]
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package macros;
|
||||
|
||||
#if macro
|
||||
import haxe.macro.Compiler;
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
|
||||
using StringTools;
|
||||
|
||||
/**
|
||||
* Macro used to add custom fields to classes without having to override the entire file.
|
||||
*/
|
||||
class CustomFieldMacro {
|
||||
public static function init() {
|
||||
var injections:Map<String, Array<Field>> = [
|
||||
"lime.utils.AssetLibrary" => [
|
||||
{
|
||||
name: "tag",
|
||||
access: [APublic],
|
||||
kind: FVar(macro: funkin.backend.assets.AssetSource),
|
||||
pos: (macro null).pos,
|
||||
}
|
||||
],
|
||||
];
|
||||
|
||||
for(lib => fields in injections) {
|
||||
var build = '@:build(macros.CustomFieldMacro.build("${MacroSerializer.run(fields)}"))';
|
||||
//Sys.println('Injecting $build into $lib');
|
||||
Compiler.addGlobalMetadata(lib, build);
|
||||
}
|
||||
}
|
||||
|
||||
public static function build(fieldData:String) {
|
||||
var fields = Context.getBuildFields();
|
||||
var customFields:Array<Field> = MacroUnserializer.run(fieldData);
|
||||
for(f in customFields)
|
||||
fields.push(f);
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
|
||||
class MacroSerializer extends haxe.Serializer {
|
||||
public static function run(v:Dynamic) {
|
||||
var s = new MacroSerializer();
|
||||
s.useEnumIndex = true;
|
||||
s.serialize(v);
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public override function serialize(v:Dynamic) {
|
||||
switch (Type.typeof(v)) {
|
||||
case TClass(c):
|
||||
if (!(#if neko untyped c.__is_String #else c == String #end)) {
|
||||
switch (#if (neko || cs || python) Type.getClassName(c) #else c #end) {
|
||||
case #if (neko || cs || python) "haxe.macro.Position" #else c if(Type.getClassName(c) == "haxe.macro.Position") #end:
|
||||
buf.add("P");
|
||||
var info = Context.getPosInfos(v);
|
||||
serialize(info.min);
|
||||
serialize(info.max);
|
||||
serialize(info.file);
|
||||
return;
|
||||
default:
|
||||
}
|
||||
}
|
||||
default:
|
||||
}
|
||||
super.serialize(v);
|
||||
}
|
||||
}
|
||||
|
||||
class MacroUnserializer extends haxe.Unserializer {
|
||||
public static function run(s:String):Dynamic {
|
||||
var u = new MacroUnserializer(s);
|
||||
return u.unserialize();
|
||||
}
|
||||
|
||||
public override function unserialize():Dynamic {
|
||||
var c = get(pos++);
|
||||
switch (c) {
|
||||
case "P".code:
|
||||
var min = unserialize();
|
||||
var max = unserialize();
|
||||
var file = unserialize();
|
||||
var o = Context.makePosition({min: min, max: max, file: file});
|
||||
return o;
|
||||
}
|
||||
pos--;
|
||||
return super.unserialize();
|
||||
}
|
||||
|
||||
}
|
||||
#end
|
||||
@@ -1,155 +0,0 @@
|
||||
package macros;
|
||||
|
||||
#if macro
|
||||
import haxe.macro.Expr;
|
||||
import haxe.macro.*;
|
||||
|
||||
using StringTools;
|
||||
using haxe.macro.PositionTools;
|
||||
|
||||
class HashLinkFixer {
|
||||
public static var buildMacroString = '@:build(macros.HashLinkFixer.build())';
|
||||
|
||||
public static var applyOn:Array<String> = [
|
||||
"lime",
|
||||
"std",
|
||||
"Math",
|
||||
"",
|
||||
];
|
||||
|
||||
public static var modifiedClasses:Array<String> = [];
|
||||
|
||||
public static function init() {
|
||||
#if !display
|
||||
if(Context.defined("display")) return;
|
||||
if(Context.defined("hl")) {
|
||||
for(apply in applyOn) {
|
||||
compile(apply);
|
||||
}
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
public static function compile(name:String) {
|
||||
#if !display
|
||||
Compiler.addGlobalMetadata(name, buildMacroString);
|
||||
#end
|
||||
}
|
||||
|
||||
public static function build():Array<Field> {
|
||||
var fields = Context.getBuildFields();
|
||||
var clRef = Context.getLocalClass();
|
||||
if (clRef == null) return fields;
|
||||
var cl = clRef.get();
|
||||
|
||||
if (cl.isAbstract || cl.isExtern || cl.isInterface) return fields;
|
||||
if (!cl.name.endsWith("_Impl_") && !cl.name.endsWith("_HSX") && !cl.name.endsWith("_HSC")) {
|
||||
if(cl.params.length > 0)
|
||||
return fields;
|
||||
|
||||
var definedFields = [];
|
||||
|
||||
for(f in fields.copy()) {
|
||||
if (f == null)
|
||||
continue;
|
||||
if (f.name == "new")
|
||||
continue;
|
||||
|
||||
if(definedFields.contains(f.name)) continue; // no duplicate fields
|
||||
|
||||
var hlNativeMeta = null;
|
||||
var hasHlNative = false;
|
||||
for(m in f.meta)
|
||||
if (m.name == ":hlNative") {
|
||||
hasHlNative = true;
|
||||
hlNativeMeta = m;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!hasHlNative) continue;
|
||||
|
||||
switch(f.kind) {
|
||||
case FFun(fun):
|
||||
if (fun == null)
|
||||
continue;
|
||||
if (fun.params != null && fun.params.length > 0) // TODO: Support for this maybe?
|
||||
continue;
|
||||
|
||||
if(fun.params == null)
|
||||
fun.params = [];
|
||||
|
||||
var overrideExpr:Expr;
|
||||
var returns:Bool = !fun.ret.match(TPath({name: "Void"}));
|
||||
|
||||
var printer = new haxe.macro.Printer();
|
||||
if(cl.module == "hl.Gc" && fun.ret == null) returns = false; // fix since they don't explicitly set :Void
|
||||
if(cl.module == "hl.Format" && fun.ret == null) returns = false; // fix since they don't explicitly set :Void
|
||||
|
||||
var name = 'hlf_${f.name}';
|
||||
|
||||
var arguments = fun.args == null ? [] : [for(a in fun.args) macro $i{a.name}];
|
||||
|
||||
var funcExpr:Expr = macro @:privateAccess $i{name}($a{arguments});
|
||||
if(returns) funcExpr = macro return $funcExpr;
|
||||
|
||||
var cleanMeta = f.meta.copy().filter(function(m) return m.name != ":hlNative");
|
||||
var hasBareMeta = hlNativeMeta.params.length == 0;
|
||||
|
||||
var meta = f.meta.copy();
|
||||
switch hlNativeMeta {
|
||||
case {params: []}:
|
||||
meta = [{name: ":hlNative", params: [macro "std", macro $v{f.name}], pos: Context.currentPos()}].concat(cleanMeta);
|
||||
case {params: [_.expr => EConst(CString(name))]}:
|
||||
meta = [{name: ":hlNative", params: [macro "std", macro $v{name}], pos: Context.currentPos()}].concat(cleanMeta);
|
||||
case {params: [_.expr => EConst(CFloat(version))]}:
|
||||
var curVersion = Context.definedValue("hl_ver");
|
||||
if(curVersion == null) curVersion = "";
|
||||
if(version > curVersion) {
|
||||
meta = cleanMeta;
|
||||
if(f.meta.filter((m) -> m.name == ":noExpr").length > 0)
|
||||
Context.error("Missing function body", f.pos);
|
||||
funcExpr = fun.expr; // restore to default behaviour
|
||||
} else {
|
||||
meta = [{name: ":hlNative", params: [macro "std", macro $v{f.name}], pos: Context.currentPos()}].concat(cleanMeta);
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
var field:Field = {
|
||||
name: name,
|
||||
pos: Context.currentPos(),
|
||||
kind: FFun({
|
||||
ret: fun.ret,
|
||||
params: fun.params.copy(),
|
||||
expr: funcExpr,
|
||||
args: fun.args.copy()
|
||||
}),
|
||||
access: f.access.copy().filter(function(a) return a != APublic && a != APrivate).concat([APrivate]),
|
||||
meta: meta
|
||||
};
|
||||
fields.push(field);
|
||||
definedFields.push(f.name);
|
||||
|
||||
// Remove meta from original function
|
||||
for(m in f.meta.copy())
|
||||
if (m.name == ":hlNative") {
|
||||
f.meta.remove(m);
|
||||
}
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
/*if(definedFields.length > 0) {
|
||||
trace(cl.module);
|
||||
|
||||
var printer = new haxe.macro.Printer();
|
||||
for(field in fields) if(field.name.startsWith("hlf_"))
|
||||
Sys.println(printer.printField(field));
|
||||
}*/
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
#end
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
<lib name="nape-haxe4" />
|
||||
|
||||
<custom name="macro-fixer" />
|
||||
|
||||
<!-- For building lime -->
|
||||
<lib global="true" name="hxp" /> <lib name="hxp" />
|
||||
<lib global="true" name="format" /> <lib name="format" />
|
||||
|
||||
@@ -207,9 +207,6 @@
|
||||
<haxelib name="markdown" />
|
||||
<haxelib name="hxcpp-debug-server" if="TEST_BUILD debug" />
|
||||
|
||||
<!-- Custom Libraries -->
|
||||
<haxelib name="macro-fixer" />
|
||||
|
||||
<!-- _________________________________ Additional stuff _______________________________ -->
|
||||
|
||||
<section if="MODCHARTING_FEATURES">
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package funkin.backend.system.macros;
|
||||
|
||||
#if macro
|
||||
import haxe.macro.Expr;
|
||||
import haxe.macro.*;
|
||||
|
||||
using StringTools;
|
||||
|
||||
class HashLinkFixer {
|
||||
public static function build():Array<Field> {
|
||||
final fields = Context.getBuildFields(), clRef = Context.getLocalClass();
|
||||
|
||||
if (clRef == null) return fields;
|
||||
final cl = clRef.get();
|
||||
|
||||
if (
|
||||
cl.isAbstract || cl.isExtern || cl.isInterface || cl.params.length > 0 ||
|
||||
cl.name.endsWith("_Impl_") || cl.name.endsWith("_HSX") || cl.name.endsWith("_HSC")
|
||||
) return fields;
|
||||
|
||||
final pos = Context.currentPos();
|
||||
for (i in 0...fields.length) {
|
||||
final f = fields[i];
|
||||
if (f == null || f.name == 'new') continue;
|
||||
|
||||
switch (f.kind) {
|
||||
case FFun(func):
|
||||
if (func == null) continue;
|
||||
|
||||
var hlNativeMeta = null;
|
||||
final cleanMeta = f.meta.filter((m) -> {
|
||||
if (m.name != ':hlNative') return true;
|
||||
else {
|
||||
hlNativeMeta = m;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (hlNativeMeta == null) continue;
|
||||
|
||||
switch (hlNativeMeta.params) {
|
||||
case []: hlNativeMeta.params = [macro "std", macro $v{f.name}];
|
||||
case [_.expr => EConst(CString(name))]: hlNativeMeta.params = [macro "std", macro $v{name}];
|
||||
case [_.expr => EConst(CFloat(version))]:
|
||||
final curVersion = Context.definedValue("hl_ver");
|
||||
if (curVersion != null && version > curVersion) {
|
||||
if (f.meta.filter((m) -> return m.name == ":noExpr").length > 0)
|
||||
Context.error("Missing function body", hlNativeMeta.pos);
|
||||
}
|
||||
else
|
||||
hlNativeMeta.params = [macro "std", macro $v{f.name}];
|
||||
default:
|
||||
}
|
||||
|
||||
final name = 'hlf_${f.name}';
|
||||
fields.push({
|
||||
name: name,
|
||||
pos: pos,
|
||||
kind: FFun({ret: func.ret, params: func.params, expr: func.expr, args: func.args}),
|
||||
access: f.access.filter((a) -> return a != APublic && a != APrivate).concat([APrivate]),
|
||||
meta: [hlNativeMeta]
|
||||
});
|
||||
|
||||
final args = func.args == null ? [] : [for (a in func.args) macro $i{a.name}];
|
||||
|
||||
f.meta = cleanMeta;
|
||||
func.expr = args.length == 0 ? macro $i{name}() : macro $i{name}($a{args});
|
||||
if (func.ret != null && !func.ret.match(TPath({name: 'Void'})))
|
||||
func.expr = macro return ${func.expr};
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
#end
|
||||
@@ -39,9 +39,9 @@ class Macros {
|
||||
|
||||
if(Context.defined("sys")) {
|
||||
for(inc in ["sys", "openfl.net", "funkin.backend.system.net"]) {
|
||||
if(!isHl)
|
||||
Compiler.include(inc, compathx4);
|
||||
if(!isHl) Compiler.include(inc, compathx4);
|
||||
else {
|
||||
|
||||
// TODO: Hashlink
|
||||
//Compiler.include(inc, compathx4.concat(["sys.net.UdpSocket", "openfl.net.DatagramSocket"]); // fixes FATAL ERROR : Failed to load function std@socket_set_broadcast
|
||||
}
|
||||
@@ -52,6 +52,20 @@ class Macros {
|
||||
}
|
||||
|
||||
public static function initMacros() {
|
||||
if (Context.defined("hl")) {
|
||||
for (c in ["lime", "std", "Math", ""]) Compiler.addGlobalMetadata(c, "@:build(funkin.backend.system.macros.HashLinkFixer.build())");
|
||||
}
|
||||
|
||||
final macroPath = 'funkin.backend.system.macros.Macros';
|
||||
Compiler.addMetadata('@:build($macroPath.buildLimeAssetLibrary())', 'lime.utils.AssetLibrary');
|
||||
}
|
||||
|
||||
public static function buildLimeAssetLibrary():Array<Field> {
|
||||
final fields:Array<Field> = Context.getBuildFields(), pos:Position = Context.currentPos();
|
||||
|
||||
fields.push({name: 'tag', access: [APublic], pos: pos, kind: FVar(macro :funkin.backend.assets.AssetSource)});
|
||||
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
#end
|
||||
Reference in New Issue
Block a user