From: David Vázquez Date: Fri, 5 Jul 2013 01:27:50 +0000 (+0200) Subject: Non-nested switch cases in codegen X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=fa3b84125e3a277ad77ca8bf70352582036fb2a8;p=jscl.git Non-nested switch cases in codegen --- diff --git a/src/compiler-codegen.lisp b/src/compiler-codegen.lisp index 480a856..83cb4b9 100644 --- a/src/compiler-codegen.lisp +++ b/src/compiler-codegen.lisp @@ -429,16 +429,18 @@ (js-expr value) (js-format "){") (dolist (case cases) - (destructuring-bind (x &body body) case - (if (eq x 'default) - (js-format "default: ") - (progn - (unless (or (stringp x) (numberp x)) - (error "Non-constant switch case `~S'." (car cases))) - (js-format "case ") - (js-expr x) - (js-format ":"))) - (mapc #'js-stmt body))) + (cond + ((and (consp case) (eq (car case) 'case)) + (js-format "case ") + (let ((value (cadr case))) + (unless (or (stringp value) (integerp value)) + (error "Non-constant switch case `~S'." value)) + (js-expr value)) + (js-format ":")) + ((eq case 'default) + (js-format "default:")) + (t + (js-stmt case)))) (js-format "}"))) (for (destructuring-bind ((start condition step) &body body) (cdr form) diff --git a/src/compiler.lisp b/src/compiler.lisp index fd7e1e0..bfa9abb 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -280,13 +280,14 @@ ,@(with-collect (dotimes (idx n-optional-arguments) (let ((arg (nth idx optional-arguments))) - (collect `(,(+ idx n-required-arguments) - (= ,(make-symbol (translate-variable (car arg))) - ,(ls-compile (cadr arg))) - ,(when (third arg) - `(= ,(make-symbol (translate-variable (third arg))) - ,(ls-compile nil))))))) - (collect `(default (break)))))))) + (collect `(case ,(+ idx n-required-arguments))) + (collect `(= ,(make-symbol (translate-variable (car arg))) + ,(ls-compile (cadr arg)))) + (collect (when (third arg) + `(= ,(make-symbol (translate-variable (third arg))) + ,(ls-compile nil)))))) + (collect 'default) + (collect '(break))))))) (defun compile-lambda-rest (ll) (let ((n-required-arguments (length (ll-required-arguments ll)))