/usr/share/maxima/5.32.1/src/trans2.lisp is in maxima-src 5.32.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; The data in this file contains enhancments. ;;;;;
;;; ;;;;;
;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
;;; All rights reserved ;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Please do not modify this file. See GJC ;;;
;;; (c) Copyright 1980 Massachusetts Institute of Technology ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(in-package :maxima)
;;; TRANSLATION PROPERTIES FOR MACSYMA OPERATORS AND FUNCTIONS.
;;; This file is for list and array manipulation optimizations.
(macsyma-module trans2)
(def%tr $random (form) `($fixnum . ($random ,@(tr-args (cdr form)))))
(def%tr mequal (form)
`($any . (simplify (list '(mequal) ,@(tr-args (cdr form))))))
(def%tr mcall (form)
(setq form (cdr form))
(let ((mode (cond ((atom (car form))
(function-mode (car form)))
(t '$any))))
(setq form (tr-args form))
(let ((op (car form)))
(call-and-simp mode 'mcall `(,op . ,(cdr form))))))
;;; Meaning of the mode properties: most names are historical.
;;; (GETL X '(ARRAY-MODE)) means it is an array callable by the
;;; old maclisp style. This is unfortunately still useful to
;;; avoid indirection through the property list to get to the
;;; array.
(defvar $translate_fast_arrays nil)
;;When $translate_fast_arrays and $use_fast_arrays are true
;;there should only be two types of arrays and they should be stored on
;;the value cell of the symbol. These should be the equivalent of the
;;zetalisp art-q and the si:equal-hash-table. Note that maxima lists
;;and maxima $matrices are also allowed for setting. Note also that
;;because of some hokey things like mqapply etc, if you want
;;fast referenceing use a[i], or b[i]:..., ie use variables,
;;since if you try something complicated it may not translate as
;;simply.
;;Idea of these is for the lispm to store the array in the value cell
;;to use equal-hash-tables, and to clean up the local variable
;;in translated code for an array.
;;txx(i,j):=block([hl],hl[i]:j,hl[i]); should leave hl unbound, after creating
;;a hash table for hl, There should be a resource of these.
(defun tr-maset (ar val inds)
;; Top-level forms need to define the variable first.
(if *macexpr-top-level-form-p*
`(nil progn (defvar ,ar ',ar) (maset ,val ,ar ,@ inds))
`(nil maset ,val ,ar ,@ inds)))
(defun maset1 ( val ar &rest inds &aux )
(cond
((and (typep ar 'cl:array)
(= (length inds) (cl:array-rank ar)))
(setf (apply #'aref ar inds) val))
((typep ar 'cl:hash-table)
(setf (gethash (if (cdr inds) (copy-list inds) (car inds))
ar)
val))
((symbolp ar)
(error "MASET1: first argument must not be a symbol; found: ~M" ar))
((and (= (length inds) 1)
(or ($listp ar) ($matrixp ar)))
(setf (nth (car inds) ar) val) val)
((and ($matrixp ar)
(= (length inds) 2))
(setf (nth (second inds) (nth (car inds) ar)) val) val)
(t (error "MASET1: invalid array reference: ~A" ar))))
;;apply is too expensive for a simple array reference. The time
;;is increased by a factor of 6. Note we use the locf form to get at
;;the local variable of the function calling maset in order to be able
;;to store a hash-table there in the case that the variable was not an
;;array
;;COULD USE THE FOLLOWING TO handle fast_arrays:true.
;;(defun set-up-hash-table (&optional val key &aux tab)
;; (setq tab (make-hash-table :test 'equal)) ;alike?
;; (setf (gethash key tab) val) tab)
;;
;;(defun maset-help1 ( val ar &rest inds &aux )
;; "returns t if it set and nil if what went in could not be set but is a variable that
;; should be set to hash array"
;; (cond ((hash-table-p ar)
;; (setf (gethash (car inds) ar) val))
;; ((symbolp ar) nil)
;; (($listp ar)
;; (setf (nth (car inds) ar) val) t)
;; (($matrixp ar) (setf (nth (second inds) (nth (car inds) ar)) val) t)
;; (t (error "not valid place ~A to put an array" ar))))
;;
;;
;;;;doesn't prevent multiple evaluation of inds val and ar.. but doesn't use locf
;;(defmacro maset (val ar &rest inds )
;; `(cond
;; ((arrayp ar) (setf (aref ar ,@ inds) ,val))
;; ((maset-help1 ,val ,ar ,@ inds) ,val)
;; (t (setf ,ar (set-up-hash-table ,val (car ,ind))),val)))
;;
;;(defmacro maref ( ar &rest inds)
;; `(cond ((arrayp ,ar) (aref ,ar ,@ inds))
;; ((hash-table-p ,ar) (gethash ,ar (car ,inds)))
;; ((symbolp ,ar)`((,ar ,@ (copy-list ,inds))))))
;;in maref in transl now
(defun tr-maref (ar inds)
`(nil maref , ar ,@ (copy-list inds)))
(defun maref1 (ar &rest inds &aux )
(cond
((and (typep ar 'cl:array)
(= (length inds) (cl:array-rank ar)))
(apply #'aref ar inds))
((typep ar 'cl:hash-table)
(gethash (if (cdr inds) inds (car inds)) ar))
((symbolp ar)
(cond ((mget ar 'hashar)
(harrfind `((,ar array) ,@(copy-list inds))))
(t
`((,ar array) ,@(copy-list inds)))))
((and (= (length inds) 1)
(or ($listp ar) ($matrixp ar)))
(nth (first inds) ar))
((and ($matrixp ar) (= (length inds) 2))
(nth (second inds) (nth (first inds) ar)))
(t
(merror (intl:gettext "Wrong number of array indices: ~M") (cons '(mlist) inds)))))
(defun tr-arraycall (form &aux all-inds)
(cond
($translate_fast_arrays (setq all-inds (mapcar 'dtranslate (cdr form)))
;;not apply changed 'tr-maref
(funcall 'tr-maref (cdr (translate (caar form))) all-inds))
(t
(translate `((marrayref)
,(if $tr_array_as_ref (caar form)
`((mquote) ,(caar form)))
,@(cdr form))))))
(defun tr-arraysetq (array-ref value)
;; actually an array SETF, but it comes from A[X]:FOO
;; which is ((MSETQ) ... ...)
(cond
($translate_fast_arrays
(funcall 'tr-maset (caar array-ref) (dtranslate value)
(mapcar 'dtranslate (copy-list (cdr array-ref)))))
(t
;; oops. Hey, I switch around order of evaluation
;; here. no need to either man. gee.
(translate `((marrayset) ,value
,(if $tr_array_as_ref (caar array-ref)
`((mquote) ,(caar array-ref)))
,@(cdr array-ref))))))
(def%tr marrayref (form)
(setq form (cdr form))
(let ((mode (cond ((atom (car form))
(get (car form) 'array-mode)))))
(cond ((null mode) (setq mode '$any)))
(setq form (tr-args form))
(let ((op (car form)))
`(,mode . (,(if (and (= (length form) 2)
(eq mode '$float))
(progn (push-autoload-def 'marrayref '(marrayref1$))
'marrayref1$)
'marrayref)
,op . ,(cdr form))))))
(def%tr marrayset (form)
(setq form (cdr form))
(let ((mode (cond ((atom (cadr form))
(get (cadr form) 'array-mode)))))
(when (null mode) (setq mode '$any))
(setq form (tr-args form))
(destructuring-let (((val aarray . inds) form))
`(,mode . (,(if (and (= (length inds) 1)
(eq mode '$float))
(progn
(push-autoload-def 'marrayset '(marrayset1$))
'marrayset1$)
'marrayset)
,val ,aarray . ,inds)))))
(def%tr mlist (form)
(if (null (cdr form)) ;;; []
'($any . '((mlist)))
`($any . (list '(mlist) . ,(tr-args (cdr form))))))
(def%tr $first (form)
(setq form (translate (cadr form)))
(call-and-simp '$any (if (eq '$list (car form))
'cadr
'$first)
(list (cdr form))))
;; Local Modes:
;; Mode: LISP
;; Comment Col: 40
;; END:
|