aboutsummaryrefslogtreecommitdiff
path: root/forth/forth/case.fs
diff options
context:
space:
mode:
Diffstat (limited to 'forth/forth/case.fs')
-rw-r--r--forth/forth/case.fs52
1 files changed, 52 insertions, 0 deletions
diff --git a/forth/forth/case.fs b/forth/forth/case.fs
new file mode 100644
index 0000000..b50070f
--- /dev/null
+++ b/forth/forth/case.fs
@@ -0,0 +1,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
+