home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 January / enter-2004-01.iso / files / maxima-5.9.0.exe / {app} / share / maxima / 5.9.0 / src / defopt.lisp < prev    next >
Encoding:
Text File  |  2003-02-09  |  3.1 KB  |  104 lines

  1. ;;; -*-  Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
  2. ;;;     (c) Copyright 1980 Massachusetts Institute of Technology         ;;;
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4.  
  5. (in-package "MAXIMA")
  6. (macsyma-module defopt macro)
  7.  
  8. ;; For defining optimizers which run on various systems.
  9. ;; Q: What is an optimizer?
  10. ;; A: A transformation which takes place in the compiler.
  11.  
  12. ;; ***==> Right now, DEFOPT is used just like you would a DEFMACRO <==***
  13. ;; (defopt <name> <arlist> <body-boo>)
  14.  
  15. ;; PDP-10 Maclisp:
  16. ;; SOURCE-TRANS property is a list of functions (F[1] F[2] ... F[n]).
  17. ;; F[k] is funcalled on the <FORM>, it returns (VALUES <NEW-FORM> <FLAG>).
  18. ;; If <FLAG> = NIL then compiler procedes to F[k+1]
  19. ;; If <FLAG> = T then compiler calls starts again with F[1].
  20.  
  21. ;; LispMachine Lisp:
  22. ;; COMPILER:OPTIMIZERS property is a list of functions as in PDP-10 Maclisp.
  23. ;; F[k] returns <NEW-FORM>. Stop condition is (EQ <FORM> <NEW-FORM>).
  24.  
  25. ;; VAX NIL (with compiler "H"):
  26. ;; SOURCE-CODE-REWRITE property is a function, returns NIL if no rewrite,
  27. ;; else returns NCONS of result to recursively call compiler on.
  28.  
  29. ;; Multics Maclisp:
  30. ;; ???
  31. ;; Franz Lisp:
  32. ;; ???
  33.  
  34. ;; General note:
  35. ;; Having a list of optimizers with stop condition doesn't provide
  36. ;; any increase in power over having a single property. For example,
  37. ;; only two functions in LISPM lisp have more than one optimizer, and
  38. ;; no maclisp functions do. It just isn't very usefull or efficient
  39. ;; to use such a crude mechanism. What one really wants is to be able
  40. ;; to define a set of production rules in a simple pattern match
  41. ;; language. The optimizer for NTH is a case in point:
  42. ;; (NTH 0 X) => (CAR X)
  43. ;; (NTH 1 X) => (CADR X)
  44. ;; ...
  45. ;; This is defined on the LISPM as a single compiler:optimizers with
  46. ;; a hand-compiled pattern matcher.
  47.  
  48. ;;;what's that damn defmacro1 doing here..
  49.  
  50. ;#+LISPM
  51. ;(progn 'compile
  52. ;(defmacro defopt-internal (name . other)
  53. ;  `(defun (,name opt) . ,other))
  54. ;(defun opt-driver (form)
  55. ;  (funcall (get (car form) 'opt) form))
  56. ;(defmacro defopt (name . other)
  57. ;  `(progn 'compile
  58. ;      ,(si:defmacro1 (cons name other) 'defopt-internal)
  59. ;      (defprop ,name (opt-driver) compiler:optimizers)))
  60. ;
  61. ;)
  62.  
  63.  
  64. #-lispm
  65. (defmacro defopt (name &rest other) name other nil)
  66.  
  67.  
  68. #+(and lispm CL)
  69. (progn 'compile
  70. (defun opt-driver (form)
  71.   (apply (get (car form) 'opt) (cdr form)))
  72.  
  73. (defmacro defopt (name . other)
  74.   `(progn 'compile
  75.       (defun-prop (,name opt) . , other)
  76.       (defprop ,name (opt-driver) compiler:optimizers)))
  77. )
  78.  
  79.  
  80. #+PDP10
  81. (progn 'compile
  82. (defun opt-driver (form)
  83.   (values (apply (get (car form) 'opt)
  84.          (cdr form))
  85.       t))
  86. ;; pdp10 maclisp has argument destructuring available in
  87. ;; vanilla defun.
  88. (defmacro defopt (name . other)
  89.   `(progn 'compile
  90.       (defun-prop (,name opt) . ,other)
  91.       (defprop ,name (opt-driver) source-trans)))
  92. )
  93.  
  94. #+NIL
  95. (defmacro defopt (name argl &rest other &aux (form (gensym)))
  96.     `(defun-prop (,name source-code-rewrite) (,form)
  97.        (compiler:debind-args ,argl ,form (list (progn ,@other)))))
  98.  
  99. #+(or Multics Franz)
  100. (defmacro defopt (name argl . other)
  101.   `(defmacro ,name ,argl . ,other))
  102.  
  103.  
  104.