summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/comp-cstr.el
diff options
context:
space:
mode:
authorAndrea Corallo <akrl@sdf.org>2020-12-29 13:29:02 +0100
committerAndrea Corallo <akrl@sdf.org>2020-12-29 17:49:30 +0100
commitc4efb49a27f05284d28eac7f60b28495c68f63fb (patch)
tree0d80e074e33c9cbfbbbdca07dbfe27da861f89bc /lisp/emacs-lisp/comp-cstr.el
parente83c6994e1f2553634e0877e86a8ebaa19fbc5d1 (diff)
downloademacs-c4efb49a27f05284d28eac7f60b28495c68f63fb.tar.gz
Constrain mvars under compare and branch with built-in predicates
* lisp/emacs-lisp/comp.el (comp-emit-assume): Update. (comp-known-predicate-p): New function. (comp-add-cond-cstrs): Extend to pattern match predicate calls. * lisp/emacs-lisp/comp-cstr.el (comp-cstr-null-p) (comp-pred-to-cstr): New function. * test/src/comp-tests.el (comp-tests-type-spec-tests): Add a number of tests and fix comments.
Diffstat (limited to 'lisp/emacs-lisp/comp-cstr.el')
-rw-r--r--lisp/emacs-lisp/comp-cstr.el11
1 files changed, 11 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/comp-cstr.el b/lisp/emacs-lisp/comp-cstr.el
index 8a8e22e030d..ce702422932 100644
--- a/lisp/emacs-lisp/comp-cstr.el
+++ b/lisp/emacs-lisp/comp-cstr.el
@@ -137,6 +137,13 @@ Integer values are handled in the `range' slot.")
(null (valset cstr))
(null (range cstr)))))
+(defsubst comp-cstr-null-p (x)
+ "Return t if CSTR is equivalent to the `null' type specifier, nil otherwise."
+ (with-comp-cstr-accessors
+ (and (null (typeset x))
+ (null (range x))
+ (equal (valset x) '(nil)))))
+
(defun comp-cstrs-homogeneous (cstrs)
"Check if constraints CSTRS are all homogeneously negated or non-negated.
Return `pos' if they are all positive, `neg' if they are all
@@ -167,6 +174,10 @@ Return them as multiple value."
:range '((1 . 1)))
"Represent the integer immediate one (1).")
+(defun comp-pred-to-cstr (predicate)
+ "Given PREDICATE return the correspondig constraint."
+ (comp-type-to-cstr (get predicate 'cl-satisfies-deftype)))
+
;;; Value handling.