> .. now I'm interested in creating intermediate code for a> test-language ... compiler created with this [python-based] tool.

> If I'm not wrong, stack-oriented code is easy to generate, but> difficult to optimize whilst three or quad code is much easy to> optimize. Any ideas? Which one should you suggest? ...

I suggest generating LLVM intermediate code in textual (assembly
language) form. There are tools provided in the LLVM distribution
that can translate between this form and the bitcode, and there are
tools provided for optimization, interpretation, and compilation to
native machine code. All in all, is is a slick package for someone
who wants to concentrate on the front end, but have a good back end,
and also is interested in still having visibility into the back end,
including being able to experiment with the effect of different
optimizations. This is what I'm having the students in my compiler
design course use.

When you first look at LLVM, you may think it is a bit hard to
generate because of it being an SSA representation. But you can
totally ignore that if you allocate memory locations for all variables
and emit load and store operations, rather than trying to keep
variables in (pseudo-)registers. The mem2reg optimization pass will
then do the dirty work of eliminating the memory operations and
generating the appropriate SSA plumbing instead. The LLVM Tutorial
illustrates this approach (in chapter 7). The tutorial assumes you
are coding your front-end in C++ and thus able to directly link in the
LLVM library. But the same approach also works with a front end in
Python (or anything else) that is generating LLVM assembly language.