(define-macro (bind-lib-val library symname type . docstring)
`(let* ((type-str ,(if (impc:ti:typealias-exists? (symbol->string type))
(impc:ti:get-typealias-ground-type-pretty (symbol->string type))
(symbol->string type)))
(type-list (impc:ir:get-type-from-pretty-str type-str))
(ds ,(if (null? docstring) "" (car docstring))))
(if (and (llvm:compile-ir
(string-append "@" ,(symbol->string symname) " = external global "
(impc:ir:get-type-str type-list)))
(llvm:bind-symbol ,library ,(symbol->string symname)))
(begin
(impc:ti:register-new-globalvar ,(symbol->string symname)
type-list
ds)
(impc:aot:insert-globalvar-binding-details ,(symbol->string library)
,(symbol->string symname)
,(symbol->string type)
ds)
(impc:compiler:print-binding-details-to-log "LibBound:"
,(symbol->string symname)
,(symbol->string type)))
(impc:compiler:print-compiler-error (string-append "could not bind-lib-val "
,(symbol->string symname)
" from library "
,(symbol->string library))))))