aboutsummaryrefslogtreecommitdiff
path: root/forth/forth/case.fs
blob: b50070f4fb676895c9c0a1386030f85b5ea887eb (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
\ *********************************************************************
\    Case for FlashForth                                              *
\    Filename:      case.txt                                          *
\    Date:          26.01.2014                                        *
\    FF Version:    5.0                                               *
\    Copyright:     Mikael Nordman                                    *
\    Author:        Mikael Nordman                                    *
\ *********************************************************************
\    FlashForth is licensed acording to the GNU General Public License*
\ *********************************************************************
\ A case implementation posted by Jenny Brien on c.l.f.
\ Modified to use for..next instead of do..loop

-case
marker -case
hex ram

\ of compare
: (of) ( n1 n2 -- n1 flag ) 
  inline over
  inline -
  0=
;

: case  (  -- #of )
  0
; immediate

: of  ( #of -- #of orig )  
    postpone (of)  ( copy and test case value)
    postpone if    ( add orig to control flow stack )
    postpone drop  ( discard case value if case is matching )
; immediate

: default ( #of -- #of orig )
  postpone true      ( Force to take the default branch )
  postpone if        ( add orig to control flow stack )
  postpone drop      ( discard case value )
; immediate

: endof ( orig1  -- orig2 #of )
   postpone else 
   swap 1+
; immediate

: endcase  ( orig1..orign #of  -- )
    postpone drop  ( discard case value )
    for
      postpone then ( resolve of branches )
    next
; immediate