boot2

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

018-sext-narrow.scm (667B)


      1 ;; tests/cc-cg/18-sext-narrow.scm — signed narrowing keeps sign on
      2 ;; re-widen.
      3 ;;
      4 ;; Models: ((int)(char)-3) == -3.
      5 ;; Forces the cg-cast narrowing path to sign-encode the result so
      6 ;; the subsequent widening cast restores -3, not 0xFD (253). The
      7 ;; comparison is against -3 as i32, so a buggy cg that masks-only
      8 ;; yields a0=253 vs a1=-3 → not equal → exit 0. Correct cg sign-
      9 ;; extends → equal → exit 1.
     10 
     11 (let ((cg (cg-init)))
     12   (cg-fn-begin cg "main" '() %t-i32)
     13   (cg-push-imm cg %t-i32 -3)
     14   (cg-cast cg %t-i8)
     15   (cg-cast cg %t-i32)
     16   (cg-push-imm cg %t-i32 -3)
     17   (cg-binop cg 'eq)
     18   (cg-return cg)
     19   (cg-fn-end cg)
     20   (write-bv-fd 1 (cg-finish cg)))