Use case instead of dispatch
parent
ce59673c12
commit
939d5bdbb0
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue