;; the characters are not really characters at all.
(define (C-quotify-data-string/breakup string)
- (let ((n-bytes (vector-8b-length string))
- (new-string
- (lambda ()
- (let ((s (make-string 66)))
- (string-set! s 0 #\")
- s))))
- (let loop ((i 0) (s (new-string)) (j 1))
- (if (fix:< i n-bytes)
- (if (fix:< j 62)
- (let ((b (vector-8b-ref string i)))
- (string-set! s j #\\)
- (string-set! s (fix:+ j 1) #\x)
- (string-set! s (fix:+ j 2)
- (digit->char (fix:quotient b #x10) 16))
- (string-set! s (fix:+ j 3)
- (digit->char (fix:remainder b #x10) 16))
- (loop (fix:+ i 1) s (fix:+ j 4)))
- (begin
- (string-set! s j #\")
- (cons s (loop i (new-string) 1))))
- (if (fix:> j 1)
- (begin
- (string-set! s j #\")
- (list (substring s 0 (fix:+ j 1))))
- '())))))
+ (let ((builder (string-builder)))
+ (map (lambda (part)
+ (builder 'reset!)
+ (builder #\")
+ (string-for-each
+ (lambda (char)
+ (let ((b (char->integer char)))
+ (builder #\\)
+ (builder #\x)
+ (builder (digit->char (fix:quotient b #x10) 16))
+ (builder (digit->char (fix:remainder b #x10) 16))))
+ part)
+ (builder #\")
+ (builder 'immutable))
+ (split-string string 64))))
+
+(define (split-string string n)
+ (let ((len (string-length string)))
+ (let loop ((start 0) (parts '()))
+ (let ((end (fix:+ start n)))
+ (if (fix:<= end len)
+ (reverse!
+ (cons (string-slice string start len)
+ parts))
+ (loop end
+ (cons (string-slice string start end)
+ parts)))))))
\f
(define (handle-objects start-offset)
(if *use-stackify?*
(define compiler:dump-info-file compiler:dump-bci-file)
\f
-;; This defintion exported to compiler to handle losing C name restrictions
+;; This definition exported to compiler to handle losing C name restrictions.
(define (canonicalize-label-name prefix)
(if (string-null? prefix)
"empty_string"
- (let* ((str (if (char-alphabetic? (string-ref prefix 0))
- (string-copy prefix)
- (string-append "Z_" prefix)))
- (len (string-length str)))
- (do ((i 0 (1+ i)))
- ((>= i len) str)
- (let ((char (string-ref str i)))
- (if (not (char-alphanumeric? char))
- (string-set! str i
- (case char
- ((#\?) #\P)
- ((#\!) #\B)
- (else #\_)))))))))
+ (string-map (lambda (char)
+ (if (char-alphanumeric? char)
+ char
+ (case char
+ ((#\?) #\P)
+ ((#\!) #\B)
+ (else #\_))))
+ (if (char-alphabetic? (string-ref prefix 0))
+ prefix
+ (string-append "Z_" prefix)))))
\ No newline at end of file
(length (string-list/length sl)))
(if (fix:< ptr (string-length current))
(begin
- (vector-8b-set! current ptr byte)
+ (string-set! current ptr (integer->char byte))
(set-string-list/pointer! sl (fix:+ ptr 1))
(set-string-list/length! sl (fix:+ length 1))
sl)
unspecific)))
(define (stackify/c-quotify str)
- (let* ((len (string-length str))
- (res (make-string len)))
- (do ((i 0 (1+ i)))
- ((>= i len) res)
- (let ((c (string-ref str i)))
- (case c
- ((#\*)
- (string-set! res i #\S))
- ((#\- #\/)
- (string-set! res i #\_))
- ((#\+)
- (string-set! res i #\P))
- (else
- (string-set! res i c)))))))
+ (string-map (lambda (c)
+ (case c
+ ((#\*) #\S)
+ ((#\- #\/) #\_)
+ ((#\+) #\P)
+ (else c)))
+ str))
(define (stackify/dump-c-enums output)
(with-output-to-file output