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

/src/tools/interpreter/builtins/liberty_interpreter_external_type_reals_builtins.e

http://github.com/tybor/Liberty
Specman e | 150 lines | 120 code | 16 blank | 14 comment | 0 complexity | ac724feca12503bb55428b57fd682a55 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_REALS_BUILTINS[E_ -> FLOAT]
 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, call_power,
 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_real (value: E_): LIBERTY_INTERPRETER_OBJECT_NATIVE[REAL_128] is
 30      deferred
 31      end
 32
 33   right_as_integer: INTEGER is
 34      local
 35         obj: LIBERTY_INTERPRETER_OBJECT_NATIVE[INTEGER_64]
 36      do
 37         builtin_call.evaluate_parameters
 38         obj ::= builtin_call.parameters.first
 39         Result := obj.item.to_integer_32
 40      end
 41
 42   call_specific (f: LIBERTY_FEATURE) is
 43      deferred
 44      end
 45
 46feature {LIBERTY_FEATURE_LOCAL_CONTEXT}
 47   call_add (f: LIBERTY_FEATURE) is
 48      do
 49         returned := new_real(left + right)
 50      end
 51
 52   call_subtract (f: LIBERTY_FEATURE) is
 53      do
 54         returned := new_real(left - right)
 55      end
 56
 57   call_times (f: LIBERTY_FEATURE) is
 58      do
 59         returned := new_real(left * right)
 60      end
 61
 62   call_divide (f: LIBERTY_FEATURE) is
 63      do
 64         returned := new_real(left / right)
 65      end
 66
 67   call_less_or_equal (f: LIBERTY_FEATURE) is
 68      do
 69         returned := interpreter.new_boolean(left <= right, builtin_call.position)
 70      end
 71
 72   call_less_than (f: LIBERTY_FEATURE) is
 73      do
 74         returned := interpreter.new_boolean(left < right, builtin_call.position)
 75      end
 76
 77   call_greater_or_equal (f: LIBERTY_FEATURE) is
 78      do
 79         returned := interpreter.new_boolean(left >= right, builtin_call.position)
 80      end
 81
 82   call_greater_than (f: LIBERTY_FEATURE) is
 83      do
 84         returned := interpreter.new_boolean(left > right, builtin_call.position)
 85      end
 86
 87   call_negative (f: LIBERTY_FEATURE) is
 88      do
 89         returned := new_real(-target)
 90      end
 91
 92   call_power (f: LIBERTY_FEATURE) is
 93      do
 94         returned := new_real(left ^ right_as_integer)
 95      end
 96
 97   call_other (f: LIBERTY_FEATURE) is
 98      do
 99         inspect
100            builtin_call.name
101         when "is_not_a_number" then
102            returned := interpreter.new_boolean(target.is_not_a_number, builtin_call.position)
103         when "is_infinity" then
104            returned := interpreter.new_boolean(target.is_infinity, builtin_call.position)
105         when "is_subnormal" then
106            returned := interpreter.new_boolean(target.is_subnormal, builtin_call.position)
107         when "is_normal" then
108            returned := interpreter.new_boolean(target.is_normal, builtin_call.position)
109         when "rounded" then
110            returned := new_real(target.rounded)
111         when "floor" then
112            returned := new_real(target.floor)
113         when "ceiling" then
114            returned := new_real(target.ceiling)
115         when "sqrt" then
116            returned := new_real(target.sqrt)
117         when "sin" then
118            returned := new_real(target.sin)
119         when "cos" then
120            returned := new_real(target.cos)
121         when "tan" then
122            returned := new_real(target.tan)
123         when "asin" then
124            returned := new_real(target.asin)
125         when "acos" then
126            returned := new_real(target.acos)
127         when "atan" then
128            returned := new_real(target.atan)
129         when "atan2" then
130            returned := new_real(target.atan2(right))
131         when "sinh" then
132            returned := new_real(target.sinh)
133         when "cosh" then
134            returned := new_real(target.cosh)
135         when "tanh" then
136            returned := new_real(target.tanh)
137         when "exp" then
138            returned := new_real(target.exp)
139         when "log" then
140            returned := new_real(target.log)
141         when "log10" then
142            returned := new_real(target.log10)
143         when "pow" then
144            returned := new_real(target.pow(right))
145         else
146            call_specific(f)
147         end
148      end
149
150end -- class LIBERTY_INTERPRETER_EXTERNAL_TYPE_REALS_BUILTINS