I am working on a macro system for Python ( as discussed here ), and one of the things I looked at is units. Although units can be implemented without macros or using static macros (for example, to identify all your blocks in advance), I love the idea of being able to dynamically expand the syntax at runtime.
To do this, I am considering using partial code evaluation at compile time. If parsing is not performed for this expression, because the macro is not available for its syntax, the compiler stops evaluating the function / block and generates the code that it already has, with a stub where the unknown expression is located. When this stub gets into runtime, the function is recompiled with the current set of macros. If this compilation fails, a parsing error will be output because execution cannot continue. If compilation succeeds, the new function replaces the old one, and execution continues.
The biggest problem that I see is that you cannot find the analysis errors until the affected code is run. However, this will not affect many cases, for example. such as [], {}, () and `` should still be conjugated (the requirement of my tokenizer / list parser), and top-level syntax such as classes and functions will not be affected, since their “run time” is indeed load the time where the syntax is evaluated and their objects are generated.
Besides the complexity of the execution and the problem described above, what problems exist with this idea?
source
share