Null
[jscl.git] / lispstrack.lisp
index 4aa57bc..9395aec 100644 (file)
@@ -6,6 +6,9 @@
        ((not ,condition))
      ,@body))
 
+(defvar *newline* "
+")
+
 ;;; simplify me, please
 (defun concat (&rest strs)
   (reduce (lambda (s1 s2) (concatenate 'string s1 s2))
              separator
              (join (cdr list) separator)))))
 
+(defun join-trailing (list separator)
+  (if (null list)
+      ""
+      (concat (car list) separator (join-trailing (cdr list) separator))))
+
 (defun integer-to-string (x)
   (if (zerop x)
       "0"
 (defvar *compilations* nil)
 
 (defun ls-compile-block (sexps env fenv)
-  (concat (join (mapcar (lambda (x)
-                          (concat (ls-compile x env fenv) ";"))
-                        sexps)
-                ";
-")))
+  (join-trailing (mapcar (lambda (x)
+                           (ls-compile x env fenv))
+                         sexps)
+                 ";
+"))
 
 (defun extend-env (args env)
   (append (mapcar #'make-var-binding args) env))
               (join (mapcar (lambda (x) (lookup-variable x new-env))
                             required-arguments)
                     ",")
-              "){
-"
+              "){"
+              *newline*
               (if rest-argument
                   (concat "var " (lookup-variable rest-argument new-env)
                           " = arguments.slice("
-                          (prin1-to-string (length required-arguments)) ");
-")
+                          (prin1-to-string (length required-arguments))
+                          ");"
+                          *newline*)
                   "")
-
               (concat (ls-compile-block (butlast body) new-env fenv)
                       "return " (ls-compile (car (last body)) new-env fenv) ";")
-              "
-})"))))
+              *newline*
+              "})"))))
 
 (define-compilation fsetq (var val)
   (concat (lookup-function var fenv)
     ((symbolp x)
      (lookup-function x fenv))))
 
+#+common-lisp
 (defmacro eval-when-compile (&body body)
   `(eval-when (:compile-toplevel :execute)
      ,@body))
       (backquote-expand-1 (cadr form))
       form))
 
+(defmacro backquote (form)
+  (backquote-expand-1 form))
+
 (define-transformation backquote (form)
   (backquote-expand-1 form))
 
 (define-compilation = (x y)
   (concat "((" (ls-compile x env fenv) ") == (" (ls-compile y env fenv) "))"))
 
+(define-compilation null (x)
+  (concat "(" (ls-compile x env fenv) "== undefined)"))
+
 (define-compilation cons (x y)
   (concat "{car: " (ls-compile x env fenv) ", cdr: " (ls-compile y env fenv) "}"))
 
 (define-compilation cdr (x)
   (concat "(" (ls-compile x env fenv) ").cdr"))
 
+
+
 (define-compilation symbol-name (x)
   (concat "(" (ls-compile x env fenv) ").name"))
 
   (setq *toplevel-compilations* nil)
   (let ((code (ls-compile sexp)))
     (prog1
-        (concat (join (mapcar (lambda (x)(concat x ";
-"))
+        (concat (join (mapcar (lambda (x) (concat x ";" *newline*))
                               *toplevel-compilations*)
                       "")
                 code)