[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint d2b7194 19/23: Evaluate `dolist' and `while'
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint d2b7194 19/23: Evaluate `dolist' and `while' |
Date: |
Sun, 29 Sep 2019 15:34:54 -0400 (EDT) |
branch: externals/relint
commit d2b71948b8fd3736c4892a249f34455eac0d86be
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Evaluate `dolist' and `while'
`dolist' is special-cased for speed right now, but could also be
expanded and handled by `while' if implemented. `while' is capped at
100 iterations to guarantee reasonable progress.
---
relint.el | 30 ++++++++++++++++++++++++++++++
test/7.elisp | 21 +++++++++++++++++++++
test/7.expected | 6 ++++++
3 files changed, 57 insertions(+)
diff --git a/relint.el b/relint.el
index 1e89278..90fc73b 100644
--- a/relint.el
+++ b/relint.el
@@ -769,6 +769,36 @@ not be evaluated safely."
(relint--eval `(let* ,(cdr bindings) ,@(cdr body))))
(relint--eval-body (cdr body)))))
+ ;; dolist: simulate its operation. We could also expand it,
+ ;; but this is somewhat faster.
+ ((eq head 'dolist)
+ (unless (and (>= (length body) 2)
+ (consp (car body)))
+ (throw 'relint-eval 'no-value))
+ (let ((var (nth 0 (car body)))
+ (seq-arg (nth 1 (car body)))
+ (res-arg (nth 2 (car body))))
+ (unless (symbolp var)
+ (throw 'relint-eval 'no-value))
+ (let ((seq (relint--eval-list seq-arg)))
+ (while (consp seq)
+ (let ((relint--locals (cons (list var (car seq))
+ relint--locals)))
+ (relint--eval-body (cdr body)))
+ (setq seq (cdr seq))))
+ (and res-arg (relint--eval res-arg))))
+
+ ;; while: this slows down simulation noticeably, but catches some
+ ;; mistakes.
+ ((eq head 'while)
+ (let ((condition (car body))
+ (loops 0))
+ (while (and (relint--eval condition)
+ (< loops 100))
+ (relint--eval-body (cdr body))
+ (setq loops (1+ loops)))
+ nil))
+
;; Loose comma: can occur if we unwittingly stumbled into a backquote
;; form. Just eval the arg and hope for the best.
((eq head '\,)
diff --git a/test/7.elisp b/test/7.elisp
new file mode 100644
index 0000000..b0ed01c
--- /dev/null
+++ b/test/7.elisp
@@ -0,0 +1,21 @@
+;;; Relint test file 7 -*- emacs-lisp -*-
+
+(defun my-dolist-fun (seq)
+ (let ((s ""))
+ (dolist (c seq)
+ (setq s (concat s (char-to-string c))))
+ s))
+
+(defun test-dolist ()
+ (looking-at (my-dolist-fun '(?a ?b ?^))))
+
+(defun my-while-fun ()
+ (let ((s "")
+ (c ?!))
+ (while (< c ?&)
+ (setq s (concat s (char-to-string c)))
+ (setq c (1+ c)))
+ s))
+
+(defun test-while ()
+ (looking-at (my-while-fun)))
diff --git a/test/7.expected b/test/7.expected
new file mode 100644
index 0000000..5275a63
--- /dev/null
+++ b/test/7.expected
@@ -0,0 +1,6 @@
+7.elisp:10:15: In call to looking-at: Unescaped literal `^' (pos 2)
+ "ab^"
+ ..^
+7.elisp:21:15: In call to looking-at: Unescaped literal `$' (pos 3)
+ "!\"#$%"
+ ....^
- [elpa] externals/relint updated (0bf6883 -> b0f0bee), Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 099b59f 01/23: Reorder strings in regexp for more efficient matching, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 1ec2d8b 02/23: More elaborate parsing of doc strings of global variables, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 95b3c07 08/23: Add `xor' and bitwise operations to the list of safe functions, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 3f3408d 07/23: Check both car and cdr of items in -regexp-alist variables, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 5142c86 09/23: Fix function evaluation bug, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 43c4644 06/23: Correct naming, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint e11b871 12/23: More robust scanning of format strings for mixup check, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 956a15b 17/23: Fix defun parsing, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 3a27cff 18/23: Handle mutation of local variables in evaluation, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint d2b7194 19/23: Evaluate `dolist' and `while',
Mattias Engdegård <=
- [elpa] externals/relint b2a86b8 04/23: Fix typo in message description and clarify, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 1cb021a 03/23: Remove relint--eval-error, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 5137ec6 11/23: Evaluate keywords correctly, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 6a07508 10/23: Handle rx `eval' form correctly, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 3a7e82a 05/23: Track some mutation of local variables in phase 2, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint bc1b5a8 16/23: Add word-search-regexp to the list of regexp generating functions, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint b890b5a 15/23: Track mutation in push and lambda in phase 2, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 02c5dd2 13/23: Prepare for easier testability, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 60d5627 21/23: Lazy evaluation of global variables, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint b0f0bee 23/23: Increment version to 1.11, Mattias Engdegård, 2019/09/29