C supports a #line directive which tells the compiler that the source location isn't in the file that compiler reads but somewhere else. Tools like Yacc use this to instruct the C compiler to generate error messages for the yacc source file rather than the intermediate C file.
Is/was there a Lisp or Scheme compiler that supports something similar?
On Sun, Jun 8, 2008 at 9:45 AM, Helmut Eller heller@common-lisp.net wrote:
C supports a #line directive which tells the compiler that the source location isn't in the file that compiler reads but somewhere else. Tools like Yacc use this to instruct the C compiler to generate error messages for the yacc source file rather than the intermediate C file.
Is/was there a Lisp or Scheme compiler that supports something similar?
SBCL has (and uses) SB-C:SOURCE-LOCATION, which has a compiler-macro that transforms it to the current source location.
Cheers,
-- Nikodemus
* Nikodemus Siivola [2008-06-08 12:39+0200] writes:
SBCL has (and uses) SB-C:SOURCE-LOCATION, which has a compiler-macro that transforms it to the current source location.
I had the impression this more like C's __LINE__. Can SB-C:SOURCE-LOCATION be used to set the current source location?
On Sun, Jun 8, 2008 at 2:07 PM, Helmut Eller heller@common-lisp.net wrote:
I had the impression this more like C's __LINE__. Can SB-C:SOURCE-LOCATION be used to set the current source location?
Sorry, I misunderstood. So you'd want something like
(grab-source-location loc (something (with-grabbed-source-location loc (something-else))
or
(grab-source-location *magic*)
(something)
(something (with-grabbed-source-location *magic* (something-else)))
which would result SOMETHING-ELSE getting the same source location as it would without the surrounding and preceding forms?
Do you need both, or only the first one?
Cheers,
-- Nikodemus
* Nikodemus Siivola [2008-06-08 13:17+0200] writes:
Sorry, I misunderstood. So you'd want something like
(grab-source-location loc (something (with-grabbed-source-location loc (something-else))
or
(grab-source-location *magic*)
(something)
(something (with-grabbed-source-location *magic* (something-else)))
which would result SOMETHING-ELSE getting the same source location as it would without the surrounding and preceding forms?
Yes, that's the idea.
Do you need both, or only the first one?
I don't have real need right now. This is more a would-be-nice-to-have thing. I'd like to have something like:
(declare (source-location "foo/bar.lisp" LINE COLUMN)) (foo) (bar)
So that (FOO) and (BAR) are compiled with the adjusted source location. Ideally this would also work inside LOCALLY. But it would be nice if the arguments could be something mundane like filenames and line-numbers rather then SBCL style source-paths or form-numbers. Those source-paths are rather hard to generate for something like Emacs.
A way to get the source location to feed it back later would also be nice. I'm thinking about something like:
(defmacro foo (exp) `(progn (declare (source-location ,(get-source-location (nth 10 exp)))) (something-new)))
In this case (SOMETHING-NEW) would have the same source location as the 10th element of exp, even though the expressions don't share any structure. Useful would be if the hypothetical GET-SOURCE-LOCATION would work on any expression returned by READ or an equivalent parsing function.
The idea is to use this in a preprocessor which generates a lisp file. The file is then compiled as usual with COMPILE-FILE. Think of a Dylan-to-Lisp translator.
Helmut.