PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/src/tools/interpreter/builtins/liberty_interpreter_external_type_native_array_builtins.e

http://github.com/tybor/Liberty
Specman e | 118 lines | 95 code | 9 blank | 14 comment | 3 complexity | 6465cc4992df64d3254556819ab1ea6a 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_EXTERNAL_TYPE_NATIVE_ARRAY_BUILTINS
 16
 17inherit
 18   LIBERTY_FEATURE_ACCELERATOR
 19
 20insert
 21   LIBERTY_INTERPRETER_EXTERNAL_BUILTINS_CALLER
 22   ARRAYED_COLLECTION_HANDLER
 23
 24creation {LIBERTY_INTERPRETER_EXTERNAL_BUILTIN_CALL}
 25   make
 26
 27feature {}
 28   integer (builtin_call: LIBERTY_INTERPRETER_FEATURE_CALL): INTEGER is
 29      local
 30         obj: LIBERTY_INTERPRETER_OBJECT_NATIVE[INTEGER_64]
 31      do
 32         builtin_call.evaluate_parameters
 33         obj ::= builtin_call.parameters.first
 34         Result := obj.item.to_integer_32
 35      end
 36
 37   pointer (builtin_call: LIBERTY_INTERPRETER_FEATURE_CALL): POINTER is
 38      local
 39         obj: LIBERTY_INTERPRETER_OBJECT_NATIVE[POINTER]
 40      do
 41         builtin_call.evaluate_parameters
 42         obj ::= builtin_call.parameters.first
 43         Result := obj.item
 44      end
 45
 46feature {LIBERTY_INTERPRETER_EXTERNAL_BUILTIN_CALL}
 47   call (builtin_call: LIBERTY_INTERPRETER_FEATURE_CALL): LIBERTY_INTERPRETER_OBJECT is
 48      local
 49         target: LIBERTY_INTERPRETER_NATIVE_ARRAY
 50         actual_type: LIBERTY_ACTUAL_TYPE
 51      do
 52         last_call_failed := False
 53         target ::= builtin_call.target
 54         inspect
 55            builtin_call.name
 56         when "element_sizeof" then
 57            Result := interpreter.new_integer(target.builtin_element_sizeof, builtin_call.position)
 58            if Result = Void then
 59               last_call_failed := True
 60            end
 61         when "calloc" then
 62            Result := target.builtin_calloc(integer(builtin_call), builtin_call.position)
 63            if Result = Void then
 64               last_call_failed := True
 65            end
 66         when "item" then
 67            Result := target.builtin_item(integer(builtin_call), builtin_call.position)
 68            if Result = Void then
 69               last_call_failed := True
 70            end
 71         when "put" then
 72            put(builtin_call)
 73         when "slice_copy" then
 74            slice_copy(builtin_call)
 75         when "from_pointer" then
 76            actual_type ::= target.result_type.known_type
 77            Result := interpreter.array_from_external(actual_type, 0, pointer(builtin_call), builtin_call.position)
 78         else
 79            last_call_failed := True
 80         end
 81      end
 82
 83feature {}
 84   put (builtin_call: LIBERTY_INTERPRETER_FEATURE_CALL) is
 85      local
 86         target: LIBERTY_INTERPRETER_NATIVE_ARRAY
 87         element: LIBERTY_INTERPRETER_OBJECT
 88         index: LIBERTY_INTERPRETER_OBJECT_NATIVE[INTEGER_64]
 89      do
 90         target ::= builtin_call.target
 91         builtin_call.evaluate_parameters
 92         check
 93            builtin_call.parameters.lower = 0
 94         end
 95         element := builtin_call.parameters.item(0)
 96         index ::= builtin_call.parameters.item(1)
 97         target.builtin_put(element.as_right_value, index.item.to_integer_32, builtin_call.position)
 98      end
 99
100   slice_copy (builtin_call: LIBERTY_INTERPRETER_FEATURE_CALL) is
101      local
102         target: LIBERTY_INTERPRETER_NATIVE_ARRAY
103         at, src_min, src_max: LIBERTY_INTERPRETER_OBJECT_NATIVE[INTEGER_64]
104         src: LIBERTY_INTERPRETER_NATIVE_ARRAY
105      do
106         target ::= builtin_call.target
107         builtin_call.evaluate_parameters
108         check
109            builtin_call.parameters.lower = 0
110         end
111         at ::= builtin_call.parameters.item(0)
112         src ::= builtin_call.parameters.item(1)
113         src_min ::= builtin_call.parameters.item(2)
114         src_max ::= builtin_call.parameters.item(3)
115         target.builtin_slice_copy(at.item.to_integer_32, src, src_min.item.to_integer_32, src_max.item.to_integer_32)
116      end
117
118end -- class LIBERTY_INTERPRETER_EXTERNAL_TYPE_NATIVE_ARRAY_BUILTINS