home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / bit_constant.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  5.9 KB  |  286 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 BIT_CONSTANT
  17. --
  18. -- For Manifest Constant BIT_N.
  19. --   
  20.  
  21. inherit EXPRESSION;
  22.    
  23. creation {EIFFEL_PARSER} make
  24.    
  25. feature 
  26.    
  27.    start_position: POSITION;
  28.    
  29.    value: STRING;
  30.  
  31.    result_type: TYPE_BIT_1;
  32.  
  33. feature {NONE}
  34.  
  35.    id: INTEGER;
  36.  
  37. feature
  38.  
  39.    use_current: BOOLEAN is false;
  40.    
  41.    is_static: BOOLEAN is false;
  42.  
  43.    is_pre_computable: BOOLEAN is false;
  44.  
  45.    can_be_dropped: BOOLEAN is true;
  46.  
  47.    c_simple: BOOLEAN is true;
  48.  
  49. feature {NONE}
  50.    
  51.    make(sp: like start_position; s: STRING) is
  52.       require
  53.      s /= Void
  54.      -- `s' contains only '0' and '1'.
  55.       do
  56.      start_position := sp;
  57.      value := s;
  58.       ensure
  59.      value.count = s.count
  60.       end;
  61.    
  62. feature 
  63.  
  64.    isa_dca_inline_argument: INTEGER is
  65.      -- *** FAIRE ***
  66.       do
  67.       end;
  68.  
  69.    dca_inline_argument(formal_arg_type: TYPE) is
  70.      -- *** FAIRE ***
  71.       do
  72.       end;
  73.  
  74.    frozen afd_check is do end;
  75.  
  76.    frozen mapping_c_target(target_type: TYPE) is
  77.       do
  78.      mapping_c_arg(target_type);
  79.       end;
  80.  
  81.    frozen mapping_c_arg(formal_arg_type: TYPE) is
  82.       do
  83.      compile_to_c;
  84.       end;
  85.  
  86.    compile_to_c is 
  87.       local
  88.      tb: TYPE_BIT;
  89.      nb: INTEGER;
  90.      ib: INTEGER;
  91.       do
  92.      tb := result_type;
  93.      ib := Integer_bits
  94.      if tb.is_c_unsigned_ptr then
  95.         compute_c_to_bit;
  96.         cpp.put_character('(');
  97.         cpp.put_character('(');
  98.         cpp.put_string(fz_unsigned);
  99.         cpp.put_character('*');
  100.         cpp.put_character(')');
  101.         cpp.put_string_c(to_bit);
  102.         cpp.put_character(')');
  103.      else
  104.         to_bit.copy(value);
  105.         if tb.is_c_char then
  106.            nb := Character_bits;
  107.         else
  108.            nb := Integer_bits;
  109.         end;
  110.         from
  111.         until 
  112.            to_bit.count = nb
  113.         loop
  114.            to_bit.extend('0');
  115.         end;
  116.         cpp.put_integer(to_bit.binary_to_integer);
  117.      end;
  118.       end;
  119.  
  120.    compile_to_c_old is do end;
  121.  
  122.    compile_to_jvm_old is do end;
  123.  
  124.    compile_target_to_jvm, compile_to_jvm is
  125.       local
  126.      i, idx: INTEGER;
  127.      ca: like code_attribute;
  128.      cp: like constant_pool;
  129.       do
  130.      ca := code_attribute;
  131.      cp := constant_pool;
  132.      idx := cp.idx_class2(fz_a0);
  133.      ca.opcode_new(idx);
  134.      ca.opcode_dup;
  135.      ca.opcode_push_integer(value.count);
  136.      idx := cp.idx_methodref3(fz_a0,fz_35,fz_27);
  137.      ca.opcode_invokespecial(idx,0);
  138.      from
  139.         i := value.count;
  140.      until
  141.         i = 0
  142.      loop
  143.         if value.item(i) = '1' then
  144.            ca.opcode_dup;
  145.            ca.opcode_push_integer(i - 1);
  146.            idx := cp.idx_methodref3(fz_a0,fz_a4,fz_27);
  147.            ca.opcode_invokevirtual(idx,-2);
  148.         end;
  149.         i := i - 1;
  150.      end;
  151.       end;
  152.    
  153.    compile_to_jvm_assignment(a: ASSIGNMENT) is
  154.       do
  155.       end;
  156.    
  157.    jvm_branch_if_false: INTEGER is
  158.       do
  159.       end;
  160.  
  161.    jvm_branch_if_true: INTEGER is
  162.       do
  163.       end;
  164.    
  165.    compile_to_jvm_into(dest: TYPE): INTEGER is
  166.       do
  167.      Result := standard_compile_to_jvm_into(dest);
  168.       end;
  169.  
  170.    to_runnable(ct: TYPE): like Current is
  171.       local
  172.      ic: INTEGER_CONSTANT;
  173.       do
  174.      if current_type = Void then
  175.         current_type := ct;
  176.         if result_type = Void then
  177.            !!ic.make(value.count,start_position);
  178.            !!result_type.make(start_position,ic);
  179.            result_type.run_class.set_at_run_time;
  180.         end;
  181.         Result := Current;
  182.      else
  183.         Result := twin;
  184.         Result.set_current_type(Void);
  185.         Result := Result.to_runnable(ct);
  186.      end;
  187.       end;
  188.    
  189.    precedence: INTEGER is
  190.       do
  191.      Result := atomic_precedence;
  192.       end;
  193.  
  194.    to_string: STRING is
  195.       do
  196.      Result := value.twin;
  197.      Result.extend('B');
  198.       end;
  199.    
  200.    bracketed_pretty_print, pretty_print is
  201.       do
  202.      fmt.put_string(value);
  203.      fmt.put_character('B');
  204.       end;
  205.    
  206.    print_as_target is
  207.       do
  208.      fmt.put_character('(');
  209.      pretty_print;
  210.      fmt.put_character(')');
  211.      fmt.put_character('.');
  212.       end;
  213.  
  214.    short is
  215.       local
  216.      i: INTEGER;
  217.       do
  218.      from
  219.         i := 1;
  220.      until
  221.         i > value.count
  222.      loop
  223.         short_print.a_character(value.item(i));
  224.         i := i + 1;
  225.      end;
  226.      short_print.a_character('B');
  227.       end;
  228.    
  229.    short_target is
  230.       do
  231.      bracketed_short;
  232.      short_print.a_dot;
  233.       end;
  234.  
  235. feature {NONE}
  236.  
  237.    compute_c_to_bit is
  238.      -- Compute in `to_bit' the C string view `value'.
  239.       local
  240.      char_bit: STRING;
  241.      i_to_bit, i_value: INTEGER;
  242.       do
  243.      from
  244.         i_to_bit := value.count // Integer_bits;
  245.         if (value.count \\ Integer_bits) /= 0 then
  246.            i_to_bit := i_to_bit + 1;
  247.         end;
  248.         i_to_bit := i_to_bit * (Integer_bits // Character_bits);
  249.         to_bit.clear;
  250.         char_bit := "01010101";
  251.         i_value := 1;
  252.      until
  253.         i_to_bit = 0
  254.      loop
  255.         from
  256.            char_bit.clear;
  257.         until
  258.            char_bit.count = Character_bits
  259.         loop
  260.            if i_value <= value.count then
  261.           char_bit.extend(value.item(i_value));
  262.            else
  263.           char_bit.extend('0');
  264.            end;
  265.            i_value := i_value + 1;
  266.         end;
  267.         to_bit.extend(char_bit.binary_to_integer.to_character);
  268.         i_to_bit := i_to_bit - 1;
  269.      end;
  270.       end;
  271.  
  272.    to_bit: STRING is
  273.       once
  274.      !!Result.make(16);
  275.       end;
  276.  
  277. feature {CREATION_CALL,EXPRESSION_WITH_COMMENT}
  278.       
  279.    jvm_assign is
  280.       do
  281.       end;
  282.  
  283. end -- BIT_CONSTANT
  284.  
  285.  
  286.