Early work-in-progress.
[sod] / tables.lisp
CommitLineData
abdf50aa
MW
1;;; -*-lisp-*-
2;;;
3;;; Main tables for the translator
4;;;
5;;; (c) 2009 Straylight/Edgeware
6;;;
7
8;;;----- Licensing notice ---------------------------------------------------
9;;;
10;;; This file is part of the Simple Object Definition system.
11;;;
12;;; SOD is free software; you can redistribute it and/or modify
13;;; it under the terms of the GNU General Public License as published by
14;;; the Free Software Foundation; either version 2 of the License, or
15;;; (at your option) any later version.
16;;;
17;;; SOD is distributed in the hope that it will be useful,
18;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;;; GNU General Public License for more details.
21;;;
22;;; You should have received a copy of the GNU General Public License
23;;; along with SOD; if not, write to the Free Software Foundation,
24;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26(cl:in-package #:sod)
27
28;;;--------------------------------------------------------------------------
29;;; Main tables.
30
31(defvar *module-map* (make-hash-table :test #'equal)
32 "A hash table mapping file truenames (pathnames) to modules.
33
34 This is used to prevent multiple inclusion of a single module, which would
35 be bad. Usually it maps pathnames to MODULE objects. As a special case,
36 the truename a module which is being parsed maps to :IN-PROGRESS, which
37 can be used to detect dependency cycles.")
38
39(defvar *type-map* (make-hash-table :test #'equal)
40 "A hash table mapping type names to the C types they describe.
41
42 Since a class is a C type, it gets its own entry in here as a C-CLASS-TYPE
43 object. This is how we find classes by name: the C-CLASS-TYPE object has
44 a reference to the underlying SOD-CLASS instance.")
45
46;;;--------------------------------------------------------------------------
47;;; Utilities.
48
49(defparameter *clear-the-decks-functions*
50 '(reset-type-and-module-map
51 populate-type-map
52 bootstrap-classes))
53
54(defun reset-type-and-module-map ()
55 "Reset the main hash tables, clearing the translator's state.
56
57 One of the *CLEAR-THE-DECKS-FUNCTIONS*."
58
59 (setf *module-map* (make-hash-table :test #'equal)
60 *type-map* (make-hash-table :test #'equal)))
61
62(defun populate-type-map ()
63 "Store some important simple types in the type map."
64 (dolist (name '("va_list" "size_t" "ptrdiff_t"))
65 (setf (gethash name *type-map*)
66 (make-simple-type name))))
67
68(defun clear-the-decks ()
69 "Reinitialize the translator's state.
70
71 This is mainly useful when testing the translator from a Lisp REPL."
72 (dolist (func *clear-the-decks-functions*)
73 (funcall func)))
74
75#+test
76(clear-the-decks)
77
78;;;----- That's all, folks --------------------------------------------------