summaryrefslogtreecommitdiff
path: root/scheme/guile/geiser/modules.scm
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2018-01-30 23:45:41 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2018-01-30 23:45:41 +0100
commit3f2272ecf02c8049ea5f250e6263d0f9441a0bd8 (patch)
tree908f6030f89a8833963377a1254ee252d40a5672 /scheme/guile/geiser/modules.scm
parent33783307abab46433ce18273f562b3a729628e8e (diff)
downloadgeiser-guile-3f2272ecf02c8049ea5f250e6263d0f9441a0bd8.tar.gz
geiser-guile-3f2272ecf02c8049ea5f250e6263d0f9441a0bd8.tar.bz2
guile 2.2: program-arities and program-module reloaded
Those two procedures are gone in these 2.2 times, and things like autodoc and xref were broken as a result. With Andy's help, apparently good enough approximations of their functionality are now in place: let's see how they go.
Diffstat (limited to 'scheme/guile/geiser/modules.scm')
-rw-r--r--scheme/guile/geiser/modules.scm29
1 files changed, 28 insertions, 1 deletions
diff --git a/scheme/guile/geiser/modules.scm b/scheme/guile/geiser/modules.scm
index 780d39e..32b0f1f 100644
--- a/scheme/guile/geiser/modules.scm
+++ b/scheme/guile/geiser/modules.scm
@@ -1,6 +1,6 @@
;;; modules.scm -- module metadata
-;; Copyright (C) 2009, 2010, 2011 Jose Antonio Ortega Ruiz
+;; Copyright (C) 2009, 2010, 2011, 2018 Jose Antonio Ortega Ruiz
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the Modified BSD License. You should
@@ -11,6 +11,7 @@
(define-module (geiser modules)
#:export (symbol-module
+ program-module
module-name?
module-path
find-module
@@ -19,10 +20,36 @@
module-location)
#:use-module (geiser utils)
#:use-module (system vm program)
+ #:use-module (system vm debug)
#:use-module (ice-9 regex)
#:use-module (ice-9 session)
#:use-module (srfi srfi-1))
+;; Return hash table mapping filename to list of modules defined in that
+;; file. H/t andy wingo.
+(define (fill-file->module-mapping! ret)
+ (define (record-module m)
+ (let ((f (module-filename m)))
+ (hash-set! ret f (cons m (hash-ref ret f '())))))
+ (define (visit-module m)
+ (record-module m)
+ (hash-for-each (lambda (k v) (visit-module v))
+ (module-submodules m)))
+ (visit-module (resolve-module '() #f))
+ ret)
+
+(define file->modules (fill-file->module-mapping! (make-hash-table)))
+
+(define (program-file p)
+ (let ((src (program-source p 0)))
+ (and (pair? src) (cadr src))))
+
+(define (program-module p)
+ (let* ((f (program-file p))
+ (mods (or (hash-ref file->modules f)
+ (hash-ref (fill-file->module-mapping! file->modules) f))))
+ (and (pair? mods) (not (null? mods)) (car mods))))
+
(define (module-name? module-name)
(and (list? module-name)
(not (null? module-name))