impc:ti:bind-lib   scheme


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

Implementation

;; this was previously called __dynamic-bind
(define impc:ti:bind-lib
  (lambda (library symname type calling-convention docstring)
    (if (llvm:get-function (symbol->string symname)) ;; if already bound!
        (begin
          (impc:ti:register-new-nativefunc (symbol->string symname) (impc:ir:get-type-from-pretty-str (symbol->string type)) "" '())
          (impc:compiler:print-lib-binding-details-to-log library symname type)
          (impc:aot:insert-nativefunc-binding-details library symname type docstring))
        (if (not (eval library))
            (impc:compiler:print-compiler-error
              (string-append "the " (symbol->string library) " dynamic library appears to have not been loaded correctly"))
            (let* ((ctype (cdr (impc:ir:get-type-from-pretty-str (symbol->string type))))
                  (ir-string (string-append "declare "
                                            "cc " (atom->string calling-convention)
                                            " "
                                            (impc:ir:get-type-str (car ctype))
                                            " @"
                                            (symbol->string symname)
                                            "("
                                            (if (null? (cdr ctype))
                                                ""
                                                (apply string-append
                                                        (impc:ir:get-type-str (cadr ctype))
                                                        (map (lambda (v)
                                                              (string-append "," (impc:ir:get-type-str v)))
                                                            (cddr ctype))))
                                            ") nounwind")))
              (if (and (llvm:compile-ir ir-string)
                      (llvm:bind-symbol (eval library) (symbol->string symname)))
                  (begin
                    (if (output-port? *impc:aot:current-output-port*) ;; *impc:compiler:aot:dll*)
                        (begin (write `(llvm:bind-symbol ,library ,(symbol->string symname)) *impc:aot:current-output-port*)
                              (newline *impc:aot:current-output-port*)))
                    (impc:ti:register-new-nativefunc (symbol->string symname) (impc:ir:get-type-from-pretty-str (symbol->string type)) "" '())
                    (impc:compiler:print-lib-binding-details-to-log library symname type)
                    (impc:aot:insert-nativefunc-binding-details library symname type docstring))
                  (impc:compiler:print-compiler-error (string-append "could not bind " (symbol->string symname)))))))))


Back to Index

Similar Entries

  • bind-lib    macro
  • bind-lib-func    macro
  • bind-lib-type    macro
  • bind-lib-val    macro
  • bind-lib-xtm-get-string    macro