boot2

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

014-take-addr.scm (705B)


      1 ;; tests/cc-cg/14-take-addr.scm — exercise cg-take-addr on an int param.
      2 ;; Models: int main(int x) { int *p = &x; return *p; }
      3 ;; (Without auto-emitted alloc for `p` since this is the cg API; we
      4 ;; just push x's lval, take-addr, push-deref, load, return.)
      5 
      6 (let* ((cg     (cg-init))
      7        (params (cg-fn-begin cg "main"
      8                             (list (cons "x" %t-i32))
      9                             %t-i32))
     10        (x*     (cdr (car params))))
     11   (cg-push-sym cg x*)        ; lval frame
     12   (cg-take-addr cg)          ; rval ptr-to-int
     13   (cg-push-deref cg)         ; lval int (through pointer)
     14   (cg-load cg)               ; rval int
     15   (cg-return cg)
     16   (cg-fn-end cg)
     17   (write-bv-fd 1 (cg-finish cg)))