SomeRanDev / reflaxe

Haxe framework for creating compilation targets using macros
MIT License
93 stars 4 forks source link

Not almost understand how the work native code inliner. #4

Closed vega0 closed 1 year ago

vega0 commented 1 year ago

So, i have the code. I need to transpile it to moonscript, what i get, that i have:

   <classes>haxe.Log.trace(__moon__("string.sub({arg0}, {arg1},{arg1} + {arg2})", "hello wolrd", 2, 4), {["fileName"]: "Code.hx", ["lineNumber"]: 136, ["className"]: "_Code.Code_Fields_", ["methodName"]: "main"}))!
  assert type(r) == "nil", "function return type 
    inline function substr(pos:Int, ?len:Int):String
    {
        return untyped __moon__ ("string.sub({arg0}, {arg1},{arg1} + {arg2})", this, pos, len);
    }

what happens wrong and why its not inlined as raw code line?

compiler init

import reflaxe.ReflectCompiler;

class CompilerInit {
    public static function Start() {
        ReflectCompiler.AddCompiler(new Compiler(), {
            fileOutputExtension: ".moon",
            outputDirDefineName: "moon-output",
            fileOutputType: FilePerClass,
            reservedVarNames: reservedNames(),
            targetCodeInjectionName: "__moon__",
            smartDCE: true,
            trackUsedTypes: true
        });
    }

    static function reservedNames() {
        return [];
    }
SomeRanDev commented 1 year ago

Are you using BaseCompiler.compileExpression to compile your expressions? This function first checks for __moon__, then calls the "impl" version.