Remove some calls to CODE
[jscl.git] / src / compiler-codegen.lisp
index 51027fd..e82b841 100644 (file)
      (js-format "~a" (js-escape-string form)))
     ((symbolp form)
      (case form
-       (true  (js-format "true"))
-       (false (js-format "false"))
-       (null  (js-format "null"))
-       (this  (js-format "this"))
+       (true      (js-format "true"))
+       (false     (js-format "false"))
+       (null      (js-format "null"))
+       (this      (js-format "this"))
+       (undefined (js-format "undefined"))
        (otherwise
         (js-identifier form))))
     (t
   (unless (or (symbolp x)
               (nth-value 1 (valid-js-identifier x))
               (and (consp x)
-                   (member (car x) '(get =))))
+                   (member (car x) '(get = property))))
     (error "Bad Javascript lvalue ~S" x)))
 
 ;;; Process the Javascript AST to reduce some syntax sugar.
        (js-expr (car args))
        (js-format "(")
        (when (cdr args)
-         (with-operator (13 'left)
+         (with-operator (12 'left)
            (js-expr (cadr args))
            (dolist (operand (cddr args))
              (let ((*js-output* t))
                (js-expr operand)))))
        (js-format ")"))
       ;; Accessors
+      (property
+       (js-expr (car args))
+       (js-format "[")
+       (js-expr (cadr args))
+       (js-format "]"))
       (get
        (multiple-value-bind (identifier identifierp)
            (valid-js-identifier (car args))
                  (js-expr condition)
                  (js-format ")")
                  (js-stmt `(progn ,@body))))
+           (for
+            (destructuring-bind ((start condition step) &body body) (cdr form)
+              (js-format "for (")
+              (js-expr start)
+              (js-format ";")
+              (js-expr condition)
+              (js-format ";")
+              (js-expr step)
+              (js-format ")")
+              (js-stmt `(progn ,@body))))
+           (for-in
+            (destructuring-bind ((x object) &body body) (cdr form)
+              (js-format "for (")
+              (js-identifier x)
+              (js-format " in ")
+              (js-expr object)
+              (js-format ")")
+              (js-stmt `(progn ,@body))))
+           (try
+            (destructuring-bind (&rest body) (cdr form)
+              (js-format "try")
+              (js-stmt `(group ,@body))))
+           (catch
+               (destructuring-bind ((var) &rest body) (cdr form)
+                 (js-format "catch (")
+                 (js-identifier var)
+                 (js-format ")")
+                 (js-stmt `(group ,@body))))
+           (finally
+            (destructuring-bind (&rest body) (cdr form)
+              (js-format "finally")
+              (js-stmt `(group ,@body))))
            (throw
                (destructuring-bind (object) (cdr form)
                  (js-format "throw ")