1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-18 17:50:29 +02:00

Change `write-bytecode' to accept a bytevector.

* module/language/assembly/compile-bytecode.scm (write-bytecode):
  Replace the WRITE-BYTE and GET-ADDR parameters with PORT.  New ADDRESS
  and EMIT-OPCODE? parameters.  Callers updated.
  [write-byte, get-addr]: New procedures.
  Adjust to write to PORT.
  (compile-bytecode): Update accordingly.

* test-suite/tests/asm-to-bytecode.test (munge-bytecode): Return a
  bytevector instead of a u8vector.
  (comp-test): Deal with bytevectors.
This commit is contained in:
Ludovic Courtès 2010-02-05 11:11:56 +01:00
parent 0c368d2b28
commit bde92e6b3b
2 changed files with 41 additions and 38 deletions

View file

@ -16,6 +16,7 @@
(define-module (test-suite tests asm-to-bytecode)
#:use-module (rnrs bytevector)
#:use-module ((rnrs io ports) #:select (open-bytevector-output-port))
#:use-module (test-suite lib)
#:use-module (system vm instruction)
#:use-module (language assembly compile-bytecode))
@ -32,7 +33,7 @@
(define (munge-bytecode v)
(let lp ((i 0) (out '()))
(if (= i (vector-length v))
(list->u8vector (reverse out))
(u8-list->bytevector (reverse out))
(let ((x (vector-ref v i)))
(cond
((symbol? x)
@ -44,16 +45,17 @@
(else (error "bad test bytecode" x)))))))
(define (comp-test x y)
(let* ((y (munge-bytecode y))
(len (u8vector-length y))
(v (make-u8vector len))
(i 0))
(define (write-byte b) (u8vector-set! v i b) (set! i (1+ i)))
(define (get-addr) i)
(let* ((y (munge-bytecode y))
(len (bytevector-length y))
(v #f))
(run-test `(length ,x) #t
(lambda ()
(write-bytecode x write-byte get-addr '())
(= i len)))
(call-with-values open-bytevector-output-port
(lambda (port get-bytevector)
(write-bytecode x port '() 0 #t)
(set! v (get-bytevector))
(= (bytevector-length v) len)))))
(run-test `(compile-equal? ,x ,y) #t
(lambda ()
(equal? v y)))))