home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / call_infix_neq.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  6.2 KB  |  252 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://www.loria.fr/SmallEiffel
  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 CALL_INFIX_NEQ
  17.    --   
  18.    --   Infix operator : "/=".
  19.    --      
  20.  
  21. inherit CALL_INFIX_EQ_NEQ;
  22.    
  23. creation make
  24.    
  25. feature
  26.    
  27.    operator: STRING is "/=";
  28.    
  29.    is_static: BOOLEAN is
  30.       do
  31.      if target.is_void then
  32.         Result := is_static_neq_void(arg1);
  33.      elseif arg1.is_void then
  34.         Result := is_static_neq_void(target);
  35.      elseif target.is_static and then arg1.is_static then
  36.         Result := true;
  37.         if target.static_value /= arg1.static_value then
  38.            static_value_mem := 1;
  39.         end;
  40.      end;
  41.       end;
  42.    
  43.    compile_to_c is
  44.       local
  45.      tt, at: TYPE;
  46.       do
  47.      tt := target.result_type.run_type;
  48.      at := arg1.result_type.run_type;
  49.      if tt.is_expanded then
  50.         if at.is_expanded then -- ------------- Expanded/Expanded :
  51.            if tt.is_user_expanded then
  52.           cmp_user_expanded(false,tt);
  53.            elseif tt.is_basic_eiffel_expanded then
  54.           cmp_basic_eiffel_expanded(false,at,tt);
  55.            elseif tt.is_bit then
  56.           cmp_bit(false,tt);
  57.            else -- NATIVE_ARRAY
  58.           cmp_basic_ref(false);
  59.            end;
  60.         else -- ------------------------------- Expanded/Reference :
  61.            c2c_exp_ref(target,tt,arg1,at);
  62.         end;
  63.      elseif at.is_expanded then -- ----------- Reference/Expanded :
  64.         c2c_exp_ref(arg1,at,target,tt);
  65.      else -- ---------------------------- Reference/Reference :
  66.         cmp_basic_ref(false);
  67.      end;
  68.       end;
  69.  
  70. feature {NONE}
  71.  
  72.    c2c_exp_ref(e: EXPRESSION; et: TYPE; r: EXPRESSION; rt: TYPE) is
  73.       do
  74.      if r.is_void then
  75.         cpp.put_string("((");
  76.         r.compile_to_c;
  77.         cpp.put_string("),1)");
  78.      else
  79.         cpp.put_string("((");
  80.         e.compile_to_c;
  81.         cpp.put_string("),(");
  82.         r.compile_to_c;
  83.         cpp.put_string("),1)");
  84.      end;
  85.       end;
  86.      
  87. feature {NONE}
  88.  
  89.    is_static_neq_void(e: EXPRESSION): BOOLEAN is
  90.       local
  91.      rt: TYPE;
  92.       do
  93.      if e.is_current or else
  94.        e.is_manifest_string or else
  95.        is_manifest_array(e)
  96.       then
  97.         Result := true;
  98.         static_value_mem := 1;
  99.      else
  100.         rt := e.result_type.run_type;
  101.         if rt.is_expanded then
  102.            Result := true;
  103.            static_value_mem := 1;
  104.         elseif e.is_static then
  105.            Result := true;
  106.            if e.static_value /= 0 then
  107.           static_value_mem := 1;
  108.            end;
  109.         end;
  110.      end;
  111.       end;
  112.  
  113. feature
  114.  
  115.    compile_to_jvm is
  116.       local
  117.      space, point1, point2: INTEGER;
  118.      rt: TYPE;
  119.      rc: RUN_CLASS;
  120.      ca: like code_attribute;
  121.       do
  122.      if target.is_void then
  123.         jvm_void_cmp(arg1);
  124.      elseif arg1.is_void then
  125.         jvm_void_cmp(target);
  126.      else
  127.         ca := code_attribute;
  128.         rt := target.result_type.smallest_ancestor(arg1.result_type);
  129.         space := target.compile_to_jvm_into(rt);
  130.         space := arg1.compile_to_jvm_into(rt);
  131.         if rt.is_user_expanded then
  132.            rc := rt.run_class;
  133.            jvm_standard_is_neq_aux(rc,rc.writable_attributes);
  134.         else
  135.            point1 := rt.jvm_if_x_eq;
  136.            ca.opcode_iconst_1;
  137.            point2 := ca.opcode_goto;
  138.            ca.resolve_u2_branch(point1);
  139.            ca.opcode_iconst_0;
  140.            ca.resolve_u2_branch(point2);
  141.         end;
  142.      end;
  143.       end;
  144.  
  145.    jvm_branch_if_false: INTEGER is
  146.       do
  147.      Result := jvm_standard_branch_if_false;
  148.       end;
  149.  
  150.    jvm_branch_if_true: INTEGER is
  151.       do
  152.      Result := jvm_standard_branch_if_true;
  153.       end;
  154.    
  155. feature {NONE}
  156.  
  157.    jvm_void_cmp(e: EXPRESSION) is
  158.       local
  159.      rt: TYPE;
  160.      point1, point2: INTEGER;
  161.      space: INTEGER;
  162.      ca: like code_attribute;
  163.       do
  164.      ca := code_attribute;
  165.      rt := e.result_type.run_type;
  166.      if rt.is_expanded then
  167.         e.compile_to_jvm;
  168.         from
  169.            space := rt.jvm_stack_space;
  170.         until
  171.            space = 0
  172.         loop
  173.            ca.opcode_pop;
  174.            space := space - 1;
  175.         end;
  176.         ca.opcode_iconst_1;
  177.      else
  178.         e.compile_to_jvm;
  179.         point1 := ca.opcode_ifnonnull;
  180.         ca.opcode_iconst_0;
  181.         point2 := ca.opcode_goto;
  182.         ca.resolve_u2_branch(point1);
  183.         ca.opcode_iconst_1;
  184.         ca.resolve_u2_branch(point2);
  185.      end;
  186.       end;
  187.  
  188. feature {NONE}
  189.  
  190.    jvm_standard_is_neq_aux(rc: RUN_CLASS; wa: ARRAY[RUN_FEATURE_2]) is
  191.       require
  192.      rc.current_type.is_user_expanded
  193.       local
  194.      ca: like code_attribute;
  195.      rf2: RUN_FEATURE_2;
  196.      point1, point2, idx, space, i: INTEGER;
  197.       do
  198.      ca := code_attribute;
  199.      if wa = Void then
  200.         ca.opcode_pop;
  201.         ca.opcode_pop;
  202.         ca.opcode_iconst_0;
  203.      else
  204.         ca.branches.clear;
  205.         ca.opcode_dup;
  206.         idx := rc.fully_qualified_constant_pool_index;
  207.         ca.opcode_instanceof(idx);
  208.         ca.branches.add_last(ca.opcode_ifeq);
  209.         from
  210.            i := wa.upper;
  211.         until
  212.            i = 0
  213.         loop
  214.            rf2 := wa.item(i);
  215.            idx := constant_pool.idx_fieldref(rf2);
  216.            space := rf2.result_type.jvm_stack_space - 1;
  217.            if i > 1 then
  218.           ca.opcode_dup2;
  219.            end;
  220.            ca.opcode_getfield(idx,space);
  221.            if space = 0 then
  222.           ca.opcode_swap;
  223.            else
  224.           ca.opcode_dup2_x1;
  225.           ca.opcode_pop2;
  226.            end;
  227.            ca.opcode_getfield(idx,space);
  228.            if i > 1 then
  229.           ca.branches.add_last(rf2.result_type.jvm_if_x_ne);
  230.            else
  231.           point1 := rf2.result_type.jvm_if_x_ne;
  232.            end;
  233.            i := i - 1;
  234.         end;
  235.         ca.opcode_iconst_0;
  236.         point2 := ca.opcode_goto;
  237.         ca.resolve_branches;
  238.         ca.opcode_pop;
  239.         ca.opcode_pop;
  240.         ca.resolve_u2_branch(point1);
  241.         ca.opcode_iconst_1;
  242.         ca.resolve_u2_branch(point2);
  243.      end;
  244.       end;
  245.  
  246. invariant
  247.    
  248.    run_feature = Void;
  249.  
  250. end -- CALL_INFIX_NEQ
  251.  
  252.