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
initialiseAssignment(Assignment b,Var var,Any value,Name scope)39 initialiseAssignment(Assignment b, Var var, Any value, Name scope)
40 { initialiseCode((Code) b);
41 
42   if ( isDefault(scope) )
43     scope = NAME_local;
44 
45   assign(b, var,   var);
46   assign(b, value, value);
47   assign(b, scope, scope);
48 
49   succeed;
50 }
51 
52 
53 static status
ExecuteAssignment(Assignment b)54 ExecuteAssignment(Assignment b)
55 { Any val;
56 
57   TRY(val = expandCodeArgument(b->value));
58   return assignVar(b->var, val, b->scope);
59 }
60 
61 
62 		 /*******************************
63 		 *	 CLASS DECLARATION	*
64 		 *******************************/
65 
66 /* Type declarations */
67 
68 static char *T_initialise[] =
69         { "variable=var", "value=any|function", "scope=[{local,outer,global}]" };
70 
71 /* Instance Variables */
72 
73 static vardecl var_assign[] =
74 { IV(NAME_var, "var", IV_BOTH,
75      NAME_storage, "Variable to be bound"),
76   IV(NAME_value, "any|function", IV_BOTH,
77      NAME_storage, "Value to give to the assignment"),
78   IV(NAME_scope, "{local,outer,global}", IV_BOTH,
79      NAME_scope, "Scope of assignment")
80 };
81 
82 /* Send Methods */
83 
84 static senddecl send_assign[] =
85 { SM(NAME_Execute, 0, NULL, ExecuteAssignment,
86      DEFAULT, "Bind the variable"),
87   SM(NAME_initialise, 3, T_initialise, initialiseAssignment,
88      DEFAULT, "Create assignment from var and value")
89 };
90 
91 /* Get Methods */
92 
93 #define get_assign NULL
94 /*
95 static getdecl get_assign[] =
96 {
97 };
98 */
99 
100 /* Resources */
101 
102 #define rc_assign NULL
103 /*
104 static classvardecl rc_assign[] =
105 {
106 };
107 */
108 
109 /* Class Declaration */
110 
111 static Name assign_termnames[] = { NAME_var, NAME_value, NAME_scope };
112 
113 ClassDecl(assign_decls,
114           var_assign, send_assign, get_assign, rc_assign,
115           3, assign_termnames,
116           "$Rev$");
117 
118 status
makeClassAssign(Class class)119 makeClassAssign(Class class)
120 { return declareClass(class, &assign_decls);
121 }
122 
123