aboutsummaryrefslogtreecommitdiff
path: root/forth/forth/case.fs
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-09-29 01:02:00 +0200
committerDimitri Sokolyuk <demon@dim13.org>2018-09-29 01:02:00 +0200
commit79cabd5b1c8bcd9f50dc49e77776e713a57dff48 (patch)
tree6eb73857e9c174610839291cf05a02d77fc82b8c /forth/forth/case.fs
parent247df3bb9d4c89d4e5ff18dcc23ba1c9532f28c0 (diff)
parent110a6411bae421260476eacf6173897c1d1f4b8a (diff)
Merge branch 'master' of dim13.org:elegoo
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
+