mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-21 04:00:19 +02:00
elisp `while' macro
* module/language/elisp/compile-tree-il.scm (compile-while): Remove. * module/language/elisp/boot.el (while): New macro. * module/language/elisp/runtime/function-slot.scm: Update module definition.
This commit is contained in:
parent
1c2f9636dc
commit
9b90b45398
3 changed files with 8 additions and 50 deletions
|
@ -90,6 +90,14 @@
|
||||||
,temp
|
,temp
|
||||||
(or ,@(cdr conditions))))))))
|
(or ,@(cdr conditions))))))))
|
||||||
|
|
||||||
|
(defmacro while (test &rest body)
|
||||||
|
(let ((loop (make-symbol "loop")))
|
||||||
|
`(labels ((,loop ()
|
||||||
|
(if ,test
|
||||||
|
(progn ,@body (,loop))
|
||||||
|
nil)))
|
||||||
|
(,loop))))
|
||||||
|
|
||||||
(defmacro catch (tag &rest body)
|
(defmacro catch (tag &rest body)
|
||||||
(let* ((temp (make-symbol "catch-temp"))
|
(let* ((temp (make-symbol "catch-temp"))
|
||||||
(elisp-key (make-symbol "catch-elisp-key"))
|
(elisp-key (make-symbol "catch-elisp-key"))
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
compile-lexical-let*
|
compile-lexical-let*
|
||||||
compile-guile-ref
|
compile-guile-ref
|
||||||
compile-guile-primitive
|
compile-guile-primitive
|
||||||
compile-while
|
|
||||||
compile-function
|
compile-function
|
||||||
compile-defmacro
|
compile-defmacro
|
||||||
compile-defun
|
compile-defun
|
||||||
|
@ -692,53 +691,6 @@
|
||||||
((,sym)
|
((,sym)
|
||||||
(make-primitive-ref loc sym))))
|
(make-primitive-ref loc sym))))
|
||||||
|
|
||||||
;;; A while construct is transformed into a tail-recursive loop like
|
|
||||||
;;; this:
|
|
||||||
;;;
|
|
||||||
;;; (letrec ((iterate (lambda ()
|
|
||||||
;;; (if condition
|
|
||||||
;;; (begin body
|
|
||||||
;;; (iterate))
|
|
||||||
;;; #nil))))
|
|
||||||
;;; (iterate))
|
|
||||||
;;;
|
|
||||||
;;; As letrec is not directly accessible from elisp, while is
|
|
||||||
;;; implemented here instead of with a macro.
|
|
||||||
|
|
||||||
(defspecial while (loc args)
|
|
||||||
(pmatch args
|
|
||||||
((,condition . ,body)
|
|
||||||
(let* ((itersym (gensym))
|
|
||||||
(compiled-body (map compile-expr body))
|
|
||||||
(iter-call (make-application loc
|
|
||||||
(make-lexical-ref loc
|
|
||||||
'iterate
|
|
||||||
itersym)
|
|
||||||
(list)))
|
|
||||||
(full-body (make-sequence loc
|
|
||||||
`(,@compiled-body ,iter-call)))
|
|
||||||
(lambda-body (make-conditional loc
|
|
||||||
(compile-expr condition)
|
|
||||||
full-body
|
|
||||||
(nil-value loc)))
|
|
||||||
(iter-thunk (make-lambda loc
|
|
||||||
'()
|
|
||||||
(make-lambda-case #f
|
|
||||||
'()
|
|
||||||
#f
|
|
||||||
#f
|
|
||||||
#f
|
|
||||||
'()
|
|
||||||
'()
|
|
||||||
lambda-body
|
|
||||||
#f))))
|
|
||||||
(make-letrec loc
|
|
||||||
#f
|
|
||||||
'(iterate)
|
|
||||||
(list itersym)
|
|
||||||
(list iter-thunk)
|
|
||||||
iter-call)))))
|
|
||||||
|
|
||||||
(defspecial function (loc args)
|
(defspecial function (loc args)
|
||||||
(pmatch args
|
(pmatch args
|
||||||
(((lambda ,args . ,body))
|
(((lambda ,args . ,body))
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
(compile-lexical-let* . lexical-let*)
|
(compile-lexical-let* . lexical-let*)
|
||||||
(compile-guile-ref . guile-ref)
|
(compile-guile-ref . guile-ref)
|
||||||
(compile-guile-primitive . guile-primitive)
|
(compile-guile-primitive . guile-primitive)
|
||||||
(compile-while . while)
|
|
||||||
(compile-function . function)
|
(compile-function . function)
|
||||||
(compile-defun . defun)
|
(compile-defun . defun)
|
||||||
(compile-defmacro . defmacro)
|
(compile-defmacro . defmacro)
|
||||||
|
@ -58,7 +57,6 @@
|
||||||
lexical-let*
|
lexical-let*
|
||||||
guile-ref
|
guile-ref
|
||||||
guile-primitive
|
guile-primitive
|
||||||
while
|
|
||||||
function
|
function
|
||||||
defun
|
defun
|
||||||
defmacro
|
defmacro
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue