Just for clarity does this mean Gambit's eval and compiler not only takes a sexp input (with or without location info annotations, depending on specific route), but also takes some kind of source code special object tree format?
Here's the implementation of source-at.
On May 31, 2013, at 9:40 AM, Marc Feeley <feeley@IRO.UMontreal.CA> wrote:
>
> On May 31, 2013, at 9:28 AM, Nathan Sorenson <takeoutweight@hotmail.com> wrote:
>
>> When translating Clojure code to Scheme, I'm finding it quite easy to preserve source code information for the Gambit interpreter, so that when I get exceptions I am notified of the offending Clojure source lines. Is there an obvious way I could do this for compiled code as well?
>
> There isn't a form for this, but that would be useful and I have thought about adding it. Something like a "source-at" special form.
>
> For example,
>
> (source-at "foo.scm" 10 2 ;; file line column
> ((source-at "foo.scm" 10 8 cons)
> (source-at "foo.scm" 10 8 x)
> (source-at "foo.scm" 10 10 y)))
>
> would be equivalent to
>
> (cons x y)
>
> but with explicit source location information.
>
> Actually this source-at form can be easily defined as a macro give me a few minutes.
Marc
;;; File: source-at.scm
(##define-syntax source-at
(lambda (form)
(define (unwrap x)
(if (##source? x) (##source-code x) x))
(apply (lambda (_ path line col expr)
(##make-source
(unwrap expr)
(##make-locat
(##path->container (unwrap path))
(##make-filepos (- (unwrap line) 1) (- (unwrap col) 1) 0))))
(unwrap form))))
;; test it:
(define (f x y)
(+ 1
(source-at "foo.scm" 10 2 ;; file line column(/ x y))))
(pp (f 100 0))
;; Output:
;;
;; % gsi source-at.scm
;; *** ERROR IN f, "foo.scm"@10.2 -- Divide by zero
;; (/ 100 0)
_______________________________________________
Gambit-list mailing list
Gambit-list@iro.umontreal.ca
https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list