Skip to content

Commit

Permalink
let the compiler figure out the type
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Oct 30, 2024
1 parent b476f9a commit 1ebf2ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
8 changes: 5 additions & 3 deletions project.hxp
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,11 @@ class Project extends HXProject {
addHaxeMacro("addMetadata('@:build(funkin.util.macro.FlxMacro.buildFlxBasic())', 'flixel.FlxBasic')");

var abstracts:Array<String> = [
'funkin.*',
'flixel.*',
'haxe.*'
'.*',
'!thx.Set',
'!cpp.*',
'!lime.*',
'!openfl.*'
];
addHaxeMacro("funkin.util.macro.PolymodMacro.buildPolymodAbstracts(['" + abstracts.join("', '") + "'])");
}
Expand Down
31 changes: 17 additions & 14 deletions source/funkin/util/macro/PolymodMacro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class PolymodMacro
}
}

abstractAliases.set('${packTypePath(cls)}', 'polymod.abstracts.${packTypePath(cls)}');
abstractAliases.set('${packTypePath(cls)}', 'polymod.abstracts.${packTypePath(cls)}${classSuffix}');
buildAbstract(cls);
break;
}
Expand Down Expand Up @@ -126,6 +126,7 @@ class PolymodMacro
}

#if macro
static var classSuffix:String = '_';
static var alreadyCalled:Bool = false;
static var skipFields:Array<String> = [];

Expand Down Expand Up @@ -160,7 +161,7 @@ class PolymodMacro
{
pos: Context.currentPos(),
pack: ['polymod', 'abstracts'].concat(abstractCls.pack),
name: abstractCls.name,
name: abstractCls.name + classSuffix,
kind: TypeDefKind.TDClass(null, [], false, false, false),
fields: fields,
}, null);
Expand Down Expand Up @@ -202,7 +203,7 @@ class PolymodMacro
funcArgs.push(
{
name: arg.name,
type: (macro :Dynamic),
type: null,
opt: arg.opt
});
funcArgNames.push(arg.name);
Expand All @@ -219,7 +220,7 @@ class PolymodMacro
kind: FieldType.FFun(
{
args: funcArgs,
ret: (macro :Dynamic),
ret: null,
expr: macro
{
@:privateAccess
Expand Down Expand Up @@ -290,23 +291,25 @@ class PolymodMacro
fieldArgs.push(
{
name: arg.name,
type: (macro :Dynamic),
type: null,
opt: arg.opt,
});
}

var returnStr:String = 'return ';
var returnType:ComplexType = (macro :Dynamic);
switch (ret)
var returnStr:String = switch (ret)
{
case Type.TAbstract(t, _):
if (t.get().name == 'Void')
{
returnStr = '';
returnType = (macro :Void);
'';
}
else
{
'return ';
}
default:
}
'return ';
};

var expr:String = '${returnStr}${moduleTypePath(cls)}.${field.name}(${exprArgs.join(', ')})';

Expand All @@ -318,7 +321,7 @@ class PolymodMacro
kind: FieldType.FFun(
{
args: fieldArgs,
ret: returnType,
ret: null,
expr: macro
{
@:privateAccess
Expand Down Expand Up @@ -348,7 +351,7 @@ class PolymodMacro
kind: FieldType.FFun(
{
args: [],
ret: (macro :Dynamic),
ret: null,
expr: macro
{
@:privateAccess
Expand Down Expand Up @@ -378,7 +381,7 @@ class PolymodMacro
kind: FieldType.FFun(
{
args: [],
ret: (macro :Dynamic),
ret: null,
expr: macro
{
@:privateAccess
Expand Down

0 comments on commit 1ebf2ed

Please sign in to comment.