declare an ops method ahead through the one prototype accessor
fn-prototype repeated sex-fn-prototype, and names? repeated mentions?; each pair kept the better half.
This commit is contained in:
47
semen.scm
47
semen.scm
@@ -428,11 +428,9 @@
|
||||
(bodies (map (lambda (m)
|
||||
(if (comment-form? m) (list m) (process-fn m (list))))
|
||||
methods))
|
||||
(early (filter (lambda (m)
|
||||
(called-before? (sex-fn-name m) m methods bodies))
|
||||
fns)))
|
||||
(early (filter (lambda (m) (called-before? m methods bodies)) fns)))
|
||||
(append (append-map identity (reverse bodies))
|
||||
(fold (lambda (m acc) (process-fn (fn-prototype m) acc)) acc early)))))
|
||||
(fold (lambda (m acc) (process-fn (sex-fn-prototype m) acc)) acc early)))))
|
||||
|
||||
;;; The method's fn form, renamed to vec2/length, once it is registered
|
||||
;;; under `length'; a comment is passed along
|
||||
@@ -446,28 +444,23 @@
|
||||
(let ((name (second core)))
|
||||
(when (get-method type name)
|
||||
(sex-error form "method is already defined on" type name))
|
||||
(let ((qualified (qualify-op type name)))
|
||||
(let* ((qualified (qualify-op type name))
|
||||
(renamed (rename-fn form qualified)))
|
||||
(add-method! type name qualified)
|
||||
;; its signature too, which a call's receiver is fitted to
|
||||
(process-fn (fn-prototype (rename-fn form qualified)) (list))
|
||||
(rename-fn form qualified))))))
|
||||
(process-fn (sex-fn-prototype renamed) (list))
|
||||
renamed)))))
|
||||
|
||||
;;; Does a body written above METHOD call it?
|
||||
(define (called-before? name method methods bodies)
|
||||
(let loop ((ms methods) (bs bodies))
|
||||
(and (not (eq? (car ms) method))
|
||||
(or (names? (car bs) name)
|
||||
(loop (cdr ms) (cdr bs))))))
|
||||
|
||||
;;; NAME anywhere in FORM, a literal's contents included
|
||||
(define (names? form name)
|
||||
(cond ((eq? form name) #t)
|
||||
((pair? form) (or (names? (car form) name) (names? (cdr form) name)))
|
||||
((vector? form) (names? (vector->list form) name))
|
||||
(else #f)))
|
||||
(define (called-before? method methods bodies)
|
||||
(let ((name (sex-fn-name method)))
|
||||
(let loop ((ms methods) (bs bodies))
|
||||
(and (not (eq? (car ms) method))
|
||||
(or (mentions? (car bs) name)
|
||||
(loop (cdr ms) (cdr bs)))))))
|
||||
|
||||
;;; (pub fn name args ret ...) -> (pub fn name args ret)
|
||||
(define (fn-prototype form)
|
||||
(define (sex-fn-prototype form)
|
||||
(let ((header (strip-fn-header-comments form)))
|
||||
(copy-form-source! form (take header (fn-header-length header)))))
|
||||
|
||||
@@ -888,9 +881,11 @@
|
||||
|
||||
(define (wildcard-type? type) (mentions? type '_))
|
||||
|
||||
(define (mentions? type word)
|
||||
(cond ((eq? type word) #t)
|
||||
((list? type) (any (lambda (part) (mentions? part word)) type))
|
||||
;;; WORD anywhere in FORM, a literal's contents included
|
||||
(define (mentions? form word)
|
||||
(cond ((eq? form word) #t)
|
||||
((pair? form) (or (mentions? (car form) word) (mentions? (cdr form) word)))
|
||||
((vector? form) (mentions? (vector->list form) word))
|
||||
(else #f)))
|
||||
|
||||
;;; `(each xs compare)' where `each' takes a closure: the argument is
|
||||
@@ -1996,12 +1991,6 @@ Returns #f if the form is not a function, returns the form otherwise"
|
||||
(fmt #f "Form " fn-form " is not a function"))
|
||||
(fourth (fn-core fn-form)))
|
||||
|
||||
(define (sex-fn-prototype fn-form)
|
||||
"Returns all except body"
|
||||
(assert (sex-fn? fn-form)
|
||||
(fmt #f "Form " fn-form " is not a function"))
|
||||
(take fn-form (fn-header-length fn-form)))
|
||||
|
||||
(define (sex-fn-body fn-form)
|
||||
(assert (sex-fn? fn-form)
|
||||
(fmt #f "Form " fn-form " is not a function"))
|
||||
|
||||
Reference in New Issue
Block a user