Implement support for converting legacy strings to bytevectors.
authorChris Hanson <org/chris-hanson/cph>
Mon, 9 Jan 2017 03:34:07 +0000 (19:34 -0800)
committerChris Hanson <org/chris-hanson/cph>
Mon, 9 Jan 2017 03:34:07 +0000 (19:34 -0800)
src/runtime/bytevector.scm
src/runtime/predicate-metadata.scm
src/runtime/runtime.pkg
src/runtime/string.scm

index 281b862475520df723e4cb7cd490375f2457cba7..23a439fb997d3ba031ff7851351ccd067b7e2ec7 100644 (file)
@@ -54,6 +54,16 @@ USA.
       (bytevector-u8-set! bytevector i (car bytes)))
     bytevector))
 
+(define (legacy-string->bytevector string)
+  (if (bytevector? string)
+      string
+      (begin
+       (guarantee legacy-string? string 'legacy-string->bytevector)
+       (object-new-type bytevector-type string))))
+
+;;; TODO(cph): eliminate after 9.3 release:
+(define-integrable bytevector-type #x33)
+
 (define (bytevector-append . bytevectors)
   (let* ((k
          (do ((bytevectors bytevectors (cdr bytevectors))
index ab66b660bed4962ad344865910731400bcd65e26..d26dcf342368875112059b36b01e421623de6bfe 100644 (file)
@@ -308,6 +308,7 @@ USA.
    (register-predicate! interned-symbol? 'interned-symbol '<= symbol?)
    (register-predicate! keyword? 'keyword '<= symbol?)
    (register-predicate! lambda-tag? 'lambda-tag)
+   (register-predicate! legacy-string? 'legacy-string)
    (register-predicate! named-structure? 'named-structure)
    (register-predicate! population? 'population)
    (register-predicate! promise? 'promise)
index 1eb46e7e71aba989e64caf7f9322ce636b62dcdc..1125727b6abca23c5c71666065dc906c74f38094 100644 (file)
@@ -969,6 +969,7 @@ USA.
          guarantee-substring-start-index
          guarantee-xstring
          hexadecimal->vector-8b
+         legacy-string?
          lisp-string->camel-case
          list->string
          make-string
@@ -1127,6 +1128,7 @@ USA.
          bytevector-u8-set!
          bytevector=?
          bytevector?
+         legacy-string->bytevector
          make-bytevector
          string->utf8
          utf8->string))
index 7e9e6b03c084e14781d1a40173e29dbc658d3675..6293b9fce4313495e652ee59c561294a6e444c76 100644 (file)
@@ -43,6 +43,7 @@ USA.
 ;;;; Primitives
 
 (define-primitives
+  (legacy-string? string? 1)
   (set-string-length! 2)
   (string-allocate 1)
   (string-hash-mod 2)