summaryrefslogtreecommitdiff
path: root/module/language/assembly
diff options
context:
space:
mode:
Diffstat (limited to 'module/language/assembly')
-rw-r--r--module/language/assembly/compile-bytecode.scm10
-rw-r--r--module/language/assembly/decompile-bytecode.scm3
2 files changed, 8 insertions, 5 deletions
diff --git a/module/language/assembly/compile-bytecode.scm b/module/language/assembly/compile-bytecode.scm
index 58afddde0..bf6c5f7b5 100644
--- a/module/language/assembly/compile-bytecode.scm
+++ b/module/language/assembly/compile-bytecode.scm
@@ -77,10 +77,12 @@
;; Ew!
(for-each write-byte (bytevector->u8-list bv)))
(define (write-break label)
- (let ((offset (- (assq-ref labels label) (+ (get-addr) 2))))
- (cond ((>= offset (ash 1 15)) (error "jump too big" offset))
- ((< offset (- (ash 1 15))) (error "reverse jump too big" offset))
- (else (write-uint16-be offset)))))
+ (let ((offset (- (assq-ref labels label)
+ (logand (+ (get-addr) 2) (lognot #x7)))))
+ (cond ((not (= 0 (modulo offset 8))) (error "unaligned jump" offset))
+ ((>= offset (ash 1 18)) (error "jump too far forward" offset))
+ ((< offset (- (ash 1 18))) (error "jump too far backwards" offset))
+ (else (write-uint16-be (ash offset -3))))))
(let ((inst (car asm))
(args (cdr asm))
diff --git a/module/language/assembly/decompile-bytecode.scm b/module/language/assembly/decompile-bytecode.scm
index 82459fc6f..0e34ab4a2 100644
--- a/module/language/assembly/decompile-bytecode.scm
+++ b/module/language/assembly/decompile-bytecode.scm
@@ -61,7 +61,8 @@
(labels '())
(i 0))
(define (ensure-label rel1 rel2)
- (let ((where (+ i (bytes->s16 rel1 rel2))))
+ (let ((where (+ (logand i (lognot #x7))
+ (* (bytes->s16 rel1 rel2) 8))))
(or (assv-ref labels where)
(begin
(let ((l (gensym ":L")))