X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=lispstrack.lisp;h=d531561a08b090e54d0f725cdaceeec62b4fbc87;hb=2bcc11276620557ab635a9698bd9b230a60e2e61;hp=cc3d183628a3a87791c2cf06e8601a49054d140c;hpb=ecdc7afa83611b0effe71862c8269d7a487d05bd;p=jscl.git diff --git a/lispstrack.lisp b/lispstrack.lisp index cc3d183..d531561 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -34,15 +34,14 @@ (defun ls-compile-sexps (sexps env) (concat (join (mapcar (lambda (x) - (ls-compile x env)) + (concat (ls-compile x env) ";")) sexps) "; "))) (defun ls-compile-block (sexps env) - (concat (ls-compile-sexps (butlast sexps env) env) - "; -return " (ls-compile (car (last sexps)) env) ";")) + (concat (ls-compile-sexps (butlast sexps) env) + "return " (ls-compile (car (last sexps)) env) ";")) (defun extend-env (args env) @@ -55,8 +54,9 @@ return " (ls-compile (car (last sexps)) env) ";")) (error "Undefined variable `~a'" symbol)))) (defmacro define-compilation (name args &body body) - "creates a new primitive `name' with parameters args and @body. The -body can access to the local environment through the variable env" + ;; Creates a new primitive `name' with parameters args and + ;; @body. The body can access to the local environment through the + ;; variable ENV. `(push (list ',name (lambda (env ,@args) ,@body)) *compilations*)) @@ -93,18 +93,19 @@ body can access to the local environment through the variable env" (define-compilation debug (form) (format nil "console.log(~a)" (ls-compile form env))) -(defun compile-test () - (with-open-file (in "test.lisp") - (with-open-file (out "test.js" :direction :output :if-exists :supersede) - (loop - for x = (read in nil) while x - do (write-string (ls-compile x) out))))) - (define-compilation while (pred &rest body) (format nil "(function(){while(~a){~a}})() " (ls-compile pred env) (ls-compile-sexps body env))) +(defmacro eval-when-compile (&body body) + `(eval-when (:compile-toplevel :execute) + ,@body)) + +(define-compilation eval-when-compile (when &rest body) + (eval body)) + +;;; aritmetic primitives (define-compilation + (x y) (concat "((" (ls-compile x env) ") + (" (ls-compile y env) "))")) @@ -117,6 +118,9 @@ body can access to the local environment through the variable env" (define-compilation / (x y) (concat "((" (ls-compile x env) ") / (" (ls-compile y env) "))")) +(define-compilation = (x y) + (concat "((" (ls-compile x env) ") == (" (ls-compile y env) "))")) + (defparameter *env* '()) (defparameter *env-fun* '()) @@ -133,3 +137,13 @@ body can access to the local environment through the variable env" (funcall (ls-compile (car sexp) env) ) ;; funcall ))))) + + +;;; Testing + +(defun compile-test () + (with-open-file (in "test.lisp") + (with-open-file (out "test.js" :direction :output :if-exists :supersede) + (loop + for x = (read in nil) while x + do (write-string (concat (ls-compile x) "; ") out)))))