X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=lispstrack.lisp;h=98f7bc0f5f217b6793a2ded92fb6fe08d7170fe2;hb=a6c50c8a33d0e918ca2b495328592832c88205cc;hp=b67749166d74f6ceb14c319f37ab6353578c2b3d;hpb=709f6ae9830e6bd5a4ac84da06083178af6bc7a3;p=jscl.git diff --git a/lispstrack.lisp b/lispstrack.lisp index b677491..98f7bc0 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -178,6 +178,9 @@ (string-length seq) (list-length seq))) + (defun concat-two (s1 s2) + (concat-two s1 s2)) + (defun mapcar (func list) (if (null list) '() @@ -249,6 +252,9 @@ (defun <= (x y) (or (< x y) (= x y))) (defun >= (x y) (not (< x y))) + (defun plusp (x) (< 0 x)) + (defun minusp (x) (< x 0)) + (defun listp (x) (or (consp x) (null x))) @@ -373,9 +379,7 @@ (defvar *newline* (string (code-char 10))) (defun concat (&rest strs) - (!reduce (lambda (s1 s2) (concat-two s1 s2)) - strs - "")) + (!reduce #'concat-two strs "")) ;;; Concatenate a list of strings, with a separator (defun join (list separator) @@ -405,6 +409,18 @@ digits) "")))) +(defun print-to-string (form) + (cond + ((symbolp form) (symbol-name form)) + ((integerp form) (integer-to-string form)) + ((stringp form) (concat "\"" (escape-string form) "\"")) + ((functionp form) (concat "#")) + ((listp form) + (concat "(" + (join (mapcar #'print-to-string form) + " ") + ")")))) + ;;;; Reader ;;; The Lisp reader, parse strings and return Lisp objects. The main @@ -630,11 +646,13 @@ (defun ls-compile-block (sexps env fenv) (join-trailing - (remove nil (mapcar (lambda (x) - (ls-compile x env fenv)) - sexps)) - "; -")) + (remove (lambda (x) + (or (null x) + (and (stringp x) + (zerop (length x))))) + (mapcar (lambda (x) (ls-compile x env fenv)) sexps)) + (concat ";" *newline*))) + (defmacro define-compilation (name args &rest body) ;; Creates a new primitive `name' with parameters args and ;; @body. The body can access to the local environment through the @@ -1019,8 +1037,7 @@ (setq *toplevel-compilations* nil) (let ((code (ls-compile sexp nil nil))) (prog1 - (concat #+common-lisp (concat "/* " (princ-to-string sexp) " */") - (join (mapcar (lambda (x) (concat x ";" *newline*)) + (concat (join (mapcar (lambda (x) (concat x ";" *newline*)) *toplevel-compilations*) "") code) @@ -1031,18 +1048,6 @@ ;;; interactive development (eval), which works calling the compiler ;;; and evaluating the Javascript result globally. -(defun print-to-string (form) - (cond - ((symbolp form) (symbol-name form)) - ((integerp form) (integer-to-string form)) - ((stringp form) (concat "\"" (escape-string form) "\"")) - ((functionp form) (concat "#")) - ((listp form) - (concat "(" - (join (mapcar #'print-to-string form) - " ") - ")")))) - #+lispstrack (progn (defmacro with-compilation-unit (&rest body)