boot2

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

005-load-binop-store.scm (827B)


      1 ;; tests/cc-cg/05-load-binop-store.scm — store rhs+lhs into an int param.
      2 ;; Models: int main(int x) { x = x + 5; return x; }
      3 ;; Exercises load → binop → assign → load → return on the same lval.
      4 
      5 (let* ((cg     (cg-init))
      6        (params (cg-fn-begin cg "main"
      7                             (list (cons "x" %t-i32))
      8                             %t-i32))
      9        (x*     (cdr (car params))))
     10   ;; x = x + 5
     11   (cg-push-sym cg x*)        ; lval (lhs)
     12   (cg-push-sym cg x*)        ; lval
     13   (cg-load cg)               ; rval
     14   (cg-push-imm cg %t-i32 5)
     15   (cg-binop cg 'add)
     16   (cg-assign cg)             ; rhs := x+5; pushes value onto stack
     17   (cg-pop cg)                ; discard expression-statement result
     18   ;; return x
     19   (cg-push-sym cg x*)
     20   (cg-load cg)
     21   (cg-return cg)
     22   (cg-fn-end cg)
     23   (write-bv-fd 1 (cg-finish cg)))