home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / lisp / liszt / cmacros.l < prev    next >
Encoding:
Text File  |  1987-12-15  |  5.7 KB  |  227 lines

  1. ;----------- macros for the compiler -------------
  2.  
  3. (setq RCS-cmacros
  4.    "$Header: cmacros.l,v 1.14 87/12/15 16:55:07 sklower Exp $")
  5.  
  6. (declare (macros t))            ; compile and save macros
  7.  
  8. ; If we are making an interpreted version, then const.l hasn't been
  9. ; loaded yet...
  10. (eval-when (compile eval)
  11.    (or (get 'const 'loaded) (load '../const.l)))
  12.  
  13. ;--- comp-err
  14. ;    comp-warn
  15. ;    comp-note
  16. ;    comp-gerr
  17. ; these are the compiler message producing macros.  The form is
  18. ; (comp-xxxx val1 val2 val3 ... valn) , all values are printed according
  19. ;  to this scheme. If vali is an atom, it is patomed, if vali is a
  20. ;  list, it is evaluated and printed. If vali is N a newline is printed
  21. ; furthermore
  22. ;    the name of the current function is printed first
  23. ;    after comp-err prints the message, it does a throw to Comp-err .
  24. ;    errors are preceeded by Error: 
  25. ;    warnings by %Warning: and
  26. ;    notes by %Note:
  27. ;     The message is sent to the message file
  28. ;
  29. (def comp-err
  30.    (macro (l)
  31.       `(progn (comp-msg "?Error: " v-ifile ": " g-fname ": "
  32.                 ,@(cdr l) )
  33.           (setq er-fatal (1+ er-fatal))
  34.           (throw nil Comp-error))))
  35.  
  36. (def comp-warn
  37.    (macro (l)
  38.       `(progn (setq er-warn (1+ er-warn))
  39.           (cond (fl-warn
  40.                 (comp-msg "%Warning: " v-ifile ": "  g-fname ": "
  41.                       ,@(cdr l)))))))
  42.  
  43. (def comp-note
  44.    (macro (l)
  45.       `(progn (cond (fl-verb
  46.                 (comp-msg "%Note: " v-ifile ": "  ,@(cdr l)))))))
  47.  
  48. (def comp-gerr
  49.    (macro (l)
  50.       `(progn (comp-msg
  51.               "?Error: " v-ifile ": " g-fname ": ",@(cdr l))
  52.           (setq er-fatal (1+ er-fatal)))))
  53.  
  54. ;--- comp-msg - port
  55. ;          - lst
  56. ;  prints the lst to the given port.  The lst is printed in the manner
  57. ; described above, that is atoms are patomed, and lists are evaluated
  58. ; and printed, and N prints a newline.   The output is always drained.
  59. ;
  60. (def comp-msg
  61.    (macro (lis)
  62.       (do ((xx (cdr lis) (cdr xx))
  63.            (res nil))
  64.           ((null xx)
  65.            `(progn ,@(nreverse (cons '(terpri) res))))
  66.           (setq res
  67.             (cons (cond ((atom (car xx))
  68.                  (cond ((eq (car xx) 'N) '(terpr))
  69.                        ((stringp (car xx)) `(patom ,(car xx)))
  70.                        (t `(niceprint ,(car xx)))))
  71.                 (t `(niceprint ,(car xx))))
  72.               res)))))
  73.  
  74. (def niceprint
  75.    (macro (l)
  76.       `((lambda (float-format) (patom ,(cadr l))) "%.2f")))
  77.  
  78. ;--- standard push macro
  79. ; (Push stackname valuetoadd)
  80.  
  81. (defmacro Push (atm val)
  82.   `(setq ,atm (cons ,val ,atm)))
  83.  
  84. ;--- unpush macro - like pop except top value is thrown away
  85. (defmacro unpush (atm)
  86.   `(setq ,atm (cdr ,atm)))
  87.  
  88. ;--- and an increment macro
  89. (defmacro incr (atm)
  90.   `(setq ,atm (1+ ,atm)))
  91.  
  92. (defmacro decr (atm)
  93.   `(setq ,atm (1- ,atm)))
  94.  
  95. ;--- add a comment
  96. (defmacro makecomment (arg)
  97.   `(cond (fl-comments (setq g-comments (cons ,arg g-comments)))))
  98.  
  99. ;--- add a comment irregardless of the fl-comments flag
  100. (defmacro forcecomment (arg)
  101.   `(setq g-comments (cons ,arg g-comments)))
  102.  
  103. ;--- write to the .s file
  104. (defmacro sfilewrite (arg)
  105.   `(patom ,arg vp-sfile))
  106.  
  107. (defmacro sfilewriteln (arg)
  108.   `(msg (P vp-sfile) ,arg N))
  109.  
  110. ;--- Liszt-file  :: keep track of rcs info regarding part of Liszt
  111. ;  This is put at the beginning of a file which makes up the lisp compiler.
  112. ; The form used is   (Liszt-file name rcs-string)
  113. ; where name is the name of this file (without the .l) and rcs-string.
  114. ;
  115. (defmacro Liszt-file (name rcs-string)
  116.    `(cond ((not (boundp 'Liszt-file-names))
  117.        (setq Liszt-file-names (ncons ,rcs-string)))
  118.       (t (setq Liszt-file-names
  119.            (append1 Liszt-file-names ,rcs-string)))))
  120.  
  121. (eval-when (compile eval load)
  122.    (defun immed-const (x)
  123.       (get_pname (concat #+(or for-vax for-tahoe) "$" #+for-68k "#" x))))
  124.  
  125. ; Indicate that this file has been loaded, before
  126. (putprop 'cmacros t 'version)
  127.  
  128. ;-------- Instruction Macros
  129.  
  130. #+(or for-vax for-tahoe)
  131. (defmacro e-add (src dst)
  132.    `(e-write3 'addl2 ,src ,dst))
  133.  
  134. #+(or for-vax for-tahoe)
  135. (defmacro e-sub (src dst)
  136.    `(e-write3 'subl2 ,src ,dst))
  137.  
  138. #+(or for-vax for-tahoe)
  139. (defmacro e-cmp (src dst)
  140.    `(e-write3 'cmpl ,src ,dst))
  141.  
  142. (defmacro e-tst (src)
  143.    `(e-write2 'tstl ,src))
  144.  
  145. #+for-vax
  146. (defmacro e-quick-call (what)
  147.    `(e-write2 "jsb" ,what))
  148.  
  149. #+for-tahoe
  150. (defmacro e-quick-call (what)
  151.    `(e-write3 "calls" "$4" ,what))
  152.  
  153. #+for-68k
  154. (defmacro e-quick-call (what)
  155.   `(e-write2 "jsbr" ,what))
  156.  
  157.  
  158. ;--- e-add3 :: add from two sources and store in the dest
  159. ;--- e-sub3 :: subtract from two sources and store in the dest
  160.  
  161. ; WARNING:  if the destination is an autoincrement addressing mode, then
  162. ;    this will not work for the 68000, because multiple instructions
  163. ;    are generated:
  164. ;        (e-add3 a b "sp@+")
  165. ;    is
  166. ;        movl b,sp@+
  167. ;        addl a,sp@+    (or addql)
  168. #+(or for-vax for-tahoe)
  169. (defmacro e-add3 (s1 s2 dest)
  170.    `(e-write4 'addl3 ,s1 ,s2 ,dest))
  171.  
  172. #+for-68k
  173. (defmacro e-add3 (s1 s2 dest)
  174.    `(progn
  175.        (e-write3 'movl ,s2 ,dest)
  176.        (e-add ,s1 ,dest)))
  177.  
  178. #+(or for-vax for-tahoe)
  179. (defmacro e-sub3 (s1 s2 dest)
  180.    `(e-write4 'subl3 ,s1 ,s2 ,dest))
  181.  
  182. #+for-68k
  183. (defmacro e-sub3 (s1 s2 dest)
  184.    `(progn
  185.        (e-write3 'movl ,s2 ,dest)
  186.        (e-sub ,s1 ,dest)))
  187.  
  188. (defmacro d-cmp (arg1 arg2)
  189.   `(e-cmp (e-cvt ,arg1) (e-cvt ,arg2)))
  190.  
  191. (defmacro d-tst (arg)
  192.   `(e-tst (e-cvt ,arg)))
  193.  
  194. ;--- d-cmpnil :: compare an IADR to nil
  195. ;
  196. (defmacro d-cmpnil (iadr)
  197.    #+(or for-vax for-tahoe) `(d-tst ,iadr)
  198.    #+for-68k `(d-cmp 'Nil ,iadr))
  199.  
  200. (defmacro e-cmpnil (eiadr)
  201.    #+(or for-vax for-tahoe) `(break 'e-cmpnil)
  202.    #+for-68k `(e-cmp (e-cvt 'Nil) ,eiadr))
  203.  
  204. (defmacro e-call-qnewint ()
  205.    `(e-quick-call '_qnewint))
  206.  
  207. (defmacro C-push (src)
  208.    #+for-68k `(e-move ,src '#.Cstack)
  209.    #+(or for-vax for-tahoe) `(e-write2 'pushl ,src))
  210.  
  211. (defmacro L-push (src)
  212.    `(e-move ,src '#.np-plus))
  213.  
  214. (defmacro C-pop (dst)
  215.    `(e-move '#.unCstack ,dst))
  216.  
  217. #+(or for-vax for-68k)
  218. (defmacro L-pop (dst)
  219.    `(e-move '#.np-minus ,dst))
  220.  
  221. #+for-tahoe
  222. (defmacro L-pop (dst)
  223.    `(progn (e-sub '($ 4) '#.np-reg)
  224.        (e-move '(0 #.np-reg) ,dst)))
  225.  
  226.