Changeset 5829


Ignore:
Timestamp:
Jan 30, 2007, 4:45:04 PM (18 years ago)
Author:
Gary Byers
Message:

%EXTERNAL-CALL-EXPANDER allows/requires a leading argument to be paired
with a structure-typed return-type.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/lib/foreign-types.lisp

    r5809 r5829  
    14391439  (declare (ignore env))
    14401440  (destructuring-bind (name &rest args) whole
    1441     (let* ((info (or (gethash name (ftd-external-function-definitions
    1442                                     *target-ftd*))
    1443                      (error "Unknown external-function: ~s" name)))
    1444            (external-name (efd-entry-name info))
    1445            (arg-specs (efd-arg-specs info))
    1446            (result (efd-result-spec info))
    1447            (monitor (eq (car args) :monitor-exception-ports)))
    1448       (when monitor
    1449         (setq args (cdr args)))
    1450       (do* ((call (if monitor '(:monitor-exception-ports) ()))
    1451             (specs arg-specs (cdr specs))
    1452             (args args (cdr args)))
    1453            ((null specs)
    1454             (if args
    1455               (error "Extra arguments in ~s" call)
    1456               `(external-call ,external-name ,@(nreverse (cons result call)))))
    1457         (let* ((spec (car specs)))
    1458           (cond ((eq spec :void)
    1459                  ;; must be last arg-spec; remaining args should be
    1460                  ;; keyword/value pairs
    1461                  (unless (evenp (length args))
    1462                    (error "Remaining arguments should be keyword/value pairs: ~s"
    1463                           args))
    1464                  (do* ()
    1465                       ((null args))
    1466                    (push (pop args) call)
    1467                    (push (pop args) call)))
    1468                 (t
    1469                  (push spec call)
    1470                  (if args
    1471                    (push (car args) call)
    1472                    (error "Missing arguments in ~s" whole)))))))))
     1441    (collect ((call))
     1442      (let* ((info (or (gethash name (ftd-external-function-definitions
     1443                                      *target-ftd*))
     1444                       (error "Unknown external-function: ~s" name)))
     1445             (external-name (efd-entry-name info))
     1446             (arg-specs (efd-arg-specs info))
     1447             (result (efd-result-spec info))
     1448             (monitor (eq (car args) :monitor-exception-ports)))
     1449        (when monitor
     1450          (setq args (cdr args))
     1451          (call :monitor-exception-ports))
     1452        (let* ((rtype (parse-foreign-type result)))
     1453          (if (typep rtype 'foreign-record-type)
     1454            (call (pop args))))
     1455        (do* ((specs arg-specs (cdr specs))
     1456              (args args (cdr args)))
     1457             ((null specs)
     1458              (call result)
     1459              (if args
     1460                (error "Extra arguments in ~s" (call))
     1461                `(external-call ,external-name ,@(call))))
     1462          (let* ((spec (car specs)))
     1463            (cond ((eq spec :void)
     1464                   ;; must be last arg-spec; remaining args should be
     1465                   ;; keyword/value pairs
     1466                   (unless (evenp (length args))
     1467                     (error "Remaining arguments should be keyword/value pairs: ~s"
     1468                            args))
     1469                   (do* ()
     1470                        ((null args))
     1471                     (call (pop args))
     1472                     (call (pop args))))
     1473                  (t
     1474                   (call spec)
     1475                   (if args
     1476                     (call (car args))
     1477                     (error "Missing arguments in ~s" whole))))))))))
    14731478
    14741479(defun translate-foreign-arg-type (foreign-type-spec)
Note: See TracChangeset for help on using the changeset viewer.