diff options
author | BT Templeton <bpt@hcoop.net> | 2011-06-17 02:10:55 -0400 |
---|---|---|
committer | BT Templeton <bpt@hcoop.net> | 2012-02-03 18:53:48 -0500 |
commit | a338fa3d87a89d5ea16e585ddabe20a254e37b02 (patch) | |
tree | 0034eac89ac03daaf93a8b0f6262ce699e730220 | |
parent | 59e46065ce209c591eda15976de60e82eb7766a7 (diff) | |
download | guile-a338fa3d87a89d5ea16e585ddabe20a254e37b02.tar.gz |
remove unnecessary elisp macros
* module/language/elisp/runtime/macros.scm (when, unless, dotimes)
(dolist, pop, push): Remove. (They are not special forms in Emacs.)
* module/language/elisp/runtime/function-slot.scm: Update import and
export lists.
* test-suite/tests/elisp-compiler.test ("Conditionals")["failing when"]
["succeeding when", "failing unless", "succeeding unless"]: Remove.
("Iteration")["dotimes", "dolist"]: Remove.
("List Built-Ins")["pop", "push"]: Remove.
-rw-r--r-- | module/language/elisp/runtime/function-slot.scm | 16 | ||||
-rw-r--r-- | module/language/elisp/runtime/macros.scm | 64 | ||||
-rw-r--r-- | test-suite/tests/elisp-compiler.test | 43 |
3 files changed, 3 insertions, 120 deletions
diff --git a/module/language/elisp/runtime/function-slot.scm b/module/language/elisp/runtime/function-slot.scm index ed755892c..a3969c0e1 100644 --- a/module/language/elisp/runtime/function-slot.scm +++ b/module/language/elisp/runtime/function-slot.scm @@ -24,17 +24,11 @@ ((macro-lambda . lambda) (macro-prog1 . prog1) (macro-prog2 . prog2) - (macro-when . when) - (macro-unless . unless) (macro-cond . cond) (macro-and . and) (macro-or . or) - (macro-dotimes . dotimes) - (macro-dolist . dolist) (macro-catch . catch) - (macro-unwind-protect . unwind-protect) - (macro-pop . pop) - (macro-push . push))) + (macro-unwind-protect . unwind-protect))) #:use-module ((language elisp compile-tree-il) #:select ((compile-progn . progn) @@ -83,16 +77,10 @@ #:re-export (lambda prog1 prog2 - when - unless cond and or - dotimes - dolist catch - unwind-protect - pop - push) + unwind-protect) ;; functions #:re-export (apply)) diff --git a/module/language/elisp/runtime/macros.scm b/module/language/elisp/runtime/macros.scm index a62f721e7..5a8d186e6 100644 --- a/module/language/elisp/runtime/macros.scm +++ b/module/language/elisp/runtime/macros.scm @@ -45,16 +45,6 @@ (lambda (form1 form2 . rest) `(progn ,form1 (prog1 ,form2 ,@rest)))) -;;; Define the conditionals when and unless as macros. - -(built-in-macro when - (lambda (condition . thens) - `(if ,condition (progn ,@thens) nil))) - -(built-in-macro unless - (lambda (condition . elses) - `(if ,condition nil (progn ,@elses)))) - ;;; Impement the cond form as nested if's. A special case is a ;;; (condition) subform, in which case we need to return the condition ;;; itself if it is true and thus save it in a local variable before @@ -109,50 +99,6 @@ ,var ,(iterate (car tail) (cdr tail)))))))))) -;;; Define the dotimes and dolist iteration macros. - -(built-in-macro dotimes - (lambda (args . body) - (if (prim or - (not (list? args)) - (< (length args) 2) - (> (length args) 3)) - (macro-error "invalid dotimes arguments" args) - (let ((var (car args)) - (count (cadr args))) - (if (not (symbol? var)) - (macro-error "expected symbol as dotimes variable")) - `(let ((,var 0)) - (while ((guile-primitive <) ,var ,count) - ,@body - (setq ,var ((guile-primitive 1+) ,var))) - ,@(if (= (length args) 3) - (list (caddr args)) - '())))))) - -(built-in-macro dolist - (lambda (args . body) - (if (prim or - (not (list? args)) - (< (length args) 2) - (> (length args) 3)) - (macro-error "invalid dolist arguments" args) - (let ((var (car args)) - (iter-list (cadr args)) - (tailvar (gensym))) - (if (not (symbol? var)) - (macro-error "expected symbol as dolist variable") - `(let (,var) - (lexical-let ((,tailvar ,iter-list)) - (while ((guile-primitive not) - ((guile-primitive null?) ,tailvar)) - (setq ,var ((guile-primitive car) ,tailvar)) - ,@body - (setq ,tailvar ((guile-primitive cdr) ,tailvar))) - ,@(if (= (length args) 3) - (list (caddr args)) - '())))))))) - ;;; Exception handling. unwind-protect and catch are implemented as ;;; macros (throw is a built-in function). @@ -196,13 +142,3 @@ (lambda () ,body) (lambda () ,@clean-ups)))) -;;; Pop off the first element from a list or push one to it. - -(built-in-macro pop - (lambda (list-name) - `(prog1 (car ,list-name) - (setq ,list-name (cdr ,list-name))))) - -(built-in-macro push - (lambda (new-el list-name) - `(setq ,list-name (cons ,new-el ,list-name)))) diff --git a/test-suite/tests/elisp-compiler.test b/test-suite/tests/elisp-compiler.test index 973291244..2d8106175 100644 --- a/test-suite/tests/elisp-compiler.test +++ b/test-suite/tests/elisp-compiler.test @@ -77,18 +77,6 @@ 3) (equal (if nil 1) nil))) - (pass-if-equal "failing when" nil-value - (when nil 1 2 3)) - (pass-if-equal "succeeding when" 42 - (progn (setq a 0) - (when t (setq a 42) a))) - - (pass-if-equal "failing unless" nil-value - (unless t 1 2 3)) - (pass-if-equal "succeeding unless" 42 - (progn (setq a 0) - (unless nil (setq a 42) a))) - (pass-if-equal "empty cond" nil-value (cond)) (pass-if-equal "all failing cond" nil-value @@ -127,27 +115,7 @@ (while (<= i 5) (setq prod (* i prod)) (setq i (1+ i))) - prod)) - - (pass-if "dotimes" - (progn (setq a 0) - (setq count 100) - (setq b (dotimes (i count) - (setq j (1+ i)) - (setq a (+ a j)))) - (setq c (dotimes (i 10 42) nil)) - (and (= a 5050) (equal b nil) (= c 42)))) - - (pass-if "dolist" - (let ((mylist '(7 2 5))) - (setq sum 0) - (setq a (dolist (i mylist) - (setq sum (+ sum i)))) - (setq b (dolist (i mylist 5) 0)) - (and (= sum (+ 7 2 5)) - (equal a nil) - (equal mylist '(7 2 5)) - (equal b 5))))) + prod))) (with-test-prefix/compile "Exceptions" @@ -628,15 +596,6 @@ (and (equal (car-safe '(1 2)) 1) (equal (cdr-safe '(1 2)) '(2)) (equal (car-safe 5) nil) (equal (cdr-safe 5) nil))) - (pass-if "pop" - (progn (setq mylist '(a b c)) - (setq value (pop mylist)) - (and (equal value 'a) - (equal mylist '(b c))))) - (pass-if-equal "push" '(a b c) - (progn (setq mylist '(b c)) - (push 'a mylist))) - (pass-if "nth and nthcdr" (and (equal (nth -5 '(1 2 3)) 1) (equal (nth 3 '(1 2 3)) nil) (equal (nth 0 '(1 2 3)) 1) (equal (nth 2 '(1 2 3)) 3) |