I would add some fair warning: lowered code is not an official API. Documenting it and stabilizing it would be nice, but for now any code that relies on details of code lowering could be fragile.
On Thu, Dec 18, 2014 at 12:01 PM, Yichao Yu <[email protected]> wrote: > Hi, > > I'm wondering if there's a way to recompile the lowered AST back into a > function and what additional information (other than the module it should > be > evaluate in) is necessary to do that what I've tried and would like to do > is > demonstrated with the code attached. The idea is that I would like to > modify > the code of a function/method before calling it (in this case, I am > replacing > it with the code from another function with the same signature). (In > another > word, the question is how to construct a function from code1 with ast2 and > run > it.) > > It will also be nice if there's more documentation on this "lowered AST" > since > it seems to be very different form the one you get in a function > definition. > (e.g. what is the array in `code_lowered(+, (Float64, Float64))[1].args[2]` > mean) > > A brief description of what I want to do. I'm writing a control system with > dynamic logic. However, since the code might not be running on a single > host, > it is hard to use an existing interpreter to do what I want. Trying to > avoid > inventing yet another language, I hope to use a subset of an existing > language > and somehow transform it into a representation that can be run somewhere > else > and it seems that the inspection and meta programming feature in julia is > very > useful for this. It might be possible to just apply a macro to every > function > / method definition but it will be much harder to write. I would rather > try to > "trace" the excution and use the AST acquired at runtime. For that I would > like to know more about the lowered AST and possibly how to execute a > modified > version in order to trace recursive / nested function calls. This might > not be > the best way to do it and I'm still in planning stage so any suggestions on > the design is also welcome. > > Cheers, > > Yichao Yu >
