impc:ir:make-string   scheme


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

Implementation

(define impc:ir:make-string
  (lambda (ast)
    (let* ((os (make-string 0))
           (cnt 0))
      (emit (impc:ir:gname "tzone" "i8*") " = load i8*, i8** %_impzPtr\n"
            (impc:ir:gname "zone" "%mzone*") " = bitcast i8* " (car (impc:ir:gname "tzone")) " to %mzone*\n"
            os)
                                        ;(emit (impc:ir:gname "zone" "%mzone*") " = call %mzone* @llvm_peek_zone_stack()\n" os)
      (emit (impc:ir:gname "string" "i8*") " = call i8* @llvm_zone_malloc(%mzone* "
            (car (impc:ir:gname "zone")) ", i64 " (number->string (+ 1 (string-length ast))) ")\n" os)
      (define strname (car (impc:ir:gname)))
      (for-each (lambda (char)
                  (emit (string-append (impc:ir:gname "val" "i8*") " = "
                                       "getelementptr i8, i8* " strname
                                       ", i32 " (number->string cnt) "\n") os)
                  (emit (string-append "store i8 " (number->string (char->integer char))
                                       ", i8* " (car (impc:ir:gname)) "\n") os)
                  (set! cnt (+ cnt 1)))
                (append (string->list ast) (list (integer->char 0))))
      (impc:ir:gname "string" (car (impc:ir:gname "string")) (cadr (impc:ir:gname "string")))
      (impc:ir:strip-space os))))


Back to Index