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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
;;; CMPMAP Map functions.
;;;
;; Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
;; This file is part of GNU Common Lisp, herein referred to as GCL
;;
;; GCL is free software; you can redistribute it and/or modify it under
;; the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; GCL is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
;; License for more details.
;;
;; You should have received a copy of the GNU Library General Public License
;; along with GCL; see the file COPYING. If not, write to the Free Software
;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
(in-package :compiler)
(si:putprop 'mapcar 'c1mapcar 'c1)
(si:putprop 'maplist 'c1maplist 'c1)
(si:putprop 'mapcar 'c2mapcar 'c2)
(si:putprop 'mapc 'c1mapc 'c1)
(si:putprop 'mapl 'c1mapl 'c1)
(si:putprop 'mapc 'c2mapc 'c2)
(si:putprop 'mapcan 'c1mapcan 'c1)
(si:putprop 'mapcon 'c1mapcon 'c1)
(si:putprop 'mapcan 'c2mapcan 'c2)
(defun c1mapcar (args) (c1map-functions 'mapcar t args))
(defun c1maplist (args) (c1map-functions 'mapcar nil args))
(defun c1mapc (args) (c1map-functions 'mapc t args))
(defun c1mapl (args) (c1map-functions 'mapc nil args))
(defun c1mapcan (args) (c1map-functions 'mapcan t args))
(defun c1mapcon (args) (c1map-functions 'mapcan nil args))
(defun c1map-functions (name car-p args &aux funob info)
(when (or (endp args) (endp (cdr args)))
(too-few-args 'map-function 2 (length args)))
(setq funob (c1funob (car args)))
(setq info (copy-info (cadr funob)))
(list name info funob car-p (c1args (cdr args) info))
)
(defun c2mapcar (funob car-p args &aux (*vs* *vs*) (*inline-blocks* 0))
(let ((label (next-label*))
(value-loc (list 'VS (vs-push)))
(handy (list 'CVAR (next-cvar)))
(handies (mapcar #'(lambda (x) (declare (ignore x))
(list 'CVAR (next-cvar)))
args))
save
)
(setq save (save-funob funob))
; (setq args (inline-args args
; (make-list (length args) :initial-element t)))
(setq args (push-changed-vars
(inline-args args (make-list (length args)
:initial-element t))
funob))
(wt-nl "{object " handy ";")
(dolist** (loc handies)
(wt-nl "object " loc "= " (car args) ";")
(pop args))
(cond (*safe-compile*
(wt-nl "if(endp(" (car handies) ")")
(dolist** (loc (cdr handies)) (wt "||endp(" loc ")"))
(wt "){"))
(t
(wt-nl "if(" (car handies) "==Cnil")
(dolist** (loc (cdr handies)) (wt "||" loc "==Cnil"))
(wt "){")))
(unwind-exit nil 'jump)
(wt "}")
(wt-nl value-loc "=" handy "=MMcons(Cnil,Cnil);")
(wt-label label)
(let* ((*value-to-go* (list 'CAR (cadr handy)))
(*exit* (next-label))
(*unwind-exit* (cons *exit* *unwind-exit*)))
(c2funcall funob
(if car-p
(mapcar
#'(lambda (loc)
(list 'LOCATION *info* (list 'CAR (cadr loc))))
handies)
(mapcar #'(lambda (loc) (list 'LOCATION *info* loc))
handies))
save)
(wt-label *exit*))
(cond (*safe-compile*
(wt-nl (car handies) "=MMcdr(" (car handies) ");")
(dolist** (loc (cdr handies))
(wt-nl loc "=MMcdr(" loc ");"))
(wt-nl "if(endp(" (car handies) ")")
(dolist** (loc (cdr handies))
(wt "||endp(" loc ")"))
(wt "){"))
(t
(wt-nl "if((" (car handies) "=MMcdr(" (car handies) "))==Cnil")
(dolist** (loc (cdr handies))
(wt "||(" loc "=MMcdr(" loc "))==Cnil"))
(wt "){")))
(unwind-exit value-loc 'jump)
(wt "}")
(wt-nl handy "=MMcdr(" handy ")=MMcons(Cnil,Cnil);")
(wt-nl) (wt-go label)
(wt "}")
(close-inline-blocks)
)
)
(defun c2mapc (funob car-p args &aux (*vs* *vs*) (*inline-blocks* 0))
(let ((label (next-label*))
value-loc
(handies (mapcar #'(lambda (x) (declare (ignore x))
(list 'CVAR (next-cvar)))
args))
save
)
(setq save (save-funob funob))
; (setq args (inline-args args
; (make-list (length args) :initial-element t)))
(setq args (push-changed-vars
(inline-args args (make-list (length args)
:initial-element t))
funob))
(setq value-loc (car args))
(wt-nl "{")
(dolist** (loc handies)
(wt-nl "object " loc "= " (car args) ";")
(pop args))
(cond (*safe-compile*
(wt-nl "if(endp(" (car handies) ")")
(dolist** (loc (cdr handies)) (wt "||endp(" loc ")"))
(wt "){"))
(t
(wt-nl "if(" (car handies) "==Cnil")
(dolist** (loc (cdr handies)) (wt "||" loc "==Cnil"))
(wt "){")))
(unwind-exit nil 'jump)
(wt "}")
(wt-label label)
(let* ((*value-to-go* 'trash)
(*exit* (next-label))
(*unwind-exit* (cons *exit* *unwind-exit*)))
(c2funcall funob
(if car-p
(mapcar
#'(lambda (loc)
(list 'LOCATION *info* (list 'CAR (cadr loc))))
handies)
(mapcar #'(lambda (loc) (list 'LOCATION *info* loc))
handies))
save)
(wt-label *exit*))
(cond (*safe-compile*
(wt-nl (car handies) "=MMcdr(" (car handies) ");")
(dolist** (loc (cdr handies))
(wt-nl loc "=MMcdr(" loc ");"))
(wt-nl "if(endp(" (car handies) ")")
(dolist** (loc (cdr handies))
(wt "||endp(" loc ")"))
(wt "){"))
(t
(wt-nl "if((" (car handies) "=MMcdr(" (car handies) "))==Cnil")
(dolist** (loc (cdr handies))
(wt "||(" loc "=MMcdr(" loc "))==Cnil"))
(wt "){")))
(unwind-exit value-loc 'jump)
(wt "}")
(wt-nl) (wt-go label)
(wt "}")
(close-inline-blocks)
)
)
(defun c2mapcan (funob car-p args &aux (*vs* *vs*) (*inline-blocks* 0))
(let ((label (next-label*))
(value-loc (list 'VS (vs-push)))
(handy (list 'CVAR (next-cvar)))
(handies (mapcar #'(lambda (x) (declare (ignore x))
(list 'CVAR (next-cvar)))
args))
save
)
(setq save (save-funob funob))
; (setq args (inline-args args
; (make-list (length args) :initial-element t)))
(setq args (push-changed-vars
(inline-args args (make-list (length args)
:initial-element t))
funob))
(wt-nl "{object " handy ";")
(dolist** (loc handies)
(wt-nl "object " loc "= " (car args) ";")
(pop args))
(cond (*safe-compile*
(wt-nl "if(endp(" (car handies) ")")
(dolist** (loc (cdr handies)) (wt "||endp(" loc ")"))
(wt "){"))
(t
(wt-nl "if(" (car handies) "==Cnil")
(dolist** (loc (cdr handies)) (wt "||" loc "==Cnil"))
(wt "){")))
(unwind-exit nil 'jump)
(wt "}")
(wt-nl value-loc "=" handy "=MMcons(Cnil,Cnil);")
(wt-label label)
(let* ((*value-to-go* (list 'cdr (cadr handy)))
(*exit* (next-label))
(*unwind-exit* (cons *exit* *unwind-exit*))
)
(c2funcall funob
(if car-p
(mapcar
#'(lambda (loc)
(list 'LOCATION *info* (list 'CAR (cadr loc))))
handies)
(mapcar #'(lambda (loc) (list 'LOCATION *info* loc))
handies))
save)
(wt-label *exit*))
(cond
(*safe-compile*
(wt-nl "{object cdr_" handy "=MMcdr(" handy ");while(!endp(cdr_" handy ")) {cdr_" handy "=MMcdr(cdr_" handy ");" handy "=MMcdr(" handy ");}}")
(wt-nl (car handies) "=MMcdr(" (car handies) ");")
(dolist** (loc (cdr handies))
(wt-nl loc "=MMcdr(" loc ");"))
(wt-nl "if(endp(" (car handies) ")")
(dolist** (loc (cdr handies))
(wt "||endp(" loc ")"))
(wt "){"))
(t
(wt-nl "while(MMcdr(" handy ")!=Cnil)" handy "=MMcdr(" handy ");")
(wt-nl "if((" (car handies) "=MMcdr(" (car handies) "))==Cnil")
(dolist** (loc (cdr handies))
(wt "||(" loc "=MMcdr(" loc "))==Cnil"))
(wt "){")))
(wt-nl value-loc "=" value-loc "->c.c_cdr;")
(unwind-exit value-loc 'jump)
(wt "}")
(wt-nl) (wt-go label)
(wt "}")
(close-inline-blocks)
)
)
(defun push-changed-vars (locs funob &aux (locs1 nil) (forms (list funob)))
(dolist (loc locs (reverse locs1))
(if (and (consp loc)
(eq (car loc) 'VAR)
(args-info-changed-vars (cadr loc) forms))
(let ((temp (list 'VS (vs-push))))
(wt-nl temp "= " loc ";")
(push temp locs1))
(push loc locs1))))
|