SomeRanDev / reflaxe.CPP

An alternative C++ target for Haxe that generates dependent-less, GC-less C++17 code.
MIT License
72 stars 5 forks source link

Haxe inline functions still generate as C++ functions #21

Open fourst4r opened 1 year ago

fourst4r commented 1 year ago

For example 😅

inline function foo() {}

function main() {
    foo();
}

Will still generate a

void _Main::Main_Fields_::foo() {

}

I only noticed this because I am generating a wrapper for which I don't know the header for, but it is guaranteed that the header is included at the call site. So, I was trying to use inline to get around that.

SomeRanDev commented 1 year ago

Sorry for the delay, I think this might be a thing with Haxe. While I could fix, that would make it less consistent with the Haxe static targets. For example, I tested this code on Haxe/C# and it doesn't inline. Let me check out how the other targets handle inline and I'll get back to this when I can, but there is a fix you can use right now!

The good news is you can force inlining by adding "extern". (inline extern function foo() { ... }), and this should work!

class Test {
  static function main() {
    bla();
  }

  inline static function bla() {
        trace("bla");
  }
}
public static void main() {
        unchecked {
            global::haxe.Log.trace.__hx_invoke2_o(default(double), ((global::haxe.lang.Function) (new global::haxe.lang.Closure(typeof(global::Test), "bla", 4897623)) ), default(double), new global::haxe.lang.DynamicObject(new int[]{302979532, 1547539107, 1648581351}, new object[]{"bla", "Test", "src/Test.hx"}, new int[]{1981972957}, new double[]{((double) (7) )}));
        }
    }

    public static void bla() {
        unchecked {
            global::haxe.Log.trace.__hx_invoke2_o(default(double), ((global::haxe.lang.Function) (new global::haxe.lang.Closure(typeof(global::Test), "bla", 4897623)) ), default(double), new global::haxe.lang.DynamicObject(new int[]{302979532, 1547539107, 1648581351}, new object[]{"bla", "Test", "src/Test.hx"}, new int[]{1981972957}, new double[]{((double) (7) )}));
        }
    }
fourst4r commented 1 year ago

Sorry for the delay

Not at all, I appreciate all the time and effort you've already put into this project.

For example, I tested this code on Haxe/C# and it doesn't inline.

Curious.

The good news is you can force inlining by adding "extern".

Thank you! That's exactly what I needed. 😁

fourst4r commented 1 year ago

Reflecting back on this now, it may have something to do with reflection.