[eeps] allow external function as literals

Tony Rogvall tony@REDACTED
Wed Oct 1 23:55:36 CEST 2014


Hi eep.

In a toy project I am doing I generate code on form:

-module(foo).
-export(['_ffe_sqr'/0,'_ffe_sum'/0]).

'_ffe_sqr'() ->
    { 0, <<"sqr">>, fun ffe:docol/4,
      fun ffe:dupe/0, fun ffe:star/0, 
      fun ffe:semis/0 }.

'_ffe_sum'() ->
    { 0, <<"sum">>, fun ffe:docol/4,
      fun ffe:lit/0,  1,
      fun ffe:pqdo/0, 4,
        fun ffe:plus/0, 
      fun ffe:ploop/0, -2, 
      fun ffe:semis/0 }.

To my (mild) surprise I discovered that the tuples above where NOT generated as literals!
So of course I checked if there was any particular reason for this.

I developed a patch produced to patch function return values:

'__ffe_sqr'() -> <<"sqr">>.

here I replaced <<"sqr">>.
with
 { 0, <<"sqr">>, fun ffe:docol/4, fun ffe:dupe/0, fun ffe:star/0, fun ffe:semis/0 }.

in the literal section of the beam file using beam_lib and a simple match.

The loader worked and the code now return constant tuples with functions in them.

Question: 
1. Is my code going to crash later ?  :-)
2. if so can I do anything about it ?
3. if not can we get external funs as supported literals ?

/Tony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/eeps/attachments/20141001/eeef73a6/attachment.htm>


More information about the eeps mailing list