PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/interpreter/builtins/liberty_interpreter_external_type_integers_builtins.e

http://github.com/tybor/Liberty
Specman e | 151 lines | 122 code | 15 blank | 14 comment | 0 complexity | 004e36449f79a990c20c78b047d55845 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--
 15deferred class LIBERTY_INTERPRETER_EXTERNAL_TYPE_INTEGERS_BUILTINS[E_ -> INTEGRAL]
 16
 17inherit
 18   LIBERTY_INTERPRETER_EXTERNAL_TYPED_BUILTINS[E_]
 19      undefine
 20         target, left, right
 21      redefine
 22         call_add, call_subtract, call_times, call_divide,
 23         call_less_or_equal, call_less_than, call_greater_or_equal, call_greater_than,
 24         call_negative,
 25         call_other
 26      end
 27
 28feature {}
 29   new_integer (value: E_): LIBERTY_INTERPRETER_OBJECT_NATIVE[INTEGER_64] is
 30      deferred
 31      end
 32
 33   int64_target: INTEGER_64 is
 34      local
 35         obj: LIBERTY_INTERPRETER_OBJECT_NATIVE[INTEGER_64]
 36      do
 37         obj ::= builtin_call.target
 38         Result := obj.item
 39      end
 40
 41   right_as_integer_8: INTEGER_8 is
 42      local
 43         obj: LIBERTY_INTERPRETER_OBJECT_NATIVE[INTEGER_64]
 44      do
 45         builtin_call.evaluate_parameters
 46         obj ::= builtin_call.parameters.first
 47         Result := obj.item.to_integer_8
 48      end
 49
 50feature {LIBERTY_FEATURE_LOCAL_CONTEXT}
 51   call_add (f: LIBERTY_FEATURE) is
 52      do
 53         returned := new_integer(left + right)
 54      end
 55
 56   call_subtract (f: LIBERTY_FEATURE) is
 57      do
 58         returned := new_integer(left - right)
 59      end
 60
 61   call_times (f: LIBERTY_FEATURE) is
 62      do
 63         returned := new_integer(left * right)
 64      end
 65
 66   call_divide (f: LIBERTY_FEATURE) is
 67      do
 68         returned := interpreter.new_real(left / right, builtin_call.position)
 69      end
 70
 71   call_less_or_equal (f: LIBERTY_FEATURE) is
 72      do
 73         returned := interpreter.new_boolean(left <= right, builtin_call.position)
 74      end
 75
 76   call_less_than (f: LIBERTY_FEATURE) is
 77      do
 78         returned := interpreter.new_boolean(left < right, builtin_call.position)
 79      end
 80
 81   call_greater_or_equal (f: LIBERTY_FEATURE) is
 82      do
 83         returned := interpreter.new_boolean(left >= right, builtin_call.position)
 84      end
 85
 86   call_greater_than (f: LIBERTY_FEATURE) is
 87      do
 88         returned := interpreter.new_boolean(left > right, builtin_call.position)
 89      end
 90
 91   call_negative (f: LIBERTY_FEATURE) is
 92      do
 93         returned := new_integer(-target)
 94      end
 95
 96   call_other (f: LIBERTY_FEATURE) is
 97      do
 98         inspect
 99            builtin_call.name
100         when "to_character" then
101            returned := interpreter.new_character(target.to_character, builtin_call.position)
102         when "to_integer_8" then
103            returned := interpreter.new_integer_8(int64_target.to_integer_8, builtin_call.position)
104         when "to_integer_16" then
105            returned := interpreter.new_integer_16(int64_target.to_integer_16, builtin_call.position)
106         when "to_integer_32" then
107            returned := interpreter.new_integer_32(int64_target.to_integer_32, builtin_call.position)
108         when "to_integer_64" then
109            returned := interpreter.new_integer_64(int64_target, builtin_call.position)
110         when "to_natural_8" then
111            not_yet_implemented
112         when "to_natural_16" then
113            not_yet_implemented
114         when "to_natural_32" then
115            not_yet_implemented
116         when "to_natural_64" then
117            not_yet_implemented
118         when "infix |>>", "bit_shift_right" then
119            returned := new_integer(left |>> right_as_integer_8)
120         when "infix |>>>", "bit_shift_right_unsigned" then
121            returned := new_integer(left |>>> right_as_integer_8)
122         when "infix |<<", "bit_shift_left" then
123            returned := new_integer(left |<< right_as_integer_8)
124         when "infix #>>", "bit_rotate_right" then
125            returned := new_integer(left #>> right_as_integer_8)
126         when "infix #<<", "bit_rotate_left" then
127            returned := new_integer(left #<< right_as_integer_8)
128         when "bit_rotate" then
129            returned := new_integer(left.bit_rotate(right_as_integer_8))
130         when "prefix ~", "bit_not" then
131            returned := new_integer(~left)
132         when "infix &", "bit_and" then
133            returned := new_integer(left & right)
134         when "infix |", "bit_or" then
135            returned := new_integer(left | right)
136         when "bit_xor" then
137            returned := new_integer(left.bit_xor(right))
138         when "infix #+" then
139            returned := new_integer(left #+ right)
140         when "infix #-" then
141            returned := new_integer(left #- right)
142         when "infix #*" then
143            returned := new_integer(left #* right)
144         when "infix #//" then
145            returned := new_integer(left #// right)
146         when "infix #\\" then
147            returned := new_integer(left #\\ right)
148         end
149      end
150
151end -- class LIBERTY_INTERPRETER_EXTERNAL_TYPE_INTEGERS_BUILTINS