home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / once_routine_pool.e < prev    next >
Text File  |  1999-06-05  |  8KB  |  275 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 ONCE_ROUTINE_POOL
  17.    --
  18.    -- Unique global object in charge of runnable once routines.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature {NONE}
  24.  
  25.    procedure_list: FIXED_ARRAY[RUN_FEATURE_5] is
  26.       once
  27.          !!Result.with_capacity(32);
  28.       end;
  29.  
  30.    procedure_flag_list: FIXED_ARRAY[INTEGER];
  31.  
  32.    function_list: FIXED_ARRAY[RUN_FEATURE_6] is
  33.       once
  34.          !!Result.with_capacity(32);
  35.       end;
  36.  
  37.    function_flag_list: FIXED_ARRAY[INTEGER];
  38.  
  39.    flag_list: FIXED_ARRAY[INTEGER] is
  40.       once
  41.          !!Result.with_capacity(32);
  42.       end;
  43.  
  44. feature {RUN_FEATURE_5}
  45.  
  46.    add_procedure(rf5: RUN_FEATURE_5) is
  47.       require
  48.          rf5 /= Void
  49.       do
  50.          check
  51.             not procedure_list.has(rf5)
  52.          end;
  53.          procedure_list.add_last(rf5);
  54.       end;
  55.  
  56. feature {RUN_FEATURE_6}
  57.  
  58.    add_function(rf6: RUN_FEATURE_6) is
  59.       require
  60.          rf6 /= Void
  61.       do
  62.          check
  63.             not function_list.has(rf6)
  64.          end;
  65.          function_list.add_last(rf6);
  66.       end;
  67.  
  68. feature {GC_HANDLER}
  69.  
  70.    gc_mark_in(c_code: STRING) is
  71.       local
  72.          i: INTEGER;
  73.          rf6: RUN_FEATURE_6;
  74.          of: ONCE_FUNCTION;
  75.          mem: FIXED_ARRAY[ONCE_FUNCTION];
  76.          rt: TYPE;
  77.          entity: STRING;
  78.       do
  79.          if function_list.count > 0 then
  80.             !!entity.make(32);
  81.             from
  82.                i := function_list.upper;
  83.                !!mem.with_capacity(i // 2);
  84.             until
  85.                i < 0
  86.             loop
  87.                rf6 := function_list.item(i);
  88.                of := rf6.base_feature;
  89.                if not mem.fast_has(of) then
  90.                   if rf6.current_type.run_class.at_run_time then
  91.                      mem.add_last(of);
  92.                      rt := rf6.result_type;
  93.                      if rt.need_gc_mark_function then
  94.                         entity.clear;
  95.                         rf6.once_result_in(entity);
  96.                         gc_handler.mark_for(c_code,entity,rt.run_class);
  97.                      end;
  98.                   end;
  99.                end;
  100.                i := i - 1;
  101.             end;
  102.          end;
  103.       end;
  104.  
  105. feature {JVM}
  106.  
  107.    fields_count: INTEGER;
  108.  
  109.    jvm_define_fields is
  110.       local
  111.          byte_idx, idx_flag, i: INTEGER;
  112.          rf5: RUN_FEATURE_5;
  113.          rf6: RUN_FEATURE_6;
  114.          bf: E_FEATURE;
  115.          name_list: FIXED_ARRAY[INTEGER];
  116.       do
  117.          !!name_list.with_capacity(fields_count);
  118.          if function_list.count > 0 then
  119.             from
  120.                i := function_list.upper;
  121.                byte_idx := constant_pool.idx_utf8(fz_41);
  122.             until
  123.                i < 0
  124.             loop
  125.                rf6 := function_list.item(i);
  126.                bf := rf6.base_feature;
  127.                idx_flag := idx_name_for_flag(bf);
  128.                if name_list.fast_has(idx_flag) then
  129.                else
  130.                   name_list.add_last(idx_flag);
  131.                   -- ---------- Static field for flag :
  132.                   field_info.add(9,idx_flag,byte_idx);
  133.                   -- ---------- Static field for result :
  134.                   field_info.add(9,
  135.                                  idx_name_for_result(bf),
  136.                                  idx_descriptor(rf6.result_type.run_type));
  137.                end;
  138.                i := i - 1;
  139.             end;
  140.          end;
  141.          if procedure_list.count > 0 then
  142.             from
  143.                i := procedure_list.upper;
  144.                byte_idx := constant_pool.idx_utf8(fz_41);
  145.             until
  146.                i < 0
  147.             loop
  148.                rf5 := procedure_list.item(i);
  149.                bf := rf5.base_feature;
  150.                idx_flag := idx_name_for_flag(bf);
  151.                if name_list.fast_has(idx_flag) then
  152.                else
  153.                   name_list.add_last(idx_flag);
  154.                   -- ---------- Static field for flag :
  155.                   field_info.add(9,idx_flag,byte_idx);
  156.                end;
  157.                i := i - 1;
  158.             end;
  159.          end;
  160.       end;
  161.  
  162.    jvm_initialize_fields is
  163.       local
  164.          i: INTEGER;
  165.       do
  166.          if flag_list.count > 0 then
  167.             from
  168.                i := flag_list.upper;
  169.             until
  170.                i < 0
  171.             loop
  172.                -- Set once flag :
  173.                code_attribute.opcode_iconst_0;
  174.                code_attribute.opcode_putstatic(flag_list.item(i),-1);
  175.                i := i - 1;
  176.             end;
  177.          end;
  178.       end;
  179.  
  180. feature {RUN_FEATURE_5,RUN_FEATURE_6}
  181.  
  182.    idx_fieldref_for_flag(rf: RUN_FEATURE): INTEGER is
  183.       require
  184.          rf /= Void
  185.       do
  186.          prepare_flag(rf.base_feature);
  187.          Result := constant_pool.idx_fieldref3(jvm_root_class,
  188.                                                flag_string,
  189.                                                fz_41);
  190.       end;
  191.  
  192. feature {RUN_FEATURE_6}
  193.  
  194.    idx_fieldref_for_result(rf6: RUN_FEATURE_6): INTEGER is
  195.       require
  196.          rf6 /= Void
  197.       do
  198.          prepare_result(rf6.base_feature);
  199.          prepare_descriptor(rf6.result_type.run_type);
  200.          Result := constant_pool.idx_fieldref3(jvm_root_class,
  201.                                                result_string,
  202.                                                descriptor_string);
  203.       end;
  204.  
  205.  
  206. feature {NONE}
  207.  
  208.    idx_descriptor(rt: TYPE): INTEGER is
  209.       require
  210.          rt /= Void
  211.       do
  212.          prepare_descriptor(rt);
  213.          Result := constant_pool.idx_utf8(descriptor_string);
  214.       end
  215.  
  216.    idx_name_for_result(bf: E_FEATURE): INTEGER is
  217.       require
  218.          bf /= Void
  219.       do
  220.          prepare_result(bf);
  221.          Result := constant_pool.idx_utf8(result_string);
  222.       end
  223.  
  224.    idx_name_for_flag(bf: E_FEATURE): INTEGER is
  225.       require
  226.          bf /= Void
  227.       do
  228.          prepare_flag(bf);
  229.          Result := constant_pool.idx_utf8(flag_string);
  230.       end
  231.  
  232.    flag_string: STRING is
  233.       once
  234.          !!Result.make(32);
  235.       end;
  236.  
  237.    prepare_flag(bf: E_FEATURE) is
  238.       do
  239.          flag_string.clear;
  240.          flag_string.extend('f');
  241.          bf.base_class.id.append_in(flag_string);
  242.          flag_string.append(bf.first_name.to_key);
  243.       end;
  244.  
  245.    result_string: STRING is
  246.       once
  247.          !!Result.make(32);
  248.       end;
  249.  
  250.    prepare_result(bf: E_FEATURE) is
  251.       do
  252.          result_string.clear;
  253.          result_string.extend('r');
  254.          bf.base_class.id.append_in(result_string);
  255.          result_string.append(bf.first_name.to_key);
  256.       end;
  257.  
  258.    prepare_descriptor(rt: TYPE) is
  259.       do
  260.          descriptor_string.clear;
  261.          if rt.is_reference then
  262.             descriptor_string.append(jvm_root_descriptor)
  263.          else
  264.             rt.jvm_descriptor_in(descriptor_string)
  265.          end;
  266.       end;
  267.  
  268.    descriptor_string: STRING is
  269.       once
  270.          !!Result.make(32);
  271.       end;
  272.  
  273. end -- ONCE_ROUTINE_POOL
  274.  
  275.