interpreter vs. compiled

castironpi castironpi at gmail.com
Fri Aug 1 01:11:29 EDT 2008


On Jul 31, 1:17 am, Tim Roberts <t... at probo.com> wrote:
> castironpi <castiro... at gmail.com> wrote:
>
> >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
>
> I don't recognize that assembly language.  Is that another intermediate
> language?

I'm looking at a system word of 1's and 0's that gets executed on a
per-cycle basis in the processor.  Could easily be that the designs
are tuned to JIT's these days and I'm out of date, what with
pipelining and lookahead branching and all, but no, it's what I
remember from system architecture class.

> >You are telling me that the same thing happens in IronPython.
>
> Yes, the same process happens.
>
> >By the
> >time the instruction pointer gets to 'x= 10', the next 7 instructions
> >are the ones shown here compiled from C.
>
> I most certainly did NOT say that, as you well know.  Different C compilers
> produce different instruction sequences for a given chunk of code.  Indeed,
> a single C compiler will produce different instruction sequences based on
> the different command-line options.  It's unreasonable to expect a Python
> compiler to produce exactly the same code as a C compiler.
>
> However, that does disqualify the Python processor as a "compiler".
>
> >CMIIW, but the CPython implementation -does- -not-.
>
> And again, I never said that it did.  CPython is an interpreter.  the
> user's code is never translated into machine language.
>
> >My point is, CPython takes more than seven steps.  My question is,
> >does IronPython?
>
> So, if compiler B isn't as good at optimization as compiler A, does that
> mean in your mind that compiler B is not a "compiler"?
> --
> Tim Roberts, t... at probo.com
> Providenza & Boekelheide, Inc.

You can translate C code to machine code, for any given C code, for
any given machine.

You can translate Python code to machine code, for some Python code,
for any given machine.

Given the restrictions (or rather, freedoms) of Python, does there
exist code that necessarily cannot translate to machine code?  In
other words, can you translate all Python code to machine code?
Similarly, I take it that the decision to make CPython a stack machine
+ VM was a design decision, not a necessity, favoring internal
simplicity over the extra 5%.

The output of the program is determined from the input by the Python
specification, regardless of implementation, but the answer still
isn't necessarily yes.  But I think the only counterexample that comes
to me is the case of a dynamic grammar, not merely dynamic data type,
so for Python maybe it is.  And furthermore, I think I'm getting
confused about what exactly constitutes an interpreter: it is whether
there is a process that runs product instructions, or the product
instructions can run standalone.  I would take 'compiler' to mean,
something that outputs an .EXE executable binary file, and I don't
just mean bundling up the python.exe executable with a file.  Python
needs to be present on the machine you run target code on, not so with
C binaries.  Can .NET bring its targets to such a state, or are those
run-times requried?  Are they just DLL's, or are they, for lack of
better word, driving?

(Of course, for futuristic abstract hardware designs, CPython may be
mostly native instructions, and the output of its processor on
function definition, can be stored and run directly, such as for a
stack machine architecture.)

But I don't want to restrict my question to a question of
optimization.  Your compiler could output something like this:

read variables into registers
reorganize variable dictionaries
perform addition
do laundry
write variables into system memory
clean sink

and run when you write 'C:\>silly.exe', and so on.  And still be
compiled, even if the live IronPython session, which you invoke with,
'C:\>ironpy.exe silly.py', outputs the same 7 MIPS instructions.



More information about the Python-list mailing list