From 7147839964f403013e94d4f5fcc445bb1a75fbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Fri, 3 Feb 2023 13:44:23 -0300 Subject: Implement flatten-typedefs --- cmamut.lisp | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'cmamut.lisp') 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 -- cgit v1.2.3