diff options
Diffstat (limited to 'module/language/assembly')
-rw-r--r-- | module/language/assembly/compile-bytecode.scm | 19 | ||||
-rw-r--r-- | module/language/assembly/decompile-bytecode.scm | 27 |
2 files changed, 15 insertions, 31 deletions
diff --git a/module/language/assembly/compile-bytecode.scm b/module/language/assembly/compile-bytecode.scm index 840c73b3a..c49c20081 100644 --- a/module/language/assembly/compile-bytecode.scm +++ b/module/language/assembly/compile-bytecode.scm @@ -65,11 +65,13 @@ (write-byte (logand (ash x -8) 255)) (write-byte (logand (ash x -16) 255)) (write-byte (logand (ash x -24) 255))) - (define (write-uint32 x) (case byte-order - ((1234) (write-uint32-le x)) - ((4321) (write-uint32-be x)) - (else (error "unknown endianness" byte-order)))) + (define (write-uint32 x) + (case byte-order + ((1234) (write-uint32-le x)) + ((4321) (write-uint32-be x)) + (else (error "unknown endianness" byte-order)))) (define (write-wide-string s) + (write-loader-len (* 4 (string-length s))) (string-for-each (lambda (c) (write-uint32 (char->integer c))) s)) (define (write-loader-len len) (write-byte (ash len -16)) @@ -133,14 +135,11 @@ ;; `scm_c_make_objcode_slice ()'. (write-bytecode meta write get-addr '())))) ((make-char32 ,x) (write-uint32-be x)) - ((load-unsigned-integer ,str) (write-loader str)) - ((load-integer ,str) (write-loader str)) ((load-number ,str) (write-loader str)) - ((load-string ,str) (write-sized-loader str)) - ((load-symbol ,str) (write-sized-loader str)) - ((load-keyword ,str) (write-sized-loader str)) + ((load-string ,str) (write-loader str)) + ((load-wide-string ,str) (write-wide-string str)) + ((load-symbol ,str) (write-loader str)) ((load-array ,bv) (write-bytevector bv)) - ((define ,str) (write-sized-loader str)) ((br ,l) (write-break l)) ((br-if ,l) (write-break l)) ((br-if-not ,l) (write-break l)) diff --git a/module/language/assembly/decompile-bytecode.scm b/module/language/assembly/decompile-bytecode.scm index a05db537d..8cdebcfd0 100644 --- a/module/language/assembly/decompile-bytecode.scm +++ b/module/language/assembly/decompile-bytecode.scm @@ -96,16 +96,6 @@ (lp (cons exp out)))))))))) (define (decode-bytecode pop) - (define (get1 bytes-per-char) - (if (= bytes-per-char 1) - (pop) - (let* ((a (pop)) - (b (pop)) - (c (pop)) - (d (pop))) - (if (= byte-order 1234) - (+ (ash d 24) (ash c 16) (ash b 8) a) - (+ (ash a 24) (ash b 16) (ash c 8) d))))) (and=> (pop) (lambda (opcode) (let ((inst (opcode->instruction opcode))) @@ -117,29 +107,24 @@ ;; the negative length indicates a variable length ;; instruction (let* ((make-sequence - (if (eq? inst 'load-array) + (if (or (memq inst '(load-array load-wide-string))) make-bytevector make-string)) (sequence-set! - (if (eq? inst 'load-array) + (if (or (memq inst '(load-array load-wide-string))) bytevector-u8-set! (lambda (str pos value) (string-set! str pos (integer->char value))))) (len (let* ((a (pop)) (b (pop)) (c (pop))) (+ (ash a 16) (ash b 8) c))) - (bytes-per-count - (if (or (eq? inst 'load-string) - (eq? inst 'load-symbol) - (eq? inst 'load-keyword) - (eq? inst 'define)) - (pop) - 1)) (seq (make-sequence len))) (let lp ((i 0)) (if (= i len) - `(,inst ,seq) + `(,inst ,(if (eq? inst 'load-wide-string) + (utf32->string seq) + seq)) (begin - (sequence-set! seq i (get1 bytes-per-count)) + (sequence-set! seq i (pop)) (lp (1+ i))))))) (else ;; fixed length |