I am experimenting with scala 2.10 macros. However, in some cases, the problem with LabelDef does not work. To some extent, I looked into the compiler code, read excerpts from the documents of Miguel Garcia , but I was still stuck.
If my understanding is correct, the pseudo-definition will be:
LabelDef(labelName, listOfParameters, stmsAndApply) , where 3 arguments are trees and:
- labelName is the identifier of the LL defined label
- listOfParameters correspond to the arguments passed when applying label-apply, as in $ L (a1, ..., an), and may be empty
- stmsAndApply matches the statement block (maybe not) and the final apply-expression
label-apply means more or less goto for the label
For example, in the case of a simple loop, LabelDef might eventually apply:
LabelDef($L, (), {...; $L()})
Now, if I want to define 2 LabelDef that jump on each other:
... LabelDef($L1, (), $L2()) ... LabelDef($L2, (), $L1()) ...
The 2nd LabelDef is fine, but the compiler throws an error on the 1st, "not found: value $ L2". I assume this is because $ L2 is not yet defined, although there is an attempt to apply it. This tree, built in such a way that would make sense to me. Do I still understand? Because if an error is not expected, this means that my implementation of macros is probably buggy.
In any case, I believe that there should be a way to apply $ L2 (i.e., jump to $ L2) from $ L1, anyway, but I just donβt know how to do it. Does anyone have an example of this or any pointer?
Other obscure points (but currently less worried) about using LabelDef in macros:
- What is the second argument, specifically, how is it used when it is not empty? In other words, what label mechanisms are applied with parameters?
- Is it really to put in the third argument the final expression is something other than a label? (not that I can't try, but the macros are still experimental)
- is it possible to execute the forwarding shortcut - apply to LabelDef? (maybe this is another question)
Any example of macro implementation in the answer is, of course, very welcome!
Cheers