I found myself in a corner where the utility code mechanism was not
fine-grained enough. Rather than adding yet-another-special-case I
decided to refactor some stuff. Reviews welcome; I can of course change
it back (though hopefully not until after 0.11.2).
a) In Code.py: GlobalState, there's now a list code_layout:
code_layout = [
'h_code',
'utility_code_proto',
'type_declarations',
'module_declarations',
'typeinfo',
'before_global_var',
'global_var',
'all_the_rest',
'utility_code_def'
]
This identifies code stream blocks that are set up initially (in that
order).
b) At any point, your code instance represents the default location, but
you can also output to other places:
otherplace = code.globalstate['typeinfo']
otherplace.putln(...)
If just the right location isn't available, just split up an existing
stream in (a).
c) An alternative to the classic utility code is now this:
if your_id not in code.globalstate.utility_codes:
code.globalstate.utility_codes.add(your_id)
somestream = code.globalstate['somestream']
somestream.putln(...)
I.e. the presence of "some utility code" is now fully orthogonal to
which code stream/location in the output the code ends up at. (The
UtilityCode class is a convenience for this with a couple of hard-coded
streams.)
http://hg.cython.org/cython-devel/rev/b86a7b374a95
http://hg.cython.org/cython-devel/rev/fd6cc8a5998d
http://hg.cython.org/cython-devel/rev/df8dd466bc4a
etc.
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev