Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

autrijus (1505)

  (email not shown publicly)

Journal of autrijus (1505)

Saturday June 25, 2005
01:00 AM

Day 141: Hackathon day #2 (continued)

[ #25354 ]
This single Perl 5 expression:

print "1..2\n";

has been translated by lwall's PERL5_MADSKILLS (also known as PPD) into a XML dump of the OP tree that looks like this (abridged):

<op_leave seq="1 -> DONE" targ="1" flags="VOID,KIDS,PARENS" private="REFCOUNTED" <op_leave seq="1 -> DONE" targ="1" flags="VOID,KIDS,PARENS" private="REFCOUNTED" refcnt="1">
<op_enter seq="2 -> 3" />
<op_nextstate seq="3 -> 4" flags="VOID" line="5" package="main" />
<op_print seq="6 -> 7" flags="VOID,KIDS">
<mad_pv key="o" val="print"/> </madprops>
<op_pushmark seq="4 -> 5" flags="SCALAR" />
<op_const seq="5 -> 6" flags="SCALAR" PV="1..2&#10;">
<madprops> <mad_op key="F">
<op_stringify seq="39 -> DONE" targ="1" flags="SCALAR,KIDS"> <op_null seq="0 -> (40)" was="pushmark" flags="SCALAR" /> <op_const seq="40 -> 39" flags="SCALAR" PV="1..2&#10;">
<madprops><mad_pv key="X" val="1..2\n"/></madprops>
<mad_pv key="o" val="&#34;1..2\n&#34;"/> <mad_pv key="_" val=" "/>
<mad_pv key="(" val=""/>
<mad_pv key=")" val=""/> </madprops>
</op_const> </op_print>

This, in turn, goes through a xml2pl program in Perl 5 that turns it into a P5AST object. After that, the object is dumped into Haskell expression:

P5AST [ OpLeave [ OpPrint [Items [ ] , Items [ Bare " " , OpConst [Bare "\"" , OpStringify [Bare "" , OpConst [Bare "1..2\\n" ] , Bare "" ] , Bare "\"" ] ] ] ] ] ...

Pugs's new Pugs.Frontend.P5AST module takes that expression, then compile to a Pugs parser tree of the Exp type:

Stmts (App (Var "&print") Nothing [Val (VStr "1..2\n")]) Noop

After that, the Pugs.Compile module takes over and turn it into a PIL intermediate code expression:

PStmts PNoop (PStmts (PExp (PApp TTailCall TCxtVoid (PExp (PVar "&print")) [PLit (PVal VStr "1..2\n"])) PNil))

Which can emit this very much unoptimised PIR code:

.sub "main" @ANON
    .local pmc P1263_lex
    P1263_lex = new .PerlUndef
    P1263_lex = find_name "&print"
    .local pmc P1264_lit
    P1264_lit = new .PerlUndef
    P1264_lit = assign "1..2\n"
    .local pmc P1265_app
    P1265_app = new .PerlUndef
    set_args '(16)', P1264_lit
    get_results "(0)", P1265_app
    invokecc P1263_lex

...and Parrot happily runs it and prints the string. Pretty cool, no? Especially cool is that we are getting the P5AST in its desugared (post-source filter) form, so it's indeed using perl to parse Perl.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • So this is the first native Perl5 program translated running on Parrot, correct? Hooray!
    • Randal L. Schwartz
    • Stonehenge