On Oct 23, 2007, at 5:45 PM, Allison Randal wrote:
Klaas-Jan Stol wrote:
Hi, attached a document describing the current macro layer of IMCC.
On the proposed modifications to macros, I have reservations on the
automatic munging of .local variable names. Macros are simple
parameterized substitutions. If someone includes a '.local' in a
macro, it's likely that they'll expect it to appear literally in the
body:
.macro declare_my_locals(x)
.local int $x
.endm
.sub bar
.declare_my_locals(foo)
foo = 5
print foo
...
.end
I believe tcl actually uses a macro to define an entire sub. It's a
little weird but it works and is useful. Some things in macros exist
but aren't specced, but forbidding them would likely cause more code in
the compiler. A call to a macro can easily cover more than one line.
That's counter-intuitive to the nature of PIR but it works and can be
clean, take a look at examples/shootout/nbody.pir. Something like this
could be useful, especially with array initialization which often uses
a lot of lines.
.macro Foo (a, b)
.local int .a
.a = .b
.endm
.sub main :main
.Foo(b, 1)
print b
print "\n"
.Foo(c, 2)
print c
print "\n"
.end
And unlikely that they'll want it to appear munged for a particular
macro name:
.sub bar
.declare_my_locals(foo)
local_declare_my_locals_foo = 5
print local_declare_my_locals_foo
...
.end
Those aren't meant to be accessed outside the macro. And imcc adds a
number to it to make it hard to guess and there's no incentive to do
that. If someone needs a certain functionality, they can write a macro
that will allow them to use that variable. Looking at
runtime/parrot/include/hllmacros.pir might show you some of the
potential uses for macros. They're rarely used, but they're available.
Comments?
Allison