From b62d728b0593c1752cb3bdb504a537cebd3f73ff Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Wed, 26 Apr 2023 22:54:21 +1000 Subject: [PATCH] Simplifying importing with pointer-pointer return. --- lsp-misc/define-import.lsp | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lsp-misc/define-import.lsp diff --git a/lsp-misc/define-import.lsp b/lsp-misc/define-import.lsp new file mode 100644 index 0000000..2b3bfc7 --- /dev/null +++ b/lsp-misc/define-import.lsp @@ -0,0 +1,39 @@ + +;; (import-define ...) is a combination of an import clause and a +;; define clause so as to set up a "raw" import with a call wrapper. +;; +; +; (context 'ALSA) +; (define-import PCM LIB +; "snd_pcm_open" "int" +; "void*" PCM ; "void*" ; snd_pcm_t **pcmp [output] +; "char*" NAME ; const char *name +; "int" STREAM ; snd_pcm_stream_t stream +; "int" MODE ; int mode +; )) + +(define-macro (define-import DATA LIB) + ;; Make a raw import + (println (history true)) + (letn ((ARGL (transpose (explode (2 (args)) 2))) + (HERE (prefix (last (ARGL 1)))) + (RAW (context (sym (string (println (term HERE)) ".raw")))) + (NAME (sym (args 0))) + (ARGS (ARGL 1)) + (FN (cons (sym (args 0) HERE) (filter (fn (x) (!= DATA x)) ARGS))) + (LIB (eval LIB)) + (IMP (apply import (filter string? (cons LIB (args))))) + ) + (println (list 'FN FN)) + (if DATA + (letex ((FN FN) + (CALL (cons IMP ARGS)) + (DATA DATA)) + (define FN + (let ((DATA (pack "Lu" 0))) + (when (>= CALL) + ((unpack "Lu" DATA) 0))))) + (letex ((FN FN) (CALL (cons IMP ARGS))) + (define FN CALL)) + ))) +(global 'define-import) -- 2.39.2