diff options
author | Andy Wingo <wingo@pobox.com> | 2009-03-02 11:23:03 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-03-02 11:23:03 +0100 |
commit | b0e4051e9e4c6669f6cfa57e38ab7b6823a7aa28 (patch) | |
tree | ee6f7d737dc5c09e8814e59f8e2e24a036fcb879 | |
parent | 6d8182ea1b9f3b09445b4a3c18c430b0217f1d13 (diff) | |
download | guile-b0e4051e9e4c6669f6cfa57e38ab7b6823a7aa28.tar.gz |
add annotation module
* module/ice-9/annotate.scm: Add annotation module, for source location
tracking with syncase, and for internal use in the compiler.
-rw-r--r-- | module/ice-9/annotate.scm | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/module/ice-9/annotate.scm b/module/ice-9/annotate.scm new file mode 100644 index 000000000..f09eb1fa9 --- /dev/null +++ b/module/ice-9/annotate.scm @@ -0,0 +1,54 @@ +;;;; Copyright (C) 2009 Free Software Foundation, Inc. +;;;; +;;;; This library is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU Lesser General Public +;;;; License as published by the Free Software Foundation; either +;;;; version 2.1 of the License, or (at your option) any later version. +;;;; +;;;; This library is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;;; Lesser General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU Lesser General Public +;;;; License along with this library; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +;;;; + + +(define-module (ice-9 annotate) + :export (<annotation> annotation? annotate make-annotation + annotation-expression annotation-source annotation-stripped + set-annotation-stripped!)) + +(define <annotation> + (make-vtable "prprpw" + (lambda (struct port) + (display "#<annotation of ") + (display (struct-ref 0)) + (display ">")))) + +(define (annotation? x) + (and (struct? x) (eq? (struct-vtable x) <annotation>))) + +(define (make-annotation e s stripped?) + (make-struct <annotation> 0 e s stripped?)) + +(define (annotation-expression a) + (struct-ref a 0)) +(define (annotation-source a) + (struct-ref a 1)) +(define (annotation-stripped a) + (struct-ref a 2)) +(define (set-annotation-stripped! a) + (struct-set! a 2 #t)) + +(define (annotate e) + (cond ((list? e) + (make-annotation (map annotate e) (source-properties e) #f)) + ((pair? e) + (make-annotation (cons (annotate (car e)) (annotate (cdr e))) + (source-properties e) #f)) + (else e))) + + |