anchor.diff:    )
   
   (defun list-of-values (operands)
  +  "Evaluates the operands recursively"
     (if (not operands)
         '()
         (cons
          (evaluate (first operands))
          (list-of-values (rest operands)))))
   
  -					;(format t "Given arguments are ~&~S~&" *args*)
  +
  +;;Contains the .text of SPIM
   (defparameter *text* (make-array 0 
   				   :element-type 'character 
   				   :adjustable t 
   				   :fill-pointer 0))
  +
  +;;Contains the .data of SPIM
   (defparameter *data* (make-array 0 
   				   :element-type 'character 
   				   :adjustable t 
   				   :fill-pointer 0))
   
   
  +
   ;;Parser
  -;;parses into a list, PERFECT!
  +;;parses into a lists
   (defun get-file (filename)
     (with-open-file (stream filename)
       (read stream)))
   
  -
  -
  -;;Parser
  -;;parses into a list, PERFECT!
  -(defun get-file (filename)
  -  (with-open-file (stream filename)
  -    (read stream)))
  -
  -
  +;;Checks if both arguments are present
   (unless (= 2 (length *args*))
     (error "Incorrect arguments given. Should be of form: %prog input-file output-file"))
  +
   (defparameter *code* (get-file (first *args*)))
  +
  +;;Drools the mucus
   (format t "~a" *code*)
   
   
  
positive.code: 	(return trap-code))
        )))
  
  ;;Environment has frames with variables in it
  ;; Let allows lexical scoping which will be helpful in environements
  ;;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))
  
  
  ;;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)))
  
  (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))
  
  
  (defun operator (expr)
  
negative.code: 	      *register-list* ))
        (push  (make-register :name (symbol-name (car part)))
  	     *register-list*)))
  
  (setf *register-list* (reverse *register-list*))
  
  ;;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"
  