From: Ralph Ronnquist Date: Wed, 26 Apr 2023 12:54:21 +0000 (+1000) Subject: Simplifying importing with pointer-pointer return. X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=b62d728b0593c1752cb3bdb504a537cebd3f73ff;p=rrq%2Flsp-utils.git Simplifying importing with pointer-pointer return. --- 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)