<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div id="yiv8239339631"><div><div style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"><div id="yiv8239339631yui_3_13_0_ym1_9_1386097232826_8"><span id="yiv8239339631yui_3_13_0_ym1_9_1386097232826_15">OK, Ulf, I'll have a look at that. It looks like there probably will be a parse transform involved somewhere.</span></div><div id="yiv8239339631yui_3_13_0_ym1_9_1386097232826_8" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><span id="yiv8239339631yui_3_13_0_ym1_9_1386097232826_18"><br clear="none"></span></div><div
id="yiv8239339631yui_3_13_0_ym1_9_1386097232826_8" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><span id="yiv8239339631yui_3_13_0_ym1_9_1386097232826_21">Best,</span></div><div id="yiv8239339631yui_3_13_0_ym1_9_1386097232826_8" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><span id="yiv8239339631yui_3_13_0_ym1_9_1386097232826_27">Thomas</span></div><div class="yiv8239339631yqt2507354186" id="yiv8239339631yqt56283"><div class="yiv8239339631yahoo_quoted" id="yiv8239339631yui_3_13_0_ym1_9_1386097232826_10" style="display: block;"> <br clear="none"> <br clear="none"> <div class="yiv8239339631yui_3_13_0_ym1_1_1386097232826_8549" style="font-family: HelveticaNeue, 'Helvetica
Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div class="yiv8239339631yui_3_13_0_ym1_1_1386097232826_8550" style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Tuesday, December 3, 2013 4:28 PM, Ulf Wiger <ulf@feuerlabs.com> wrote:<br clear="none"> </font> </div> <blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;margin-top:5px;padding-left:5px;"> <div class="yiv8239339631y_msg_container"><br clear="none">The ct_expand transform has a variation of this, where it also ‘funnifies’ local functions, in order to be able to evaluate them at compile-time.<br clear="none"><br clear="none">The locks_watcher also has a simple inlining transform that transforms a ‘pseudo-function’ into an abstract expression list that can be evaluated without the need of compiled code. It chases down
calls to local functions and transforms those functions into funs inside the expression list.<br clear="none"><br clear="none"><a rel="nofollow" shape="rect" target="_blank" href="https://github.com/uwiger/locks/blob/master/src/locks_watcher.erl#L109">https://github.com/uwiger/locks/blob/master/src/locks_watcher.erl#L109</a><br clear="none"><br clear="none">BR,<br clear="none">Ulf W<br clear="none"><div class="yiv8239339631yqt5206518773" id="yiv8239339631yqtfd71074"><br clear="none">On 3 Dec 2013, at 14:02, Richard Carlsson <<a rel="nofollow" shape="rect" ymailto="mailto:carlsson.richard@gmail.com" target="_blank" href="mailto:carlsson.richard@gmail.com">carlsson.richard@gmail.com</a>> wrote:<br clear="none"><br clear="none">> On 2013-12-03 13:14 , Thomas Lindgren wrote:<br clear="none">>> Hi guys,<br clear="none">>> <br clear="none">>> Before I start hacking on something, I thought I'd ask whether there<br
clear="none">>> already is a standard way to get the original code from a compiled<br clear="none">>> fun/closure. (I know you can get it for interpreted funs by using fun_info.)<br clear="none">>> <br clear="none">>> E.g., for code like this:<br clear="none">>> <br clear="none">>> -module(a).<br clear="none">>> -compile(export_all).<br clear="none">>> adder(N) -> fun(X) X+N end.<br clear="none">>> <br clear="none">>> I'd like to be able to write something like this:<br clear="none">>> <br clear="none">>> > c(a), F =
a:adder(3), magic:get_code(F).<br clear="none">>> {fun, 0, [{clause, 0, [{var, 0, 'X'}], [], [{op, '+', {var,<br clear="none">>> 0,'X'},{var,0,'N'}}]}], [{'N', 3}]} %% AST of fun F with free var env<br clear="none">>> <br clear="none">>> Or the equivalent.<br clear="none">> <br clear="none">> Use fun_info to get the name/arity of the generated function and dig it out from the debug_info AST (or for bonus points, reverse-compile the beam code)?<br clear="none">> <br clear="none">> Keep in mind that if the code in the fun contains a local call to a function in the same module, you'll need to include the code for all reachable functions as well. Hence, the whole AST or the .beam file as a binary might be more suitable for whatever it is you're doing.<br clear="none">> <br clear="none">> /Richard</div><br clear="none">> <br clear="none">> _______________________________________________<br
clear="none">> erlang-questions mailing list<br clear="none">> <a rel="nofollow" shape="rect" ymailto="mailto:erlang-questions@erlang.org" target="_blank" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br clear="none">> <a rel="nofollow" shape="rect" target="_blank" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a><br clear="none"><br clear="none">Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.<br clear="none"><a rel="nofollow" shape="rect" target="_blank" href="http://feuerlabs.com/">http://feuerlabs.com</a><div class="yiv8239339631yqt5206518773" id="yiv8239339631yqtfd83778"><br clear="none"><br clear="none"><br clear="none"></div><br clear="none"><br clear="none"></div> </blockquote> </div> </div> </div></div> </div></div></div></div></body></html>