1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: UFFI -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: UFFI source to C function defintions
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
10 ;;;; $Id: functions.cl,v 1.6 2002/04/06 19:53:08 kevin Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
22 (defun process-function-args (args)
29 (push (process-one-function-arg arg) processed))
30 (nreverse processed))))
32 (defun process-one-function-arg (arg)
33 (let ((name (car arg))
34 (type (convert-from-uffi-type (cadr arg) :routine)))
37 #+(or allegro lispworks)
38 (if (and (listp type) (listp (car type)))
39 (append (list name) type)
43 (defun allegro-convert-return-type (type)
44 (if (and (listp type) (not (listp (car type))))
48 ;; name is either a string representing foreign name, or a list
49 ;; of foreign-name as a string and lisp name as a symbol
50 (defmacro def-function (names args &key module returning)
51 #+(or cmu allegro) (declare (ignore module))
53 (let* ((result-type (convert-from-uffi-type returning :return))
54 (function-args (process-function-args args))
55 (foreign-name (if (atom names) names (car names)))
56 (lisp-name (if (atom names) (make-lisp-name names) (cadr names))))
59 `(ff:def-foreign-call (,lisp-name ,foreign-name)
61 :returning ,(allegro-convert-return-type result-type)
65 `(alien:def-alien-routine (,foreign-name ,lisp-name)
69 `(fli:define-foreign-function (,lisp-name ,foreign-name :source)
71 ,@(if module (list :module module) (values))
72 :result-type ,result-type
73 :calling-convention :cdecl)
77 (defun make-lisp-name (name)
78 (let ((converted (substitute #\- #\_ name)))
80 #+case-sensitive converted
81 #-case-sensitive (string-upcase converted))))