mescc: Tinycc support: more list initializers.
* module/language/c99/compiler.mes (init-declr->name): Handle array, pointer array. (init-declr->pointer): Likewise. (decl->info): Generalize list initializers, add pointer variant. FIXME: AST-rewriting?
This commit is contained in:
parent
16b9a21712
commit
e8023cd2ef
|
@ -1290,7 +1290,9 @@
|
|||
(pmatch o
|
||||
((ident ,name) name)
|
||||
((ptr-declr ,pointer (ident ,name)) name)
|
||||
((array-of (ident ,name)) name)
|
||||
((array-of (ident ,name) ,index) name)
|
||||
((ptr-declr (pointer) (array-of (ident ,name) (p-expr ,size))) name)
|
||||
(_ (error "init-declr->name unsupported: " o))))
|
||||
|
||||
(define (init-declr->pointer o)
|
||||
|
@ -1298,6 +1300,8 @@
|
|||
((ident ,name) 0)
|
||||
((ptr-declr ,pointer (ident ,name)) (ptr-declr->pointer pointer))
|
||||
((array-of (ident ,name) ,index) 1)
|
||||
((array-of (ident ,name)) 1)
|
||||
((ptr-declr (pointer) (array-of (ident ,name) (p-expr ,size))) -2)
|
||||
(_ (error "init-declr->pointer unsupported: " o))))
|
||||
|
||||
(define (statements->clauses statements)
|
||||
|
@ -1646,7 +1650,7 @@
|
|||
|
||||
;; DECL
|
||||
;; char *bla[] = {"a", "b"};
|
||||
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (array-of (ident ,name))) (initzer (initzer-list . ,initzers)))))
|
||||
((decl (decl-spec-list (type-spec ,type)) (init-declr-list (init-declr (ptr-declr (pointer) (array-of (ident ,name))) (initzer (initzer-list . ,initzers)))))
|
||||
(let* ((type (decl->ast-type type))
|
||||
(entries (filter identity (append-map (initzer->globals globals) initzers)))
|
||||
(entry-size 4)
|
||||
|
@ -1691,12 +1695,20 @@
|
|||
(clone info #:globals globals)))))
|
||||
|
||||
;; int i = 0, j = 0;
|
||||
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ident ,name) . ,initzer) . ,rest))
|
||||
((decl (decl-spec-list (type-spec ,type)) (init-declr-list (init-declr (ident ,name) . ,initzer) . ,rest))
|
||||
(let loop ((inits `((init-declr (ident ,name) ,@initzer) ,@rest)) (info info))
|
||||
(if (null? inits) info
|
||||
(loop (cdr inits)
|
||||
((decl->info info)
|
||||
`(decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list ,(car inits))))))))
|
||||
`(decl (decl-spec-list (type-spec ,type)) (init-declr-list ,(car inits))))))))
|
||||
|
||||
;; int *i = 0, j ..;
|
||||
((decl (decl-spec-list (type-spec ,type)) (init-declr-list (init-declr (ptr-declr ,pointer (ident ,name)) . ,initzer) . ,rest))
|
||||
(let loop ((inits `((init-declr (ptr-declr ,pointer (ident ,name)) ,@initzer) ,@rest)) (info info))
|
||||
(if (null? inits) info
|
||||
(loop (cdr inits)
|
||||
((decl->info info)
|
||||
`(decl (decl-spec-list (type-spec ,type)) (init-declr-list ,(car inits))))))))
|
||||
|
||||
((decl (decl-spec-list (stor-spec (typedef)) ,type) ,name)
|
||||
(format (current-error-port) "SKIP: typedef=~s\n" o)
|
||||
|
@ -1941,6 +1953,7 @@
|
|||
(let ((value (assoc-ref (.constants info) name)))
|
||||
(int->bv32 (or value 0))))
|
||||
((initzer (p-expr (fixed ,value))) (int->bv32 (cstring->number value)))
|
||||
((initzer (p-expr (char ,char))) (int->bv32 (char->integer (string-ref char 0))))
|
||||
((initzer (neg (p-expr (fixed ,value)))) (int->bv32 (- (cstring->number value))))
|
||||
((initzer (ref-to (p-expr (ident ,name)))) `(,name #f #f #f))
|
||||
((initzer (p-expr (string ,string))) `((#:string ,string) #f #f #f))
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
struct foo;
|
||||
|
||||
struct foo* krak;
|
||||
|
||||
typedef struct foo foo_struct;
|
||||
|
||||
struct foo
|
||||
|
@ -30,6 +32,18 @@ struct foo
|
|||
int bar[2];
|
||||
};
|
||||
|
||||
int a, b;
|
||||
int i, *j;
|
||||
int *k = 0, l;
|
||||
|
||||
typedef struct baz
|
||||
{
|
||||
int bar;
|
||||
//struct baz *f, *g;
|
||||
struct baz *f;
|
||||
struct baz *g;
|
||||
} baz;
|
||||
|
||||
int
|
||||
test ()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue