cmp: small changes to c1form-*-p

c1form-movable-p uses c1form-pure-p

  The predicate opencoded the exact body of the latter.

c1form-unmodified-p does not explicitly check for global-var-p

  The function VAR-CHANGED-IN-FORM-LIST takes care of special and global
  variables, so there is no need for an explicit check. When the variable is
  global and no form has sp-change, then it is still unmodified.
This commit is contained in:
Daniel Kochmański 2023-12-14 11:00:20 +01:00
parent 63ca129a79
commit 3ae6fadac7

View file

@ -60,22 +60,22 @@
(defun c1form-add-info-loop (form dependents)
(loop with subform
while (consp dependents)
when (c1form-p (setf subform (pop dependents)))
do (progn
(when (c1form-sp-change subform)
(setf (c1form-sp-change form) t
(c1form-side-effects form) t))
(when (c1form-side-effects subform)
(setf (c1form-side-effects form) t))
(unless (eq (c1form-name subform) 'LOCATION)
(when (rest (c1form-parents subform))
(error "Running twice through same form"))
(setf (c1form-parents subform)
(nconc (c1form-parents subform)
(c1form-parents form)))))
when (consp subform)
do (c1form-add-info-loop form subform)))
while (consp dependents)
when (c1form-p (setf subform (pop dependents)))
do (progn
(when (c1form-sp-change subform)
(setf (c1form-sp-change form) t
(c1form-side-effects form) t))
(when (c1form-side-effects subform)
(setf (c1form-side-effects form) t))
(unless (eq (c1form-name subform) 'LOCATION)
(when (rest (c1form-parents subform))
(error "Running twice through same form"))
(setf (c1form-parents subform)
(nconc (c1form-parents subform)
(c1form-parents form)))))
when (consp subform)
do (c1form-add-info-loop form subform)))
(defun c1form-add-info (form dependents)
(let ((record (gethash (c1form-name form) +c1-form-hash+)))
@ -137,6 +137,9 @@
do (traverse-c1form-tree f function))
(funcall function tree))))
(defun c1form-pure-p (form)
(third (gethash (c1form-name form) +c1-form-hash+)))
(defun c1form-movable-p (form)
(flet ((abort-on-not-pure (form)
(let ((name (c1form-name form)))
@ -146,20 +149,16 @@
(var-set-nodes var))
(return-from c1form-movable-p nil))))
((or (c1form-side-effects form)
(not (third (gethash name +c1-form-hash+))))
(not (c1form-pure-p form)))
(return-from c1form-movable-p nil))))))
(abort-on-not-pure form)))
(defun c1form-pure-p (form)
(third (gethash (c1form-name form) +c1-form-hash+)))
(defun c1form-unmodified-p (form rest-form)
(flet ((abort-on-not-pure (form)
(let ((name (c1form-name form)))
(cond ((eq name 'VARIABLE)
(let ((var (c1form-arg 0 form)))
(when (or (global-var-p var)
(var-changed-in-form-list var rest-form))
(when (var-changed-in-form-list var rest-form)
(return-from c1form-unmodified-p nil))))
((or (c1form-side-effects form)
(not (c1form-pure-p form)))