According to wikipedia, p-code is "the assembly language of a hypothetical CPU".

Perl does compile to an intermediary form, and it does have the appearance of assembly language. Perl never serialised the opcodes into a binary for that hypothetical CPU, but the possibility is there.

I always thought of perl as a purely interpreted language.

It's definitely not purely interpreted.

Also, does anyone have any flow-diagrams of how source code makes it to machine code for each category (compiled, JIT, & interpreted)?

Perl code is compiled into a tree of Perl opcode. Optimisations are applied, then the tree is turned into a link list. (I might have the order wrong.) The product looks like:

>perl -MO=Concise,-exec -E"say 'Hello, World' for 1..3" 1 <0> enter 2 <;> nextstate(main 47 -e:1) v:%,{,2048 3 <;> nextstate(main 47 -e:1) v:%,{,2048 4 <0> pushmark s 5 <$> const[IV 1] s 6 <$> const[IV 3] s 7 <#> gv[*_] s 8 <{> enteriter(next->c last->f redo->9) lKS/8 d <0> iter s e <|> and(other->9) vK/1 9 <0> pushmark s a <$> const[PV "Hello, World"] s b <@> say vK c <0> unstack v goto d f <2> leaveloop vK/2 g <@> leave[1 ref] vKP/REFC -e syntax OK

The opcodes are then executed using the following loop in run.c:

while ((PL_op = op = op->op_ppaddr(aTHX))) { }

(That's the whole thing.)

There's no jit compiling yet. Work is being down to provide the option to compile Perl5 to LLVM bytecode. This, in turn, can be jit compiled into machine code. This is the same approach Java uses.


In reply to Re: is perl p-code? by ikegami
in thread is perl p-code? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.