Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add --var-signature option and some bugs fixed

  • Loading branch information...
commit 011f5437e84218303a101714a7086e2bf66cf2a3 1 parent 131b0b5
@miura1729 authored
View
9 lib/llvmutil.rb
@@ -248,13 +248,11 @@ def gen_loop_proc(para)
if rec[0].type.is_a?(ComplexType) then
rec[0].type.element_type.add_same_type atype
# atype.add_same_type rec[0].type.element_type
- else
- rec[0].add_same_type atype
- atype.add_same_type rec[0]
end
end
lambda {|b, context, lst, led, body, recval, excl|
+=begin
if argsize == 1 then
if rec[0].type.is_a?(ComplexType) then
rec[0].type.element_type.add_same_type atype
@@ -265,6 +263,7 @@ def gen_loop_proc(para)
end
end
RubyType.resolve
+=end
bcond = context.builder.create_block
bbody = context.builder.create_block
@@ -466,6 +465,10 @@ def gen_method_select(rectype, lexklass, mname)
elsif candidatenum < MaxSmallPolymotphicNum then
# TODO : Use inline hash function generation
+ p rectype.conflicted_types.keys
+ p rectype.inspect2
+ p rectype.name
+ p lexklass
raise("Not implimented polymorphic methed call yet '#{mname}' #{lexklass}")
else
View
7 lib/methoddef.rb
@@ -103,9 +103,9 @@ module MethodDefinition
case arr[0].type
when ArrayType
- val[0].add_same_type(arr[0].type.element_type)
- arr[0].type.element_type.add_same_type(val[0])
- RubyType.resolve
+# val[0].add_same_type(arr[0].type.element_type)
+# arr[0].type.element_type.add_same_type(val[0])
+# RubyType.resolve
ftype = Type.function(Type::VoidTy,
[VALUE, MACHINE_WORD, VALUE])
func = context.builder.external_function('rb_ary_store', ftype)
@@ -520,6 +520,7 @@ module MethodDefinition
context
else
+ p rec[0].conflicted_types.keys
raise "Do not supported #{rec[0].inspect2}"
end
}]
View
4 lib/type.rb
@@ -819,7 +819,7 @@ def has_cycle?
def inspect2
if @element_type then
if has_cycle? then
- "Array of VALUE"
+ "Array of Array of ..."
else
"Array of #{@element_type.inspect2}"
end
@@ -886,7 +886,7 @@ def has_cycle?
def inspect2
if @element_type then
if has_cycle? then
- "Hash of VALUE"
+ "Hash of Hash of ..."
else
"Hash of #{@element_type.inspect2}"
end
View
69 lib/vmtraverse.rb
@@ -252,6 +252,16 @@ def initialize(iseq, bind, preload)
def run
super
+ if OPTION[:var_signature] then
+ @global_var_tab.each do |vn, vtab|
+ if tinfo = vtab[:type] then
+ print "#{vn} : #{tinfo.inspect2} \n"
+ else
+ print "#{vn} : nil \n"
+ end
+ end
+ end
+
# generate code for access Ruby internal
if OPTION[:cache_instance_variable] then
if @instance_var_tab.size != 0 then
@@ -950,8 +960,8 @@ def visit_local_block_end(code, ins, local_vars, ln, info)
# don't call before visit_block_start call.
if @is_live == nil then
@is_live = true
+ @prev_label = ln
end
- @prev_label = ln
# p @expstack.map {|n| n[1]}
end
@@ -1267,6 +1277,7 @@ def visit_setglobal(code, ins, local_vars, ln, info)
srctype.add_same_value(dsttype)
dsttype.add_same_type(srctype)
srctype.extent = :global
+ dsttype.extent = :global
oldrescode = @rescode
@rescode = lambda {|b, context|
@@ -2044,6 +2055,7 @@ def visit_leave(code, ins, local_vars, ln, info)
rett2 = nil
if code.lblock_list.last != ln then
@is_live = false
+ @prev_label = ln
end
if retexp == nil then
@@ -2146,6 +2158,7 @@ def visit_jump(code, ins, local_vars, ln, info)
end
bval = nil
@is_live = false
+ @prev_label = ln
@jump_from[lab] ||= []
@jump_from[lab].push ln
@rescode = lambda {|b, context|
@@ -2202,6 +2215,7 @@ def visit_branchif(code, ins, local_vars, ln, info)
bval = [valexp[0], valexp[1].call(b, context).rc]
context.block_value[iflab] = bval
end
+
condval = cond[1].call(b, context).rc
if cond[0].type.llvm != Type::Int1Ty then
vcond = cond[0].type.to_value(condval, b, context)
@@ -2839,7 +2853,14 @@ def visit_opt_ltlt(code, ins, local_vars, ln, info)
if s1[0].type
if s1[0].type.klass == :String then
rettype = check_same_type_2arg_static(s1, s2)
- elsif s1[0].type.klass != :Array then
+ elsif s1[0].type.klass == :Array then
+ rettype = RubyType.array(info[3], "Return type of ltlt")
+ s1[0].add_same_type rettype
+ rettype.add_same_type s1[0]
+ s2[0].add_same_type rettype.type.element_type
+ rettype.type.element_type.add_same_type s2[0]
+ RubyType.resolve
+ else
rettype = check_same_type_2arg_static(s1, s2)
end
end
@@ -2887,7 +2908,26 @@ def opt_aref_aux(b, context, arr, idx, rettype, level, info, indx)
when :Array
context = idx[1].call(b, context)
idxp = context.rc
- if OPTION[:array_range_check] then
+ if idx[0].klass == :Range then
+ context = arr[1].call(b, context)
+ arrp = context.rc
+
+ idxptr = context.array_alloca_area
+ b.store(idxp, idxptr)
+
+ ftype = Type.function(VALUE, [LONG, P_VALUE, VALUE])
+ func = context.builder.external_function('rb_ary_aref', ftype)
+ av = b.call(func, 1.llvm, idxptr, arrp)
+ arrelet = arr[0].type.element_type.type
+ if arrelet then
+ context.rc = arrelet.from_value(av, b, context)
+ else
+ context.rc = av
+ end
+ context
+
+
+ elsif OPTION[:array_range_check] then
context = arr[1].call(b, context)
arrp = context.rc
ftype = Type.function(VALUE, [VALUE, MACHINE_WORD])
@@ -3028,18 +3068,11 @@ def opt_aref_aux(b, context, arr, idx, rettype, level, info, indx)
def visit_opt_aref(code, ins, local_vars, ln, info)
idx = @expstack.pop
arr = @expstack.pop
- case arr[0].klass
- when :Array
- fix = RubyType.fixnum(info[3])
- idx[0].add_same_type(fix)
- fix.add_same_value(idx[0])
- # fix.resolve
- end
+
RubyType.resolve
# AbstrubctContainorType is type which have [] and []= as method.
if arr[0].type == nil then
- # RubyType.new(AbstructContainerType.new(nil)).add_same_type arr[0]
arr[0].type = AbstructContainerType.new(nil)
end
@@ -3047,7 +3080,19 @@ def visit_opt_aref(code, ins, local_vars, ln, info)
indx = nil
case arr[0].klass
when :Array #, :Object
- rettype = arr[0].type.element_type
+ if idx[0].klass == :Range then
+ rettype = arr[0].dup_type
+ level = @expstack.size
+ if @array_alloca_size == nil or @array_alloca_size < 1 + level then
+ @array_alloca_size = 1 + level
+ end
+ else
+ fix = RubyType.fixnum(info[3])
+ idx[0].add_same_type(fix)
+ fix.add_same_value(idx[0])
+
+ rettype = arr[0].type.element_type
+ end
when :Struct, :Hash
rettype = RubyType.value
View
1  lib/yarv2llvm.rb
@@ -34,6 +34,7 @@ module YARV2LLVM
:dump_yarv => false,
:write_bc => false,
:func_signature => false,
+ :var_signature => false,
:array_range_check => true,
View
18 runtime/prelude.rb
@@ -1,5 +1,4 @@
module YARV2LLVM
-#=begin
# type definition of method
@@ -57,7 +56,7 @@ module YARV2LLVM
:rettype => rt,
:copy_rettype => true,
}
-#=begin
+
MethodDefinition::RubyMethod[:at][:Array] = {
:self => nil,
:argtype => [RubyType.new(nil)],
@@ -70,7 +69,7 @@ module YARV2LLVM
rt
},
}
-#=end
+
st = RubyType.array
rt = RubyType.new(nil)
rt.add_same_type(st.type.element_type)
@@ -98,6 +97,17 @@ module YARV2LLVM
rt = RubyType.array
rt.add_same_type(st)
st.add_same_type(rt)
+ MethodDefinition::RubyMethod[:sort][:Array] = {
+ :self => st,
+ :argtype => [],
+ :rettype => rt,
+ :copy_rettype => true,
+ }
+
+ st = RubyType.array
+ rt = RubyType.array
+ rt.add_same_type(st)
+ st.add_same_type(rt)
MethodDefinition::RubyMethod[:slice!][:Array] = {
:self => st,
:argtype => [RubyType.new(nil), RubyType.new(nil)],
@@ -151,7 +161,7 @@ module YARV2LLVM
:rettype => lst,
:copy_rettype => true,
}
-#=end
+
end
<<-'EOS'
View
7 test/test_unsafe.rb
@@ -7,7 +7,7 @@
class UnsafeTests < Test::Unit::TestCase
def test_unsafe
- YARV2LLVM::compile(<<-EOS, {:disasm => true, :dump_yarv => true, :optimize=> true})
+ YARV2LLVM::compile(<<-EOS, {:disasm => false, :dump_yarv => false, :optimize=> true})
def tunsafe
type = LLVM::struct([RubyHelpers::VALUE, LLVM::Type::Int32Ty, RubyHelpers::VALUE, RubyHelpers::VALUE])
a = [:a, :b]
@@ -28,7 +28,7 @@ def tunsafe2
end
def test_define_external_function
- YARV2LLVM::compile(<<-EOS, {:disasm => true, :dump_yarv => true, :optimize=> true, :func_signature => true})
+ YARV2LLVM::compile(<<-EOS, {:disasm => false, :dump_yarv => false, :optimize=> true, :func_signature => true})
def tdefine_external_function
value = RubyHelpers::VALUE
int32ty = LLVM::Type::Int32Ty
@@ -45,7 +45,7 @@ def tdefine_external_function
end
def test_define_macro
- YARV2LLVM::compile(<<-'EOS', {:disasm => true, :dump_yarv => true, :optimize=> false, :func_signature => false})
+ YARV2LLVM::compile(<<-'EOS', {:disasm => false, :dump_yarv => false, :optimize=> false, :func_signature => false})
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
EOS
assert_equal(tdefine_macro, "hello")
end
-
end
View
5 yarv2llvm.rb
@@ -78,6 +78,11 @@
y2lopt[:func_signature] = f
end
+ opt.on('--[no-]var-signature',
+ 'Display type inferenced inforamtion about global variable') do |f|
+ y2lopt[:var_signature] = f
+ end
+
opt.on('--[no-]type-message',
'Display type message for example Type Conflict Error') do |f|
y2lopt[:type_message] = f
Please sign in to comment.
Something went wrong with that request. Please try again.