Skip to content
This repository
Browse code

Add --var-signature option and some bugs fixed

  • Loading branch information...
commit 011f5437e84218303a101714a7086e2bf66cf2a3 1 parent 131b0b5
Miura Hideki authored September 21, 2009
9  lib/llvmutil.rb
@@ -248,13 +248,11 @@ def gen_loop_proc(para)
248 248
       if rec[0].type.is_a?(ComplexType) then
249 249
         rec[0].type.element_type.add_same_type atype
250 250
         # atype.add_same_type rec[0].type.element_type
251  
-      else
252  
-        rec[0].add_same_type atype
253  
-        atype.add_same_type rec[0]
254 251
       end
255 252
     end
256 253
     
257 254
     lambda {|b, context, lst, led, body, recval, excl|
  255
+=begin
258 256
       if argsize == 1 then
259 257
         if rec[0].type.is_a?(ComplexType) then
260 258
           rec[0].type.element_type.add_same_type atype
@@ -265,6 +263,7 @@ def gen_loop_proc(para)
265 263
         end
266 264
       end
267 265
       RubyType.resolve
  266
+=end
268 267
       
269 268
       bcond = context.builder.create_block
270 269
       bbody = context.builder.create_block
@@ -466,6 +465,10 @@ def gen_method_select(rectype, lexklass, mname)
466 465
 
467 466
     elsif candidatenum < MaxSmallPolymotphicNum then
468 467
       # TODO : Use inline hash function generation
  468
+      p rectype.conflicted_types.keys
  469
+      p rectype.inspect2
  470
+      p rectype.name
  471
+      p lexklass
469 472
       raise("Not implimented polymorphic methed call yet '#{mname}' #{lexklass}")
470 473
 
471 474
     else
7  lib/methoddef.rb
@@ -103,9 +103,9 @@ module MethodDefinition
103 103
 
104 104
             case arr[0].type
105 105
             when ArrayType
106  
-              val[0].add_same_type(arr[0].type.element_type)
107  
-              arr[0].type.element_type.add_same_type(val[0])
108  
-              RubyType.resolve
  106
+#              val[0].add_same_type(arr[0].type.element_type)
  107
+#              arr[0].type.element_type.add_same_type(val[0])
  108
+#              RubyType.resolve
109 109
               ftype = Type.function(Type::VoidTy, 
110 110
                                     [VALUE, MACHINE_WORD, VALUE])
111 111
               func = context.builder.external_function('rb_ary_store', ftype)
@@ -520,6 +520,7 @@ module MethodDefinition
520 520
                   context
521 521
                   
522 522
                 else
  523
+                  p rec[0].conflicted_types.keys
523 524
                   raise "Do not supported #{rec[0].inspect2}"
524 525
                 end
525 526
             }]
4  lib/type.rb
@@ -819,7 +819,7 @@ def has_cycle?
819 819
   def inspect2
820 820
     if @element_type then
821 821
       if has_cycle? then
822  
-        "Array of VALUE"
  822
+        "Array of Array of ..."
823 823
       else
824 824
         "Array of #{@element_type.inspect2}"
825 825
       end
@@ -886,7 +886,7 @@ def has_cycle?
886 886
   def inspect2
887 887
     if @element_type then
888 888
       if has_cycle? then
889  
-        "Hash of VALUE"
  889
+        "Hash of Hash of ..."
890 890
       else
891 891
         "Hash of #{@element_type.inspect2}"
892 892
       end
69  lib/vmtraverse.rb
@@ -252,6 +252,16 @@ def initialize(iseq, bind, preload)
252 252
   def run
253 253
     super
254 254
 
  255
+    if OPTION[:var_signature] then
  256
+      @global_var_tab.each do |vn, vtab|
  257
+        if tinfo = vtab[:type] then
  258
+          print "#{vn} : #{tinfo.inspect2} \n"
  259
+        else
  260
+          print "#{vn} : nil \n"
  261
+        end
  262
+      end
  263
+    end
  264
+
255 265
     # generate code for access Ruby internal
256 266
     if OPTION[:cache_instance_variable] then
257 267
       if @instance_var_tab.size != 0 then
@@ -950,8 +960,8 @@ def visit_local_block_end(code, ins, local_vars, ln, info)
950 960
     # don't call before visit_block_start call.
951 961
     if @is_live == nil then
952 962
       @is_live = true
  963
+      @prev_label = ln
953 964
     end
954  
-    @prev_label = ln
955 965
 
956 966
     # p @expstack.map {|n| n[1]}
957 967
   end
@@ -1267,6 +1277,7 @@ def visit_setglobal(code, ins, local_vars, ln, info)
1267 1277
     srctype.add_same_value(dsttype)
1268 1278
     dsttype.add_same_type(srctype)
1269 1279
     srctype.extent = :global
  1280
+    dsttype.extent = :global
1270 1281
 
1271 1282
     oldrescode = @rescode
1272 1283
     @rescode = lambda {|b, context|
@@ -2044,6 +2055,7 @@ def visit_leave(code, ins, local_vars, ln, info)
2044 2055
     rett2 = nil
2045 2056
     if code.lblock_list.last != ln then
2046 2057
       @is_live = false
  2058
+      @prev_label = ln
2047 2059
     end
2048 2060
 
2049 2061
     if retexp == nil then
@@ -2146,6 +2158,7 @@ def visit_jump(code, ins, local_vars, ln, info)
2146 2158
     end
2147 2159
     bval = nil
2148 2160
     @is_live = false
  2161
+    @prev_label = ln
2149 2162
     @jump_from[lab] ||= []
2150 2163
     @jump_from[lab].push ln
2151 2164
     @rescode = lambda {|b, context|
@@ -2202,6 +2215,7 @@ def visit_branchif(code, ins, local_vars, ln, info)
2202 2215
         bval = [valexp[0], valexp[1].call(b, context).rc]
2203 2216
         context.block_value[iflab] = bval
2204 2217
       end
  2218
+
2205 2219
       condval = cond[1].call(b, context).rc
2206 2220
       if cond[0].type.llvm != Type::Int1Ty then
2207 2221
         vcond = cond[0].type.to_value(condval, b, context)
@@ -2839,7 +2853,14 @@ def visit_opt_ltlt(code, ins, local_vars, ln, info)
2839 2853
     if s1[0].type 
2840 2854
       if s1[0].type.klass == :String then
2841 2855
         rettype = check_same_type_2arg_static(s1, s2)
2842  
-      elsif s1[0].type.klass != :Array then
  2856
+      elsif s1[0].type.klass == :Array then
  2857
+        rettype = RubyType.array(info[3], "Return type of ltlt")
  2858
+        s1[0].add_same_type rettype
  2859
+        rettype.add_same_type s1[0]
  2860
+        s2[0].add_same_type rettype.type.element_type
  2861
+        rettype.type.element_type.add_same_type s2[0]
  2862
+        RubyType.resolve
  2863
+      else
2843 2864
         rettype = check_same_type_2arg_static(s1, s2)
2844 2865
       end
2845 2866
     end
@@ -2887,7 +2908,26 @@ def opt_aref_aux(b, context, arr, idx, rettype, level, info, indx)
2887 2908
     when :Array
2888 2909
       context = idx[1].call(b, context)
2889 2910
       idxp = context.rc
2890  
-      if OPTION[:array_range_check] then
  2911
+      if idx[0].klass == :Range then
  2912
+        context = arr[1].call(b, context)
  2913
+        arrp = context.rc
  2914
+
  2915
+        idxptr = context.array_alloca_area
  2916
+        b.store(idxp, idxptr)
  2917
+
  2918
+        ftype = Type.function(VALUE, [LONG, P_VALUE, VALUE])
  2919
+        func = context.builder.external_function('rb_ary_aref', ftype)
  2920
+        av = b.call(func, 1.llvm, idxptr, arrp)
  2921
+        arrelet = arr[0].type.element_type.type
  2922
+        if arrelet then
  2923
+          context.rc = arrelet.from_value(av, b, context)
  2924
+        else
  2925
+          context.rc = av
  2926
+        end
  2927
+        context
  2928
+        
  2929
+        
  2930
+      elsif OPTION[:array_range_check] then
2891 2931
         context = arr[1].call(b, context)
2892 2932
         arrp = context.rc
2893 2933
         ftype = Type.function(VALUE, [VALUE, MACHINE_WORD])
@@ -3028,18 +3068,11 @@ def opt_aref_aux(b, context, arr, idx, rettype, level, info, indx)
3028 3068
   def visit_opt_aref(code, ins, local_vars, ln, info)
3029 3069
     idx = @expstack.pop
3030 3070
     arr = @expstack.pop
3031  
-    case arr[0].klass
3032  
-    when :Array
3033  
-      fix = RubyType.fixnum(info[3])
3034  
-      idx[0].add_same_type(fix)
3035  
-      fix.add_same_value(idx[0])
3036  
-    #  fix.resolve
3037  
-    end
  3071
+
3038 3072
     RubyType.resolve
3039 3073
 
3040 3074
     # AbstrubctContainorType is type which have [] and []= as method.
3041 3075
     if arr[0].type == nil then
3042  
-   #   RubyType.new(AbstructContainerType.new(nil)).add_same_type arr[0]
3043 3076
       arr[0].type = AbstructContainerType.new(nil)
3044 3077
     end
3045 3078
 
@@ -3047,7 +3080,19 @@ def visit_opt_aref(code, ins, local_vars, ln, info)
3047 3080
     indx = nil
3048 3081
     case arr[0].klass
3049 3082
     when :Array                 #, :Object
3050  
-      rettype = arr[0].type.element_type
  3083
+      if idx[0].klass == :Range then
  3084
+        rettype = arr[0].dup_type
  3085
+        level = @expstack.size
  3086
+        if @array_alloca_size == nil or @array_alloca_size < 1 + level then
  3087
+          @array_alloca_size = 1 + level
  3088
+        end
  3089
+      else
  3090
+        fix = RubyType.fixnum(info[3])
  3091
+        idx[0].add_same_type(fix)
  3092
+        fix.add_same_value(idx[0])
  3093
+
  3094
+        rettype = arr[0].type.element_type
  3095
+      end
3051 3096
       
3052 3097
     when :Struct, :Hash
3053 3098
       rettype = RubyType.value
1  lib/yarv2llvm.rb
@@ -34,6 +34,7 @@ module YARV2LLVM
34 34
   :dump_yarv => false,
35 35
   :write_bc => false,
36 36
   :func_signature => false,
  37
+  :var_signature => false,
37 38
 
38 39
   :array_range_check => true,
39 40
 
18  runtime/prelude.rb
... ...
@@ -1,5 +1,4 @@
1 1
 module YARV2LLVM
2  
-#=begin
3 2
 
4 3
   # type definition of method
5 4
 
@@ -57,7 +56,7 @@ module YARV2LLVM
57 56
     :rettype => rt,
58 57
     :copy_rettype => true,
59 58
   }
60  
-#=begin
  59
+
61 60
   MethodDefinition::RubyMethod[:at][:Array] = {
62 61
     :self => nil,
63 62
     :argtype => [RubyType.new(nil)],
@@ -70,7 +69,7 @@ module YARV2LLVM
70 69
       rt
71 70
     },
72 71
   }
73  
-#=end
  72
+
74 73
   st = RubyType.array
75 74
   rt = RubyType.new(nil)
76 75
   rt.add_same_type(st.type.element_type)
@@ -98,6 +97,17 @@ module YARV2LLVM
98 97
   rt = RubyType.array
99 98
   rt.add_same_type(st)
100 99
   st.add_same_type(rt)
  100
+  MethodDefinition::RubyMethod[:sort][:Array] = {
  101
+    :self => st,
  102
+    :argtype => [],
  103
+    :rettype => rt,
  104
+    :copy_rettype => true,
  105
+  }
  106
+
  107
+  st = RubyType.array
  108
+  rt = RubyType.array
  109
+  rt.add_same_type(st)
  110
+  st.add_same_type(rt)
101 111
   MethodDefinition::RubyMethod[:slice!][:Array] = {
102 112
     :self => st,
103 113
     :argtype => [RubyType.new(nil), RubyType.new(nil)],
@@ -151,7 +161,7 @@ module YARV2LLVM
151 161
     :rettype => lst,
152 162
     :copy_rettype => true,
153 163
   }
154  
-#=end
  164
+
155 165
 end
156 166
 
157 167
 <<-'EOS'
7  test/test_unsafe.rb
@@ -7,7 +7,7 @@
7 7
 class UnsafeTests < Test::Unit::TestCase
8 8
 
9 9
   def test_unsafe
10  
-    YARV2LLVM::compile(<<-EOS, {:disasm => true, :dump_yarv => true, :optimize=> true})
  10
+    YARV2LLVM::compile(<<-EOS, {:disasm => false, :dump_yarv => false, :optimize=> true})
11 11
 def tunsafe
12 12
   type = LLVM::struct([RubyHelpers::VALUE, LLVM::Type::Int32Ty, RubyHelpers::VALUE, RubyHelpers::VALUE])
13 13
   a = [:a, :b]
@@ -28,7 +28,7 @@ def tunsafe2
28 28
   end
29 29
 
30 30
   def test_define_external_function
31  
-    YARV2LLVM::compile(<<-EOS, {:disasm => true, :dump_yarv => true, :optimize=> true, :func_signature => true})
  31
+    YARV2LLVM::compile(<<-EOS, {:disasm => false, :dump_yarv => false, :optimize=> true, :func_signature => true})
32 32
 def tdefine_external_function
33 33
   value = RubyHelpers::VALUE
34 34
   int32ty = LLVM::Type::Int32Ty
@@ -45,7 +45,7 @@ def tdefine_external_function
45 45
   end
46 46
 
47 47
   def test_define_macro
48  
-    YARV2LLVM::compile(<<-'EOS', {:disasm => true, :dump_yarv => true, :optimize=> false, :func_signature => false})
  48
+    YARV2LLVM::compile(<<-'EOS', {:disasm => false, :dump_yarv => false, :optimize=> false, :func_signature => false})
49 49
 
50 50
 
51 51
 YARV2LLVM::define_macro :myif do |arg| `if #{_sender_env[:args][2]} then #{_sender_env[:args][1]} else #{_sender_env[:args][0]} end` end
@@ -57,5 +57,4 @@ def tdefine_macro
57 57
 EOS
58 58
     assert_equal(tdefine_macro, "hello")
59 59
   end
60  
-
61 60
 end
5  yarv2llvm.rb
@@ -78,6 +78,11 @@
78 78
     y2lopt[:func_signature] = f
79 79
   end
80 80
 
  81
+  opt.on('--[no-]var-signature', 
  82
+         'Display type inferenced inforamtion about global variable') do |f|
  83
+    y2lopt[:var_signature] = f
  84
+  end
  85
+
81 86
   opt.on('--[no-]type-message', 
82 87
          'Display type message for example Type Conflict Error') do |f|
83 88
     y2lopt[:type_message] = f

0 notes on commit 011f543

Please sign in to comment.
Something went wrong with that request. Please try again.