Commit 12a40813 authored by rtoy's avatar rtoy
Browse files

Support the Fortran capability of passing an array of one type

to a routine expecting a different type.  Currently only supports REAL
and COMPLEX arrays (and their double precison versions).

NOTES:
o Update

f2cl0.l:
o Export new symbols f2cl-copy-seq and make-compatible-seq.

f2cl1.l:
o New variable *copy-array-parameter* for keeping track of the option
  for f2cl and f2cl-compile.
o Update f2cl and f2cl-compile to recognize :copy-array-parameter.
o Modify massage-arglist and generate-call-to-routine to handle the
  new :copy-array-parameter capability.

f2cl5.l:
o Fix issue where quoted elements were modified.  They shouldn't be.
o Fix issue where (array simple-float (*)) would get erroneously
  converted to (array simple-float (f2cl-lib:int-mul)).  We want to
  leave bare * alone.

macros.l:
o New macro f2cl-copy-seq to generate code to copy a sequence
  appropriately.
o New function to create a compatible array to support
  :copy-array-parameter.
parent 0961e13d
-*- Mode: text -*-
Changes:
Feb 2010
--------
o Some old-style Fortran code passes arrays of different types to
routines expecting a different type. For example, passing a COMPLEX
array to a routine expecting a REAL array. This works in Fortran,
but not in Lisp. To solve this, f2cl will now create a new array of
the correct type, copy the elements of the original array into it,
call the routine, and then copy the results back. This feature is
controlled by :copy-array-parameter and defaults to off. Currently,
this only works for converting REAL arrays to COMPLEX arrays and
vice versa.
Apr 2009
--------
o Bind *READ-DEFAULT-FLOAT-FORMAT* to 'SINGLE-FLOAT when reading the
......
......@@ -32,6 +32,8 @@
#:int-add #:int-sub #:int-mul
;; Utilities
#:array-slice #:array-initialize
#:f2cl-copy-seq
#:make-compatible-seq
;; Intrinsic functions
#:abs #:acos #:aimag #:dimag #:aint #:alog #:alog10 #:amax0 #:amax1
#:amin1 #:amod #:anint #:asin #:atan #:atan2
......@@ -64,8 +66,38 @@
;;;-------------------------------------------------------------------------
;;; end of f2cl0.l
;;;
;;; $Id: f2cl0.l,v c66529c968c9 2009/01/08 15:54:01 rtoy $
;;; $Id: f2cl0.l,v db7ba752d7ac 2010/02/23 00:59:12 rtoy $
;;; $Log$
;;; Revision 1.25 2010/02/23 00:59:12 rtoy
;;; Support the Fortran capability of passing an array of one type
;;; to a routine expecting a different type. Currently only supports REAL
;;; and COMPLEX arrays (and their double precison versions).
;;;
;;; NOTES:
;;; o Update
;;;
;;; f2cl0.l:
;;; o Export new symbols f2cl-copy-seq and make-compatible-seq.
;;;
;;; f2cl1.l:
;;; o New variable *copy-array-parameter* for keeping track of the option
;;; for f2cl and f2cl-compile.
;;; o Update f2cl and f2cl-compile to recognize :copy-array-parameter.
;;; o Modify massage-arglist and generate-call-to-routine to handle the
;;; new :copy-array-parameter capability.
;;;
;;; f2cl5.l:
;;; o Fix issue where quoted elements were modified. They shouldn't be.
;;; o Fix issue where (array simple-float (*)) would get erroneously
;;; converted to (array simple-float (f2cl-lib:int-mul)). We want to
;;; leave bare * alone.
;;;
;;; macros.l:
;;; o New macro f2cl-copy-seq to generate code to copy a sequence
;;; appropriately.
;;; o New function to create a compatible array to support
;;; :copy-array-parameter.
;;;
;;; Revision 1.24 2009/01/08 15:54:01 rtoy
;;; Remove junk comments.
;;;
......
This diff is collapsed.
......@@ -50,7 +50,7 @@
(in-package :f2cl)
(defparameter *f2cl5-version*
"$Id: f2cl5.l,v 47ad80500186 2009/12/14 22:36:46 rtoy $")
"$Id: f2cl5.l,v db7ba752d7ac 2010/02/23 00:59:12 rtoy $")
;; functions for setting up varaible declarations and initialisations
(eval-when (compile load eval)
......@@ -520,6 +520,9 @@
((eq (first p) 'declare)
;; Skip over declarations
p)
((eq (first p) 'quote)
;; Skip over quoted objects
p)
((eq (first p) 'fdo)
;; FDO handled specially
(destructuring-bind (fdo (var1 init step-form)
......@@ -562,7 +565,8 @@
((eq (first p) 'truncate)
;; Hmm, make sure truncate returns a integer4
`(the integer4 ,p))
((member (first p) '(+ - *))
((and (member (first p) '(+ - *))
(rest p))
;; Basic arithmetic operations. Division has already been
;; handled by converting / to f2cl/ which is optimized
;; somewhere else.
......@@ -579,7 +583,6 @@
(- . int-sub)
(* . int-mul))))
(first p))))
;;(format t "fun = ~A~%" fun)
`(,fun ,@(mapcar #'optimize-integer-arithmetic (rest p)))))
((listp (first p))
`(,(mapcar #'optimize-integer-arithmetic
......@@ -3847,8 +3850,38 @@
;;;-----------------------------------------------------------------------------
;;; end of f2cl5.l
;;;
;;; $Id: f2cl5.l,v 47ad80500186 2009/12/14 22:36:46 rtoy $
;;; $Id: f2cl5.l,v db7ba752d7ac 2010/02/23 00:59:12 rtoy $
;;; $Log$
;;; Revision 1.202 2010/02/23 00:59:12 rtoy
;;; Support the Fortran capability of passing an array of one type
;;; to a routine expecting a different type. Currently only supports REAL
;;; and COMPLEX arrays (and their double precison versions).
;;;
;;; NOTES:
;;; o Update
;;;
;;; f2cl0.l:
;;; o Export new symbols f2cl-copy-seq and make-compatible-seq.
;;;
;;; f2cl1.l:
;;; o New variable *copy-array-parameter* for keeping track of the option
;;; for f2cl and f2cl-compile.
;;; o Update f2cl and f2cl-compile to recognize :copy-array-parameter.
;;; o Modify massage-arglist and generate-call-to-routine to handle the
;;; new :copy-array-parameter capability.
;;;
;;; f2cl5.l:
;;; o Fix issue where quoted elements were modified. They shouldn't be.
;;; o Fix issue where (array simple-float (*)) would get erroneously
;;; converted to (array simple-float (f2cl-lib:int-mul)). We want to
;;; leave bare * alone.
;;;
;;; macros.l:
;;; o New macro f2cl-copy-seq to generate code to copy a sequence
;;; appropriately.
;;; o New function to create a compatible array to support
;;; :copy-array-parameter.
;;;
;;; Revision 1.201 2009/12/14 22:36:46 rtoy
;;; GENERATE-WITH-ARRAY in INSERT-DECLARATIONS was figuring out the type
;;; of strings incorrectly.
......
......@@ -6,7 +6,7 @@
(in-package :f2cl-lib)
(defparameter *f2cl-macros-version*
"$Id: macros.l,v 0852a0f34095 2009/01/08 12:57:19 rtoy $")
"$Id: macros.l,v db7ba752d7ac 2010/02/23 00:59:12 rtoy $")
(eval-when
#+gcl (compile load eval)
......@@ -1462,11 +1462,97 @@ causing all pending operations to be flushed"
(unless *stop-signals-error-p*
(cerror "Continue anyway" "STOP reached")))
(defmacro f2cl-copy-seq (dst src dst-type src-type)
(flet ((copy-error ()
(error "F2CL cannot copy arrays of element type ~A to ~A~%"
src-type dst-type)))
(cond ((subtypep dst-type 'float)
;; Copy to float array
(cond ((subtypep src-type 'float)
`(replace ,dst ,src))
((subtypep src-type 'complex)
;; Copy complex to float by putting each real and
;; imaginary part into the float array, in order.
(let ((idx (gensym "IDX-"))
(el (gensym "EL-")))
`(loop for ,idx of-type fixnum from 0 by 2 below (length ,dst)
for ,el of-type ,src-type across ,src
do
(progn
(setf (aref ,dst ,idx) (realpart ,el))
(setf (aref ,dst (1+ ,idx)) (imagpart ,el))))))
(t
(copy-error))))
((subtypep dst-type 'complex)
;; Copy to complex array
(cond ((subtypep src-type 'float)
(let ((idx (gensym "IDX-"))
(dst-idx (gensym "DST-IDX-")))
`(loop for ,idx of-type fixnum from 0 by 2 below (length ,src)
for ,dst-idx of-type fixnum from 0 below (length ,dst)
do
(setf (aref ,dst ,dst-idx) (complex (aref ,src ,idx)
(aref ,src (1+ ,idx)))))))
((subtypep src-type 'complex)
`(replace ,dst ,src))
(t
(copy-error))))
(t
(copy-error)))))
(defun make-compatible-seq (type array)
(let ((element-type (second type))
(array-type (array-element-type array))
(len (length array)))
(cond ((subtypep element-type 'float)
(cond ((subtypep array-type 'complex)
(make-array (* 2 len) :element-type element-type))
(t
(make-array len :element-type element-type))))
((subtypep element-type 'complex)
(cond ((subtypep array-type 'complex)
(make-array len :element-type element-type))
(t
(make-array (ceiling len 2) :element-type element-type))))
(t
(error "Don't know how to make an array with element-type ~A~%" element-type)))))
;;;-------------------------------------------------------------------------
;;; end of macros.l
;;;
;;; $Id: macros.l,v 0852a0f34095 2009/01/08 12:57:19 rtoy $
;;; $Id: macros.l,v db7ba752d7ac 2010/02/23 00:59:12 rtoy $
;;; $Log$
;;; Revision 1.113 2010/02/23 00:59:12 rtoy
;;; Support the Fortran capability of passing an array of one type
;;; to a routine expecting a different type. Currently only supports REAL
;;; and COMPLEX arrays (and their double precison versions).
;;;
;;; NOTES:
;;; o Update
;;;
;;; f2cl0.l:
;;; o Export new symbols f2cl-copy-seq and make-compatible-seq.
;;;
;;; f2cl1.l:
;;; o New variable *copy-array-parameter* for keeping track of the option
;;; for f2cl and f2cl-compile.
;;; o Update f2cl and f2cl-compile to recognize :copy-array-parameter.
;;; o Modify massage-arglist and generate-call-to-routine to handle the
;;; new :copy-array-parameter capability.
;;;
;;; f2cl5.l:
;;; o Fix issue where quoted elements were modified. They shouldn't be.
;;; o Fix issue where (array simple-float (*)) would get erroneously
;;; converted to (array simple-float (f2cl-lib:int-mul)). We want to
;;; leave bare * alone.
;;;
;;; macros.l:
;;; o New macro f2cl-copy-seq to generate code to copy a sequence
;;; appropriately.
;;; o New function to create a compatible array to support
;;; :copy-array-parameter.
;;;
;;; Revision 1.112 2009/01/08 12:57:19 rtoy
;;; f2cl0.l:
;;; o Export *STOP-SIGNALS-ERROR-P*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment