I just popped in my mind that this really looks like some kind of "with"
statement semantics, which some languages have.

Maybe it's worthwhile to have a PAST::Op( :pasttype('with') ) node, where
the first child evaluates to some object, on which the 2nd..nth children are
operating.

Not sure if this works well with for instance :pasttype('callmethod') where
the invocant is actually the 2nd (or first, if there's a :name() ) child,
instead of the first child of the :pasttype('with') node.

anyway, just a thought.

kjs



On Feb 2, 2008 1:57 PM, via RT Klaas-Jan Stol <
[EMAIL PROTECTED]> wrote:

> # New Ticket Created by  Klaas-Jan Stol
> # Please include the string:  [perl #50472]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=50472 >
>
>
> hi,
>
> consider the next scenario (using lua as HLL)
>
> -- create a new table object (just a hash/array combination), and
> initialize
> with some values.
> foo = { a = 1, b = 2, c = 3}
>
> This can be roughly translated to this PIR:
>
> $P0 = new "LuaTable"
> $P0["a"] = 1
> $P0["b"] = 2
> $P0["c"] = 3
>
> (using PCT, these integer values will be created as "Integer" PMCs, but
> that's not important for now)
>
> to generate such a thing using PAST nodes, we'd do something like (I think
> there are other solutions, but this is straightforward):
>
> method table_constructor($/) {
>   my $past := PAST::Stmts.new( :node($/) );
>
>   my $table := PAST::Op.new( :inline('    %r = new "LuaTable"') );
>   $past.push($table); # push the table construction onto list of
> statements
>
>   # now for each init. field, we'd like to generate a "$P0[<field>] =
> <value>" statement
>   for $<field> {
>     my $field := $( $_ );
>      $past.push( PAST::Var.new( $table, $field, :scope('keyed') ) );
>   }
>
>   make $past;
> }
>
>
> However, when doing this, every time $table is specified as an argument in
> the for loop, it will generate an instruction
>
> $P0 = new "LuaTable"
>
> which is not what we want, obviously.
> Somehow, there's the need to refer only to the result register in which
> the
> new LuaTable is stored, the register that is generated from the %r symbol
> above.
>
> There are more scenarios that need to reference only the result of a
> certain
> expression.
> PAST does not support this currently, and I think it would be helpful.
>
> possibly through a method $table.result() or whatever, but that's only
> what
> comes to my mind initially.
>
> kjs
>

Reply via email to