declare a record's typedef ahead of its struct
It came after, so a record pointing at itself, (next (* node)), named a type C had not been told of yet.
This commit is contained in:
14
semen.scm
14
semen.scm
@@ -1895,13 +1895,19 @@
|
|||||||
(unless (symbol? name)
|
(unless (symbol? name)
|
||||||
(sex-error form "record needs a name" form))
|
(sex-error form "record needs a name" form))
|
||||||
(add-typedef name `(typedef ,name (struct ,name)))
|
(add-typedef name `(typedef ,name (struct ,name)))
|
||||||
(cons (copy-form-source! form `(typedef (struct ,name) ,name))
|
;; the typedef first, so a field may point back at the record, and
|
||||||
(process-struct
|
;; the docstring ahead of both
|
||||||
|
(let-values (((doc struct)
|
||||||
|
(extract-aggregate-docstring
|
||||||
(copy-form-source! form
|
(copy-form-source! form
|
||||||
(if (eq? (car form) 'pub)
|
(if (eq? (car form) 'pub)
|
||||||
`(pub struct ,@(cdr core))
|
`(pub struct ,@(cdr core))
|
||||||
`(struct ,@(cdr core))))
|
`(struct ,@(cdr core)))))))
|
||||||
acc))))
|
(process-struct
|
||||||
|
struct
|
||||||
|
(with-docstring doc
|
||||||
|
(copy-form-source! form `(typedef (struct ,name) ,name))
|
||||||
|
acc)))))
|
||||||
|
|
||||||
(define (register-aggregate! form)
|
(define (register-aggregate! form)
|
||||||
(let* ((f (if (eq? (car form) 'pub) (cdr form) form))
|
(let* ((f (if (eq? (car form) 'pub) (cdr form) form))
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
(input)
|
(input)
|
||||||
(output "p 3 4 / n 7 zoe / area 12 / sizes 8 8")
|
(output "p 3 4 / n 7 zoe / area 12 / sizes 8 8"
|
||||||
|
"chain 1 2")
|
||||||
(return 0)
|
(return 0)
|
||||||
|
|
||||||
;;; A record is a struct that also names itself, so the bare name
|
;;; A record is a struct that also names itself, so the bare name
|
||||||
@@ -18,6 +19,10 @@
|
|||||||
|
|
||||||
(struct raw ((a int) (b int)))
|
(struct raw ((a int) (b int)))
|
||||||
|
|
||||||
|
;;; A record naming itself in its own fields: the name is a type before
|
||||||
|
;;; the fields are
|
||||||
|
(record node ((value int) (next (* node))))
|
||||||
|
|
||||||
(fn shift ((p (* point)) (dx int) (dy int)) void
|
(fn shift ((p (* point)) (dx int) (dy int)) void
|
||||||
(+= (. p x) dx)
|
(+= (. p x) dx)
|
||||||
(+= (. p y) dy))
|
(+= (. p y) dy))
|
||||||
@@ -43,4 +48,8 @@
|
|||||||
(. p x) (. p y) (. n id) (. n first-name)
|
(. p x) (. p y) (. n id) (. n first-name)
|
||||||
(area [ps 0])
|
(area [ps 0])
|
||||||
(sizeof point) (sizeof (struct raw)))
|
(sizeof point) (sizeof (struct raw)))
|
||||||
|
|
||||||
|
(var tail node #(node : 2 NULL))
|
||||||
|
(var head node #(node : 1 (& tail)))
|
||||||
|
(printf "chain %d %d\n" (. head value) (. head next value))
|
||||||
(return (+ (. [ps 1] x) (- (. r a) 1))))
|
(return (+ (. [ps 1] x) (- (. r a) 1))))
|
||||||
|
|||||||
Reference in New Issue
Block a user