guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting source location information


From: Rob Browning
Subject: Re: Getting source location information
Date: Wed, 30 Nov 2005 11:00:45 -0800
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

address@hidden (Ludovic Courtès) writes:

> If you want to use source locations in a Guile-friendly way (so that
> Guile can, for instance, display location information in
> backtraces), then you may want to use `scm_set_source_property_x
> (sexp, key, datum)' (where KEY may be one of SCM_SYM_FILENAME,
> SCM_SYM_LINE, SCM_SYM_COLUMN) which is defined in `srcprop.h'.

I think this is probably more along the lines of what he wants, but is
the above going to work correctly if there are multiple lines of
Scheme code?  For example:

   [This is an example ]
   (do-something (foo) (bar))
   (let ((baz bax))
     (do-something-else baz)
     (more-stuff baz)
     (and-even-more baz))
   [ ...with several lines of embedded Scheme code. ]

If I'm guesssing correctly about how scm_set_source_property_x works
(I haven't used it), then it seems like it might be a lot of work to
turn the above lines of Scheme code into a properly filename, line
(and column?) annotated set of forms.

If so, then I wondered if it might be possible to just implement the
function mentioned originally
i.e. ag_scm_c_eval_string_from_file_line, and here's what I came up
with.  Note that I have no idea if this will actually work; I haven't
tested it, and I don't know the semantics of the port related
filename, line, and column bits offhand.

  (define (eval-port port)
    ;; See strports.c inner_eval_string for similar code.
    (let loop ((next-form (read port))
               (any-read? #f)
               (result #f))
      (if (eof-object? next-form)
          (if any-read? result)
          (loop (read port)
                #t
                (primitive-eval next-form)))))

  (define (eval-string-from-file str filename line column)
    (call-with-input-string str
        (lambda (port)
          (set-port-filename! port filename)
          (set-port-line! port line)
          (set-port-column! port column)
          (eval-port port))))

-- 
Rob Browning
rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]