/[eiffelstudio]/FreeELKS/trunk/library/kernel/routine.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/kernel/routine.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91477 - (show annotations)
Sun Jan 14 09:47:13 2007 UTC (13 years ago) by ericb
File size: 10119 byte(s)
Synchronized with ISE 6.0.65740
1 indexing
2 description: "[
3 Objects representing delayed calls to a routine,
4 with some operands possibly still open
5 ]"
6 library: "Free implementation of ELKS library"
7 copyright: "Copyright (c) 1986-2004, Eiffel Software and others"
8 license: "Eiffel Forum License v2 (see forum.txt)"
9 date: "$Date$"
10 revision: "$Revision$"
11
12 deferred class
13 ROUTINE [BASE_TYPE, OPEN_ARGS -> TUPLE create default_create end]
14
15 inherit
16 HASHABLE
17 redefine
18 copy,
19 is_equal
20 end
21
22 feature -- Initialization
23
24 adapt (other: like Current) is
25 -- Initialize from `other'.
26 -- Useful in descendants.
27 require
28 other_exists: other /= Void
29 conforming: conforms_to (other)
30 do
31 rout_disp := other.rout_disp
32 encaps_rout_disp := other.encaps_rout_disp
33 calc_rout_addr := other.calc_rout_addr
34 closed_operands := other.closed_operands
35 operands := other.operands
36 class_id := other.class_id
37 feature_id := other.feature_id
38 is_precompiled := other.is_precompiled
39 is_basic := other.is_basic
40 is_target_closed := other.is_target_closed
41 is_inline_agent := other.is_inline_agent
42 open_count := other.open_count
43 end
44
45 feature -- Access
46
47 frozen operands: OPEN_ARGS
48
49 target: ANY is
50 -- Target of call.
51 do
52 if is_target_closed then
53 Result := closed_operands.item (1)
54 elseif operands /= Void and then operands.count > 0 then
55 Result := operands.item (1)
56 end
57 end
58
59 hash_code: INTEGER is
60 -- Hash code value.
61 do
62 Result := rout_disp.hash_code.bit_xor (
63 class_id.hash_code).bit_xor (
64 feature_id.hash_code)
65 end
66
67 precondition (args: like operands): BOOLEAN is
68 -- Do `args' satisfy routine's precondition
69 -- in current state?
70 do
71 Result := True
72 --| FIXME compiler support needed!
73 end
74
75 postcondition (args: like operands): BOOLEAN is
76 -- Does current state satisfy routine's
77 -- postcondition for `args'?
78 do
79 Result := True
80 --| FIXME compiler support needed!
81 end
82
83 empty_operands: OPEN_ARGS is
84 -- Empty tuple matching open operands
85 do
86 create Result
87 ensure
88 empty_operands_not_void: Result /= Void
89 end
90
91 feature -- Status report
92
93 callable: BOOLEAN is True
94 -- Can routine be called on current object?
95
96 is_equal (other: like Current): BOOLEAN is
97 -- Is associated routine the same as the one
98 -- associated with `other'.
99 do
100 --| Do not compare implementation data
101 Result := equal (closed_operands, other.closed_operands)
102 and then equal (operands, other.operands)
103 and then equal (open_map, other.open_map)
104 and then (rout_disp = other.rout_disp)
105 and then (class_id = other.class_id)
106 and then (feature_id = other.feature_id)
107 and then (encaps_rout_disp = other.encaps_rout_disp)
108 and then (calc_rout_addr = other.calc_rout_addr)
109 end
110
111 valid_operands (args: OPEN_ARGS): BOOLEAN is
112 -- Are `args' valid operands for this routine?
113 local
114 i, arg_type_code: INTEGER
115 arg: ANY
116 int: INTERNAL
117 open_type_codes: STRING
118 do
119 create int
120 if args = Void then
121 -- Void operands are only allowed
122 -- if object has no open operands.
123 Result := (open_count = 0)
124 elseif int.generic_count (args) >= open_count then
125 from
126 Result := True
127 open_type_codes := eif_gen_typecode_str ($Current)
128 i := 1
129 until
130 i > open_count or not Result
131 loop
132 arg_type_code := args.item_code (i)
133 Result := arg_type_code = open_type_codes.item (i + 1).code
134 if Result and then arg_type_code = {TUPLE}.reference_code then
135 arg := args.item (i)
136 Result := arg = Void or else
137 int.type_conforms_to (int.dynamic_type (arg), open_operand_type (i))
138 end
139 i := i + 1
140 end
141 end
142 if Result and then not is_target_closed then
143 Result := args.item (1) /= Void
144 end
145 end
146
147 valid_target (args: TUPLE): BOOLEAN is
148 -- Is the first element of tuple `args' a valid target
149 do
150 if args /= Void and then args.count > 0 then
151 if args.is_reference_item (1) then
152 Result := args.reference_item (1) /= Void
153 else
154 Result := True
155 end
156 end
157 end
158
159 feature -- Measurement
160
161 open_count: INTEGER
162 -- Number of open operands.
163
164 feature -- Settings
165
166 frozen set_operands (args: OPEN_ARGS) is
167 -- Use `args' as operands for next call.
168 require
169 valid_operands: valid_operands (args)
170 do
171 operands := args
172 ensure
173 operands_set: (operands /= Void implies equal (operands, args)) or
174 (operands = Void implies (args = Void or else args.is_empty))
175 end
176
177 feature -- Duplication
178
179 copy (other: like Current) is
180 -- Use same routine as `other'.
181 do
182 open_map := other.open_map
183 rout_disp := other.rout_disp
184 calc_rout_addr := other.calc_rout_addr
185 encaps_rout_disp := other.encaps_rout_disp
186 class_id := other.class_id
187 feature_id := other.feature_id
188 is_precompiled := other.is_precompiled
189 is_basic := other.is_basic
190 is_target_closed := other.is_target_closed
191 is_inline_agent := other.is_inline_agent
192 closed_operands := other.closed_operands
193 open_count := other.open_count
194 ensure then
195 same_call_status: other.callable implies callable
196 end
197
198 feature -- Basic operations
199
200 call (args: OPEN_ARGS) is
201 -- Call routine with `args'.
202 require
203 valid_operands: valid_operands (args)
204 deferred
205 end
206
207 apply is
208 -- Call routine with `operands' as last set.
209 require
210 valid_operands: valid_operands (operands)
211 deferred
212 end
213
214 feature -- Obsolete
215
216 adapt_from (other: like Current) is
217 -- Adapt from `other'. Useful in descendants.
218 obsolete
219 "Please use `adapt' instead (it's also a creation procedure)"
220 require
221 other_exists: other /= Void
222 conforming: conforms_to (other)
223 do
224 adapt (other)
225 end
226
227 feature {ROUTINE} -- Implementation
228
229 frozen closed_operands: TUPLE
230 -- All closed arguments provided at creation time
231
232 closed_count: INTEGER is
233 -- The number of closed operands (including the target if it is closed)
234 do
235 if closed_operands /= Void then
236 Result := closed_operands.count
237 end
238 end
239
240 frozen rout_disp: POINTER
241 -- Routine dispatcher
242
243 frozen calc_rout_addr: POINTER
244 -- Address of the final routine
245
246 frozen open_map: SPECIAL [INTEGER]
247 -- Index map for open arguments
248
249 frozen encaps_rout_disp: POINTER
250 -- Eiffel routine dispatcher
251
252 frozen class_id: INTEGER
253
254 frozen feature_id: INTEGER
255
256 frozen is_precompiled: BOOLEAN
257
258 frozen is_basic: BOOLEAN
259
260 frozen is_target_closed: BOOLEAN
261
262 frozen is_inline_agent: BOOLEAN
263
264 frozen set_rout_disp (a_rout_disp, a_encaps_rout_disp, a_calc_rout_addr: POINTER
265 a_class_id, a_feature_id: INTEGER; a_open_map: SPECIAL [INTEGER]
266 a_is_precompiled, a_is_basic, a_is_target_closed, a_is_inline_agent: BOOLEAN
267 a_closed_operands: TUPLE; a_open_count: INTEGER) is
268 -- Initialize object.
269 require
270 target_valid: a_is_target_closed implies valid_target (a_closed_operands)
271 do
272 set_rout_disp_int (a_rout_disp, a_encaps_rout_disp, a_calc_rout_addr, a_class_id, a_feature_id,
273 a_open_map, a_is_precompiled, a_is_basic, a_is_target_closed,
274 a_is_inline_agent, a_closed_operands, a_open_count)
275 end
276
277 frozen set_rout_disp_final (a_rout_disp, a_encaps_rout_disp, a_calc_rout_addr: POINTER
278 a_closed_operands: TUPLE; a_is_target_closed: BOOLEAN; a_open_count: INTEGER) is
279 -- Initialize object.
280 do
281 rout_disp := a_rout_disp
282 encaps_rout_disp := a_encaps_rout_disp
283 calc_rout_addr := a_calc_rout_addr
284 closed_operands := a_closed_operands
285 is_target_closed := a_is_target_closed
286 open_count := a_open_count
287 end
288
289 frozen set_rout_disp_int (a_rout_disp, a_encaps_rout_disp, a_calc_rout_addr: POINTER
290 a_class_id, a_feature_id: INTEGER; a_open_map: SPECIAL [INTEGER]
291 a_is_precompiled, a_is_basic, a_is_target_closed, a_is_inline_agent: BOOLEAN
292 a_closed_operands: TUPLE; a_open_count: INTEGER) is
293 -- Initialize object.
294 require
295 a_class_id_valid: a_class_id > -1
296 a_feature_id_valid: a_feature_id > -1
297 do
298 rout_disp := a_rout_disp
299 encaps_rout_disp := a_encaps_rout_disp
300 calc_rout_addr := a_calc_rout_addr
301 class_id := a_class_id
302 feature_id := a_feature_id
303 open_map := a_open_map
304 is_precompiled := a_is_precompiled
305 is_basic := a_is_basic
306 is_target_closed := a_is_target_closed
307 is_inline_agent := a_is_inline_agent
308 closed_operands := a_closed_operands
309 open_count := a_open_count
310 ensure
311 rout_disp_set: rout_disp = a_rout_disp
312 encaps_rout_disp_set: encaps_rout_disp = a_encaps_rout_disp
313 calc_rout_addr_set: calc_rout_addr = a_calc_rout_addr
314 class_id_set: class_id = a_class_id
315 feature_id_set: feature_id = a_feature_id
316 open_map_set: open_map = a_open_map
317 is_target_closed_set: is_target_closed = a_is_target_closed
318 is_precompiled_set: is_precompiled = a_is_precompiled
319 is_basic_set: is_basic = a_is_basic
320 is_inline_agent_set: is_inline_agent = a_is_inline_agent
321 closed_operands_set: closed_operands = a_closed_operands
322 open_count_set: open_count = a_open_count
323 end
324
325 feature {NONE} -- Implementation
326
327 frozen open_types: ARRAY [INTEGER]
328 -- Types of open operands
329
330 open_operand_type (i: INTEGER): INTEGER is
331 -- Type of `i'th open operand.
332 require
333 positive: i >= 1
334 within_bounds: i <= open_count
335 local
336 l_internal: INTERNAL
337 do
338 if open_types = Void then
339 create open_types.make (1, open_count)
340 end
341 Result := open_types.item (i)
342 if Result = 0 then
343 create l_internal
344 Result := l_internal.generic_dynamic_type_of_type (
345 l_internal.generic_dynamic_type (Current, 2), i)
346 open_types.force (Result, i)
347 end
348 end
349
350 feature {NONE} -- Externals
351
352 eif_gen_typecode_str (obj: POINTER): STRING is
353 -- Code name for generic parameter `pos' in `obj'.
354 external
355 "C signature (EIF_REFERENCE): EIF_REFERENCE use %"eif_gen_conf.h%""
356 end
357
358 feature -- Obsolete
359
360 arguments: OPEN_ARGS is
361 obsolete
362 "use operands"
363 do
364 Result := operands
365 end
366
367 set_arguments (args: OPEN_ARGS) is
368 obsolete
369 "use set_operands"
370 do
371 set_operands (args)
372 end
373
374 valid_arguments (args: OPEN_ARGS): BOOLEAN is
375 obsolete
376 "use valid_operands"
377 do
378 Result := valid_operands (args)
379 end
380
381 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23