Skip to content

Commit

Permalink
Revert "Allow returns and tagbody on dolist, dotimes, do-symbols and …
Browse files Browse the repository at this point in the history
…do-external-symbols (euslisp#241)"

This reverts commit b9f3b4b.
  • Loading branch information
Affonso-Gui committed Nov 20, 2022
1 parent 6244dee commit d2ae2ce
Showing 1 changed file with 54 additions and 76 deletions.
130 changes: 54 additions & 76 deletions lisp/l/common.l
Original file line number Diff line number Diff line change
Expand Up @@ -145,89 +145,67 @@
(unless (symbolp sym) (error type-error "symbol expected"))
`(send ',sym :constant ,val ,doc) )


(defmacro dotimes (vars &rest forms)
(let ((endvar (gensym "DOTIMES"))
(loop-tag (gensym "DOTIMES")))
`(block nil
(let ((,(car vars) 0)
(,endvar ,(cadr vars)))
(declare (integer ,(car vars) ,endvar))
(tagbody ,loop-tag
(if (> ,endvar ,(car vars))
(tagbody
,@forms
(setq ,(car vars) (1+ ,(car vars)))
(go ,loop-tag))))
,(caddr vars)))))
(let ((endvar (gensym "DOTIMES")))
`(let ((,(car vars) 0) (,endvar ,(cadr vars)))
(declare (integer ,(car vars) ,endvar))
(while (< ,(car vars) ,endvar)
,@forms
(setq ,(car vars) (1+ ,(car vars))))
,(caddr vars))))

(defmacro dolist (vars &rest forms)
(let ((lists (gensym "DOLIST"))
(loop-tag (gensym "DOLIST"))
(decl (car forms)))
(if (and (consp decl) (eq (car decl) 'declare))
(setq forms (cdr forms))
(setq decl nil))
`(block nil
(let ((,(car vars) nil)
(,lists ,(cadr vars)))
,decl
(tagbody ,loop-tag
(if (endp ,lists)
(setq ,(car vars) nil)
(progn
(setq ,(car vars) (pop ,lists))
(tagbody
,@forms
(go ,loop-tag)))))
,(caddr vars)))))
(let ((lists (gensym "DOLIST")) (decl (car forms)))
(if (and (consp decl) (eq (car decl) 'declare))
(setq forms (cdr forms))
(setq decl nil))
`(let ((,(car vars) nil) (,lists ,(cadr vars)))
,decl
(while ,lists
(setq ,(car vars) (pop ,lists))
,@forms)
,(caddr vars))))

(defmacro do-symbols (vars &rest forms)
(let* ((symbols (gensym "DOSYM"))
(v (car vars))
(pkg (if (cadr vars) (cadr vars) '*package*))
(pkgv (gensym))
(i (gensym))
(size (gensym))
(svec (gensym))
(loop-tag (gensym "DO-SYMBOLS")))
`(block nil
(let* ((,v nil)
(,pkgv (find-package ,pkg))
(,i 0)
(,svec (,pkgv . intsymvector))
(,size (length ,svec)))
(tagbody ,loop-tag
(if (< ,i ,size)
(tagbody
(setq ,v (elt ,svec ,i))
(inc ,i)
(when (symbolp ,v) . ,forms)
(go ,loop-tag))))
,(caddr vars)))))
(let* ((symbols (gensym "DOSYM"))
(v (car vars))
(pkg (if (cadr vars) (cadr vars) '*package*))
(pkgv (gensym))
(i (gensym))
(size (gensym))
(svec (gensym))
)
`(let* ((,v nil)
(,pkgv (find-package ,pkg))
(,i 0)
(,svec (,pkgv . intsymvector))
(,size (length ,svec)))
(while (< ,i ,size)
(setq ,v (elt ,svec ,i))
(inc ,i)
(when (symbolp ,v) . ,forms))
,(caddr vars))))

(defmacro do-external-symbols (vars &rest forms)
(let* ((symbols (gensym "DOEXTSYM"))
(v (car vars))
(pkg (if (cadr vars) (cadr vars) '*package*))
(pkgv (gensym))
(i (gensym))
(size (gensym))
(svec (gensym))
(loop-tag (gensym "DO-EXTERNAL-SYMBOLS")))
`(block nil
(let* ((,v nil)
(,pkgv (find-package ,pkg))
(,i 0)
(,svec (,pkgv . symvector))
(,size (length ,svec)))
(tagbody ,loop-tag
(if (< ,i ,size)
(tagbody
(setq ,v (elt ,svec ,i))
(inc ,i)
(when (symbolp ,v) . ,forms)
(go ,loop-tag))))
,(caddr vars)))))
(let* ((symbols (gensym "DOEXTSYM"))
(v (car vars))
(pkg (if (cadr vars) (cadr vars) '*package*))
(pkgv (gensym))
(i (gensym))
(size (gensym))
(svec (gensym))
)
`(let* ((,v nil)
(,pkgv (find-package ,pkg))
(,i 0)
(,svec (,pkgv . symvector))
(,size (length ,svec)))
(while (< ,i ,size)
(setq ,v (elt ,svec ,i))
(inc ,i)
(when (symbolp ,v) . ,forms))
,(caddr vars))))

(defmacro do-all-symbols (var &rest forms)
(let ((apackage (gensym "DOALLSYM")))
Expand Down

0 comments on commit d2ae2ce

Please sign in to comment.