home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / code_printer.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  5.9 KB  |  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://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. deferred class CODE_PRINTER
  17.    --
  18.    -- Common root for C_PRETTY_PRINTER and JVM.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature 
  24.    
  25.    incr_static_expression_count is
  26.       do
  27.      static_expression_count := static_expression_count + 1;
  28.       end;
  29.    
  30. feature {NONE}
  31.    
  32.    inlined_procedure_count: INTEGER;
  33.    
  34.    inlined_function_count: INTEGER;
  35.    
  36.    procedure_count: INTEGER;
  37.  
  38.    function_count: INTEGER;
  39.  
  40.    real_procedure_count: INTEGER;
  41.  
  42.    real_function_count: INTEGER;
  43.    
  44.    static_expression_count: INTEGER;
  45.  
  46. feature {RUN_FEATURE_3}
  47.    
  48.    incr_inlined_procedure_count is
  49.       do
  50.      inlined_procedure_count := inlined_procedure_count + 1;
  51.       end;
  52.    
  53.    incr_real_procedure_count is
  54.       do
  55.      real_procedure_count := real_procedure_count + 1;
  56.       end;
  57.    
  58.    incr_procedure_count is
  59.       do
  60.      procedure_count := procedure_count + 1;
  61.       end;
  62.    
  63. feature {RUN_FEATURE_4}
  64.    
  65.    incr_inlined_function_count is
  66.       do
  67.      inlined_function_count := inlined_function_count + 1;
  68.       end;
  69.    
  70.    incr_real_function_count is
  71.       do
  72.      real_function_count := real_function_count + 1;
  73.       end;
  74.    
  75.    incr_function_count is
  76.       do
  77.      function_count := function_count + 1;
  78.       end;
  79.    
  80. feature {RUN_FEATURE_6}
  81.    
  82.    incr_pre_computed_once_count(rf6: RUN_FEATURE_6) is
  83.       do
  84.      if pre_computed_once = Void then
  85.         pre_computed_once := <<rf6>>;
  86.      else
  87.         pre_computed_once.add_last(rf6);
  88.      end;
  89.       end;
  90.    
  91. feature {NONE}
  92.    
  93.    pre_computed_once: ARRAY[RUN_FEATURE_6]
  94.  
  95. feature {NONE} -- Context stacks :
  96.    
  97.    top: INTEGER;
  98.      -- Index for top of followings stacks.
  99.    
  100.    stack_code: FIXED_ARRAY[INTEGER] is
  101.      -- The indicating stack. It contains only one 
  102.      -- of the following unique code.
  103.       once
  104.      !!Result.make(stack_first_size);
  105.       end;
  106.  
  107.    C_direct_call: INTEGER is unique;
  108.      -- Target is sure not to be Void and there is only one possible 
  109.      -- type (target is often Current, a manifest string or an expanded).
  110.    
  111.    C_check_id: INTEGER is unique; 
  112.      -- Target is a reference type which can be Void but only one type 
  113.      -- is the good one. 
  114.    
  115.    C_switch: INTEGER is unique;
  116.      -- Target is a reference type with more than one possibility. 
  117.    
  118.    C_inside_new: INTEGER is unique;
  119.      -- Target has been just created inside a creation call and 
  120.      -- need some ititializing call.
  121.    
  122.    C_expanded_initialize: INTEGER is unique;
  123.      -- Target is some expanded to initialize.
  124.    
  125.    C_inline_dca: INTEGER is unique;
  126.      -- Inlining of a direct call applied on attribute of target.
  127.      -- Target is the one given at `top-1' plus the access to 
  128.      -- the corresponding attribute stored at level `top'.
  129.      -- Arguments are taken at `top-1' context.
  130.  
  131.    C_same_target: INTEGER is unique;
  132.      -- Target is stored at level top - 1;
  133.  
  134.    C_inline_one_pc: INTEGER is unique;
  135.      -- Inlining `one_pc' of RUN_FEATURE_3;
  136.  
  137.    C_inside_twin: INTEGER is unique;
  138.          -- In order to call the user's `copy'.
  139.  
  140.    -- Contents of stacks depends on `stack_code'.
  141.    stack_rf: FIXED_ARRAY[RUN_FEATURE] is
  142.       once
  143.      !!Result.make(stack_first_size);
  144.       end;
  145.  
  146.    stack_target: FIXED_ARRAY[EXPRESSION] is
  147.       once
  148.      !!Result.make(stack_first_size);
  149.       end;
  150.  
  151.    stack_args: FIXED_ARRAY[EFFECTIVE_ARG_LIST] is
  152.       once
  153.      !!Result.make(stack_first_size);
  154.       end;
  155.  
  156.    stack_static_rf: FIXED_ARRAY[RUN_FEATURE] is
  157.       once
  158.      !!Result.make(stack_first_size);
  159.       end;
  160.  
  161.    stack_cpc: FIXED_ARRAY[CALL_PROC_CALL] is
  162.       once
  163.      !!Result.make(stack_first_size);
  164.       end;
  165.  
  166.    stack_first_size: INTEGER is 12;
  167.    
  168.    stack_push(code: INTEGER) is
  169.       -- Push the `code' and resize all stacks if needed.
  170.       local
  171.      new_size: INTEGER;
  172.       do
  173.      top := top + 1;
  174.      if top > stack_code.upper then
  175.         new_size := stack_code.upper * 2;
  176.         stack_code.resize(new_size);
  177.         stack_rf.resize(new_size);
  178.         stack_target.resize(new_size);
  179.         stack_args.resize(new_size);
  180.         stack_static_rf.resize(new_size);
  181.         stack_cpc.resize(new_size);
  182.         if new_size > 2048 then
  183.            stack_overflow
  184.         end;
  185.      end;
  186.      stack_code.put(code,top);
  187.       end;
  188.  
  189. feature {NONE}
  190.  
  191.    stack_overflow is
  192.       local
  193.      i: INTEGER;
  194.      rf: RUN_FEATURE;
  195.      rtm: STRING;
  196.      rtma: FIXED_ARRAY[STRING];
  197.       do
  198.      eh.append("Infinite inlining loop (bad recursion ??). ");
  199.      from
  200.         i := top - 1;
  201.      until
  202.         i < stack_code.lower
  203.      loop
  204.         rf := stack_rf.item(i);
  205.         if rf /= Void then
  206.            eh.add_position(rf.start_position);
  207.            rtm := rf.current_type.run_time_mark;
  208.            if rtma = Void then
  209.           !!rtma.with_capacity(top);
  210.           rtma.add_last(rtm);
  211.           eh.append(rtm);
  212.            elseif rtma.fast_has(rtm) then
  213.            else
  214.           rtma.add_last(rtm);
  215.           eh.append(", ");
  216.           eh.append(rtm);
  217.            end;
  218.         end;
  219.         i := i - 1;
  220.      end;
  221.      eh.fatal_error(",...");
  222.       end;
  223.    
  224. feature    
  225.    
  226.    pop is
  227.       do
  228.      check
  229.         stack_code.lower <= top;
  230.      end;
  231.      top := top - 1;
  232.       ensure
  233.      old(top) = top + 1
  234.       end;
  235.    
  236. feature {NONE}
  237.    
  238.    check_id_count: INTEGER;
  239.    
  240.    direct_call_count: INTEGER;
  241.    
  242.    sure_void_count: INTEGER;
  243.    
  244.    switch_count: INTEGER;
  245.  
  246. end -- CODE_PRINTER
  247.  
  248.