From 2f83a0bea9da444e3d70569eba3d6847ca02be03 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 21 Sep 2018 21:59:17 +0200 Subject: ... --- forth/forth/case.fs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 forth/forth/case.fs (limited to 'forth/forth/case.fs') 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 + -- cgit v1.2.3