Use case instead of dispatch
parent
ce59673c12
commit
939d5bdbb0
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2007 Gavin Harrison
|
! Copyright (C) 2007 Gavin Harrison
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel math sequences kernel.private namespaces arrays io io.files
|
USING: kernel math sequences kernel.private namespaces arrays io
|
||||||
splitting io.binary math.functions vectors quotations sequences.private ;
|
io.files splitting io.binary math.functions vectors quotations
|
||||||
|
combinators ;
|
||||||
IN: icfp.2006
|
IN: icfp.2006
|
||||||
|
|
||||||
SYMBOL: regs
|
SYMBOL: regs
|
||||||
|
@ -9,10 +10,6 @@ SYMBOL: arrays
|
||||||
SYMBOL: finger
|
SYMBOL: finger
|
||||||
SYMBOL: open-arrays
|
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 ;
|
: reg-val ( m -- n ) regs get nth ;
|
||||||
|
|
||||||
: set-reg ( val n -- ) regs get set-nth ;
|
: set-reg ( val n -- ) regs get set-nth ;
|
||||||
|
@ -117,11 +114,21 @@ SYMBOL: open-arrays
|
||||||
: run-op ( -- bool )
|
: run-op ( -- bool )
|
||||||
advance
|
advance
|
||||||
{
|
{
|
||||||
[ op0 ] [ op1 ] [ op2 ] [ op3 ]
|
{ 0 [ op0 ] }
|
||||||
[ op4 ] [ op5 ] [ op6 ] [ drop t ]
|
{ 1 [ op1 ] }
|
||||||
[ op8 ] [ op9 ] [ op10 ] [ op11 ]
|
{ 2 [ op2 ] }
|
||||||
[ op12 ] [ op13 ]
|
{ 3 [ op3 ] }
|
||||||
} call-nth ;
|
{ 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 -- )
|
: exec-loop ( bool -- )
|
||||||
[ run-op exec-loop ] unless ;
|
[ run-op exec-loop ] unless ;
|
||||||
|
|
Loading…
Reference in New Issue