HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.14k stars 653 forks source link

Feature request: allow macro to handle compiler files emission #6986

Open elsassph opened 6 years ago

elsassph commented 6 years ago

One recurring discussion is to add an API for the Haxe compiler to function in memory - this is desirable for tooling.

My last idea, to permit it without having any hard-coded protocol in the compiler is to offer macros to register a callback to emit files:

haxe.macro.Context.onEmitFile( callback:String->String->Void );

Register a callback receiving:

Note: it's probably naïve and would require more options to emit binary files.

Using such API, a macro could freely:

Simn commented 6 years ago

I would be fine with that from an API point of view, but it might be a little tricky to implement because the compiler doesn't hold the output as a plain string in order to avoid OCaml memory limitation problems.

elsassph commented 6 years ago

Oh so output is direct to file? maybe we'd need a stream, which could be either directly to file or to memory. Effectively we need to support situations where the JS output is tens of MBs.

Simn commented 6 years ago

It uses some rope-based buffer. At least on Js. So maybe it's not actually a problem.

back2dos commented 6 years ago

How about fileName:String->haxe.io.Output for the callback? Then you can pull all kinds of fancy tricks, like open a process and return its stdout or what not.