3 ;;; simplify me, please
4 (defun concat (&rest strs)
5 (reduce (lambda (s1 s2) (concatenate 'string s1 s2))
11 (defvar *compilations* nil)
13 (defmacro define-compilation (name args &body body)
14 "creates a new primitive `name' with parameters args and @body. The
15 body can access to the local environment through the variable env"
16 `(push (list ',name (lambda (env ,@args) ,@body))
19 (define-compilation if (condition true false)
20 (format nil "((~a)? (~a) : (~a))"
21 (ls-compile condition env)
23 (ls-compile false env)))
25 (define-compilation lambda (args &rest body)
27 (format nil "~{V_~a~^, ~}" args)
29 (ls-compile-block body (extend-env args env))
33 (defun extend-env (args env)
34 (append (mapcar #'list args) env))
36 (defparameter *env* '())
37 (defparameter *env-fun* '())
40 (defun ls-compile (sexp &optional env)
42 ((symbolp sexp) (if (assoc sexp env)
43 (format nil "V_~a" sexp)
44 (error "Undefined variable `~a'" sexp)))
45 ((integerp sexp) (format nil " ~a " sexp))
46 ((stringp sexp) (format nil " \"~a\" " sexp))
49 (let ((compiler-func (second (assoc (car sexp) *compilations*))))
51 (apply compiler-func env (cdr sexp))
55 (defun ls-compile-block (sexps env)
57 "~{~#[~; return ~a;~:;~a;~%~]~}"