anchor.diff:  	      *register-list* ))
         (push  (make-register :name (symbol-name (car part)))
   	     *register-list*)))
  +
   (setf *register-list* (reverse *register-list*))
  -;;(format t "~%All registers loaded~%")
  +
  +;;TODO Can be rewritten using find
  +
  +(defun find-empty-t-register ()
  +  "find an empty register of type t"
  +  (dolist (reg *register-list*)
  +    (when (and (equal (register-type reg) '$t)
  +	       (register-free? reg))
  +      (return reg))))
  +
  +(defun temp-register-allot (constant)
  +  "Temporarily allot a t register"
  +  (let ((a  (find-empty-t-register)))
  +    (with-output-to-string (stream *text*)
  +      (format stream "li ~a , ~a ~%" a constant))
  +    (setf (register-value a) constant
  +	  (register-temp? a) t
  +	  (register-free? a) nil)
  +    a))
  +
  +
  +(defun var-register-allot (constant)
  +  "Allot a t register to a variable"
  +  (let ((a  (find-empty-t-register)))
  +    (with-output-to-string (stream *text*)
  +      (format stream "li ~a , ~a ~%" a constant))
  +    (setf (register-value a) constant
  +	  (register-temp? a) nil
  +	  (register-free? a) nil)
  +    a))
  +
  +;; TODO: Convert into a macro for freeing register
  +
  +(defun free-temp-register (params)
  +  "Takes a list of registers and frees those which are temporary"
  +  (dolist (param params)
  +    (when (and param (register-temp? param))
  +      (setf (register-free? param) t))))
  +
  +
  +(defun free-register-list (params)
  +  "Takes a list of registers and frees those which are temporary"
  +  (dolist (param params)
  +    (setf (register-free? param) t)))
  +
  +;;Environment has frames with variables in it
  +
  +(defparameter *env* '())
  +
  +(defun make-frame (var-val-list)
  +  "var-val list is ((var value) (var value)). Value defaults to 0"
  +  (let ((frame '()))
  +    (dolist (var-val var-val-list)
  +      (if (listp var-val)
  +	  (setf frame (acons (first var-val) (var-register-allot (second var-val))  frame))
  +	  (setf frame (acons (first var-val) (var-register-allot 0)  frame ))))
  +    (format t "Frame to be added ~a ~%" frame)
  +    frame))
  +
  +(defun add-frame (var-val-list)
  +  (format t "Adding frame with vars ~a ~%" var-val-list)
  +  (push (make-frame var-val-list) *env*))
  +
  +(defun pop-frame ()
  +  (let ((register-list '()))
  +    (dolist ( var (first *env*))
  +      (push (cdr var) register-list))
  +    (free-register-list register-list)))
  +
  +(defparameter *procedures* (make-hash-table))
  +
  +(defmacro defprocedure (func &body body)
  +  "make primitive procedures"
  +  `(setf (gethash ,func *procedures*) (lambda (params)
  +					(let ((output ( find-empty-t-register)))
  +					  (with-output-to-string (s *text*)
  +					    ,@body)
  +					  (free-temp-register params)
  +					  output)))
  +  )
  +
  +(defprocedure '+
  +  (format s "add ~{~a~^,  ~} ~%" (cons output params) ))
  +
  +(defprocedure '-
  +  (format s "sub ~{~a~^,  ~} ~%" (cons output params) ))
  +
  +(defprocedure '*
  +  (format s "mul ~{~a~^,  ~} ~%" (cons output params) ))
  +
  +(defprocedure '/
  +  (format s "div ~{~a~^,  ~} ~%"  params )
  +  (format s "mflo ~a~%" output))
  +
  +(defprocedure '%
  +  (format s "div ~{~a~^,  ~} ~%"  params )
  +  (format s "mfhi ~a~%") output)
  +
  +(defprocedure 'set
  +    (format s "move ~{~a~^, ~} ~%" params))
  +
  +(setf (gethash 'print-string *procedures*) (lambda (params)
  +				    (with-output-to-string (s *text*)
  +				      (format s "la $a0 , ~a~%" (first params) )
  +				      (format s "li $v0 , 4~%")
  +				      (format s "syscall~%")
  +				      )
  +				    ))
  +
  +
   
   (defun get-trap-code (function)
     "Returns the trap code for syscalls"
  
positive.code:   (format t "~(~a~)" *data*)
    (format t ".text~%.globl main~%main:~%")
    (format t "~(~a~)" *text*)
    
    (close stream))
  
  
  
  
negative.code: 	(return trap-code))
        )))
  
  
  
  (defun operator (expr)
  