boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

052-init-array-str.scm (836B)


      1 ;; tests/cc-cg/52-init-array-str.scm — global char[] from a string-literal
      2 ;; initializer. §E.4.
      3 ;;
      4 ;; Models: char s[] = "abc"; return *s;   (== 'a' == 97)
      5 ;; The init is a single 4-byte bv {97,98,99,0}.
      6 
      7 (let* ((cg  (cg-init))
      8        (elem %t-i8)
      9        (aty (%ctype 'arr 4 1 (cons elem 4)))
     10        (s   (%sym "s" 'var 'static aty #f))
     11        (bv  (make-bytevector 4 0))
     12        (_a  (bytevector-u8-set! bv 0 97))
     13        (_b  (bytevector-u8-set! bv 1 98))
     14        (_c  (bytevector-u8-set! bv 2 99)))
     15   (cg-emit-global cg s (list bv))
     16   (cg-fn-begin cg "main" '() %t-i32)
     17   ;; Read the first byte from cc__s. Just take address, cast to char*,
     18   ;; deref.
     19   (cg-push-sym cg s) (cg-take-addr cg)
     20   (cg-cast cg (%ctype 'ptr 8 8 elem))
     21   (cg-push-deref cg) (cg-load cg)
     22   (cg-return cg)
     23   (cg-fn-end cg)
     24   (write-bv-fd 1 (cg-finish cg)))