ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl6-internals
perl6-internals
Re: Past-pm basic string types
by Patrick R. Michaud other posts by this author
Dec 13 2006 1:54PM messages near this date
Re: Past-pm basic string types | Side effect between exit & .HLL
On Tue, Dec 12, 2006 at 01:57:20PM -0800, Allison Randal wrote:
>  Patrick R. Michaud wrote:
>  >I can modify PAST-pm to provide a "send exactly this string to PIR" 
>  >option for PAST::Val.  
>  
>  Yes, good idea for the simple case.

After sleeping on it overnight, I realized that PAST-pm already
has this feature.

Currently PAST-pm checks the PAST::Val node's "ctype"
attribute to decide whether to encode the literal value 
as a Parrot form -- if the node doesn't have ctype that indicates
"string constant", then PAST-pm just uses the literal value
directly in the output.

So, just don't set "ctype", and whatever the node has as
its "name" attribute will go directly into the PIR output.

Here's an example:

    $ cat x.pir
    .sub main :main
        load_bytecode 'PAST-pm.pbc'
        .local pmc valnode, blocknode, pir
    
        ##  $S0 is the string we want to appear in the output
        $S0 = '"\n"'
        valnode = new 'PAST::Val'
        valnode.'init'('vtype'=> '.String', 'name'=>$S0)
        blocknode = valnode.'new'('PAST::Block', valnode, 'name'=> 'anon')
    
        ##  compile the tree to PIR and print the result
        $P99 = compreg 'PAST'
        pir = $P99.'compile'(blocknode, 'target'=> 'pir')
        print pir
    .end

    $ ./parrot x.pir
    
    .sub "anon"
        new $P10, .String
        assign $P10, "\n"
        .return ($P10)
    .end

Eventually the handling of "ctype" is going to change -- first,
the name will change to be more descriptive (but I'll leave a 'ctype'
accessor in place to give compilers time to switch); second, any
ctype specifications will be held in a HLL class mapping table 
instead of in each PAST::Val node.

There is a good chance that PAST-pm will treat PAST::Val nodes
of type .String as needing their values to be encoded for Parrot,
but to protect against this punie (and other compilers) can
use .Undef:

        $S0 = '"\n"'
        valnode = new 'PAST::Val'
        valnode.'init'('vtype'=> '.Undef', 'name'=>$S0)

Since the node isn't a string type, PAST-pm will use the "name"
$S0 value directly in the output PIR without performing any
encoding on the literal value, and the generated PIR from the node
would look like

        new $P10, .Undef
        assign $P10, "\n"

And this does exactly what you want.  :-)

Pm
Thread:
Allison Randal
Patrick R. Michaud
Allison Randal
Patrick R. Michaud

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved