Changeset 5790


Ignore:
Timestamp:
Jan 24, 2007, 10:41:24 PM (18 years ago)
Author:
Gary Byers
Message:

First cut at callback-bindings thing; may not even compile.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/lib/ffi-linuxppc32.lisp

    r5760 r5790  
    8585            `(,@enclosing-form ,call)
    8686            call))))))
     87
     88;;; Return N values:
     89;;; A list of RLET bindings
     90;;; A list of LET* bindings
     91;;; A list of DYNAMIC-EXTENT declarations for the LET* bindings
     92;;; A list of initializaton forms for (some) structure args
     93;;; A FOREIGN-TYPE representing the "actual" return type.
     94(defun linux32::generate-callback-bindings (stack-ptr argvars argspecs result-spec struct-result-name)
     95  (collect ((lets)
     96            (rlets)
     97            (dynamic-extent-names))
     98    (let* ((rtype (parse-foreign-type result-spec)))
     99      (when (typep rtype 'foreign-record-type)
     100        (let* ((bits (ensure-foreign-type-bits rtype)))
     101          (if (<= bits 64)
     102            (rlets (list struct-result-name (foreign-record-type-name rtype)))
     103            (setq argvars (cons struct-result-name argvars)
     104                  argspecs (cons :address argspecs)
     105                  rtype *void-foreign-type))))
     106          (let* ((offset  96)
     107                 (gpr 0)
     108                 (fpr 32))
     109            (do* ((argvars argvars (cdr argvars))
     110                  (argspecs argspecs (cdr argspecs)))
     111                 ((null argvars)
     112                  (values (rlets) (lets) (dynamic-extent-names) (inits) rtype))
     113              (let* ((name (car argvars))
     114                     (spec (car argspecs))
     115                     (nextgpr gpr)
     116                     (nextfpr fpr)
     117                     (nextoffset offset)
     118                     (target gpr)
     119                     (bias 0)
     120                     (argtype (parse-foreign-type spec)))
     121                (if (typep argtype 'foreign-record-type)
     122                  (setq spec :address))
     123                (let* ((access-form
     124                        `(,(case spec
     125                                 (:single-float
     126                                   (incf nextfpr 8)
     127                                   (if (< fpr 96)
     128                                     (setq target fpr)
     129                                     (setq target (+ offset (logand offset 4))
     130                                           nextoffset (+ target 8)))
     131                                   '%get-single-float-from-double-ptr)
     132                                  (:double-float
     133                                   (incf nextfpr 8)
     134                                   (if (< fpr 96)
     135                                     (setq target fpr)
     136                                     (setq target (+ offset (logand offset 4))
     137                                           nextoffset (+ target 8)))
     138                                   '%get-double-float)
     139                                  (:signed-doubleword
     140                                   (if (< gpr 56)
     141                                     (setq target (+ gpr (logand gpr 4))
     142                                           nextgpr (+ 8 target))
     143                                     (setq target (+ offset (logand offset 4))
     144                                           nextoffset (+ 8 offset)))
     145                                   '%%get-signed-longlong)
     146                                  (:unsigned-doubleword
     147                                   (if (< gpr 56)
     148                                     (setq target (+ gpr (logand gpr 4))
     149                                           nextgpr (+ 8 target))
     150                                     (setq target (+ offset (logand offset 4))
     151                                           nextoffset (+ 8 offset)))
     152                                   '%%get-unsigned-longlong)
     153                                  (t
     154                                   (incf nextgpr 4)
     155                                   (if (< gpr 64)
     156                                     (setq target gpr)
     157                                     (setq target offset nextoffset (+ offset 4)))
     158                                   (ecase type
     159                                     (:signed-fullword '%get-signed-long)
     160                                     (:signed-halfword (setq bias 2) '%get-signed-word)
     161                                     (:signed-byte (setq bias 3) '%get-signed-byte)
     162                                     (:unsigned-fullword '%get-unsigned-long)
     163                                     (:unsigned-halfword (setq bias 2) '%get-unsigned-word)
     164                                     (:unsigned-byte (setq bias 3) '%get-unsigned-byte)
     165                                     (:address '%get-ptr))))
     166                          ,stack-ptr
     167                          ,(+ target bias))))
     168                  (lets (list name access-form))
     169                  (when (eq spec :address)
     170                    (dynamic-extent-names name))
     171                  (setq gpr nextgpr fpr nextfpr offset nextoffset)))))
     172          (values (rlets)
     173                  (lets)
     174                  (dynamic-extent-names)
     175                  nil
     176                  rtype))))
     177               
     178                 
Note: See TracChangeset for help on using the changeset viewer.