Re: Macros and symbols across packages
- From: tar@xxxxxxxxxxxxx (Thomas A. Russ)
- Date: 31 May 2005 11:29:53 -0700
"Jeff M." <massung@xxxxxxxxx> writes:
> I'm curious if there is a method of making sure that symbols will
> evaluate "properly" across packages for use in a macro. For example, I
> have a package that will generate ARM assembly code like so:
>
> (addne r0 r0 r1 :lsl 4) => #x...
>
> Of course, when I use these macros from outside the ARM package,
> though, none of my symbols (registers) match those in the ARM package.
> The only two ideas I can think of to ensure that they match would be
> to:
>
> 1. Modify the instruction macro to always intern register symbols into
> the current package (bad, IMO, but only for gut reasons) or
As Pascal already pointed out, it is too late by the time your macro
executes, since the symbols have already been interned by the reader.
That is unless you decide to make the input be a string instead.
One solution, which BTW is used by the CL LOOP macro, is also mentioned
by Pascal: Test symbols via SYMBOL-NAME rather than EQ. That means the
macro that expands into the assembler doesn't care about the package,
but only about the name of the symbol used in this language.
> 2. Create a reader character macro that will change which package I'm
> in for the rest of the read:
No. I would not go this way.
> { (addne r0 r0 r1 :lsl 4) }
>
> I'm willing to do (2) if that is general practice, but I was hoping
> there might be something else I can do that may be a simpler solution
> (as I have a lot of assembly code already in place -- I just recently
> put the ARM macros in its own package.
>
What you left out was what I would consider the most reasonable way,
namely to export the symbols in the ARM package and then use that
package in places where you want the ARM macros to appear. I imagine
that you already did something like this to get your macro to be found.
I think that gives you the cleanest solution.
--
Thomas A. Russ, USC/Information Sciences Institute
.
- References:
- Macros and symbols across packages
- From: Jeff M.
- Macros and symbols across packages
- Prev by Date: Overlord programs
- Next by Date: Has Rational Rose a Lisp history?
- Previous by thread: Re: Macros and symbols across packages
- Next by thread: MOP/Macroexpansion
- Index(es):
Relevant Pages
|