home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / type_real.e < prev    next >
Text File  |  1999-06-05  |  6KB  |  244 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class TYPE_REAL
  17. --
  18. -- For REAL declaration :
  19. --        foo : REAL;
  20. --
  21.  
  22. inherit
  23.    TYPE_BASIC_EIFFEL_EXPANDED
  24.       redefine is_real
  25.       end;
  26.  
  27. creation make
  28.  
  29. feature
  30.  
  31.    is_real: BOOLEAN is true;
  32.  
  33.    id: INTEGER is 4;
  34.  
  35. feature
  36.  
  37.    make(sp: like start_position) is
  38.       do
  39.          !!base_class_name.make(as_real,sp);
  40.       end;
  41.  
  42.    is_a(other: TYPE): BOOLEAN is
  43.       do
  44.          if other.is_real or else other.is_double then
  45.             Result := true;
  46.          elseif base_class.is_subclass_of(other.base_class) then
  47.             Result := true;
  48.             used_as_reference;
  49.          elseif other.run_time_mark = as_double_ref then
  50.             Result := true;
  51.             type_double.used_as_reference;
  52.          end;
  53.          if not Result then
  54.             eh.add_type(Current,fz_inako);
  55.             eh.add_type(other,fz_dot);
  56.          end;
  57.       end;
  58.  
  59.    used_as_reference is
  60.       once
  61.          load_ref(as_real_ref);
  62.       end;
  63.  
  64.    smallest_ancestor(other: TYPE): TYPE is
  65.       local
  66.          rto: TYPE;
  67.       do
  68.          rto := other.run_type;
  69.          if rto.is_integer then
  70.             Result := Current;
  71.          elseif rto.is_real then
  72.             Result := Current;
  73.          elseif rto.is_double then
  74.             Result := other;
  75.          else
  76.             Result := type_real_ref.smallest_ancestor(rto);
  77.          end;
  78.       end;
  79.  
  80.    space_for_variable, space_for_object: INTEGER is
  81.       do
  82.          Result := (0.0).object_size;
  83.       end;
  84.  
  85.    to_runnable(rt: TYPE): like Current is
  86.       do
  87.          Result := Current;
  88.          check_type;
  89.       end;
  90.  
  91.    written_mark, run_time_mark: STRING is
  92.       do
  93.          Result := as_real;
  94.       end;
  95.  
  96.    c_type_for_argument_in(str: STRING) is
  97.       do
  98.          str.extend('T');
  99.          str.extend('4');
  100.       end;
  101.  
  102.    cast_to_ref is
  103.       do
  104.          type_real_ref.mapping_cast;
  105.       end;
  106.  
  107.    jvm_descriptor_in(str: STRING) is
  108.       do
  109.          str.extend('F');
  110.       end;
  111.  
  112.    jvm_return_code is
  113.       do
  114.          code_attribute.opcode_freturn;
  115.       end;
  116.  
  117.    jvm_push_local(offset: INTEGER) is
  118.       do
  119.          code_attribute.opcode_fload(offset);
  120.       end;
  121.  
  122.    jvm_push_default: INTEGER is
  123.       do
  124.          code_attribute.opcode_fconst_0;
  125.          Result := 1;
  126.       end;
  127.  
  128.    jvm_write_local(offset: INTEGER) is
  129.       do
  130.          code_attribute.opcode_fstore(offset);
  131.       end;
  132.  
  133.    jvm_xnewarray is
  134.       do
  135.          code_attribute.opcode_newarray(6);
  136.       end;
  137.  
  138.    jvm_xastore is
  139.       do
  140.          code_attribute.opcode_fastore;
  141.       end;
  142.  
  143.    jvm_xaload is
  144.       do
  145.          code_attribute.opcode_faload;
  146.       end;
  147.  
  148.    jvm_if_x_eq: INTEGER is
  149.       do
  150.          code_attribute.opcode_fcmpg;
  151.          Result := code_attribute.opcode_ifeq;
  152.       end;
  153.  
  154.    jvm_if_x_ne: INTEGER is
  155.       do
  156.          code_attribute.opcode_fcmpg;
  157.          Result := code_attribute.opcode_ifne;
  158.       end;
  159.  
  160.    jvm_to_reference is
  161.       local
  162.          rc: RUN_CLASS;
  163.          idx: INTEGER;
  164.          ca: like code_attribute;
  165.       do
  166.          ca := code_attribute;
  167.          rc := type_real_ref.run_class;
  168.          rc.jvm_basic_new;
  169.          ca.opcode_dup_x1;
  170.          ca.opcode_swap;
  171.          idx := rc.jvm_constant_pool_index;
  172.          idx := constant_pool.idx_fieldref4(idx,as_item,fz_78);
  173.          ca.opcode_putfield(idx,-2);
  174.       end;
  175.  
  176.    jvm_expanded_from_reference(other: TYPE): INTEGER is
  177.       local
  178.          rc: RUN_CLASS;
  179.          idx: INTEGER;
  180.          ca: like code_attribute;
  181.       do
  182.          ca := code_attribute;
  183.          rc := type_real_ref.run_class;
  184.          rc.opcode_checkcast;
  185.          idx := rc.jvm_constant_pool_index;
  186.          idx := constant_pool.idx_fieldref4(idx,as_item,fz_78);
  187.          ca.opcode_getfield(idx,0);
  188.          Result := 1;
  189.       end;
  190.  
  191.    jvm_convert_to(destination: TYPE): INTEGER is
  192.       do
  193.          Result := 1;
  194.          if destination.is_reference then
  195.             jvm_to_reference;
  196.          elseif destination.is_double then
  197.             code_attribute.opcode_f2d;
  198.             Result := 2;
  199.          elseif destination.is_real then
  200.          else
  201.             -- Validity error.
  202.             check
  203.                destination.is_integer
  204.             end;
  205.             code_attribute.opcode_f2i;
  206.          end;
  207.       end;
  208.  
  209.    to_reference is
  210.       do
  211.          cpp.to_reference(Current,type_real_ref);
  212.       end;
  213.  
  214.    to_expanded is
  215.       do
  216.          cpp.to_expanded(Current,type_real_ref);
  217.       end;
  218.  
  219. feature {NONE}
  220.  
  221.    check_type is
  222.       -- Do some checking for type REAL.
  223.       local
  224.          bc: BASE_CLASS;
  225.          rc: RUN_CLASS;
  226.       once
  227.          bc := base_class;
  228.          if nb_errors = 0 then
  229.             rc := run_class;
  230.          end;
  231.          if nb_errors = 0 then
  232.             if not bc.is_expanded then
  233.                error(start_position,"REAL must be expanded.");
  234.             end;
  235.          end;
  236.       end;
  237.  
  238. invariant
  239.  
  240.    written_mark = as_real
  241.  
  242. end -- TYPE_REAL
  243.  
  244.