-
-
-(defmacro with-eval-when-compilation (&body body)
- `(setq *eval-when-compilations*
- (concat *eval-when-compilations* (progn ,@body))))
-
-(defun %compile-defvar (name)
- (push (make-var-binding name) *env*)
- (with-eval-when-compilation
- (format nil "var ~a" (lookup-variable name *env*))))
-
-(defun %compile-defun (name)
- (push (make-func-binding name) *fenv*)
- (with-eval-when-compilation
- (format nil "var ~a" (lookup-variable name *fenv*))))
-
-(defun %compile-defmacro (name lambda)
- (push (cons name (cons 'macro lambda)) *fenv*))
+(define-compilation equal (x y)
+ (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 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 error (string)
+ (concat "(function (){ throw " (ls-compile string env fenv) ";" "return 0;})()"))
+
+(define-compilation new ()
+ "{}")
+
+(define-compilation get (object key)
+ (concat "(" (ls-compile object env fenv) ")[" (ls-compile key env fenv) "]"))
+
+(define-compilation set (object key value)
+ (concat "(("
+ (ls-compile object env fenv)
+ ")["
+ (ls-compile key env fenv) "]"
+ " = " (ls-compile value env fenv) ")"))
+
+(defun macrop (x)
+ (and (symbolp x) (eq (binding-type (lookup-function x *fenv*)) 'macro)))