Writing an emulator in python - implementation questions (for performance)

greg greg at cosc.canterbury.ac.nz
Fri Nov 13 22:44:07 EST 2009


Santiago Romero wrote:

>  Can the above be easily done with another already-existing
> application? (example: can m4 do this job)?

The problem you're going to have with something like
m4 is indentation. When you inline a function call,
somehow the inserted code has to be shifted to the
same indentation level as the statement containing
the call.

I don't know of any off-the-shelf macro processor
that can handle that sort of thing easily.

You may want to consider writing a custom one in
Python. You could use the ast facilities to parse
the code, operate on the parse tree and then write
it back out as code.

You might be able to get some ideas from 2to3,
which does similar kinds of source-to-source
translations.

-- 
Greg



More information about the Python-list mailing list