home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / run_feature_6.e < prev    next >
Text File  |  1999-06-05  |  10KB  |  366 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 RUN_FEATURE_6
  17.  
  18. inherit RUN_FEATURE redefine base_feature end;
  19.  
  20. creation make
  21.  
  22. feature
  23.  
  24.    base_feature: ONCE_FUNCTION;
  25.  
  26.    arguments: FORMAL_ARG_LIST;
  27.  
  28.    result_type: TYPE;
  29.  
  30.    require_assertion: RUN_REQUIRE;
  31.  
  32.    local_vars: LOCAL_VAR_LIST;
  33.  
  34.    routine_body: COMPOUND;
  35.  
  36.    rescue_compound: COMPOUND;
  37.  
  38.    ensure_assertion: E_ENSURE;
  39.  
  40. feature
  41.  
  42.    is_once_function: BOOLEAN is true;
  43.  
  44.    is_static: BOOLEAN is false;
  45.  
  46.    static_value_mem: INTEGER is 0;
  47.  
  48. feature
  49.  
  50.    afd_check is
  51.       do
  52.          routine_afd_check;
  53.       end;
  54.  
  55.    can_be_dropped: BOOLEAN is
  56.       do
  57.          Result := is_pre_computable;
  58.       end;
  59.  
  60.    mapping_c is
  61.       do
  62.          if is_pre_computable then
  63.             cpp_once_result;
  64.          else
  65.             default_mapping_function;
  66.          end;
  67.       end;
  68.  
  69.    c_define is
  70.       local
  71.          bfbc: BASE_CLASS;
  72.       do
  73.          bfbc := base_feature.base_class;
  74.          if is_pre_computable then
  75.             if not bfbc.once_flag(once_mark) then
  76.                once_variable;
  77.             end;
  78.             cpp.add_pre_computed_once_function(Current);
  79.          else
  80.             if not bfbc.once_flag(once_mark) then
  81.                once_boolean;
  82.                once_variable;
  83.             end;
  84.             define_prototype;
  85.             cpp.put_string("if(");
  86.             once_flag;
  87.             cpp.put_string("==0){%N");
  88.             c_define_opening;
  89.             once_flag;
  90.             cpp.put_string("=1;%N");
  91.             if routine_body /= Void then
  92.                routine_body.compile_to_c;
  93.             end;
  94.             c_define_closing;
  95.             cpp.put_string("}%N");
  96.             cpp.put_string("return ");
  97.             cpp_once_result;
  98.             cpp.put_string(";}%N");
  99.             c_frame_descriptor;
  100.          end;
  101.       end;
  102.  
  103. feature {ABSTRACT_RESULT}
  104.  
  105.    cpp_once_result is
  106.          -- Produce the C name of the once Result.
  107.       do
  108.          c_code.clear;
  109.          once_result_in(c_code);
  110.          cpp.put_string(c_code);
  111.       end;
  112.  
  113.    once_variable is
  114.       do
  115.          c_code.clear;
  116.          c_code.extend('T');
  117.          if result_type.is_expanded then
  118.             result_type.id.append_in(c_code);
  119.             c_code.extend(' ');
  120.          else
  121.             c_code.extend('0');
  122.             c_code.extend('*');
  123.          end;
  124.          once_result_in(c_code);
  125.          c_code2.clear;
  126.          result_type.c_initialize_in(c_code2);
  127.          cpp.put_extern5(c_code,c_code2);
  128.       end;
  129.  
  130. feature {CALL_PROC_CALL}
  131.  
  132.    collect_c_tmp is
  133.       do
  134.       end;
  135.  
  136. feature {ADDRESS_OF_POOL}
  137.  
  138.    address_of_c_define(caller: ADDRESS_OF) is
  139.       do
  140.          if run_control.boost then
  141.             if use_current then
  142.             else
  143.                address_of_c_define_wrapper(caller);
  144.             end;
  145.          else
  146.             address_of_c_define_wrapper(caller);
  147.          end;
  148.       end;
  149.  
  150. feature {ADDRESS_OF}
  151.  
  152.    address_of_c_mapping is
  153.       do
  154.          if run_control.boost then
  155.             if use_current then
  156.                mapping_name;
  157.             else
  158.                address_of_c_mapping_wrapper;
  159.             end;
  160.          else
  161.             address_of_c_mapping_wrapper;
  162.          end;
  163.       end;
  164.  
  165. feature {C_PRETTY_PRINTER}
  166.  
  167.    is_pre_computable: BOOLEAN is
  168.       do
  169.          if frozen_general.fast_has(name.to_string) then
  170.             Result := true;
  171.          elseif arguments = Void and then not use_current then
  172.             if routine_body = Void then
  173.                Result := true;
  174.             elseif not run_control.invariant_check then
  175.                Result := routine_body.is_pre_computable;
  176.             end;
  177.          end;
  178.          if Result then
  179.             if require_assertion /= Void then
  180.                require_assertion.clear_run_feature;
  181.             end;
  182.             if ensure_assertion /= Void then
  183.                ensure_assertion.clear_run_feature;
  184.             end;
  185.          end;
  186.       end;
  187.  
  188.    c_pre_computing is
  189.       require
  190.          is_pre_computable;
  191.          cpp.on_c;
  192.       local
  193.          bfbc: BASE_CLASS;
  194.       do
  195.          bfbc := base_feature.base_class;
  196.          echo.put_character('%T');
  197.          echo.put_string(bfbc.name.to_string);
  198.          echo.put_character('.');
  199.          echo.put_string(name.to_string);
  200.          echo.put_character('%N');
  201.          if run_control.require_check then
  202.             if require_assertion /= Void then
  203.                require_assertion.compile_to_c;
  204.             end;
  205.          end;
  206.          if result_type.is_expanded then 
  207.             -- *** Is this useful ? ***
  208.             cpp_once_result;
  209.             cpp.put_character('=');
  210.             result_type.c_initialize;
  211.             cpp.put_string(fz_00);
  212.          end;
  213.          if local_vars /= Void then
  214.             cpp.put_character('{');
  215.             local_vars.c_declare;
  216.          end;
  217.          if routine_body /= Void then
  218.             routine_body.compile_to_c;
  219.          end;
  220.          if run_control.ensure_check then
  221.             if ensure_assertion /= Void then
  222.                ensure_assertion.compile_to_c;
  223.             end;
  224.          end;
  225.          if local_vars /= Void then
  226.             cpp.put_character('}');
  227.          end;
  228.          cpp.put_string("/*PCO*/%N");
  229.       end;
  230.  
  231.    tmp_string: STRING is
  232.       once
  233.          !!Result.make(10);
  234.       end;
  235.  
  236. feature {RUN_CLASS}
  237.  
  238.    jvm_field_or_method is
  239.       do
  240.          jvm.add_method(Current);
  241.       end;
  242.  
  243. feature
  244.  
  245.    mapping_jvm is
  246.       do
  247.          routine_mapping_jvm;
  248.       end;
  249.  
  250. feature {JVM}
  251.  
  252.    jvm_define is
  253.       local
  254.          branch, idx_flag: INTEGER;
  255.          ca: like code_attribute;
  256.       do
  257.          ca := code_attribute;
  258.          idx_flag := once_routine_pool.idx_fieldref_for_flag(Current);
  259.          method_info_start;
  260.          ca.opcode_getstatic(idx_flag,1);
  261.          branch := ca.opcode_ifne;
  262.          ca.opcode_iconst_1;
  263.          ca.opcode_putstatic(idx_flag,-1);
  264.          jvm_define_opening;
  265.          if routine_body /= Void then
  266.             routine_body.compile_to_jvm;
  267.          end;
  268.          jvm_define_closing;
  269.          ca.resolve_u2_branch(branch);
  270.          jvm_result_load;
  271.          result_type.run_type.jvm_return_code;
  272.          method_info.finish;
  273.       end;
  274.  
  275. feature {ONCE_RESULT}
  276.  
  277.    c_variable_name: STRING is
  278.       do
  279.          c_code.clear;
  280.          once_result_in(c_code);
  281.          Result := c_code;
  282.       end;
  283.  
  284.    jvm_result_load is
  285.       local
  286.          result_space, idx_result: INTEGER;
  287.       do
  288.          result_space := result_type.jvm_stack_space;
  289.          idx_result := once_routine_pool.idx_fieldref_for_result(Current);
  290.          code_attribute.opcode_getstatic(idx_result,result_space);
  291.       end;
  292.  
  293.    jvm_result_store is
  294.       local
  295.          result_space, idx_result: INTEGER;
  296.       do
  297.          result_space := result_type.jvm_stack_space;
  298.          idx_result := once_routine_pool.idx_fieldref_for_result(Current);
  299.          code_attribute.opcode_putstatic(idx_result,- result_space);
  300.       end;
  301.  
  302.    fe_vffd7 is
  303.       do
  304.          eh.add_position(result_type.start_position);
  305.          fatal_error("Result type of a once function must %
  306.                      %not be anchored (VFFD.7).");
  307.       end;
  308.  
  309. feature {RUN_FEATURE_6}
  310.  
  311.    initialize is
  312.       do
  313.          result_type := base_feature.result_type;
  314.          arguments := base_feature.arguments;
  315.          if result_type.is_anchored then
  316.             fe_vffd7;
  317.          elseif result_type.is_formal_generic then
  318.             eh.add_position(result_type.start_position);
  319.             fatal_error("Result type of a once function must %
  320.                         %not be a formal generic argument (VFFD.7).");
  321.          end;
  322.          result_type := result_type.to_runnable(current_type);
  323.          if arguments /= Void then
  324.             if not arguments.is_runnable(current_type) then
  325.                !!arguments.with(arguments,current_type);
  326.             end;
  327.          end;
  328.          local_vars := base_feature.local_vars;
  329.          if local_vars /= Void then
  330.             local_vars := local_vars.to_runnable(current_type);
  331.          end;
  332.          routine_body := base_feature.routine_body;
  333.          if routine_body /= Void then
  334.             routine_body := routine_body.to_runnable(current_type);
  335.          end;
  336.          if run_control.require_check then
  337.             require_assertion := run_require;
  338.          end;
  339.          if run_control.ensure_check then
  340.             ensure_assertion := run_ensure;
  341.          end;
  342.          rescue_compound := base_feature.rescue_compound;
  343.          if rescue_compound /= Void then
  344.             exceptions_handler.set_used;
  345.             rescue_compound := rescue_compound.to_runnable(current_type);
  346.          end;
  347.          once_routine_pool.add_function(Current);
  348.       end;
  349.  
  350.    frozen_general: ARRAY[STRING] is
  351.       once
  352.          Result := <<as_std_error, as_std_input, as_io, as_std_output>>;
  353.       end;
  354.  
  355.    compute_use_current is
  356.       do
  357.          std_compute_use_current;
  358.       end;
  359.  
  360.    update_tmp_jvm_descriptor is
  361.       do
  362.          routine_update_tmp_jvm_descriptor;
  363.       end;
  364.  
  365. end -- RUN_FEATURE_6
  366.