As noted, the new assembler is now in place. There isn't much
resemblance to the old assembler, excepting the fact that they both
(almost) read the same .pasm files. The new macro syntax is documented
in assemble.pl and can be read with perldoc, but I'll summarize things
later in the message.

The new assembler introduces two major changes and three new features,
which should get us a long way towards the 1.0 release. Let's look at
the fun stuff first.

Support for keyed parameters now exists. I need to change the name of
the 'set_keyed' and 'get_keyed' operator to just 'set', since they
should be relatively unambiguous. Anyway, here's the new syntax
available at the assembly level:

set_keyed P15["foo"],I7
get_keyed N3,P2[S5]

This is, of course, a simple example. Now, there isn't much magic going
on here, primarily because all it's doing is the following transform:

set_keyed P15["foo"],I7

into

set_keyed P15,"foo",I7

It's really just syntactical sugar, with a little better error checking.

The next feature which Clinton used in his BASIC compiler but had to do
by hand is a manifest constant. You can use the following syntax to
define an assemble-time constant:

..constant PerlHash 6 # Important, because the special names 'PerlHash'
&c went away
new P5,.PerlHash # Again, note the pervasive '.', telling you that
you're dealing with a macro expansion.

These constants are kept in a dynamic hash, and redefined every time you
redefine them as you progress through the file. The last feature was
alluded to earlier, but not stated.

Constants such as '.Array' and '.IntQueue' are predefined for you, so
you can use them as follows without defining them yourself:

..constant ARGV P0
new .ARGV,.PerlHash # .PerlHash is defined for you.

However, it's currently a static list inside assembler.pl, and not
explicitly generated from include/parrot/pmc.h. It should be, but it's
not. I'm planning to add '.include' and '.sub' later on, but I'm not
going to spend too much time on things that won't really be used by
compilers. I'd hope that they can spend time optimizing out uses of
macros and such during register allocation and other passes.

Now, onto the changes.

The changes here are designed to make the various syntaxes more
orthogonal. In the new assembler, every command or argument preceded by
a '.' is a macro argument of some variety. Therefor, after expansion,
nothing in a .pasm file should ever have a '.' prepended to it.

Macros used to look like:
answer macro ( A, B )
  print A
  print "\n"
  print B
endm
answer(1,5)

The new style changes 'macro' and 'endm' so the assembler knows the're
not new instructions, and does the same for 'A' and 'B' so the assembler
knows they're not labels. Here's how that now looks, with comments.

..macro answer ( A, B ) # Macro expansions are prefaced by '.', and the
                       # first item, so no lookahead is required to
                       # determine if 'macro' is a label.
  print .A             # At one time, 'A' might have been confused with
                       # a forward-referenced label. No longer.
  print "\n"
  print .B
..endm
..answer(1,5) # Again, anything to be expanded is prefaced by a '.'.

The next change is to local labels. These are now no longer treated
specially by the assembler, and are considered simply macro expansions
inside a macro definition. Local labels really shouldn't be necessary
outside of a macro definition. At the global level, there really isn't a
need to have more than one label with the same name, although I'll admit
it's convenient. Inside a macro, there is a reason, because three macro
invocations each with 'LOOP_START' probably shouldn't die in the
assembler with "multiple label definitions".

I removed local labels at the global level really only for one reason: I
couldn't decide how the semantics should work. Multiple 'ret'
instructions can occur in a single subroutine, which means that we can't
tell if a label invoked twice between rets and between definitions is
pointing to the first label creation or the second. This is sort of hard
to explain at 12:30 am, so I won't continue.

Anyway, the old local label syntax looks like:

$foo: set I0,32
      branch $foo

Now, the local label syntax (only available in macros, remember) is:

..local $foo: set I0,32     # The '.local' now sets off the macro.
             branch .$foo  # And '.' now prefaces the macro invocation.

So, hopefully the bad news isn't too bad. Local labels are still
available where you -really- need them, and macro syntax hasn't changed
too much, but it should be easier to assemble.
--
Jeff <[EMAIL PROTECTED]>

Reply via email to