Skip to content

Commit

Permalink
Add comp::dump-method and fix class reference when compiling parent m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
Affonso-Gui committed Dec 25, 2022
1 parent 95cc304 commit 1e322a5
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions lisp/comp/comp.l
Original file line number Diff line number Diff line change
Expand Up @@ -2044,14 +2044,34 @@
(eval-when (load eval)

(defun dump-function (file &rest names)
(with-open-file (f file :direction :output)
(let (acc)
(with-open-file (f file :direction :output)
(dolist (funmac names)
(let ((def (symbol-function funmac)) dump)
(setq dump
(case (car def)
(lambda `(defun ,funmac . ,(cdr def)))
(macro `(defmacro ,funmac . ,(cdr def)))))
(pprint dump f) ))) )
(when (consp def)
(setq dump
(case (car def)
(lambda `(defun ,funmac . ,(cdr def)))
(macro `(defmacro ,funmac . ,(cdr def)))
(t (error value-error "unknown function type: ~A" (car def)))))
(pprint dump f)
(push funmac acc)))))
(nreverse acc)))

(defun dump-method (file obj &rest methods)
(let (acc)
(with-open-file (f file :direction :output)
(dolist (meth methods)
(let ((def (if (classp obj)
(let ((body (assoc meth (send obj :methods))))
(if body (list obj body)))
(find-method obj meth))))
(when def
(multiple-value-bind (cls body) def
(when (and (consp body) (not (compiled-function-p (second body))))
(pprint `(defmethod ,(send cls :name) ,body) f)
(push meth acc)))))))
(nreverse acc)))

(defun comfile (&rest files) (dolist (f files) (send comp :compile-file f)))
(defun compile-file (file &rest keys)
Expand All @@ -2077,32 +2097,20 @@
pname))

(defun compile (&rest funcs)
(let ((fname (format nil "eus~d~A.l" (unix:getpid)
(symbol-name (gensym "C")))))
(setq funcs (remove-if #'compiled-function-p funcs :key #'symbol-function))
(apply #'dump-function fname funcs)
(let* ((fname (format nil "eus~d~A.l" (unix:getpid)
(symbol-name (gensym "C"))))
(res (apply #'dump-function fname funcs)))
(when res
(compile-tmp fname)
funcs))
res)))

(defun compile-method (obj &rest meths)
(let ((fname (format nil "eus~d~A.l" (unix:getpid)
(symbol-name (gensym "C"))))
(kls (if (classp obj) obj (class obj)))
body)
(labels ((get-method (meth)
(if (classp obj)
(assoc meth (send obj :methods))
(cadr (find-method obj meth))))
(to-compile (def)
(and (consp def) (not (compiled-function-p (second def))))))

(setq body (mapcar #'get-method meths))
(setq body (remove-if-not #'to-compile body))
(when body
(with-open-file (f fname :direction :output)
(format f "~S~%" `(defmethod ,(send kls :name) ,@body)))
(compile-tmp fname)
(mapcar #'car body)))))
(let* ((fname (format nil "eus~d~A.l" (unix:getpid)
(symbol-name (gensym "C"))))
(res (apply #'dump-method fname obj meths)))
(when res
(compile-tmp fname)
res)))

(defun compile-file-if-src-newer (srcfile &optional (objdir "./")
&rest args)
Expand Down

0 comments on commit 1e322a5

Please sign in to comment.