(size (type->size info type)))
(append-text info (wrap-as (i386:value->accu size)))))
+ ((sizeof-type (type-name (decl-spec-list (type-spec (struct-ref (ident (,name)))))))
+ (let* ((type (list "struct" name))
+ (size (ast-type->size info type)))
+ (append-text info (wrap-as (i386:value->accu size)))))
+
((sizeof-type (type-name (decl-spec-list (type-spec (struct-ref (ident ,name))))))
(let* ((type (list "struct" name))
(size (type->size info type)))
((decl-spec-list (type-spec (fixed-type ,type)))
(type->size info type))
((decl-spec-list (type-qual ,qual) (type-spec (fixed-type ,type)))
- (type->size info type))
+ (type->type info type))
+ ((struct-ref (ident (,type)))
+ (type->type info `("struct" ,type)))
((struct-ref (ident ,type))
(type->size info `("struct" ,type)))
(void 4)
(pmatch o
((fixed-type ,type)
type)
+ ((typename ,type)
+ type)
+ ((struct-ref (ident (,type)))
+ (list "struct" type))
((struct-ref (ident ,type))
(list "struct" type))
(_ (stderr "SKIP: type=~s\n" o)
(define (decl->type o)
(pmatch o
((fixed-type ,type) type)
+ ((struct-ref (ident (,name))) (list "struct" name))
((struct-ref (ident ,name)) (list "struct" name))
((struct-def (ident ,name) . ,fields) (list "struct" name))
((decl (decl-spec-list (type-spec (struct-ref (ident ,name))))) ;; "scm"
((string-prefix? "0" s) (string->number s 8))
(else (string->number s))))
-(define (struct-field o)
- (pmatch o
- ((comp-decl (decl-spec-list (type-spec (enum-ref (ident ,type))))
- (comp-declr-list (comp-declr (ident ,name))))
- (list name type 4))
- ((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ident ,name))))
- (list name type 4))
- ((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ident ,name))))
- (list name type 4))
- ((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer (pointer)) (ident ,name)))))
- (list name type 4)) ;; FIXME: **
- ((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ftn-declr (scope (ptr-declr (pointer) (ident ,name))) (param-list . ,param-list)))))
- (list name type 4)) ;; FIXME function / int
- ((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
- (list name type 4)) ;; FIXME: ptr/char
- ((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer (pointer)) (ident ,name)))))
- (list name type 4)) ;; FIXME: **
- ((comp-decl (decl-spec-list (type-spec (void))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
- (list name '(void) 4)) ;; FIXME: *
- ((comp-decl (decl-spec-list (type-spec (void))) (comp-declr-list (comp-declr (ftn-declr (scope (ptr-declr (pointer) (ident ,name))) (param-list . ,param-list)))))
- (list name '(void) 4))
- ((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
- (list name '(void) 4))
- ((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer) (array-of (ident ,name) (p-expr (fixed ,count)))))))
- (let ((size 4)
- (count (cstring->number count)))
- (list name type (* count size) 0)))
- ((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (array-of (ident ,name) (p-expr (fixed ,count))))))
- (let ((size 4)
- (count (cstring->number count)))
- (list name type (* count size) 0)))
- ((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (array-of (ident ,name) (p-expr (fixed ,count))))))
- (let ((size 4)
- (count (cstring->number count)))
- (list name type (* count size) 0)))
- ;; struct InlineFunc **inline_fns;
- ((comp-decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (comp-declr-list (comp-declr (ptr-declr (pointer (pointer)) (ident ,name)))))
- (list name type 4))
- ((comp-decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
- (list name type 4))
- (_ (error "struct-field: unsupported: " o))))
+(define (struct-field info)
+ (lambda (o)
+ (pmatch o
+ ((comp-decl (decl-spec-list (type-spec (enum-ref (ident ,type))))
+ (comp-declr-list (comp-declr (ident ,name))))
+ (list name type 4))
+ ((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ident ,name))))
+ (list name type 4))
+ ((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ident ,name))))
+ (list name type 4))
+ ((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer (pointer)) (ident ,name)))))
+ (list name type 4)) ;; FIXME: **
+ ((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ftn-declr (scope (ptr-declr (pointer) (ident ,name))) (param-list . ,param-list)))))
+ (list name type 4)) ;; FIXME function / int
+ ((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
+ (list name type 4)) ;; FIXME: ptr/char
+ ((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer (pointer)) (ident ,name)))))
+ (list name type 4)) ;; FIXME: **
+ ((comp-decl (decl-spec-list (type-spec (void))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
+ (list name '(void) 4)) ;; FIXME: *
+ ((comp-decl (decl-spec-list (type-spec (void))) (comp-declr-list (comp-declr (ftn-declr (scope (ptr-declr (pointer) (ident ,name))) (param-list . ,param-list)))))
+ (list name '(void) 4))
+ ((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
+ (list name type 4))
+ ((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer) (array-of (ident ,name) (p-expr (fixed ,count)))))))
+ (let ((size 4)
+ (count (cstring->number count)))
+ (list name type (* count size) 0)))
+ ((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (array-of (ident ,name) (p-expr (fixed ,count))))))
+ (let ((size 4)
+ (count (cstring->number count)))
+ (list name type (* count size) 0)))
+ ((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (array-of (ident ,name) (p-expr (fixed ,count))))))
+ (let ((size 4)
+ (count (cstring->number count)))
+ (list name type (* count size) 0)))
+ ;; struct InlineFunc **inline_fns;
+ ((comp-decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (comp-declr-list (comp-declr (ptr-declr (pointer (pointer)) (ident ,name)))))
+ (list name type 4))
+ ((comp-decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
+ (list name type 4))
+
+ ((comp-decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (comp-declr-list (comp-declr (ident ,name))))
+ (let ((size (type->size info `("struct" ,type))))
+ (list name type size 0)))
+
+ (_ (error "struct-field: unsupported: " o)))
+ )
+ )
(define (ident->decl info o)
(or (assoc-ref (.locals info) o)
(clone info #:functions (cons (cons name #f) functions))))
(pmatch o
+ ;; FIXME: Nyacc sometimes produces extra parens: (ident (<struct-name>))
+ ((decl (decl-spec-list (stor-spec ,spec) (type-spec (struct-ref (ident (,type))))) ,init)
+ ((decl->info info) `(decl (decl-spec-list (stor-spec ,spec) (type-spec (struct-ref (ident ,type)))) ,init)))
+ ((decl (decl-spec-list (type-spec (struct-ref (ident (,type))))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)))))
+ ((decl->info info) `(decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)))))))
+
+ ((decl (decl-spec-list (type-spec (struct-def (ident (,type)) ,field-list))))
+ ((decl->info info) `(decl (decl-spec-list (type-spec (struct-def (ident ,type) ,field-list))))))
+
+
+
((decl (decl-spec-list (type-spec (typename ,type))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list . ,param-list)))))
(declare name))
((decl (decl-spec-list (stor-spec (extern)) (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)))))
info)
- ((decl (decl-spec-list (stor-spec (typedef)) (type-spec (struct-ref (ident (,type))))) (init-declr-list (init-declr (ident ,name))))
- (clone info #:types (cons (cons name (or (get-type types type) `(typedef ("struct" ,type)))) types)))
-
((decl (decl-spec-list (stor-spec (typedef)) (type-spec (struct-ref (ident ,type)))) (init-declr-list (init-declr (ident ,name))))
(clone info #:types (cons (cons name (or (get-type types type) `(typedef ("struct" ,type)))) types)))
(clone info #:types (cons (cons name (or (get-type types type) `(typedef ,type))) types)))
((decl (decl-spec-list (stor-spec (typedef)) (type-spec (struct-def ,field-list))) (init-declr-list (init-declr (ident ,name))))
- (let ((info ((ast->info info) `(decl (decl-spec-list (type-spec (struct-def (ident ,name) ,field-list))) (init-declr-list (init-declr (ident ,name)))))))
- (clone info #:types (cons (cons name (or (get-type types `("struct" ,name)) `(typedef ,name))) types))))
+ ((decl->info info) `(decl (decl-spec-list (stor-spec (typedef)) (type-spec (struct-def (ident ,name) ,field-list))) (init-declr-list (init-declr (ident ,name))))))
+
+ ((decl (decl-spec-list (stor-spec (typedef)) (type-spec (struct-def (ident ,type) ,field-list))) (init-declr-list (init-declr (ident ,name))))
+ (let* ((info ((decl->info info) `(decl (decl-spec-list (type-spec (struct-def (ident ,type) ,field-list))))))
+ (types (.types info)))
+ (clone info #:types (cons (cons name (or (get-type types `("struct" ,type)) `(typedef ,type))) types))))
+
((decl (decl-spec-list (stor-spec (typedef)) (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)))))
(let* ((type (get-type types type))
;; struct
((decl (decl-spec-list (type-spec (struct-def (ident ,name) (field-list . ,fields)))))
- (let ((type-entry (struct->type-entry name (map struct-field fields))))
+ (let ((type-entry (struct->type-entry name (map (struct-field info) fields))))
(clone info #:types (cons type-entry types))))
;; enum e i;
(clone info
#:constants (append constants (.constants info)))))
- ;; FIXME TCC/Nyacc madness here: extra parentheses around struct name?!?
- ;; struct (FOO) WTF?
- ((decl (decl-spec-list (type-spec (struct-def (ident (,name)) (field-list . ,fields)))))
- (let ((type-entry (struct->type-entry name (map struct-field fields))))
+ ((decl (decl-spec-list (type-spec (struct-def (ident ,name) (field-list . ,fields)))))
+ (let ((type-entry (struct->type-entry name (map (struct-field info) fields))))
(clone info #:types (cons type-entry types))))
- ((decl (decl-spec-list (type-spec (struct-def (ident (,type)) (field-list . ,fields))))
+ ((decl (decl-spec-list (type-spec (struct-def (ident ,type) (field-list . ,fields))))
(init-declr-list (init-declr (ident ,name))))
- (let ((info ((ast->info info) `(decl (decl-spec-list (type-spec (struct-def (ident ,type) (field-list . ,fields))))))))
- ((ast->info info)
- `(decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (init-declr-list (init-declr (ident ,name)))))))
+ (let ((info ((decl->info info) `(decl (decl-spec-list (type-spec (struct-def (ident ,type) (field-list . ,fields))))))))
+ ((decl->info info) `(decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (init-declr-list (init-declr (ident ,name)))))))
;; struct f = {...};
;; LOCALS!
(let loop ((inits `((init-declr (ident ,name) ,@initzer) ,@rest)) (info info))
(if (null? inits) info
(loop (cdr inits)
- ((ast->info info)
+ ((decl->info info)
`(decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list ,(car inits))))))))
-
((decl (decl-spec-list (stor-spec (typedef)) ,type) ,name)
(format (current-error-port) "SKIP: typedef=~s\n" o)
info)
(format (current-error-port) "SKIP: at=~s\n" o)
info)
- ((decl . _) (error "ast->info: unsupported: " o))))))
+ ((decl . _) (error "decl->info: unsupported: " o))))))
(define (ast->info info)
(lambda (o)
(define (type->info info o)
(pmatch o
((struct-def (ident ,name) (field-list . ,fields))
- (let ((type-entry (struct->type-entry name (map struct-field fields))))
+ (let ((type-entry (struct->type-entry name (map (struct-field info) fields))))
(clone info #:types (cons type-entry (.types info)))))
(_ info)))