develooper Front page | perl.perl5.porters | Postings from January 2008

expanding macros

Thread Next
From:
Nicholas Clark
Date:
January 4, 2008 10:21
Subject:
expanding macros
Message ID:
20080104182130.GW23703@plum.flirble.org
Fed up with trying to work out how macros expand, I've just added a small
program to do it. It works like this:

$ perl Porting/expand-macro.pl mPUSHp
`sh  cflags "optimize='-g'" try.c` -E try.c > try.i
          CCCMD =  ccache gcc -DPERL_CORE -c -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include  -std=c89 -g -Wall -ansi -W -Wextra -Wdeclaration-after-statement -Wendif-labels 
# 3 "mPUSHp expands to"
Perl_sv_setpvn(my_perl, (*++sp = (Perl_sv_newmortal(my_perl))),(A0),(A1))

or this:

$ perl Porting/expand-macro.pl SvIOK_off
`sh  cflags "optimize='-g'" try.c` -E try.c > try.i
          CCCMD =  ccache gcc -DPERL_CORE -c -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include  -std=c89 -g -Wall -ansi -W -Wextra -Wdeclaration-after-statement -Wendif-labels 
# 3 "SvIOK_off expands to"
((A0)->sv_flags &= ~(0x00000100|0x00001000|0x80000000))

or this:

$ perl Porting/expand-macro.pl dSP     
`sh  cflags "optimize='-g'" try.c` -E try.c > try.i
          CCCMD =  ccache gcc -DPERL_CORE -c -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include  -std=c89 -g -Wall -ansi -W -Wextra -Wdeclaration-after-statement -Wendif-labels 
# 3 "dSP expands to"
SV **sp = (my_perl->Istack_sp)

Arguments, if any, passed to the macro are named A0, A1, A2, ...
I'm now suspecting that some C compilers will choke with spaces in the file
names in the #line directive :-)

Nicholas Clark

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About