Closed gambiteer closed 6 years ago
Here is an improved patch (doesn't depend on default setting of built gambit):
firefly:~/programs/r7rs-benchmarks> git diff src/GambitC-prelude.scm
diff --git a/src/GambitC-prelude.scm b/src/GambitC-prelude.scm
index 51ffde0..09e7e64 100644
--- a/src/GambitC-prelude.scm
+++ b/src/GambitC-prelude.scm
@@ -35,6 +35,21 @@
(define write-string write)
(define (this-scheme-implementation-name) (string-append "gambitc-" (system-version-string)))
+
+(define (string->utf8 s)
+ (with-output-to-u8vector
+ (list char-encoding: 'UTF-8)
+ (lambda ()
+ (display s))))
+
+(define (utf8->string v)
+ (let ((p (open-input-u8vector (list char-encoding: 'UTF-8 init: v))))
+ (list->string (read-all p read-char))))
+
+(define make-bytevector make-u8vector)
+
+(define bytevector-u8-set! u8vector-set!)
+
;; TODO: load syntax-case here, to get syntax-rules.
;; google says (load "~~/syntax-case"), but that doesn't work on my machine :-/
This one uses Gambit's builtin functions better:
firefly:~/programs/r7rs-benchmarks> git diff src/GambitC-prelude.scm
diff --git a/src/GambitC-prelude.scm b/src/GambitC-prelude.scm
index 51ffde0..af07f2a 100644
--- a/src/GambitC-prelude.scm
+++ b/src/GambitC-prelude.scm
@@ -35,6 +35,25 @@
(define write-string write)
(define (this-scheme-implementation-name) (string-append "gambitc-" (system-version-string)))
+
+(define (string->utf8 s)
+ (with-output-to-u8vector
+ (list char-encoding: 'UTF-8)
+ (lambda ()
+ (display s))))
+
+(define (utf8->string bstr #!optional (enc 'UTF-8))
+ (let* ((in (open-input-u8vector `(char-encoding: ,enc init: ,bstr)))
+ (len (u8vector-length bstr))
+ (out (make-string len))
+ (n (read-substring out 0 len in)))
+ (string-shrink! out n)
+ out))
+
+(define make-bytevector make-u8vector)
+
+(define bytevector-u8-set! u8vector-set!)
+
;; TODO: load syntax-case here, to get syntax-rules.
;; google says (load "~~/syntax-case"), but that doesn't work on my machine :-/
I'm not sure that these lines in the femtolisp prelude:
are really true---are utf8-encoded strings really just byte-vectors in femtolisp? It does make the benchmark to faster, though!