summaryrefslogtreecommitdiff
path: root/guix/utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-09-01 19:21:06 +0200
committerLudovic Courtès <ludo@gnu.org>2012-09-03 01:07:01 +0200
commitff352cfb9792d6777a1240fc057708d251027e07 (patch)
tree280c53c9d670fed131179159e8eb861c8e7d0e54 /guix/utils.scm
parentea52a52d7c635e0fed70903c720a52de7d2b6d2e (diff)
Move <location> to (guix utils).
* guix/packages.scm (<location>, location): Move to... * guix/utils.scm: ... here.
Diffstat (limited to 'guix/utils.scm')
-rw-r--r--guix/utils.scm37
1 files changed, 37 insertions, 0 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index cec6df935b..a87f119558 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -48,6 +48,14 @@
define-record-type*
compile-time-value
memoize
+
+ location
+ location?
+ location-file
+ location-line
+ location-column
+ source-properties->location
+
gnu-triplet->nix-system
%current-system))
@@ -605,3 +613,32 @@ returned by `config.guess'."
(define %current-system
;; System type as expected by Nix, usually ARCHITECTURE-KERNEL.
(make-parameter (gnu-triplet->nix-system %host-type)))
+
+
+;;;
+;;; Source location.
+;;;
+
+;; A source location.
+(define-record-type <location>
+ (make-location file line column)
+ location?
+ (file location-file) ; file name
+ (line location-line) ; 1-indexed line
+ (column location-column)) ; 0-indexed column
+
+(define location
+ (memoize
+ (lambda (file line column)
+ "Return the <location> object for the given FILE, LINE, and COLUMN."
+ (and line column file
+ (make-location file line column)))))
+
+(define (source-properties->location loc)
+ "Return a location object based on the info in LOC, an alist as returned
+by Guile's `source-properties', `frame-source', `current-source-location',
+etc."
+ (let ((file (assq-ref loc 'filename))
+ (line (assq-ref loc 'line))
+ (col (assq-ref loc 'column)))
+ (location file (and line (+ line 1)) col)))