impc:ir:gname   scheme


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

Implementation

;; impc:ir:gname
;; usage:
;; (gname [previous name]) ;; find distance to this
;; (gname "fred" type) ;; set current name
;; (gname "fred" "%fredxxx" type) ;; set current
;; (gname) ;; get current name
;; (gname 2) ;; get name 2 previous
;; (gname -2) ;; revert to name 2 previous
(define impc:ir:gname
  (lambda args
    (if (null? args)
        (list (impc:ir:getname "current")
              (impc:ir:gettype "current"))
        (if (> (length args) 1)
            (if (> (length args) 2)
                (impc:ir:addtodict (car args) (cadr args) (caddr args))
                (let ((str (if (or (number? (string->atom (car args)))
                                   (regex:match? (car args) "^0x"))
                               (car args)
                               (if (regex:match? (car args) "^@")
                                   (car args)
                                   (string-append "%" (car args)
                                                  (number->string (llvm:count++)))))))
                  (impc:ir:addtodict (car args) str (cadr args))
                  str))
            (if (number? (car args))
                (if (<> (abs (car args)) 1)
                    (log-error "Only allowed 1 or -1 in impc:ir:gname")
                    (if (< (car args) 0)
                        (begin (impc:ir:addtodict "current"
                                                  (impc:ir:getname "previous")
                                                  (impc:ir:getname "previous"))
                               (list (impc:ir:getname "current")
                                     (impc:ir:gettype "current")))
                        (list (impc:ir:getname "previous")
                              (impc:ir:gettype "previous"))))
                (if (impc:ir:getname (car args))
                    (begin (list (impc:ir:getname (car args))
                                 (impc:ir:gettype (car args))))
                    (log-error "Could not locate name " (car args) "in impc:ir:gname")))))))


Back to Index