forked from alex-eg/sex
let a realization's methods call one another
Each was registered as its body was walked, so a method could not call one coming after it -- a default included, defaults coming after the written ones. All are registered first now, as an ops block's are.
This commit is contained in:
33
semen.scm
33
semen.scm
@@ -340,11 +340,21 @@
|
||||
(let ((wanted (spec-methods spec))
|
||||
(parameter (spec-parameter spec)))
|
||||
(check-realization form name type parameter wanted given)
|
||||
(fold (lambda (entry acc)
|
||||
(process-realized-method form name type
|
||||
(and pub? (cdr entry)) (car entry) acc))
|
||||
acc
|
||||
(realization-methods type parameter wanted given))))))
|
||||
;; every method is registered before any body is walked, so they
|
||||
;; may call one another in any order, as an ops block's may; one
|
||||
;; called above its definition is declared ahead of them all
|
||||
(let* ((methods (map (lambda (entry)
|
||||
(register-realized-method form name type
|
||||
(and pub? (cdr entry))
|
||||
(car entry)))
|
||||
(realization-methods type parameter wanted given)))
|
||||
(bodies (map (lambda (m) (process-fn m (list))) methods))
|
||||
(early (filter (lambda (m) (called-before? m methods bodies))
|
||||
methods)))
|
||||
(append (append-map identity (reverse bodies))
|
||||
(fold (lambda (m acc) (process-fn (sex-fn-prototype m) acc))
|
||||
acc
|
||||
early)))))))
|
||||
|
||||
;;; What is written here, which a pub realization exports, and then
|
||||
;;; every default nobody overrode, which it does not: a default is
|
||||
@@ -396,16 +406,19 @@
|
||||
|
||||
;;; A realization is public or private as a unit -- its methods do
|
||||
;;; not carry `pub' of their own, the way an ops block's do, because
|
||||
;;; the spec already says which of them there are.
|
||||
(define (process-realized-method form spec type pub? method acc)
|
||||
;;; the spec already says which of them there are. The method's fn
|
||||
;;; form, renamed to pointːsizedːtotal, once it is registered under
|
||||
;;; `total' and its signature known.
|
||||
(define (register-realized-method form spec type pub? method)
|
||||
(let* ((name (second method))
|
||||
(qualified (qualify-op (qualify-op type spec) name))
|
||||
(renamed (rename-fn method qualified)))
|
||||
(renamed (copy-form-source! form (rename-fn method qualified)))
|
||||
(fn (if pub? (copy-form-source! form (cons 'pub renamed)) renamed)))
|
||||
(when (get-method type name)
|
||||
(sex-error form "method is already defined on" type name))
|
||||
(add-method! type name qualified)
|
||||
(process-fn (copy-form-source! form (if pub? (cons 'pub renamed) renamed))
|
||||
acc)))
|
||||
(process-fn (sex-fn-prototype fn) (list))
|
||||
fn))
|
||||
|
||||
;;; T in a spec's method stands for whatever realizes it
|
||||
(define (substitute-parameter parameter type form)
|
||||
|
||||
Reference in New Issue
Block a user