|
Both reltool and rebar needs to parse escripts. They are currently
using an undocumented function called escript:foldl/3. It folds a
function over all files in the body of an escript. If the body
contains source code the function compiles it and the gives debug
compiled beam code to the fold fun. If the body is an archive the fun
is applied for all files in the archive.
Instead of making the undocumented function public, the new functions
escript:create/2 and escript:extract/2 has been introduced. Together
with the new zip:foldl/3 function they have the same functionality as
escript:foldl/3 in a more flexible and generic way.
escript:foldl/3 should be removed as soon as reltool and rebar has
been adopted to use the new functions. The simplest way for reltool
and rebar to do this is to just copy the code from
escript_SUITE:escript_foldl/3, which happens to provide a future
compatible implementation of an emulated escript:foldl/3 function.
I was quite hesitant when I introduced the compile_source option. It
feels that it does not belong there but the alternative felt worse.
The rationale for the compile_source option is that it is a bit
cumbersome to compile the source code, as the source in most cases is
partial. In order to do compile the source you need to know about some
internals in escript. Without compile_source I think that these
internals should be documented. Further you need to duplicate parts of
the code.
Without the compile_source option you need to first parse the source
to forms, using an undocumented function in epp with an extended
format of predefined macros which also is undocumented. Then you need
to investigate the forms to see if you need to add an export form for
main. When that is done you can run the rest of the compiler passes as
usual. It is not so much code (60 lines or so) to write, but I do not
want to urge people to write it. I actually wrote the code (see
escript_SUITE:escript_foldl/3) before I decided to introduce the
compile_source option.
|