interpreter vs. compiled

castironpi castironpi at gmail.com
Wed Jul 30 00:54:04 EDT 2008


On Jul 29, 1:46 am, Tim Roberts <t... at probo.com> wrote:
> castironpi <castiro... at gmail.com> wrote:
>
> >In CPython yes.  In IronPython yes:  the parts that are compiled into
> >machine code are the interpreter, *not user's code*.
>
> WRONG!  You are WRONG.  At "compile" time, the Python code is compiled to
> an intermediate language.  At "run" time, the intermediate language (which
> is still the user's code, just in another representation) is compiled into
> machine language.  It is the user's program, not the interpreter.
>
> It's the exact same process that occurs in a C compiler.  Most C compilers
> translate the C program to an intermediate form before finally converting
> it to machine language.  The only difference is that, in a C compiler, both
> steps occur within the compiler.  In IronPython, the two steps are
> separated in time.  There is no other difference.
>
> >Without that
> >step, the interpreter would be running on an interpreter, but that
> >doesn't get the user's statement 'a= b+ 1' into registers-- it gets
> >'push, push, add, pop' into registers.
>
> You have a fundamental misunderstanding of the compilation process.
> --
> Tim Roberts, t... at probo.com
> Providenza & Boekelheide, Inc.

In C, we have:

int x, y;
x= 10;
y= x+ 1;

It translates as, roughly:


8000 .data
7996 ffffffff #x
7992 ffffffff #y
7988 .end data
7984 loadi reg0 7996
7980 loadi reg1 7992
7976 loadi reg2 10
7972 loadi reg3 1
7968 storv reg2 reg0
7964 add reg0 reg1 reg2
7960 storv reg3 reg1


You are telling me that the same thing happens in IronPython.  By the
time the instruction pointer gets to 'x= 10', the next 7 instructions
are the ones shown here compiled from C.

CMIIW, but the CPython implementation -does- -not-.  Instead, it has,

push 10
stor x
push 1
add
stor y

which each amounts to, to give a rough figure, 5-10 machine
instructions.  push 10, for example, with instruction_pointer in reg0:

loadi reg1 4 #add 4 to stack pointer (one word)
add reg0 reg1 reg2
load reg0 reg2
loadi reg2 10 #load ten
stor reg0 reg2 #store at top of stack

And this is all not to mention (i) the extra comparisons in
intobject.h,

#define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)

(ii) the huge case statement just to evaluate add, OR (iii)

   a = PyInt_AS_LONG(v);
   b = PyInt_AS_LONG(w);

because CPython -does- -not- -know- ahead of time which op it will be
executing, or what addresses (remember __coerce__), it will be
performing the op on.  Does not know EVER, not until it gets there.

My point is, CPython takes more than seven steps.  My question is,
does IronPython?



More information about the Python-list mailing list