~ubuntu-branches/ubuntu/trusty/librep/trusty

« back to all changes in this revision

Viewing changes to lisp/rep/structures.jl

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2001-11-13 15:06:22 UTC
  • Revision ID: james.westby@ubuntu.com-20011113150622-vgmgmk6srj3kldr3
Tags: upstream-0.15.2
ImportĀ upstreamĀ versionĀ 0.15.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#| rep.structures bootstrap
 
2
 
 
3
   $Id: structures.jl,v 1.3 2000/09/03 20:15:13 john Exp $
 
4
 
 
5
   Copyright (C) 2000 John Harper <john@dcs.warwick.ac.uk>
 
6
 
 
7
   This file is part of librep.
 
8
 
 
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)
 
12
   any later version.
 
13
 
 
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.
 
18
 
 
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.
 
22
|#
 
23
 
 
24
(declare (in-module rep.structures))
 
25
 
 
26
(open-structures '(rep.lang.symbols
 
27
                   rep.data))
 
28
 
 
29
(make-structure nil nil nil '%interfaces)
 
30
 
 
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))
 
34
 
 
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)
 
39
         (cdr sig))
 
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))))
 
44
        ((symbolp 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)))))
 
49
 
 
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))
 
53
 
 
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."
 
57
  (when imported
 
58
    (let ((tem (structure-exports-p (get-structure (car imported)) var)))
 
59
      (cond ((null tem)
 
60
             (locate-binding var (cdr imported)))
 
61
            ((eq tem 'external)
 
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))))))
 
67
 
 
68
(export-bindings '(make-interface parse-interface
 
69
                   alias-structure locate-binding))