bugfixes #66

Merged
pkulev merged 43 commits from bugfixes into main 2026-10-19 21:14:40 +02:00
Showing only changes of commit 049d97b5e1 - Show all commits

View File

@@ -428,11 +428,9 @@
(bodies (map (lambda (m) (bodies (map (lambda (m)
(if (comment-form? m) (list m) (process-fn m (list)))) (if (comment-form? m) (list m) (process-fn m (list))))
methods)) methods))
(early (filter (lambda (m) (early (filter (lambda (m) (called-before? m methods bodies)) fns)))
(called-before? (sex-fn-name m) m methods bodies))
fns)))
(append (append-map identity (reverse bodies)) (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 ;;; The method's fn form, renamed to vec2/length, once it is registered
;;; under `length'; a comment is passed along ;;; under `length'; a comment is passed along
@@ -446,28 +444,23 @@
(let ((name (second core))) (let ((name (second core)))
(when (get-method type name) (when (get-method type name)
(sex-error form "method is already defined on" 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) (add-method! type name qualified)
;; its signature too, which a call's receiver is fitted to ;; its signature too, which a call's receiver is fitted to
(process-fn (fn-prototype (rename-fn form qualified)) (list)) (process-fn (sex-fn-prototype renamed) (list))
(rename-fn form qualified)))))) renamed)))))
;;; Does a body written above METHOD call it? ;;; Does a body written above METHOD call it?
(define (called-before? name method methods bodies) (define (called-before? method methods bodies)
(let loop ((ms methods) (bs bodies)) (let ((name (sex-fn-name method)))
(and (not (eq? (car ms) method)) (let loop ((ms methods) (bs bodies))
(or (names? (car bs) name) (and (not (eq? (car ms) method))
(loop (cdr ms) (cdr bs)))))) (or (mentions? (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)))
;;; (pub fn name args ret ...) -> (pub fn name args ret) ;;; (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))) (let ((header (strip-fn-header-comments form)))
(copy-form-source! form (take header (fn-header-length header))))) (copy-form-source! form (take header (fn-header-length header)))))
@@ -888,9 +881,11 @@
(define (wildcard-type? type) (mentions? type '_)) (define (wildcard-type? type) (mentions? type '_))
(define (mentions? type word) ;;; WORD anywhere in FORM, a literal's contents included
(cond ((eq? type word) #t) (define (mentions? form word)
((list? type) (any (lambda (part) (mentions? part word)) type)) (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))) (else #f)))
;;; `(each xs compare)' where `each' takes a closure: the argument is ;;; `(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")) (fmt #f "Form " fn-form " is not a function"))
(fourth (fn-core fn-form))) (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) (define (sex-fn-body fn-form)
(assert (sex-fn? fn-form) (assert (sex-fn? fn-form)
(fmt #f "Form " fn-form " is not a function")) (fmt #f "Form " fn-form " is not a function"))