From 4db44cd23f57c41284debe0e196a9fb77f6c1b49 Mon Sep 17 00:00:00 2001
From: Slava Pestov <slava@slava-pestovs-macbook-pro.local>
Date: Tue, 30 Jun 2009 18:11:15 -0500
Subject: [PATCH] %dispatch: sometimes the generated sequence is one byte
 longer, so instead of hard-coding it, compute the right length

---
 basis/cpu/x86/32/32.factor | 4 +++-
 basis/cpu/x86/64/64.factor | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/basis/cpu/x86/32/32.factor b/basis/cpu/x86/32/32.factor
index e908f52952..86cd53712d 100755
--- a/basis/cpu/x86/32/32.factor
+++ b/basis/cpu/x86/32/32.factor
@@ -30,12 +30,14 @@ M: x86.32 temp-reg-2 EDX ;
 M:: x86.32 %dispatch ( src temp -- )
     ! Load jump table base.
     temp src HEX: ffffffff [+] LEA
+    building get length cell - :> start
     0 rc-absolute-cell rel-here
     ! Go
     temp HEX: 7f [+] JMP
+    building get length :> end
     ! Fix up the displacement above
     cell code-alignment
-    [ 7 + building get dup pop* push ]
+    [ end start - + building get dup pop* push ]
     [ align-code ]
     bi ;
 
diff --git a/basis/cpu/x86/64/64.factor b/basis/cpu/x86/64/64.factor
index 2c8fb3f18f..5390d7e0c8 100644
--- a/basis/cpu/x86/64/64.factor
+++ b/basis/cpu/x86/64/64.factor
@@ -23,15 +23,17 @@ M: x86.64 rs-reg R15 ;
 M: x86.64 stack-reg RSP ;
 
 M:: x86.64 %dispatch ( src temp -- )
+    building get length :> start
     ! Load jump table base.
     temp HEX: ffffffff MOV
     0 rc-absolute-cell rel-here
     ! Add jump table base
     temp src ADD
     temp HEX: 7f [+] JMP
+    building get length :> end
     ! Fix up the displacement above
     cell code-alignment
-    [ 15 + building get dup pop* push ]
+    [ end start - 2 - + building get dup pop* push ]
     [ align-code ]
     bi ;