]> gitweb.factorcode.org Git - factor.git/commitdiff
Use case instead of dispatch
authorSlava Pestov <slava@factorcode.org>
Thu, 14 Feb 2008 07:06:27 +0000 (01:06 -0600)
committerSlava Pestov <slava@factorcode.org>
Thu, 14 Feb 2008 07:06:27 +0000 (01:06 -0600)
extra/icfp/2006/2006.factor

index 2a35ed08f8f985f77334b4633ea89f6a8eeb2428..ae0e058490155eb823ed3de824ac06a153ecf034 100755 (executable)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2007 Gavin Harrison
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math sequences kernel.private namespaces arrays io io.files
-    splitting io.binary math.functions vectors quotations sequences.private ;
+USING: kernel math sequences kernel.private namespaces arrays io
+io.files splitting io.binary math.functions vectors quotations
+combinators ;
 IN: icfp.2006
 
 SYMBOL: regs
@@ -9,10 +10,6 @@ SYMBOL: arrays
 SYMBOL: finger
 SYMBOL: open-arrays
 
-: call-nth ( n array -- )
-    >r >fixnum r> 2dup nth quotation?
-    [ dispatch ] [ "Not a quotation" throw ] if ; inline
-
 : reg-val ( m -- n ) regs get nth ;
 
 : set-reg ( val n -- ) regs get set-nth ;
@@ -117,11 +114,21 @@ SYMBOL: open-arrays
 : run-op ( -- bool )
     advance
     {
-        [ op0 ] [ op1 ] [ op2 ] [ op3 ]
-        [ op4 ] [ op5 ] [ op6 ] [ drop t ]
-        [ op8 ] [ op9 ] [ op10 ] [ op11 ]
-        [ op12 ] [ op13 ]
-    } call-nth ;
+        { 0 [ op0 ] }
+        { 1 [ op1 ] }
+        { 2 [ op2 ] }
+        { 3 [ op3 ] }
+        { 4 [ op4 ] }
+        { 5 [ op5 ] }
+        { 6 [ op6 ] }
+        { 7 [ drop t ] }
+        { 8 [ op8 ] }
+        { 9 [ op9 ] }
+        { 10 [ op10 ] }
+        { 11 [ op11 ] }
+        { 12 [ op12 ] }
+        { 13 [ op13 ] }
+    } case ;
 
 : exec-loop ( bool -- )
     [ run-op exec-loop ] unless ;