bind-lib-func   macro


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/runtime/llvmti.xtm

Implementation

;;; this here for binding to CLOSURE in dylib
;;
;; arg is for *optional* zone size arg
(define-macro (bind-lib-func library symname type zone-size docstring body)
  `(begin
     (bind-lib ,library ,symname ,type fastcc)
     (bind-lib ,library ,(string->symbol (string-append (symbol->string symname) "_setter")) [void]*)
     (bind-lib ,library ,(string->symbol (string-append (symbol->string symname) "_getter")) [i8*]*)
     (bind-lib ,library ,(string->symbol (string-append (symbol->string symname) "_callback")) [void,i8*]*)
     (if (impc:ti:create-scm-wrapper? ,(symbol->string symname))
         (bind-lib ,library ,(string->symbol (string-append (symbol->string symname) "_scheme")) [i8*,i8*,i8*]*))
     (bind-lib ,library ,(string->symbol (string-append (symbol->string symname) "_native")) ,type)
     (bind-lib ,library ,(string->symbol (string-append (symbol->string symname) "_maker"))
               ,(string->symbol (string-append "[" (symbol->string type) ",i8*]*")))
     (if (not (llvm:compile-ir
               (string-append "@" ,(symbol->string symname) "_var = external global [1 x i8*]\n\n"
                              "@" ,(symbol->string symname) "_var_zone = external global [1 x i8*]\n\n")))
         (impc:compiler:print-compiler-error "failed to compile IR in bind-lib-func" ,symname))
     (llvm:bind-symbol ,library ,(string-append (symbol->string symname) "_var"))
     (llvm:bind-symbol ,library ,(string-append (symbol->string symname) "_var_zone"))
     ;; bind scheme function
     (if (impc:ti:create-scm-wrapper? ,(symbol->string symname))
         (eval (define ,symname
                 (impc:ti:create-scheme-wrapper (symbol->string ',symname)))
               (interaction-environment))
         (impc:compiler:print-no-scheme-stub-notification (symbol->string ',symname)))
     (impc:ti:register-new-closure ,(symbol->string symname)
                                   (impc:ir:get-type-from-pretty-str ,(symbol->string type))
                                   ,zone-size
                                   ,docstring
                                   ,body)
     (impc:compiler:print-binding-details-to-log "LibBound:"
                                                 ,(symbol->string symname)
                                                 ,(symbol->string type))
     (impc:ti:initialize-closure-with-new-zone ,(symbol->string symname)
                                               ,zone-size)))


Back to Index