diff --git a/module/language/assembly/compile-bytecode.scm b/module/language/assembly/compile-bytecode.scm index 5c0e11533..0423b96e1 100644 --- a/module/language/assembly/compile-bytecode.scm +++ b/module/language/assembly/compile-bytecode.scm @@ -50,8 +50,9 @@ (let ((start (port-position port))) (lambda () (+ address (- (port-position port) start))))) - (define (write-string s) - (put-bytevector port (string->utf8 s))) + (define (write-latin1-string s) + (write-loader-len (string-length s)) + (string-for-each (lambda (c) (write-byte (char->integer c))) s)) (define (write-int24-be x) (bytevector-s32-set! u32-bv 0 x (endianness big)) (put-bytevector port u32-bv 1 3)) @@ -68,9 +69,6 @@ (write-byte (ash len -16)) (write-byte (logand (ash len -8) 255)) (write-byte (logand len 255))) - (define (write-loader str) - (write-loader-len (string-length str)) - (write-string str)) (define (write-bytevector bv) (write-loader-len (bytevector-length bv)) (put-bytevector port bv)) @@ -103,10 +101,10 @@ ;; assembly)'. (write-bytecode meta port '() 0 #f))) ((make-char32 ,x) (write-uint32-be x)) - ((load-number ,str) (write-loader str)) - ((load-string ,str) (write-loader str)) + ((load-number ,str) (write-latin1-string str)) + ((load-string ,str) (write-latin1-string str)) ((load-wide-string ,str) (write-wide-string str)) - ((load-symbol ,str) (write-loader str)) + ((load-symbol ,str) (write-latin1-string str)) ((load-array ,bv) (write-bytevector bv)) ((br ,l) (write-break l)) ((br-if ,l) (write-break l)) diff --git a/test-suite/tests/asm-to-bytecode.test b/test-suite/tests/asm-to-bytecode.test index 6e89d860f..1f0163640 100644 --- a/test-suite/tests/asm-to-bytecode.test +++ b/test-suite/tests/asm-to-bytecode.test @@ -1,4 +1,4 @@ -;;;; test assembly to bytecode compilation -*- scheme -*- +;;;; Assembly to bytecode compilation -*- mode: scheme; coding: iso-8859-1; -*- ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -78,7 +78,10 @@ (comp-test '(load-symbol "foo") (vector 'load-symbol 0 0 3 (char->integer #\f) (char->integer #\o) (char->integer #\o))) - + + (comp-test '(load-string "æ") ;; a non-ASCII Latin-1 string + (vector 'load-string 0 0 1 230)) + (comp-test '(load-program () 3 #f (make-int8 3) (return)) #(load-program (uint32 3) ;; len