diff --git a/src/cmp/cmpglobals.lsp b/src/cmp/cmpglobals.lsp index 5f0f9afed326f0f5f56139c4db78e8ce7f82a19b..000b224b6b05c93d04f6c2b28f8c427936652f7b 100644 --- a/src/cmp/cmpglobals.lsp +++ b/src/cmp/cmpglobals.lsp @@ -265,6 +265,7 @@ lines are inserted, but the order is preserved") (defvar *global-funs* nil) ; holds { fun }* (defvar *use-c-global* nil) ; honor si::c-global declaration (defvar *global-cfuns-array* nil) ; holds { fun }* +(defvar *external-cfuns* '()) ; holds { external-c-funs }* (defvar *local-funs* nil) ; holds { fun }* (defvar *top-level-forms* nil) ; holds { top-level-form }* (defvar *make-forms* nil) ; holds { top-level-form }* diff --git a/src/cmp/cmptop.lsp b/src/cmp/cmptop.lsp index 23fa7fb18ab8fe2b0008365c67dbe1405c29390a..2e0a6a5edf999fb627f1bd69d7fd8e5324cdf9bd 100644 --- a/src/cmp/cmptop.lsp +++ b/src/cmp/cmptop.lsp @@ -124,6 +124,8 @@ (wt-nl-h "#ifdef __cplusplus") (wt-nl-h "extern \"C\" {") (wt-nl-h "#endif") + (format *compiler-output2* "~%~{~a~%~}" *external-cfuns*) + (setq *external-cfuns* '()) ;;; Initialization function. (let* ((*opened-c-braces* 0) (*aux-closure* nil) diff --git a/src/lsp/ffi.lsp b/src/lsp/ffi.lsp index d4e289e2c4193eb90bab9814409ad2ceaa037163..53ad7d27708d39d229ab026973ea61674769f778 100644 --- a/src/lsp/ffi.lsp +++ b/src/lsp/ffi.lsp @@ -58,6 +58,9 @@ Defines a new foreign type." (cons (%convert-to-ffi-type (first type) context) (%convert-to-ffi-type (rest type) context)))) +(defun %convert-to-c-type (type) + (compiler::rep-type-c-name (compiler::rep-type-record type))) + (defmacro %align-data (data align) `(setf ,data (* (ceiling (/ ,data ,align)) ,align))) @@ -618,7 +621,9 @@ Declares a foreign function." (lisp-to-c-name name) (let* ((arguments (mapcar #'first args)) (arg-types (mapcar #'(lambda (type) (%convert-to-arg-type (second type))) args)) + (c-types (mapcar #'(lambda (type) (%convert-to-c-type (second type))) args)) (return-type (%convert-to-return-type returning)) + (c-return-type (%convert-to-c-type returning)) (nargs (length arguments)) (c-string (produce-function-call c-name nargs)) (casting-required (not (or (member return-type '(:void :cstring)) @@ -628,6 +633,11 @@ Declares a foreign function." ,c-string :one-liner t :side-effects t))) + (push (format nil "~A ~A(~{~a~^, ~});" + c-return-type + c-name + c-types) + compiler::*external-cfuns*) (when casting-required (setf inline-form `(si::foreign-data-recast ,inline-form