xref: /titanic_52/usr/src/lib/efcode/fcode_test/loop.fth (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate\ #ident	"%Z%%M%	%I%	%E% SMI"
2*7c478bd9Sstevel@tonic-gate\ Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate\ Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate\
5*7c478bd9Sstevel@tonic-gate\ CDDL HEADER START
6*7c478bd9Sstevel@tonic-gate\
7*7c478bd9Sstevel@tonic-gate\ The contents of this file are subject to the terms of the
8*7c478bd9Sstevel@tonic-gate\ Common Development and Distribution License, Version 1.0 only
9*7c478bd9Sstevel@tonic-gate\ (the "License").  You may not use this file except in compliance
10*7c478bd9Sstevel@tonic-gate\ with the License.
11*7c478bd9Sstevel@tonic-gate\
12*7c478bd9Sstevel@tonic-gate\ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13*7c478bd9Sstevel@tonic-gate\ or http://www.opensolaris.org/os/licensing.
14*7c478bd9Sstevel@tonic-gate\ See the License for the specific language governing permissions
15*7c478bd9Sstevel@tonic-gate\ and limitations under the License.
16*7c478bd9Sstevel@tonic-gate\
17*7c478bd9Sstevel@tonic-gate\ When distributing Covered Code, include this CDDL HEADER in each
18*7c478bd9Sstevel@tonic-gate\ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19*7c478bd9Sstevel@tonic-gate\ If applicable, add the following below this CDDL HEADER, with the
20*7c478bd9Sstevel@tonic-gate\ fields enclosed by brackets "[]" replaced with your own identifying
21*7c478bd9Sstevel@tonic-gate\ information: Portions Copyright [yyyy] [name of copyright owner]
22*7c478bd9Sstevel@tonic-gate\
23*7c478bd9Sstevel@tonic-gate\ CDDL HEADER END
24*7c478bd9Sstevel@tonic-gate\
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate." Interactive begin .. while .. repeat: "
27*7c478bd9Sstevel@tonic-gate	" no loop (1) "		1 begin 0 while 1- repeat .passed?
28*7c478bd9Sstevel@tonic-gate	" loop to 0 (1)"	9 begin dup while 1- repeat  0= .passed?
29*7c478bd9Sstevel@tonic-gatecr
30*7c478bd9Sstevel@tonic-gate." Compiled begin .. while .. repeat: "
31*7c478bd9Sstevel@tonic-gate	: btest1		1 begin 0 while 1- repeat .passed? ;
32*7c478bd9Sstevel@tonic-gate	: btest2		9 begin dup while 1- repeat 0= .passed? ;
33*7c478bd9Sstevel@tonic-gate	" no loop (2) "		btest1
34*7c478bd9Sstevel@tonic-gate	" loop to 0 (2)"	btest2
35*7c478bd9Sstevel@tonic-gatecr
36*7c478bd9Sstevel@tonic-gate." Interactive begin..until: "
37*7c478bd9Sstevel@tonic-gate	" no loop (3)"		1 begin  dup until .passed?
38*7c478bd9Sstevel@tonic-gate	" loop to 0 (3)"	9 begin  1- dup 0= until 0= .passed?
39*7c478bd9Sstevel@tonic-gatecr
40*7c478bd9Sstevel@tonic-gate." Compiled begin..until: "
41*7c478bd9Sstevel@tonic-gate	: btest3		1 begin  dup until .passed? ;
42*7c478bd9Sstevel@tonic-gate	: btest4		9 begin  1- dup 0= until 0= .passed? ;
43*7c478bd9Sstevel@tonic-gate	" no loop (4)"		btest3
44*7c478bd9Sstevel@tonic-gate	" loop to 0 (4)"	btest4
45*7c478bd9Sstevel@tonic-gatecr
46*7c478bd9Sstevel@tonic-gate." Interactive do .. loop: "
47*7c478bd9Sstevel@tonic-gate	" loop (1)"	0 h# 10 0 do drop i loop h# f = .passed?
48*7c478bd9Sstevel@tonic-gate	" no loop (1)"	1 0 0 ?do 1- loop .passed?
49*7c478bd9Sstevel@tonic-gate	" leave (1)"	h# 10 0 do i 5 = if 1 leave drop 0 then loop .passed?
50*7c478bd9Sstevel@tonic-gatecr
51*7c478bd9Sstevel@tonic-gate." Compiled do .. loop: "
52*7c478bd9Sstevel@tonic-gate	: loop1			do drop i loop h# f = .passed? ;
53*7c478bd9Sstevel@tonic-gate	: loop2			?do 1- loop .passed? ;
54*7c478bd9Sstevel@tonic-gate	: loop3			do i 3 = if drop i leave 0 then loop ;
55*7c478bd9Sstevel@tonic-gate	: loop7			do i 4 = if drop i unloop exit then loop ;
56*7c478bd9Sstevel@tonic-gate	" loop (2)"		0 h# 10 0 loop1
57*7c478bd9Sstevel@tonic-gate	" no loop (2)"		1 0 0 loop2
58*7c478bd9Sstevel@tonic-gate	" leave (2)"		3 4 0 loop3 3 = .passed?
59*7c478bd9Sstevel@tonic-gate	" unloop"		5 6 0 loop7 4 = .passed?
60*7c478bd9Sstevel@tonic-gatecr
61*7c478bd9Sstevel@tonic-gate." Interactive do .. +loop: "
62*7c478bd9Sstevel@tonic-gate	" loop by 2"		0 h# 10 0 do drop i 2 +loop h# e = .passed?
63*7c478bd9Sstevel@tonic-gate	" loop down by 2"	0 -2 h# 10 do drop i -2 +loop h# -2 = .passed?
64*7c478bd9Sstevel@tonic-gatecr
65*7c478bd9Sstevel@tonic-gate." Compiled do .. +loop: "
66*7c478bd9Sstevel@tonic-gate	: loop4			0 h# 10  0 do drop i 2 +loop h# e = .passed? ;
67*7c478bd9Sstevel@tonic-gate	: loop5			0 -2 h# 10 do drop i -2 +loop -2 = .passed? ;
68*7c478bd9Sstevel@tonic-gate	" loop (4)"		loop4
69*7c478bd9Sstevel@tonic-gate	" loop (5)"		loop5
70*7c478bd9Sstevel@tonic-gatecr
71*7c478bd9Sstevel@tonic-gate." Nested loops: "
72*7c478bd9Sstevel@tonic-gate	: loop6		0 h# 4 0 do 8 0 do 1 j 3 lshift i + lshift xor loop loop ;
73*7c478bd9Sstevel@tonic-gate	" i,j sum"		loop6 lwsplit over = swap h# ffff = and .passed?
74*7c478bd9Sstevel@tonic-gatecr
75*7c478bd9Sstevel@tonic-gate." Negative Limit Loops: "
76*7c478bd9Sstevel@tonic-gate	" loop.7"       h# 10 -37 8 bounds do drop i loop -30 = .passed?
77*7c478bd9Sstevel@tonic-gate	" loop.8"       h# 10 -37 -30 do drop i -1 +loop  -37 = .passed?
78*7c478bd9Sstevel@tonic-gatecr
79*7c478bd9Sstevel@tonic-gate." Compiled begin...again: "
80*7c478bd9Sstevel@tonic-gate	: loop9 begin true exit again false ; loop9 " loop9" rot .passed?
81*7c478bd9Sstevel@tonic-gate	0 value in-count
82*7c478bd9Sstevel@tonic-gate	0 value out-count
83*7c478bd9Sstevel@tonic-gate	: loop10
84*7c478bd9Sstevel@tonic-gate	   begin
85*7c478bd9Sstevel@tonic-gate	      out-count 1+ to out-count
86*7c478bd9Sstevel@tonic-gate 	      begin
87*7c478bd9Sstevel@tonic-gate	         in-count 10 >= if
88*7c478bd9Sstevel@tonic-gate	            exit
89*7c478bd9Sstevel@tonic-gate	         then in-count 1+ to in-count
90*7c478bd9Sstevel@tonic-gate	      again
91*7c478bd9Sstevel@tonic-gate	      -1 to in-count
92*7c478bd9Sstevel@tonic-gate	      exit
93*7c478bd9Sstevel@tonic-gate	   again
94*7c478bd9Sstevel@tonic-gate	   -2 to in-count
95*7c478bd9Sstevel@tonic-gate	;
96*7c478bd9Sstevel@tonic-gate	" loop.10" loop10 in-count 10 = out-count 1 = and  .passed?
97*7c478bd9Sstevel@tonic-gatecr
98