From 932b38980ea9d47f2c80142eb739a25e0d814b65 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Tue, 22 May 2018 18:24:32 +0200 Subject: [PATCH] mescc: Tinycc support: Handle short struct initializer. * module/language/c99/compiler.mes (array-init-element->data): Handle short struct initializer. --- module/language/c99/compiler.mes | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 3c146d59..26d37eb6 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -2101,12 +2101,16 @@ ((initzer (p-expr (fixed ,fixed))) (int->bv type (expr->number info fixed))) ((initzer (initzer-list . ,inits)) - (if (structured-type? type) - (map (cut init->data <> <> info) (map cdr (struct->init-fields type)) inits) - (begin - (stderr "array-init-element->data: oops:~s\n" o) - (stderr "type:~s\n" type) - (error "array-init-element->data: not supported: " o)))) + (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: not supported: " o)))) (_ (init->data type o info)) (_ (error "array-init-element->data: not supported: " o))))