From fbb8a269e0af1f0ea29cee2b0bc910c91595ddc0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Sun, 30 Jun 2013 17:23:42 +0200 Subject: [PATCH] SWITCH support --- src/compiler-codegen.lisp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/compiler-codegen.lisp b/src/compiler-codegen.lisp index 4552430..2c9e1e8 100644 --- a/src/compiler-codegen.lisp +++ b/src/compiler-codegen.lisp @@ -373,9 +373,11 @@ (js-format ":") (js-stmt `(progn ,@body)))) (break - (destructuring-bind (label) (cdr form) - (js-format "break ") - (js-identifier label) + (destructuring-bind (&optional label) (cdr form) + (js-format "break") + (when label + (js-format " ") + (js-identifier label)) (js-format ";"))) (return (destructuring-bind (value) (cdr form) @@ -419,6 +421,23 @@ (js-expr condition) (js-format ")") (js-stmt `(progn ,@body)))) + (switch + (destructuring-bind (value &rest cases) (cdr form) + (js-format "switch(") + (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))) + (js-format "}"))) (for (destructuring-bind ((start condition step) &body body) (cdr form) (js-format "for (") -- 1.7.10.4