Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

macros, local variables...

1 view
Skip to first unread message

William Coleda

unread,
Oct 7, 2004, 9:49:22 PM10/7/04
to Perl 6 Internals
A macro example in the docs shows:

.macro swap (A,B,TEMP) # . marks the directive
set .TEMP,.A # . marks the special variable.
set .A,.B
set .B,.TEMP
.endm # And . marks the end of the macro.


Is there a way to write this macro without specifying the TEMP parameter? For example, something like:

.macro swap (A,B)
.local pmc .TEMP
.TEMP = .A
.A = .B
.B = .TEMP
.endm

I've tried a few obvious permutations, but don't see anything that works as is.

Michael Walter

unread,
Oct 7, 2004, 10:35:00 PM10/7/04
to William Coleda, Perl 6 Internals
gensym, hehe. History repeats ;-)

- Michael

Leopold Toetsch

unread,
Oct 8, 2004, 4:11:14 AM10/8/04
to William Coleda, Perl 6 Internals
William Coleda wrote:
> A macro example in the docs shows:
>
> .macro swap (A,B,TEMP) # . marks the directive
> set .TEMP,.A # . marks the special variable.
> set .A,.B
> set .B,.TEMP
> .endm # And . marks the end of the macro.
>
>
> Is there a way to write this macro without specifying the TEMP
> parameter? For example, something like:
>
> .macro swap (A,B)
> .local pmc .TEMP

.local inside macros creates a local *label*.

As the macro arguments could be any kind of register, the macro can't
have the TEMP hidden inside. If you are gonna swap PMCs only, you could
write it as:

.macro swapP (A,B)
$P0 = .A
.A = .B
.B = $P0
.endm

(untested)

*But* we have an opcode called *exchange* ... It's even JITted on i386.

leo

William Coleda

unread,
Oct 8, 2004, 12:15:12 PM10/8/04
to Leopold Toetsch, Perl 6 Internals

Leopold Toetsch wrote:
> .macro swapP (A,B)
> $P0 = .A
> .A = .B
> .B = $P0
> .endm
>
> (untested)

Seems to work, thanks.

> *But* we have an opcode called *exchange* ... It's even JITted on i386.

This was just an example. Thanks.

> leo
>
>

0 new messages