add record, a struct that names itself
(record point ...) emits the struct and a typedef of the same name, so point stands alone wherever (struct point) had to -- in a var, a pointer, an arglist, a sizeof. struct, union and enum keep C's meaning, for a type that came from a header or is laid out to match one.
This commit is contained in:
22
semen.scm
22
semen.scm
@@ -82,6 +82,8 @@
|
||||
((or ('fn . _)
|
||||
('pub 'fn . _)
|
||||
('extern 'fn . _)) (process-fn sex-form acc))
|
||||
((or ('record . _)
|
||||
('pub 'record . _)) (process-record sex-form acc))
|
||||
((or ('struct . _)
|
||||
('pub 'struct . _)) (process-struct sex-form acc))
|
||||
((or ('union . _)
|
||||
@@ -1120,6 +1122,26 @@
|
||||
(register-aggregate! form)
|
||||
(with-docstring doc form acc))))
|
||||
|
||||
;;; (record point ((x int) (y int))) is a struct that also names
|
||||
;;; itself, so `point' alone stands where `(struct point)' had to:
|
||||
;;; (var p point ...), (* const point), (sizeof point).
|
||||
;;;
|
||||
;;; struct, union and enum keep C's meaning, for a type that comes from
|
||||
;;; a header or is laid out to match one.
|
||||
(define (process-record form acc)
|
||||
(let* ((core (if (eq? (car form) 'pub) (cdr form) form))
|
||||
(name (and (pair? (cdr core)) (cadr core))))
|
||||
(unless (symbol? name)
|
||||
(sex-error form "record needs a name" form))
|
||||
(add-typedef name `(typedef ,name (struct ,name)))
|
||||
(cons (copy-form-source! form `(typedef (struct ,name) ,name))
|
||||
(process-struct
|
||||
(copy-form-source! form
|
||||
(if (eq? (car form) 'pub)
|
||||
`(pub struct ,@(cdr core))
|
||||
`(struct ,@(cdr core))))
|
||||
acc))))
|
||||
|
||||
(define (register-aggregate! form)
|
||||
(let* ((f (if (eq? (car form) 'pub) (cdr form) form))
|
||||
(name (and (pair? (cdr f)) (symbol? (cadr f)) (cadr f))))
|
||||
|
||||
Reference in New Issue
Block a user