Re: perl language
by ikegami (Patriarch) on Nov 12, 2007 at 13:20 UTC
|
>perl -MO=Concise -e"my $x = 1; $x += 2; print $x"
e <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
5 <2> sassign vKS/2 ->6
3 <$> const[IV 1] s ->4
4 <0> padsv[$x:1,2] sRM*/LVINTRO ->5
6 <;> nextstate(main 2 -e:1) v ->7
9 <2> add[t2] vKS/2 ->a
7 <0> padsv[$x:1,2] sRM ->8
8 <$> const[IV 2] s ->9
a <;> nextstate(main 2 -e:1) v ->b
d <@> print vK ->e
b <0> pushmark s ->c
c <0> padsv[$x:1,2] l ->d
-e syntax OK
| [reply] [d/l] |
|
|
| [reply] |
|
|
| [reply] |
|
|
Yeah, I suppose it's not really a tree, it's only represented as one. You can even see from the B::Concise output (->##) that it's really a graph.
| [reply] [d/l] |
Re: perl language
by Corion (Patriarch) on Nov 12, 2007 at 11:36 UTC
|
Perl is compiled to bytecode, but the results of the compilation are not saved to disk.
Update: This is wrong, see below - it's not bytecode but an internal low level representation.
| [reply] |
|
|
Perl is compiled to bytecode
no, that is false, the Perl program is not compiled to bytecode (unless you use the B::Bytecode backend).
It is parsed into an internal low level representation that is used later, on the execution stage (see ikegami response below), but this internal representation is not bytecode (for most definitions of bytecode :-)
| [reply] |
A reply falls below the community's threshold of quality. You may see it by logging in.
|
|
|
The result of compilation can be saved to disk as bytecode: see B::Bytecode.
The bytecode can then be executed with ByteLoader.
The Perl FAQ talks a bit about the compiled/interpreted question in
Is it a Perl program or a Perl script? but doesn't get down to brass tacks.
A word spoken in Mind will reach its own level, in the objective world, by its own weight
| [reply] |
|
|
Would it improve performance if the byte-code could be saved and used instead ?
Cheers LuCa
| [reply] |
|
|
A past attempt resulted in slower code, but that could have been implementation-specific.
There's also a lack of volunteers to maintain that part of the code, so it will be removed from 5.10 for being perpetually broken and hopelessly out of date.
| [reply] |
|
|
|
|
|
Re: perl language
by Joost (Canon) on Nov 12, 2007 at 19:15 UTC
|
This is actually a quite complex question to answer, since neither "compiled" nor "interpreted" are all that well defined.
IIRC, "old school" interpreters interpret each source statement/line/whatever every time that statement is executed. Almost no serious "interpreted" language does that nowadays, with the possible exception of shells.
Most current "interpreted" languages like perl, are transformed into some kind of intermediate form that is then executed by/via the runtime environment. This form may or may not be anything like Java's bytecode programs - for one thing, IIRC a/the Java runtime doesn't necessarily run the bytecode directly, but (can) also transform the code to more efficient lower-level/machine instructions. I know perl's model is supposedly quite different, but I don't know the details.
If you bundle the runtime environment with the "intermediate form" you may end up with something quite a lot like the threaded code model that is/was used in Forth (which apparently also can mix "compiled" and "interpreted" code, but as far as I know is usually regarded as a compiled language - and it's still used for embedded software due to, at least, the small size of the generated executables).
| [reply] |
Re: perl language
by bart (Canon) on Nov 12, 2007 at 14:51 UTC
|
| [reply] |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Re: perl language
by RaduH (Scribe) on Nov 12, 2007 at 16:06 UTC
|
The clear distinction is obvious when you ask/answer the question "who executes the code?" In the end it is always the processor, but the question is: is that code run by the processor directly or is it handled by a virtual machine (see Java). While the Perl Virtual Machine is not a coined term, the Perl code is read an interpreted by a similar virtual machine. C code is compiled directly in binary read, understood, and executed by the processor directly. The Perl code does not reach such a stage of refinement. A compiled code only needs a processor to run, interpreted code needs this run-time environment to execute (Perl interpreter, JVM, etc.) | [reply] |
|
|
Well ... C code may be compiled to a machine language understood by the processor, but it's still just as dependent on it's run-time environment as Perl code is. Sometimes the runtime is linked into the program, but most of the time it's an external dynamicaly loaded library.
And of course very few programs, no matter in what langauge, can get by without the help from the OS.
Plus some processors do not really implement their machine language in the wires and transistors, but instead the ops are implemented in another, more low-level language. It's just that it's built into the processor and you are not allowed to use the microinstructions directly.
| [reply] |
|
|
So Perl is like java which is compiled and interpreted and c is compiled-linked and run by the processor.. That makes sense..
| [reply] |
|
|
So Perl is like java which is compiled and interpreted and c is compiled-linked and run by the processor.. That makes sense..
Usually, when a lot of brute-force processing needs to be done, you want to avoid virtual machines, and get right to the hardware, preferably with a language which can generate very good machine code, e.g., when you need to run a 1,000,000 DOF finite-element model, large-scale n-body simulations, or climate modeling, saving a few nanoseconds per computation can really add up.
Most tasks aren't anywhere near that computationally intensive.
"Interpreted" also sometimes seems to mean "entered into an IDE which continually checks syntax," with "compiled" meaning "completely entered into a file, which is then passed through a 'compiler' or 'interpreter'."
By this, I mean something like this: (> indicates what person enters; < indicates what system returns)
<PIRNT 'Today is Tuesday'
>PIRNT NOT RECOGNIZED
<WRITE 'Today is Tuesday'
>WRITE NOT RECOGNIZED
<PRINT 'Today is Tuesday'
>Today is Tuesday
<QUIT
ciao
| [reply] [d/l] |
Re: perl language
by kyle (Abbot) on Nov 12, 2007 at 17:06 UTC
|
| [reply] |
Re: perl language
by ysth (Canon) on Nov 13, 2007 at 23:02 UTC
|
| [reply] |