1 /* Part of XPCE --- The SWI-Prolog GUI toolkit
2
3 Author: Jan Wielemaker and Anjo Anjewierden
4 E-mail: jan@swi.psy.uva.nl
5 WWW: http://www.swi.psy.uva.nl/projects/xpce/
6 Copyright (c) 1985-2002, University of Amsterdam
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12
13 1. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in
18 the documentation and/or other materials provided with the
19 distribution.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <h/kernel.h>
36
37
38 static status
initialiseWhile(While w,Code cond,Code body)39 initialiseWhile(While w, Code cond, Code body)
40 { initialiseCode((Code) w);
41
42 if ( isDefault(body) )
43 body = NIL;
44
45 assign(w, condition, cond);
46 assign(w, body, body);
47
48 succeed;
49 }
50
51
52 static status
ExecuteWhile(While w)53 ExecuteWhile(While w)
54 { while ( executeCode(w->condition) )
55 { if ( notNil(w->body) )
56 { TRY( executeCode(w->body) );
57 }
58 }
59
60 succeed;
61 }
62
63
64 /*******************************
65 * CLASS DECLARATION *
66 *******************************/
67
68 /* Type declarations */
69
70 static char *T_initialise[] =
71 { "condition=code", "statement=[code]*" };
72
73 /* Instance Variables */
74
75 static vardecl var_while[] =
76 { IV(NAME_condition, "code", IV_BOTH,
77 NAME_statement, "Condition to be tested"),
78 IV(NAME_body, "code*", IV_BOTH,
79 NAME_statement, "Statement to execute")
80 };
81
82 /* Send Methods */
83
84 static senddecl send_while[] =
85 { SM(NAME_Execute, 0, NULL, ExecuteWhile,
86 DEFAULT, "Execute body until test fails"),
87 SM(NAME_initialise, 2, T_initialise, initialiseWhile,
88 DEFAULT, "Create from condition and statement")
89 };
90
91 /* Get Methods */
92
93 #define get_while NULL
94 /*
95 static getdecl get_while[] =
96 {
97 };
98 */
99
100 /* Resources */
101
102 #define rc_while NULL
103 /*
104 static classvardecl rc_while[] =
105 {
106 };
107 */
108
109 /* Class Declaration */
110
111 static Name while_termnames[] = { NAME_condition, NAME_body };
112
113 ClassDecl(while_decls,
114 var_while, send_while, get_while, rc_while,
115 2, while_termnames,
116 "$Rev$");
117
118 status
makeClassWhile(Class class)119 makeClassWhile(Class class)
120 { return declareClass(class, &while_decls);
121 }
122
123
124
125