--- /dev/null
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of GNU Mes.
+ *
+ * GNU Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * GNU Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <mes/lib.h>
+
+struct foo
+{
+ int field;
+ int array[3];
+};
+
+struct foo foes[] =
+ {
+ {10, {11, 12, 13}},
+ {20, {21, 22}},
+ {30, {31}},
+ {40, {41}},
+ {0}
+ };
+
+int
+main ()
+{
+ for (struct foo *p = foes; p->field; p++)
+ {
+ oputs ("{");
+ oputs (itoa (p->field)); oputs (",");
+ oputs ("{");
+ oputs (itoa (p->array[0])); oputs (",");
+ oputs (itoa (p->array[1])); oputs (",");
+ oputs (itoa (p->array[2]));
+ oputs ("}");
+ oputs ("},\n");
+ }
+ oputs ("{0}\n");
+ oputs ("};\n");
+
+ return 0;
+}
((bits . ,bits) bits)
(_ (list o))))
-(define (struct->init-fields o)
+(define (struct->init-fields o) ;; FIXME REMOVEME: non-recursive unroll
(pmatch o
(_ (guard (and (type? o) (eq? (type:type o) 'struct)))
(append-map struct->init-fields (type:description o)))
(int->bv type (expr->number info fixed) info))
(int->bv type (expr->number info fixed) info)))
((initzer (initzer-list . ,inits))
- (if (structured-type? type)
- (let* ((fields (map cdr (struct->init-fields type)))
- (missing (max 0 (- (length fields) (length inits))))
- (inits (append inits
- (map (const '(fixed "0")) (iota missing)))))
- (map (cut init->data <> <> info) fields inits))
- (begin
- (stderr "array-init-element->data: oops:~s\n" o)
- (stderr "type:~s\n" type)
- (error "array-init-element->data: unstructured not supported: " o))))
+ (cond ((structured-type? type)
+ (let* ((fields (map cdr (struct->init-fields type)))
+ (missing (max 0 (- (length fields) (length inits))))
+ (inits (append inits
+ (map (const '(fixed "0")) (iota missing)))))
+ (map (cut array-init-element->data <> <> info) fields inits)))
+ ((c-array? type)
+ (let* ((missing (max 0 (- (c-array:count type) (length inits))))
+ (inits (append inits
+ (map (const '(fixed "0")) (iota missing)))))
+ (map (cut array-init-element->data (c-array:type type) <> info) inits)))
+ (else
+ (stderr "array-init-element->data: oops:~s\n" o)
+ (stderr "type:~s\n" type)
+ (error "array-init-element->data: not supported: " o))))
(_ (init->data type o info))
(_ (error "array-init-element->data: not supported: " o))))
((initzer (initzer-list . ,inits))
(let ((type (c-array:type type)))
(if (structured-type? type)
- (let* ((fields (length (struct->init-fields type))))
+ (let* ((init-fields (struct->init-fields type)) ;; FIXME
+ (count (length init-fields)))
(let loop ((inits inits))
(if (null? inits) '()
(let ((init (car inits)))
((initzer (initzer-list . ,car-inits))
(append (array-init-element->data type init info)
(loop (cdr inits))))
- (_ (let* ((count (min (length inits) fields))
+ (_
+ (let* ((count (min (length inits) (length init-fields)))
(field-inits (list-head inits count)))
- (append (array-init-element->data type `(initzer-list ,@field-inits) info)
- (loop (list-tail inits count))))))))))
+ (append (array-init-element->data type `(initzer-list ,@field-inits) info)
+ (loop (list-tail inits count))))))))))
(map (cut array-init-element->data type <> info) inits))))
(((initzer (initzer-list . ,inits)))