home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / type_bit.e < prev    next >
Text File  |  1999-06-05  |  14KB  |  570 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. deferred class TYPE_BIT
  17.    --
  18.    -- For declarations of the form :
  19.    --        foo : BIT 32;
  20.    --        foo : BIT Real_size;
  21.    --
  22.    -- And then it is the root class of TYPE_BIT_1 and TYPE_BIT_2.
  23.    --
  24.  
  25. inherit TYPE redefine is_bit end;
  26.  
  27. feature
  28.  
  29.    start_position: POSITION;
  30.          -- Of BIT class name.
  31.  
  32.    written_mark: STRING;
  33.  
  34.    run_time_mark: STRING;
  35.  
  36. feature
  37.  
  38.    is_bit: BOOLEAN is true;
  39.  
  40.    is_expanded: BOOLEAN is true;
  41.  
  42.    is_basic_eiffel_expanded: BOOLEAN is false;
  43.  
  44.    is_reference: BOOLEAN is false;
  45.  
  46.    is_dummy_expanded: BOOLEAN is false;
  47.  
  48.    is_user_expanded: BOOLEAN is false;
  49.  
  50.    is_generic: BOOLEAN is false;
  51.  
  52.    is_any: BOOLEAN is false;
  53.  
  54.    need_c_struct: BOOLEAN is false;
  55.  
  56.    is_array: BOOLEAN is false;
  57.  
  58.    is_none: BOOLEAN is false;
  59.  
  60.    is_like_current: BOOLEAN is false;
  61.  
  62.    is_like_argument: BOOLEAN is false;
  63.  
  64.    is_like_feature: BOOLEAN is false;
  65.  
  66.    jvm_method_flags: INTEGER is 9;
  67.  
  68. feature {NONE}
  69.  
  70.    Cchar, Cint, Cuptr: INTEGER is unique;
  71.  
  72.    mapping_code: INTEGER is
  73.       do
  74.          if nb <= Character_bits then
  75.             Result := Cchar;
  76.          elseif nb <= Integer_bits then
  77.             Result := Cint;
  78.          else
  79.             Result := Cuptr;
  80.          end;
  81.       end;
  82.  
  83. feature
  84.  
  85.    is_c_char: BOOLEAN is
  86.       do
  87.          Result := Cchar = mapping_code;
  88.       end;
  89.  
  90.    is_c_int: BOOLEAN is
  91.       do
  92.          Result := Cint = mapping_code;
  93.       end;
  94.  
  95.    is_c_unsigned_ptr: BOOLEAN is
  96.       do
  97.          Result := Cuptr = mapping_code;
  98.       end;
  99.  
  100.    static_base_class_name: CLASS_NAME is
  101.       do
  102.          Result := base_class_name; 
  103.       end;
  104.  
  105.    base_class_name: CLASS_NAME is
  106.       once
  107.          !!Result.make(as_bit_n,Void);
  108.       end;
  109.  
  110.    nb: INTEGER is
  111.          -- Number of bits.
  112.       deferred
  113.       ensure
  114.          nb > 0
  115.       end;
  116.  
  117.    frozen run_class: RUN_CLASS is
  118.       do
  119.          Result := small_eiffel.run_class(Current);
  120.       end;
  121.  
  122.    id: INTEGER is
  123.       do
  124.          Result := run_class.id;
  125.       end;
  126.  
  127.    expanded_initializer: RUN_FEATURE_3 is
  128.       do
  129.       end;
  130.  
  131.    frozen generic_list: ARRAY[TYPE] is
  132.       do
  133.          fatal_error_generic_list;
  134.       end;
  135.  
  136.    jvm_target_descriptor_in, jvm_descriptor_in(str: STRING) is
  137.       do
  138.          str.append(fz_a9);
  139.       end;
  140.  
  141.    jvm_return_code is
  142.       do
  143.          code_attribute.opcode_areturn;
  144.       end;
  145.  
  146.    jvm_push_local(offset: INTEGER) is
  147.       do
  148.          code_attribute.opcode_aload(offset);
  149.       end;
  150.  
  151.    jvm_check_class_invariant is
  152.       do
  153.       end;
  154.  
  155.    jvm_push_default: INTEGER is
  156.       local
  157.          idx: INTEGER;
  158.          ca: like code_attribute;
  159.          cp: like constant_pool;
  160.       do
  161.          ca := code_attribute;
  162.          cp := constant_pool;
  163.          idx := cp.idx_class2(fz_a0);
  164.          ca.opcode_new(idx);
  165.          ca.opcode_dup;
  166.          ca.opcode_push_integer(nb);
  167.          idx := cp.idx_methodref3(fz_a0,fz_35,fz_27);
  168.          ca.opcode_invokespecial(idx,0);
  169.       end;
  170.  
  171.    jvm_write_local(offset: INTEGER) is
  172.       local
  173.          ca: like code_attribute;
  174.       do
  175.          ca := code_attribute;
  176.          ca.opcode_bitset_clone;
  177.          ca.opcode_astore(offset);
  178.       end;
  179.  
  180.    jvm_xnewarray is
  181.       local
  182.          idx: INTEGER;
  183.       do
  184.          idx := constant_pool.idx_java_lang_object;
  185.          code_attribute.opcode_anewarray(idx);
  186.       end;
  187.  
  188.    jvm_xastore is
  189.       do
  190.          code_attribute.opcode_aastore;
  191.       end;
  192.  
  193.    jvm_xaload is
  194.       do
  195.          code_attribute.opcode_aaload;
  196.       end;
  197.  
  198.    jvm_if_x_eq: INTEGER is
  199.       local
  200.          idx: INTEGER;
  201.          ca: like code_attribute;
  202.          cp: like constant_pool;
  203.       do
  204.          ca := code_attribute;
  205.          cp := constant_pool;
  206.          idx := cp.idx_methodref3(fz_a0,fz_a1,fz_a8);
  207.          ca.opcode_invokevirtual(idx,0);
  208.          Result := ca.opcode_ifne;
  209.       end;
  210.  
  211.    jvm_if_x_ne: INTEGER is
  212.       local
  213.          idx: INTEGER;
  214.          ca: like code_attribute;
  215.          cp: like constant_pool;
  216.       do
  217.          ca := code_attribute;
  218.          cp := constant_pool;
  219.          idx := cp.idx_methodref3(fz_a0,fz_a1,fz_a8);
  220.          ca.opcode_invokevirtual(idx,0);
  221.          Result := ca.opcode_ifeq;
  222.       end;
  223.  
  224.    jvm_to_reference is
  225.       local
  226.          rc: RUN_CLASS;
  227.          idx: INTEGER;
  228.          type_bit_ref: TYPE_BIT_REF;
  229.          ca: like code_attribute;
  230.       do
  231.          ca := code_attribute;
  232.          idx := mem_ref_nb.fast_index_of(nb);
  233.          type_bit_ref := mem_type_bit_ref.item(idx);
  234.          rc := type_bit_ref.run_class;
  235.          rc.jvm_basic_new;
  236.          ca.opcode_dup_x1;
  237.          ca.opcode_swap;
  238.          idx := rc.jvm_constant_pool_index;
  239.          idx := constant_pool.idx_fieldref4(idx,as_bitn,fz_a9);
  240.          ca.opcode_putfield(idx,-2);
  241.       end;
  242.  
  243.    frozen jvm_expanded_from_reference(other: TYPE): INTEGER is
  244.       do
  245.          check
  246.             false
  247.          end;
  248.       end;
  249.  
  250.    frozen jvm_convert_to(destination: TYPE): INTEGER is
  251.       local
  252.          space, idx, loc1, loc2: INTEGER;
  253.          point1, point2, point3: INTEGER;
  254.          other_bit: TYPE_BIT;
  255.          ca: like code_attribute;
  256.          cp: like constant_pool;
  257.       do
  258.          Result := 1;
  259.          if destination.is_reference then
  260.             jvm_to_reference;
  261.          else
  262.             ca := code_attribute;
  263.             cp := constant_pool;
  264.             other_bit ?= destination;
  265.             space := other_bit.jvm_push_default;
  266.             ca.opcode_swap;
  267.             loc1 := ca.extra_local_size1;
  268.             ca.opcode_push_integer(other_bit.nb);
  269.             ca.opcode_istore(loc1);
  270.             loc2 := ca.extra_local_size1;
  271.             ca.opcode_push_integer(nb);
  272.             ca.opcode_istore(loc2);
  273.             ca.opcode_iload(loc2);
  274.             point1 := ca.program_counter;
  275.             point2 := ca.opcode_ifeq;
  276.             ca.opcode_iinc(loc1,255);
  277.             ca.opcode_iinc(loc2,255);
  278.             ca.opcode_dup2;
  279.             ca.opcode_iload(loc2);
  280.             idx := cp.idx_methodref3(fz_a0,fz_a2,fz_a3);
  281.             ca.opcode_invokevirtual(idx,0);
  282.             point3 := ca.opcode_ifne;
  283.             ca.opcode_pop;
  284.             ca.opcode_iload(loc2);
  285.             ca.opcode_goto_backward(point1);
  286.             ca.resolve_u2_branch(point3);
  287.             ca.opcode_iload(loc1);
  288.             idx := cp.idx_methodref3(fz_a0,fz_a4,fz_27);
  289.             ca.opcode_invokevirtual(idx,0);
  290.             ca.opcode_iload(loc2);
  291.             ca.opcode_goto_backward(point1);
  292.             ca.resolve_u2_branch(point2);
  293.             ca.opcode_pop;
  294.          end;
  295.       end;
  296.  
  297.    jvm_standard_is_equal is
  298.       local
  299.          rc: RUN_CLASS;
  300.          wa: ARRAY[RUN_FEATURE_2];
  301.       do
  302.          rc := run_class;
  303.          wa := rc.writable_attributes;
  304.          jvm.std_is_equal(rc,wa);
  305.       end;
  306.  
  307.    frozen c_header_pass1 is
  308.       local
  309.          mc, mem_id: INTEGER;
  310.       do
  311.          mc := mapping_code;
  312.          mem_id := id;
  313.          tmp_string.copy(fz_typedef);
  314.          inspect
  315.             mapping_code
  316.          when Cchar then
  317.             tmp_string.append(fz_unsigned);
  318.             tmp_string.extend(' ');
  319.             tmp_string.append(fz_char);
  320.          when Cint then
  321.             tmp_string.append(fz_unsigned);
  322.             tmp_string.extend(' ');
  323.             tmp_string.append(fz_int);
  324.          when Cuptr then
  325.             tmp_string.append(fz_unsigned);
  326.          end;
  327.          tmp_string.extend(' ');
  328.          tmp_string.extend('T');
  329.          mem_id.append_in(tmp_string);
  330.          if mapping_code = Cuptr then
  331.             tmp_string.extend('[');
  332.             nb_unsigned.append_in(tmp_string);
  333.             tmp_string.extend(']');
  334.          end;
  335.          tmp_string.append(fz_00);
  336.          cpp.put_string(tmp_string);
  337.       end;
  338.  
  339.    frozen c_header_pass2 is
  340.       do
  341.       end;
  342.  
  343.    frozen c_header_pass3 is
  344.       do
  345.       end;
  346.  
  347.    frozen c_header_pass4 is
  348.       do
  349.          standard_c_print_function;
  350.       end;
  351.  
  352.    frozen c_type_for_argument_in(str: STRING) is
  353.       do
  354.          str.extend('T');
  355.          id.append_in(str);
  356.       end;
  357.  
  358.    frozen c_type_for_target_in(str: STRING) is
  359.       do
  360.          c_type_for_argument_in(str);
  361.       end;
  362.  
  363.    frozen c_type_for_result_in(str: STRING) is
  364.       do
  365.          c_type_for_argument_in(str);
  366.       end;
  367.  
  368.    frozen space_for_variable, frozen space_for_object: INTEGER is
  369.       do
  370.          Result := nb_unsigned * (Integer_bits // Character_bits);
  371.       end;
  372.  
  373.    frozen has_creation(fn: FEATURE_NAME): BOOLEAN is
  374.       do
  375.       end;
  376.  
  377.    frozen smallest_ancestor(other: TYPE): TYPE is
  378.       local
  379.          other_bit: TYPE_BIT;
  380.       do
  381.          other_bit ?= other.run_type;
  382.          if other_bit /= Void then
  383.             if nb < other_bit.nb then
  384.                Result := Current;
  385.             else
  386.                Result := other_bit;
  387.             end;
  388.          else
  389.             Result := type_any;
  390.          end;
  391.       end;
  392.  
  393.    frozen is_a(other: TYPE): BOOLEAN is
  394.       local
  395.          other_bit: TYPE_BIT;
  396.       do
  397.          if other.is_bit then
  398.             other_bit ?= other.run_type;
  399.             if nb <= other_bit.nb then
  400.                Result := true;
  401.             else
  402.                eh.add_type(Current,fz_inako);
  403.                eh.add_type(other," (VNCB.2).");
  404.             end;
  405.          elseif base_class.is_subclass_of(other.base_class) then
  406.             Result := true;
  407.             used_as_reference;
  408.          else
  409.             eh.add_type(Current,fz_inako);
  410.             eh.add_type(other,fz_dot);
  411.          end;
  412.       end;
  413.  
  414.    frozen run_type: TYPE_BIT is
  415.       do
  416.          Result := Current;
  417.       end;
  418.  
  419.    frozen c_initialize is
  420.       local
  421.          i: INTEGER;
  422.       do
  423.          if mapping_code = Cuptr then
  424.             tmp_string.clear;
  425.             tmp_string.extend('{');
  426.             from
  427.                i := nb_unsigned;
  428.             until
  429.                i = 0
  430.             loop
  431.                tmp_string.extend('0');
  432.                i := i - 1;
  433.                if i > 0 then
  434.                   tmp_string.extend(',');
  435.                end;
  436.             end;
  437.             tmp_string.extend('}');
  438.             cpp.put_string(tmp_string);
  439.          else
  440.             cpp.put_character('0');
  441.          end;
  442.       end;
  443.  
  444.    frozen c_initialize_in(str: STRING) is
  445.       local
  446.          i: INTEGER;
  447.       do
  448.          if mapping_code = Cuptr then
  449.             str.extend('{');
  450.             from
  451.                i := nb_unsigned;
  452.             until
  453.                i = 0
  454.             loop
  455.                str.extend('0');
  456.                i := i - 1;
  457.                if i > 0 then
  458.                   str.extend(',');
  459.                end;
  460.             end;
  461.             str.extend('}');
  462.          else
  463.             str.extend('0');
  464.          end;
  465.       end;
  466.  
  467. feature
  468.  
  469.    frozen to_reference is
  470.       local
  471.          idx: INTEGER;
  472.          type_bit_ref: TYPE_BIT_REF;
  473.       do
  474.          idx := mem_ref_nb.fast_index_of(nb);
  475.          type_bit_ref := mem_type_bit_ref.item(idx);
  476.          cpp.put_string(fz_to_t);
  477.          cpp.put_integer(type_bit_ref.id);
  478.       end;
  479.  
  480.    frozen used_as_reference is
  481.       local
  482.          type_bit_ref: TYPE_BIT_REF;
  483.          rc: RUN_CLASS;
  484.          rf: RUN_FEATURE;
  485.       do
  486.          if mem_ref_nb.fast_has(nb) then
  487.          else
  488.             mem_ref_nb.add_last(nb);
  489.             !!type_bit_ref.make(Current);
  490.             mem_type_bit_ref.add_last(type_bit_ref);
  491.             rc := type_bit_ref.run_class;
  492.             rc.set_at_run_time;
  493.             rf := rc.get_feature_with(as_bitn);
  494.          end;
  495.       end;
  496.  
  497. feature {RUN_CLASS,TYPE}
  498.  
  499.    need_gc_mark_function: BOOLEAN is false;
  500.  
  501.    frozen just_before_gc_mark_in(str: STRING) is
  502.       do
  503.       end;
  504.  
  505.    frozen gc_info_in(str: STRING) is
  506.       do
  507.       end;
  508.  
  509.    frozen gc_define1 is
  510.       do
  511.       end;
  512.  
  513.    frozen gc_define2 is
  514.       do
  515.       end;
  516.  
  517. feature {NONE}
  518.  
  519.    mem_type_bit_ref: FIXED_ARRAY[TYPE_BIT_REF] is
  520.       once
  521.          !!Result.with_capacity(4);
  522.       end;
  523.  
  524.    mem_ref_nb: FIXED_ARRAY[INTEGER] is
  525.       once
  526.          !!Result.with_capacity(4);
  527.       end;
  528.  
  529. feature {NONE}
  530.  
  531.    set_run_time_mark is
  532.       do
  533.          tmp_string.copy(fz_bit_foo);
  534.          tmp_string.append(nb.to_string);
  535.          run_time_mark := string_aliaser.item(tmp_string);
  536.       end;
  537.  
  538. feature {NATIVE_SMALL_EIFFEL}
  539.  
  540.    unsigned_padding: INTEGER is
  541.       do
  542.          Result := (nb_unsigned * Integer_bits) - nb;
  543.       end;
  544.  
  545. feature {NONE}
  546.  
  547.    to_runnable_1_2 is
  548.       local
  549.          rc: RUN_CLASS;
  550.          rf: RUN_FEATURE;
  551.       do
  552.          rc := run_class;
  553.          rf := rc.get_feature_with(as_put_0);
  554.          rf := rc.get_feature_with(as_put_1);
  555.       end;
  556.  
  557.    nb_unsigned: INTEGER is
  558.       local
  559.          ib: INTEGER;
  560.       do
  561.          ib := Integer_bits
  562.          Result := nb // ib;
  563.          if (nb \\ ib) > 0 then
  564.             Result := Result + 1;
  565.          end;
  566.       end;
  567.  
  568. end -- TYPE_BIT
  569.  
  570.