1
#| rep.structures bootstrap
3
$Id: structures.jl,v 1.3 2000/09/03 20:15:13 john Exp $
5
Copyright (C) 2000 John Harper <john@dcs.warwick.ac.uk>
7
This file is part of librep.
9
librep is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2, or (at your option)
14
librep is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with librep; see the file COPYING. If not, write to
21
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
(declare (in-module rep.structures))
26
(open-structures '(rep.lang.symbols
29
(make-structure nil nil nil '%interfaces)
31
(defun make-interface (name sig)
32
"Create an interface called NAME exporting the list of symbols SIG."
33
(structure-define (get-structure '%interfaces) name sig))
35
(defun parse-interface (sig)
36
"Return the list of symbols described by the module interface SIG."
37
(cond ((null sig) '())
38
((eq (car sig) 'export)
40
((eq (car sig) 'compound-interface)
41
(apply append (mapcar parse-interface (cdr sig))))
42
((eq (car sig) 'structure-interface)
43
(structure-interface (intern-structure (cadr sig))))
45
(let ((interfaces (get-structure '%interfaces)))
46
(or (structure-bound-p interfaces sig)
47
(error "No such interface: %s" sig))
48
(%structure-ref interfaces sig)))))
50
(defun alias-structure (from to)
51
"Create an alias of the structure called FROM as the name TO."
52
(name-structure (get-structure from) to))
54
(defun locate-binding (var imported)
55
"Return the name of the structure binding VAR, using the list of module
56
names IMPORTED as the search start points."
58
(let ((tem (structure-exports-p (get-structure (car imported)) var)))
60
(locate-binding var (cdr imported)))
62
;; this module exports it, but it doesn't define
63
;; it, so search its imports
64
(locate-binding var (structure-imports
65
(get-structure (car imported)))))
66
(t (car imported))))))
68
(export-bindings '(make-interface parse-interface
69
alias-structure locate-binding))