diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-02-03 13:44:23 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-02-03 13:44:48 -0300 |
commit | 7147839964f403013e94d4f5fcc445bb1a75fbf5 (patch) | |
tree | 207b7d22c2bf96338f1b204201f71e9ed3a3a044 /cmamut.lisp | |
parent | db6fbae7a27d955550d28f8aa469f1a5592bd59a (diff) | |
download | cmamut-7147839964f403013e94d4f5fcc445bb1a75fbf5.tar.gz cmamut-7147839964f403013e94d4f5fcc445bb1a75fbf5.zip |
Implement flatten-typedefs
Diffstat (limited to 'cmamut.lisp')
-rw-r--r-- | cmamut.lisp | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/cmamut.lisp b/cmamut.lisp index d30821e..9918c5d 100644 --- a/cmamut.lisp +++ b/cmamut.lisp @@ -132,29 +132,16 @@ ; Typedefs get "flattened" so that resolving is just a lookup. (defun flatten-typedefs (raw-typedefs) (let ((type-associations (make-hash-table :test #'equal :size 256))) - (labels ((take-deps - (deps) - (let (remaining) - (dolist (i deps) - (let ((tag (gethash "tag" (gethash "type" i)))) - (if (gethash tag type-associations) - (setf (gethash (gethash "name" i) type-associations) tag) - (push i remaining)))) - (if (= (length deps) (length remaining)) - remaining - (take-deps remaining))))) - (let ((result (take-deps raw-typedefs))) - (labels ((associate-base-type - (k v) - (let ((new-v (gethash v type-associations))) - (if (eq new-v t) - (setf (gethash k type-associations) v) - (associate-base-type k new-v))))) - (maphash (lambda (k v) - (unless (eq v t) - (associate-base-type k v))) - type-associations)) - result)))) + (dolist (i raw-typedefs) + (setf (gethash (gethash "name" i) type-associations) (gethash "type" i))) + (labels ((flatten-typedef + (k v) + (let ((new-v (gethash (gethash "tag" v) type-associations))) + (when new-v + (setf (gethash k type-associations) new-v) + (flatten-typedef k new-v))))) + (maphash #'flatten-typedef type-associations)) + type-associations)) (defstruct spec functions |