boot2

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

013-call-5args.scm (1762B)


      1 ;; tests/cc-cg/13-call-5args.scm — 5-arg call exercises both sides of
      2 ;; the >4-arg ABI: the prologue's LDARG path in cg-fn-begin (callee
      3 ;; reads param 4 from the staging area) and the staging emission in
      4 ;; cg-call (caller writes arg 4 to [sp + 0*8]).
      5 ;; Models:
      6 ;;   int sum5(int a, int b, int c, int d, int e) { return a+b+c+d+e; }
      7 ;;   int main(void) { return sum5(1, 2, 3, 4, 5); }   /* expected: 15 */
      8 
      9 (let* ((cg         (cg-init))
     10        (sum5-fnty  (%ctype 'fn 8 8
     11                            (cons %t-i32
     12                                  (cons (list %t-i32 %t-i32 %t-i32 %t-i32 %t-i32) #f))))
     13        (sum5-sym   (%sym "sum5" 'fn 'extern sum5-fnty #f)))
     14   (let* ((params (cg-fn-begin cg "sum5"
     15                               (list (cons "a" %t-i32) (cons "b" %t-i32)
     16                                     (cons "c" %t-i32) (cons "d" %t-i32)
     17                                     (cons "e" %t-i32))
     18                               %t-i32))
     19          (a* (cdr (car params)))
     20          (b* (cdr (car (cdr params))))
     21          (c* (cdr (car (cdr (cdr params)))))
     22          (d* (cdr (car (cdr (cdr (cdr params))))))
     23          (e* (cdr (car (cdr (cdr (cdr (cdr params))))))))
     24     (cg-push-sym cg a*) (cg-load cg)
     25     (cg-push-sym cg b*) (cg-load cg) (cg-binop cg 'add)
     26     (cg-push-sym cg c*) (cg-load cg) (cg-binop cg 'add)
     27     (cg-push-sym cg d*) (cg-load cg) (cg-binop cg 'add)
     28     (cg-push-sym cg e*) (cg-load cg) (cg-binop cg 'add)
     29     (cg-return cg)
     30     (cg-fn-end cg))
     31   (cg-fn-begin cg "main" '() %t-i32)
     32   (cg-push-sym cg sum5-sym)
     33   (cg-push-imm cg %t-i32 1)
     34   (cg-push-imm cg %t-i32 2)
     35   (cg-push-imm cg %t-i32 3)
     36   (cg-push-imm cg %t-i32 4)
     37   (cg-push-imm cg %t-i32 5)
     38   (cg-call cg 5 #t)
     39   (cg-return cg)
     40   (cg-fn-end cg)
     41   (write-bv-fd 1 (cg-finish cg)))