From: David Vázquez Date: Wed, 19 Jun 2013 05:02:25 +0000 (+0200) Subject: Get unary - and unary + working with increment/decrement operators X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=b35fab7529c8acdb9213fb891a8e70c2ff52fe60;p=jscl.git Get unary - and unary + working with increment/decrement operators --- diff --git a/experimental/codegen.lisp b/experimental/codegen.lisp index adf5de7..f1b2972 100644 --- a/experimental/codegen.lisp +++ b/experimental/codegen.lisp @@ -97,7 +97,9 @@ (defun js-primary-expr (form) (cond ((numberp form) - (js-format "~a" form)) + (if (<= 0 form) + (js-format "~a" form) + (js-expr `(- ,(abs form))))) ((stringp form) (js-format "~a" (js-escape-string form))) ((symbolp form) @@ -276,8 +278,11 @@ (unary-op post-- "--" 1 right :lvalue t :post t) (unary-op not "!" 1 right) (unary-op bit-not "~" 1 right) - (unary-op unary+ "+" 1 right) - (unary-op unary- "-" 1 right) + ;; Note that the leading space is necessary because it + ;; could break with post++, for example. TODO: Avoid + ;; leading space when it's possible. + (unary-op unary+ " +" 1 right) + (unary-op unary- " -" 1 right) (unary-op delete "delete " 1 right) (unary-op void "void " 1 right) (unary-op typeof "typeof " 1 right)