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