| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: C -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; |
| 5 |
;;;; CMPFFI -- Foreign functions interface. |
| 6 |
|
| 7 |
;;;; Copyright (c) 2003, Juan Jose Garcia-Ripoll. |
| 8 |
;;;; |
| 9 |
;;;; See file 'LICENSE' for the copyright details. |
| 10 |
|
| 11 |
(in-package "COMPILER") |
| 12 |
|
| 13 |
;;; ---------------------------------------------------------------------- |
| 14 |
;;; C/C++ DECLARATIONS AND HEADERS |
| 15 |
;;; |
| 16 |
;;; All lines from CLINES statements are grouped at the beginning of the header |
| 17 |
;;; Notice that it does not make sense to guarantee that c-lines statements |
| 18 |
;;; are produced in-between the function definitions, because two functions |
| 19 |
;;; might be collapsed into one, or we might not produce that function at all |
| 20 |
;;; and rather inline it. |
| 21 |
;;; |
| 22 |
|
| 23 |
;;; FIXME pass1 handler defined in the pass2 module. |
| 24 |
(defun c1clines (args) |
| 25 |
(unless (every #'stringp args) |
| 26 |
(cmperr "The argument to CLINES, ~s, is not a list of strings." args)) |
| 27 |
(setf *clines-string-list* (nconc *clines-string-list* (copy-list args))) |
| 28 |
'(progn)) |
| 29 |
|
| 30 |
(defun output-clines (output-stream) |
| 31 |
(loop for s in *clines-string-list* |
| 32 |
do (terpri output-stream) |
| 33 |
do (if (find #\@ s) |
| 34 |
(cmperr "The character #\\@ is not allowed in ~s." 'FFI:CLINES) |
| 35 |
(write-string s output-stream))) |
| 36 |
(terpri output-stream) |
| 37 |
(setf *clines-string-list* nil)) |
| 38 |
|
| 39 |
;; ---------------------------------------------------------------------- |
| 40 |
;; C/C++ INLINE CODE |
| 41 |
;; |
| 42 |
|
| 43 |
(defun c2c-progn (c1form variables statements) |
| 44 |
(declare (ignore c1form)) |
| 45 |
(loop with *destination* = 'TRASH |
| 46 |
for form in statements |
| 47 |
do (cond ((stringp form) |
| 48 |
(wt-nl) |
| 49 |
(wt-c-inline-loc :void form variables |
| 50 |
t ; side effects |
| 51 |
nil) ; no output variables |
| 52 |
) |
| 53 |
(t |
| 54 |
(c2expr* form))) |
| 55 |
finally (unwind-exit *vv-nil*))) |
| 56 |
|
| 57 |
(defun c2c-inline (c1form arguments &rest rest) |
| 58 |
(declare (ignore c1form)) |
| 59 |
(with-inline-blocks () |
| 60 |
(unwind-exit (apply #'produce-inline-loc (inline-args arguments) rest)))) |