+(define-compilation symbolp (x)
+ (compile-bool
+ (concat "(function(){ var tmp = "
+ (ls-compile x env fenv)
+ "; return (typeof tmp == 'object' && 'name' in tmp); })()")))
+
+(define-compilation make-symbol (name)
+ (concat "{name: " (ls-compile name env fenv) "}"))
+
+(define-compilation symbol-name (x)
+ (concat "(" (ls-compile x env fenv) ").name"))
+
+(define-compilation eq (x y)
+ (compile-bool
+ (concat "(" (ls-compile x env fenv) " === " (ls-compile y env fenv) ")")))
+
+(define-compilation equal (x y)
+ (compile-bool
+ (concat "(" (ls-compile x env fenv) " == " (ls-compile y env fenv) ")")))
+
+(define-compilation string (x)
+ (concat "String.fromCharCode(" (ls-compile x env fenv) ")"))
+
+(define-compilation stringp (x)
+ (compile-bool
+ (concat "(typeof(" (ls-compile x env fenv) ") == \"string\")")))
+
+(define-compilation string-upcase (x)
+ (concat "(" (ls-compile x env fenv) ").toUpperCase()"))
+
+(define-compilation string-length (x)
+ (concat "(" (ls-compile x env fenv) ").length"))
+
+(define-compilation char (string index)
+ (concat "("
+ (ls-compile string env fenv)
+ ").charCodeAt("
+ (ls-compile index env fenv)
+ ")"))
+
+(define-compilation concat-two (string1 string2)
+ (concat "("
+ (ls-compile string1 env fenv)
+ ").concat("
+ (ls-compile string2 env fenv)
+ ")"))
+
+(define-compilation funcall (func &rest args)
+ (concat "("
+ (ls-compile func env fenv)
+ ")("
+ (join (mapcar (lambda (x)
+ (ls-compile x env fenv))
+ args)
+ ", ")
+ ")"))
+
+(define-compilation apply (func &rest args)
+ (if (null args)
+ (concat "(" (ls-compile func env fenv) ")()")
+ (let ((args (butlast args))
+ (last (car (last args))))
+ (concat "(function(){" *newline*
+ "var f = " (ls-compile func env fenv) ";" *newline*
+ "var args = [" (join (mapcar (lambda (x)
+ (ls-compile x env fenv))
+ args)
+ ", ")
+ "];" *newline*
+ "var tail = (" (ls-compile last env fenv) ");" *newline*
+ "while (tail != " (ls-compile nil env fenv) "){" *newline*
+ " args.push(tail.car);" *newline*
+ " tail = tail.cdr;" *newline*
+ "}" *newline*
+ "return f.apply(this, args);" *newline*
+ "})()" *newline*))))
+
+(define-compilation js-eval (string)
+ (concat "eval.apply(window, [" (ls-compile string env fenv) "])"))
+
+(define-compilation error (string)
+ (concat "(function (){ throw " (ls-compile string env fenv) ";" "return 0;})()"))
+
+(define-compilation new ()
+ "{}")
+
+(define-compilation get (object key)
+ (concat "(function(){ var tmp = "
+ "(" (ls-compile object env fenv) ")[" (ls-compile key env fenv) "]"
+ ";"
+ "return tmp == undefined? " (ls-compile nil nil nil) ": tmp ;"
+ "})()"))
+
+(define-compilation set (object key value)
+ (concat "(("
+ (ls-compile object env fenv)
+ ")["
+ (ls-compile key env fenv) "]"
+ " = " (ls-compile value env fenv) ")"))
+
+(define-compilation in (key object)
+ (compile-bool
+ (concat "(" (ls-compile key env fenv) " in " (ls-compile object env fenv) ")")))
+
+
+(defun macrop (x)
+ (and (symbolp x) (eq (binding-type (lookup-function x *fenv*)) 'macro)))
+
+(defun ls-macroexpand-1 (form env fenv)
+ (if (macrop (car form))
+ (let ((binding (lookup-function (car form) *env*)))
+ (if (eq (binding-type binding) 'macro)
+ (apply (eval (binding-translation binding)) (cdr form))
+ form))
+ form))