[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with #$ and the compiler
- To: Ranson <ranson@lannion.cnet.fr>
- Subject: Problem with #$ and the compiler
- From: Bill St. Clair <bill>
- Date: Tue, 28 May 91 11:00:25 -0400
- Cc: info-mcl
From: Ranson <ranson@lannion.cnet.fr>
Subject: Problem with #$ and the compiler
X400-Received: by /PRMD=inria/ADMD=atlas/C=FR/; Relayed; 28 May 91
04:33:02+0100
X400-Received: by /PRMD=CNET/ADMD=ATLAS/C=FR/; Relayed; 28 May 91
09:24:00 GMT
To: bug-mcl@cambridge.apple.com, info-macl@cambridge.apple.com
Cc: ranson@lannion.cnet.fr
(Using 2.0b1p2)
The compiler does not seem to consider interface constants like #$optionKey
as real constants, but instead generates code with a reference to the NAME
of the constant. The effect is that if you load the binary in a fresh MCL,
you will get unbound variable errors when running the code.
This may be fixed either by loading the needed interface each time, or refe-
ring to such constants as #.#$xxx, but I'd prefer to call it a bug.
Daniel Ranson (ranson@lannion.cnet.fr)
The compiler DOES consider interface constants to be constants:
? (defun foo ()
#$optionKey)
FOO
? (disassemble *)
0 (JSR_SUBPRIM $SP-NOARGS)
4 (MOVE.L (FIXNUM 2048) D0)
10 (ADDQ.W 4 SP)
12 (RTS)
What the compiler doesn't (and shouldn't) do is remove the reference
by name to a symbolic constant from it's appearance in a macro
expansion.
? (defmacro macro-foo ()
`#$OptionKey)
MACRO-FOO
? (disassemble *)
0 (JSR_SUBPRIM $SP-TWO-ARGS-VPUSH)
4 (MOVE.L (VSP 4) ATEMP0)
8 (SET_NARGS 0)
10 (JSR_SUBPRIM $SP-DBMACRO)
14 (MOVE.L 'TRAPS::$OPTIONKEY D0)
20 (SPOP VSP)
22 (RTS)
What you need to do is to make sure that the constant is looked up when
code using the macro is compiled (or say "#.#$xxx"). The
REQUIRE-TRAP-CONSTANT macro is provided for just this purpose:
? (defmacro correct-macro-foo ()
`(require-trap-constant #$OptionKey))
The same problem will happen with traps, for which the REQUIRE-TRAP macro
provides the solution:
? (defmacro my-newptr (size)
`(require-trap #_NewPtr ,size))
Unfortunately, neither REQUIRE-TRAP nor REQUIRE-TRAP-CONSTANT made it into
the 2.0b1 documentation.