X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=lispstrack.lisp;h=d463be5c900c59d64c03930e8cd352cc1e61a2a1;hb=467386b7ff2f1da406760f72d4bb9b3de4cd56cb;hp=1419eb95f7c5e9a9bbc16785deb34986ebd5c5c2;hpb=d439d330be4452ee5e9b3863e342c3ae42ee30d7;p=jscl.git diff --git a/lispstrack.lisp b/lispstrack.lisp index 1419eb9..d463be5 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -11,6 +11,8 @@ (defvar *compilations* nil) (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" `(push (list ',name (lambda (env ,@args) ,@body)) *compilations*)) @@ -24,16 +26,22 @@ (concat "(function (" (format nil "~{V_~a~^, ~}" args) "){ " - (ls-compile-block body env) + (ls-compile-block body (extend-env args env)) "}) ")) +(defun extend-env (args env) + (append (mapcar #'list args) env)) + (defparameter *env* '()) (defparameter *env-fun* '()) + (defun ls-compile (sexp &optional env) (cond - ((symbolp sexp) (format nil "V_~a" sexp)) + ((symbolp sexp) (if (assoc sexp env) + (format nil "V_~a" sexp) + (error "Undefined variable `~a'" sexp))) ((integerp sexp) (format nil " ~a " sexp)) ((stringp sexp) (format nil " \"~a\" " sexp)) ; list