home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / type_integer.e < prev    next >
Text File  |  1999-06-05  |  6KB  |  245 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_INTEGER
  17. --
  18. -- For INTEGER declaration :
  19. --        foo: INTEGER;
  20. --
  21.  
  22. inherit
  23.    TYPE_BASIC_EIFFEL_EXPANDED
  24.       redefine is_integer
  25.       end;
  26.  
  27. creation make
  28.  
  29. feature
  30.  
  31.    is_integer: BOOLEAN is true;
  32.  
  33.    id: INTEGER is 2;
  34.  
  35. feature
  36.  
  37.    make(sp: like start_position) is
  38.       do
  39.          !!base_class_name.make(as_integer,sp);
  40.       end;
  41.  
  42.    space_for_variable, space_for_object: INTEGER is
  43.       do
  44.          Result := space_for_integer;
  45.       end;
  46.  
  47.    used_as_reference is
  48.       once
  49.          load_ref(as_integer_ref);
  50.       end;
  51.  
  52.    smallest_ancestor(other: TYPE): TYPE is
  53.       local
  54.          rto: TYPE;
  55.       do
  56.          rto := other.run_type;
  57.          if rto.is_integer then
  58.             Result := Current;
  59.          elseif rto.is_real then
  60.             Result := other;
  61.          elseif rto.is_double then
  62.             Result := other;
  63.          else
  64.             Result := type_integer_ref.smallest_ancestor(rto);
  65.          end;
  66.       end;
  67.  
  68.    is_a(other: TYPE): BOOLEAN is
  69.       do
  70.          if other.is_integer or else other.is_double or else
  71.             other.is_real then
  72.             Result := true
  73.          else
  74.             Result := base_class.is_subclass_of(other.base_class);
  75.             if Result then
  76.                used_as_reference;
  77.             end;
  78.          end;
  79.          if not Result then
  80.             eh.add_type(Current,fz_inako);
  81.             eh.add_type(other,fz_dot);
  82.          end;
  83.       end;
  84.  
  85. feature
  86.  
  87.    to_runnable(rt: TYPE): like Current is
  88.       do
  89.          Result := Current;
  90.          check_type;
  91.       end;
  92.  
  93.    written_mark, run_time_mark: STRING is
  94.       do
  95.          Result := as_integer;
  96.       end;
  97.  
  98.    c_type_for_argument_in(str: STRING) is
  99.       do
  100.          str.extend('T');
  101.          str.extend('2');
  102.       end;
  103.  
  104.    cast_to_ref is
  105.       do
  106.          type_integer_ref.mapping_cast;
  107.       end;
  108.  
  109.    jvm_descriptor_in(str: STRING) is
  110.       do
  111.          str.extend('I');
  112.       end;
  113.  
  114.    jvm_return_code is
  115.       do
  116.          code_attribute.opcode_ireturn;
  117.       end;
  118.  
  119.    jvm_push_local(offset: INTEGER) is
  120.       do
  121.          code_attribute.opcode_iload(offset);
  122.       end;
  123.  
  124.    jvm_push_default: INTEGER is
  125.       do
  126.          code_attribute.opcode_iconst_0;
  127.          Result := 1;
  128.       end;
  129.  
  130.    jvm_write_local(offset: INTEGER) is
  131.       do
  132.          code_attribute.opcode_istore(offset);
  133.       end;
  134.  
  135.    jvm_xnewarray is
  136.       do
  137.          code_attribute.opcode_newarray(10);
  138.       end;
  139.  
  140.    jvm_xastore is
  141.       do
  142.          code_attribute.opcode_iastore;
  143.       end;
  144.  
  145.    jvm_xaload is
  146.       do
  147.          code_attribute.opcode_iaload;
  148.       end;
  149.  
  150.    jvm_if_x_eq: INTEGER is
  151.       do
  152.          Result := code_attribute.opcode_if_icmpeq;
  153.       end;
  154.  
  155.    jvm_if_x_ne: INTEGER is
  156.       do
  157.          Result := code_attribute.opcode_if_icmpne;
  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_integer_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_i);
  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_integer_ref.run_class;
  184.          rc.opcode_checkcast;
  185.          idx := rc.jvm_constant_pool_index;
  186.          idx := constant_pool.idx_fieldref4(idx,as_item,fz_i);
  187.          ca.opcode_getfield(idx,0);
  188.          Result := 1;
  189.       end;
  190.  
  191.    jvm_convert_to(destination: TYPE): INTEGER is
  192.       do
  193.          if destination.is_reference then
  194.             jvm_to_reference;
  195.             Result := 1;
  196.          elseif destination.is_real then
  197.             code_attribute.opcode_i2f;
  198.             Result := 1;
  199.          elseif destination.is_double then
  200.             code_attribute.opcode_i2d;
  201.             Result := 2;
  202.          else
  203.             check
  204.                destination.is_integer
  205.             end;
  206.             Result := 1;
  207.          end;
  208.       end;
  209.  
  210.    to_reference is
  211.       do
  212.          cpp.to_reference(Current,type_integer_ref);
  213.       end;
  214.  
  215.    to_expanded is
  216.       do
  217.          cpp.to_expanded(type_integer_ref,Current);
  218.       end;
  219.  
  220. feature {NONE}
  221.  
  222.    check_type is
  223.       -- Do some checking for type INTEGER to be runnable.
  224.       local
  225.          bc: BASE_CLASS;
  226.          rc: RUN_CLASS;
  227.       once
  228.          bc := base_class;
  229.          if nb_errors = 0 then
  230.             rc := run_class;
  231.          end;
  232.          if nb_errors = 0 then
  233.             if not bc.is_expanded then
  234.                error(start_position,"INTEGER must be expanded.");
  235.             end;
  236.          end;
  237.       end;
  238.  
  239. invariant
  240.  
  241.    written_mark = as_integer
  242.  
  243. end -- TYPE_INTEGER
  244.  
  245.