boot2

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

080-u8-literal.scm (1104B)


      1 ; #u8(...) — bytevector literal. Each element is a fixnum byte (0..255);
      2 ; result is a HDR.BV with those exact bytes.
      3 
      4 ; Empty literal.
      5 (define e #u8())
      6 (if (bytevector=? e (make-bytevector 0 0)) 0 (sys-exit 1))
      7 
      8 ; Length and per-byte access.
      9 (define a #u8(1 2 3))
     10 (if (= (bytevector-length a) 3) 0 (sys-exit 2))
     11 (if (= (bytevector-u8-ref a 0) 1) 0 (sys-exit 3))
     12 (if (= (bytevector-u8-ref a 1) 2) 0 (sys-exit 4))
     13 (if (= (bytevector-u8-ref a 2) 3) 0 (sys-exit 5))
     14 
     15 ; The boot2 bridge compares the disjoint types by encoded bytes.
     16 (if (bytes=? #u8(65 66 67) "ABC") 0 (sys-exit 6))
     17 (if (not (equal? #u8(65 66 67) "ABC")) 0 (sys-exit 11))
     18 
     19 ; Hex element values are accepted (parser shares atom dispatch).
     20 (define b #u8(#x00 #xff))
     21 (if (= (bytevector-length b) 2) 0 (sys-exit 7))
     22 (if (= (bytevector-u8-ref b 0) 0)   0 (sys-exit 8))
     23 (if (= (bytevector-u8-ref b 1) 255) 0 (sys-exit 8))
     24 
     25 ; Whitespace and comments inside the literal.
     26 (define c #u8( 10  20  ; trailing comment
     27               30 ))
     28 (if (= (bytevector-length c) 3) 0 (sys-exit 9))
     29 (if (= (bytevector-u8-ref c 2) 30) 0 (sys-exit 10))
     30 
     31 (sys-exit 0)