From b35fab7529c8acdb9213fb891a8e70c2ff52fe60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Wed, 19 Jun 2013 07:02:25 +0200 Subject: [PATCH] Get unary - and unary + working with increment/decrement operators --- experimental/codegen.lisp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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) -- 1.7.10.4