Day 141: Hackathon day #2 (continued)

autrijus on 2005-06-25T06:00:47

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):





 


 
  




 

 
 

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
.end
...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.


Historic, no?

merlyn on 2005-06-25T11:36:33

So this is the first native Perl5 program translated running on Parrot, correct? Hooray!