PageRenderTime 22ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/interpreter/liberty_interpreter_agent.e

http://github.com/tybor/Liberty
Specman e | 235 lines | 191 code | 24 blank | 20 comment | 6 complexity | 3504980637fa2cdbe674f687a3c04e66 MD5 | raw file
  1-- This file is part of Liberty Eiffel.
  2--
  3-- Liberty Eiffel is free software: you can redistribute it and/or modify
  4-- it under the terms of the GNU General Public License as published by
  5-- the Free Software Foundation, version 3 of the License.
  6--
  7-- Liberty Eiffel is distributed in the hope that it will be useful,
  8-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 10-- GNU General Public License for more details.
 11--
 12-- You should have received a copy of the GNU General Public License
 13-- along with Liberty Eiffel.  If not, see <http://www.gnu.org/licenses/>.
 14--
 15class LIBERTY_INTERPRETER_AGENT
 16
 17inherit
 18   LIBERTY_INTERPRETER_OBJECT
 19
 20creation {LIBERTY_INTERPRETER_OBJECT_CREATOR}
 21   make
 22
 23feature {ANY}
 24   type: LIBERTY_ACTUAL_TYPE
 25   call: LIBERTY_CALL_EXPRESSION
 26   arguments: TRAVERSABLE[LIBERTY_INTERPRETER_OBJECT]
 27   creation_target: LIBERTY_INTERPRETER_OBJECT
 28
 29   hash_code: INTEGER is
 30      do
 31         Result := to_pointer.hash_code
 32      end
 33
 34   is_equal (other: LIBERTY_INTERPRETER_OBJECT): BOOLEAN is
 35      do
 36         Result := other = Current
 37      end
 38
 39   converted_to (target_type: LIBERTY_ACTUAL_TYPE): LIBERTY_INTERPRETER_OBJECT is
 40      do
 41         not_yet_implemented
 42      end
 43
 44feature {LIBERTY_INTERPRETER}
 45   set_call (a_target: like creation_target; a_call: like call; args: like arguments) is
 46      require
 47         call = Void
 48         a_call.is_agent_call
 49         args.count = a_call.actuals.count
 50      do
 51         if a_call.target = Void then
 52            creation_target := a_target
 53         else
 54            a_call.target.accept(interpreter.expressions)
 55            creation_target := interpreter.expressions.eval_as_target
 56         end
 57         call := a_call
 58         arguments := args
 59      ensure
 60         call = a_call
 61         arguments = args
 62      end
 63
 64feature {LIBERTY_INTERPRETER_EXTERNAL_TYPE_FUNCTION_BUILTINS}
 65   item_agent (parameters: TRAVERSABLE[LIBERTY_INTERPRETER_OBJECT]; call_position: LIBERTY_POSITION): LIBERTY_INTERPRETER_OBJECT is
 66      local
 67         target, real_target: LIBERTY_INTERPRETER_OBJECT
 68         args: TRAVERSABLE[LIBERTY_INTERPRETER_OBJECT]
 69      do
 70         if call.target = Void then
 71            real_target := creation_target
 72            args := unpack_tuple_and_closed(parameters, call_position, False)
 73         else
 74            call.target.accept(interpreter.expressions)
 75            target := interpreter.expressions.eval_as_target
 76            real_target := unpack_target(target, parameters, call_position)
 77            args := unpack_tuple_and_closed(parameters, call_position, target.is_open)
 78         end
 79         Result := interpreter.item_feature(real_target, call.entity.feature_definition, args, call_position)
 80      end
 81
 82feature {LIBERTY_INTERPRETER_EXTERNAL_TYPE_ROUTINE_BUILTINS}
 83   call_agent (parameters: TRAVERSABLE[LIBERTY_INTERPRETER_OBJECT]; call_position: LIBERTY_POSITION) is
 84      local
 85         lost_object: LIBERTY_INTERPRETER_OBJECT
 86      do
 87         -- Because the `call' feature of a routine may call a function; in that case the result is lost
 88         -- (temporary because of SmartEiffel)
 89         --
 90         -- ECMA instead sets the `last_result' attribute of ROUTINE; but how the hell is `last_result'
 91         -- typed?? (seems not to be specified)
 92         --
 93         lost_object := item_agent(parameters, call_position)
 94      end
 95
 96feature {}
 97   unpack_target (target: LIBERTY_INTERPRETER_OBJECT; parameters: TRAVERSABLE[LIBERTY_INTERPRETER_OBJECT]; call_position: LIBERTY_POSITION): LIBERTY_INTERPRETER_OBJECT is
 98      local
 99         tuple: LIBERTY_INTERPRETER_TUPLE
100      do
101         check
102            parameters.count = 1
103            tuple ?:= parameters.first
104         end
105         if target.is_open then
106            tuple ::= parameters.first
107            Result := tuple.first
108         else
109            Result := target
110         end
111      end
112
113   unpack_tuple_and_closed (parameters: TRAVERSABLE[LIBERTY_INTERPRETER_OBJECT]; call_position: LIBERTY_POSITION; target_is_open: BOOLEAN): TRAVERSABLE[LIBERTY_INTERPRETER_OBJECT] is
114      local
115         tuple: LIBERTY_INTERPRETER_TUPLE
116         tuple_index: INTEGER
117         arg: LIBERTY_INTERPRETER_OBJECT
118         i: INTEGER
119         args: FAST_ARRAY[LIBERTY_INTERPRETER_OBJECT]
120      do
121         check
122            parameters.count = 1
123            tuple ?:= parameters.first
124         end
125         tuple ::= parameters.first
126         tuple_index := tuple.lower
127         if target_is_open then
128            tuple_index := tuple_index + 1
129         end
130         if arguments.count = 0 then
131            Result := tuple
132         else
133            create args.with_capacity(arguments.count)
134            Result := args
135            from
136               i := arguments.lower
137            until
138               i > arguments.upper
139            loop
140               arg := arguments.item(i)
141               if arg.is_open then
142                  arg := tuple.item(tuple_index)
143                  check
144                     arg.type.is_conform_to(arguments.item(i).type)
145                  end
146                  tuple_index := tuple_index + 1
147               end
148               check
149                  not arg.is_open
150               end
151               args.add_last(arg)
152               i := i + 1
153            end
154         end
155      end
156
157feature {LIBERTY_INTERPRETER_EXTERNAL_TYPE_ANY_BUILTINS} -- Standard builtings
158   builtin_is_equal (other: LIBERTY_INTERPRETER_OBJECT; a_position: LIBERTY_POSITION): BOOLEAN is
159      do
160         not_yet_implemented
161      end
162
163   builtin_standard_is_equal (other: LIBERTY_INTERPRETER_OBJECT; a_position: LIBERTY_POSITION): BOOLEAN is
164      do
165         not_yet_implemented
166      end
167
168   builtin_copy (other: LIBERTY_INTERPRETER_OBJECT; a_position: LIBERTY_POSITION) is
169      do
170         not_yet_implemented
171      end
172
173   builtin_twin (a_position: LIBERTY_POSITION): like Current is
174      do
175         not_yet_implemented
176      end
177
178   builtin_standard_copy (other: LIBERTY_INTERPRETER_OBJECT; a_position: LIBERTY_POSITION) is
179      do
180         not_yet_implemented
181      end
182
183   builtin_standard_twin (a_position: LIBERTY_POSITION): like Current is
184      do
185         not_yet_implemented
186      end
187
188feature {LIBERTY_INTERPRETER_OBJECT}
189   do_deep_twin (deep_twin_memory: DICTIONARY[LIBERTY_INTERPRETER_OBJECT, LIBERTY_INTERPRETER_OBJECT]; a_position: LIBERTY_POSITION): LIBERTY_INTERPRETER_OBJECT is
190      do
191         not_yet_implemented
192      end
193
194   do_deep_equal (object: LIBERTY_INTERPRETER_OBJECT; deep_equal_memory: SET[LIBERTY_INTERPRETER_OBJECT]; a_position: LIBERTY_POSITION): BOOLEAN is
195      do
196         not_yet_implemented
197      end
198
199feature {LIBERTY_INTERPRETER_OBJECT_PRINTER, LIBERTY_INTERPRETER_FEATURE_CALL}
200   show_stack (o: OUTPUT_STREAM; indent: INTEGER) is
201      do
202         o.put_string(once "agent {")
203         o.put_string(call.entity.target_type.known_type.full_name)
204         o.put_string(once "}.")
205         o.put_line(call.entity.feature_name.full_name)
206      end
207
208feature {}
209   expanded_twin: like Current is
210      do
211         check False end
212      end
213
214feature {}
215   make (a_interpreter: like interpreter; a_type: like type; a_position: like position) is
216      require
217         a_interpreter /= Void
218         a_type /= Void
219         a_position /= Void
220      do
221         interpreter := a_interpreter
222         type := a_type
223         position := a_position
224      ensure
225         interpreter = a_interpreter
226         type = a_type
227         position = a_position
228      end
229
230invariant
231   call /= Void implies call.is_agent_call
232   call /= Void implies arguments /= Void
233   call /= Void implies creation_target /= Void
234
235end -- class LIBERTY_INTERPRETER_AGENT