mescc: Tinycc support: bitwise-or initializer.

* module/language/c99/compiler.mes (initzer->value): New function.
  (initzer->data): Use it to support bitwise-or initializer.
* scaffold/tests/74-multi-line-string.c (test): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-07-21 00:21:31 +02:00
parent 3687740b64
commit 11fb4e03dc
2 changed files with 14 additions and 1 deletions

View file

@ -1966,6 +1966,12 @@
`(initzer (p-expr (fixed ,(number->string value)))))) `(initzer (p-expr (fixed ,(number->string value))))))
(_ o)))) (_ o))))
(define (initzer->value info)
(lambda (o)
(pmatch o
((p-expr (fixed ,value)) (cstring->number value))
(_ (error "initzer->value: " o)))))
(define (initzer->data info) (define (initzer->data info)
(lambda (o) (lambda (o)
(pmatch o (pmatch o
@ -1979,6 +1985,10 @@
((initzer (p-expr (string ,string))) `((#:string ,string) #f #f #f)) ((initzer (p-expr (string ,string))) `((#:string ,string) #f #f #f))
((initzer (p-expr (string . ,strings))) `((#:string ,(string-join strings "")) #f #f #f)) ((initzer (p-expr (string . ,strings))) `((#:string ,(string-join strings "")) #f #f #f))
((initzer (initzer-list . ,initzers)) (append-map (initzer->data info) initzers)) ((initzer (initzer-list . ,initzers)) (append-map (initzer->data info) initzers))
((initzer (bitwise-or . ,values))
(let loop ((values (map (initzer->value info) values)) (value 0))
(if (null? values) (int->bv32 value)
(loop (cdr values) (logior value (car values))))))
(() (int->bv32 0)) (() (int->bv32 0))
(_ (error "initzer->data: unsupported: " o))))) (_ (error "initzer->data: unsupported: " o)))))

View file

@ -31,7 +31,10 @@ char const* help =
int int
test () test ()
{ {
if (printf ("belong to us"), strcmp (help, "All your base are")) return 1; if (printf ("belong to us\n"), strcmp (help, "All your base are")) return 1;
int i = 1 | 2 | 4;
if (i != 7) return 1;
return 2,1,0; return 2,1,0;
} }