Get unary - and unary + working with increment/decrement operators
authorDavid Vázquez <davazp@gmail.com>
Wed, 19 Jun 2013 05:02:25 +0000 (07:02 +0200)
committerDavid Vázquez <davazp@gmail.com>
Wed, 19 Jun 2013 05:02:25 +0000 (07:02 +0200)
experimental/codegen.lisp

index adf5de7..f1b2972 100644 (file)
@@ -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)
            (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)