aboutsummaryrefslogtreecommitdiff
path: root/forth/forth/jmptbl-test.fs
blob: a49b1d9eabc623181eea35ed80b693cd56f0606d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
\ *********************************************************************
\                                                                     *
\    Filename:      jmptbl-test.txt                                   *
\    FlashForth:    5.0                                               *
\                                                                     *
\    Author:        Pete Zawasky                                      *
\    Created:       Tuesday, January 15 2008 - 18:50  ppz             *
\    Last Edit      Tuesday, January 29 2008 - 12:25  ppz             *
\                                                                     *
\ *********************************************************************
\  Based on jt.fth by Mikael Nordman, Jump_Table by Haskell           *
\ *********************************************************************
\  FlashForth is licensed acording to the GNU General Public License  *
\ *********************************************************************

hex

\ Create an execution table with n entries.
\ Each entry consists of 'nn' cell sized comparison value
\   and 'an' the address of the corresponding word to be executed.
\ At least two entries must be provided, the last one being the
\   default action.
\
\ Jump Table (from Haskell)
\ Example:
\
\    JUMP_TABLE do.key
\               control H  |  bkspace
\               control Q  |  quit
\               HEX 2B     |  escape  DECIMAL
\               DEFAULT    |  chrout
\ Useage:
\    do.key  ( n -- )   \ enter with n=code-to-match on TOS
\

\ *********************************************************************
hex ram

: .1st    ( -- )
  ." First "
;

: .2nd    ( -- )
  ." Second "
;

: .3rd    ( -- )
  ." Third "
;

: .4th    ( -- )
  ." Default "
;

jumptable do_test
          $00    | .1st
          $01    | .2nd
          $02    | .3rd
          default| .4th

ram
1 do_test
2 do_test
9 do_test

\ 1 do_test Second ok <16,2>
\ 2 do_test Third ok <16,2>
\ 9 do_test Default ok <16,2>