home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / type_double.e < prev    next >
Text File  |  1999-06-05  |  6KB  |  248 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_DOUBLE
  17.    --
  18.    -- Handling of DOUBLE type mark.
  19.    --
  20.  
  21. inherit
  22.    TYPE_BASIC_EIFFEL_EXPANDED
  23.       redefine is_double
  24.       end;
  25.  
  26. creation make
  27.  
  28. feature
  29.  
  30.    is_double: BOOLEAN is true;
  31.  
  32.    id: INTEGER is 5;
  33.  
  34. feature
  35.  
  36.    make(sp: like start_position) is
  37.       do
  38.          !!base_class_name.make(as_double,sp);
  39.       end;
  40.  
  41.    used_as_reference is
  42.       once
  43.          load_ref(as_double_ref);
  44.       end;
  45.  
  46.    space_for_variable, space_for_object: INTEGER is
  47.       do
  48.          Result := (0.0).to_double.object_size;
  49.       end;
  50.  
  51.    is_a(other: TYPE): BOOLEAN is
  52.       do
  53.          if other.is_double then
  54.             Result := true;
  55.          elseif base_class.is_subclass_of(other.base_class) then
  56.             Result := true;
  57.             used_as_reference;
  58.          end;
  59.          if not Result then
  60.             eh.add_type(Current,fz_inako);
  61.             eh.add_type(other,fz_dot);
  62.          end;
  63.       end;
  64.  
  65.    smallest_ancestor(other: TYPE): TYPE is
  66.       local
  67.          rto: TYPE;
  68.       do
  69.          rto := other.run_type;
  70.          if rto.is_integer then
  71.             Result := Current;
  72.          elseif rto.is_real then
  73.             Result := Current;
  74.          elseif rto.is_double then
  75.             Result := Current;
  76.          else
  77.             Result := type_double_ref.smallest_ancestor(rto);
  78.          end;
  79.       end;
  80.  
  81.    to_runnable(rt: TYPE): like Current is
  82.       do
  83.          Result := Current;
  84.          check_type;
  85.       end;
  86.  
  87.    written_mark, run_time_mark: STRING is
  88.       do
  89.          Result := as_double
  90.       end;
  91.  
  92.    c_type_for_argument_in(str: STRING) is
  93.       do
  94.          str.extend('T');
  95.          str.extend('5');
  96.       end;
  97.  
  98.    cast_to_ref is
  99.       do
  100.          type_double_ref.mapping_cast;
  101.       end;
  102.  
  103.    jvm_descriptor_in(str: STRING) is
  104.       do
  105.          str.extend('D');
  106.       end;
  107.  
  108.    jvm_return_code is
  109.       do
  110.          code_attribute.opcode_dreturn;
  111.       end;
  112.  
  113.    jvm_push_local(offset: INTEGER) is
  114.       do
  115.          code_attribute.opcode_dload(offset);
  116.       end;
  117.  
  118.    jvm_push_default: INTEGER is
  119.       do
  120.          code_attribute.opcode_dconst_0;
  121.          Result := 2;
  122.       end;
  123.  
  124.    jvm_write_local(offset: INTEGER) is
  125.       do
  126.          code_attribute.opcode_dstore(offset);
  127.       end;
  128.  
  129.    jvm_xnewarray is
  130.       do
  131.          code_attribute.opcode_newarray(7);
  132.       end;
  133.  
  134.    jvm_xastore is
  135.       do
  136.          code_attribute.opcode_dastore;
  137.       end;
  138.  
  139.    jvm_xaload is
  140.       do
  141.          code_attribute.opcode_daload;
  142.       end;
  143.  
  144.    jvm_if_x_eq: INTEGER is
  145.       local
  146.          ca: like code_attribute;
  147.       do
  148.          ca := code_attribute;
  149.          ca.opcode_dcmpg;
  150.          Result := ca.opcode_ifeq;
  151.       end;
  152.  
  153.    jvm_if_x_ne: INTEGER is
  154.       local
  155.          ca: like code_attribute;
  156.       do
  157.          ca := code_attribute;
  158.          ca.opcode_dcmpg;
  159.          Result := ca.opcode_ifne;
  160.       end;
  161.  
  162.    jvm_to_reference is
  163.       local
  164.          rc: RUN_CLASS;
  165.          idx: INTEGER;
  166.          ca: like code_attribute;
  167.       do
  168.          ca := code_attribute;
  169.          rc := type_double_ref.run_class;
  170.          rc.jvm_basic_new;
  171.          ca.opcode_dup_x2;
  172.          ca.opcode_dup_x2;
  173.          ca.opcode_pop;
  174.          idx := rc.jvm_constant_pool_index;
  175.          idx := constant_pool.idx_fieldref4(idx,as_item,fz_77);
  176.          ca.opcode_putfield(idx,-3);
  177.       end;
  178.  
  179.    jvm_expanded_from_reference(other: TYPE): INTEGER is
  180.       local
  181.          rc: RUN_CLASS;
  182.          idx: INTEGER;
  183.          ca: like code_attribute;
  184.       do
  185.          ca := code_attribute;
  186.          rc := type_double_ref.run_class;
  187.          rc.opcode_checkcast;
  188.          idx := rc.jvm_constant_pool_index;
  189.          idx := constant_pool.idx_fieldref4(idx,as_item,fz_77);
  190.          ca.opcode_getfield(idx,1);
  191.          Result := 2;
  192.       end;
  193.  
  194.    jvm_convert_to(destination: TYPE): INTEGER is
  195.       do
  196.          if destination.is_reference then
  197.             jvm_to_reference;
  198.             Result := 1;
  199.          elseif destination.is_real then
  200.             code_attribute.opcode_d2f
  201.             Result := 1;
  202.          elseif destination.is_integer then
  203.             code_attribute.opcode_d2i
  204.             Result := 1;
  205.          else
  206.             check
  207.                destination.is_double
  208.             end;
  209.             Result := 2;
  210.          end;
  211.       end;
  212.  
  213.    to_reference is
  214.       do
  215.          cpp.to_reference(Current,type_double_ref);
  216.       end;
  217.  
  218.    to_expanded is
  219.       do
  220.          cpp.to_expanded(type_double_ref,Current);
  221.       end;
  222.  
  223. feature {NONE}
  224.  
  225.    check_type is
  226.       -- Do some checking for type DOUBLE.
  227.       local
  228.          bc: BASE_CLASS;
  229.          rc: RUN_CLASS;
  230.       once
  231.          bc := base_class;
  232.          if nb_errors = 0 then
  233.             rc := run_class;
  234.          end;
  235.          if nb_errors = 0 then
  236.             if not bc.is_expanded then
  237.                error(start_position,"DOUBLE must be expanded.");
  238.             end;
  239.          end;
  240.       end;
  241.  
  242. invariant
  243.  
  244.    written_mark = as_double
  245.  
  246. end -- TYPE_DOUBLE
  247.  
  248.