Permalink
Browse files

support for Ruby 1.9.3 buggy

  • Loading branch information...
2 parents fef581f + 7919e50 commit 42c6a163ef0e702ab7552c1d7b95649aa3c3ce6f @miura1729 committed May 15, 2010
Showing with 402 additions and 92 deletions.
  1. +2 −2 lib/instruction.rb
  2. +21 −7 lib/intruby.rb
  3. +83 −6 lib/llvmutil.rb
  4. +16 −9 lib/methoddef.rb
  5. +10 −10 lib/type.rb
  6. +193 −36 lib/vmtraverse.rb
  7. +4 −0 lib/yarv2llvm.rb
  8. +1 −1 lib/yarv2ruby.rb
  9. +55 −12 runtime/prelude.rb
  10. +6 −3 sample/hello.rb
  11. +3 −4 test/test_unsafe.rb
  12. +2 −1 y2llib/llvmruby.rb
  13. +6 −1 yarv2llvm.rb
View
4 lib/instruction.rb 100644 → 100755
@@ -6,8 +6,8 @@
module VMLib
class InstSeqTree
Headers = %w(magic major_version minor_version format_type
- misc name filename type locals args exception_table)
-# misc name filename line type locals args exception_table)
+ misc name filename filepath line typhe locals args exception_table)
+# misc name filename type locals args exception_table)
# call-seq:
# VMLib::InstSeqTree.new(parent, iseq)
# parent Partent of InstSeqTree
View
28 lib/intruby.rb 100644 → 100755
@@ -17,6 +17,20 @@ module LLVM::RubyInternals
VALUE # u3
])
P_RNODE = Type.pointer(RNODE)
+ METHOD_DEFINITION = Type::struct([LONG, # type
+ VALUE, # original_id
+ VALUE, # cfunc
+ LONG # alias_count
+ ])
+ P_METHOD_DEFINITION = Type.pointer(METHOD_DEFINITION)
+
+ METHOD_ENTRY = Type::struct([LONG, # flag
+ P_METHOD_DEFINITION, # def
+ VALUE, # called_id
+ VALUE # klass
+ ])
+ P_METHOD_ENTRY = Type.pointer(METHOD_ENTRY)
+
end
module YARV2LLVM
@@ -68,14 +82,14 @@ def gen_get_method_cfunc_common(builder, issing)
klass = b.call(sing_class, klass)
end
- ftype = Type.function(P_RNODE, [VALUE, VALUE, VALUE])
- rmn = builder.external_function('rb_get_method_body', ftype)
- pnode = b.call(rmn, klass, id, 0.llvm)
+ ftype = Type.function(P_METHOD_ENTRY, [VALUE, VALUE])
+# rmn = builder.external_function('rb_get_method_entry', ftype)
+ rmn = builder.external_function('rb_method_entry_get_without_cache', ftype)
+ pme = b.call(rmn, klass, id)
- vpcnode = b.struct_gep(pnode, 3)
- vcnode =b.load(vpcnode)
- pcnode = b.int_to_ptr(vcnode, P_RNODE)
- pcfunc = b.struct_gep(pcnode, 2)
+ vpmdef = b.struct_gep(pme, 1)
+ vmdef =b.load(vpmdef)
+ pcfunc = b.struct_gep(vmdef, 2)
cfunc = b.load(pcfunc)
b.store(cfunc, cachep)
b.return(cfunc)
View
89 lib/llvmutil.rb 100644 → 100755
@@ -41,6 +41,15 @@ def implicit_type_conversion(b, context, val, type)
val
end
+ def implicit_type_conversion2(b, context, val, srctype, dsttype)
+ if dsttype.type.llvm == Type::DoubleTy and
+ srctype.type.llvm == Type::Int32Ty then
+
+ val = b.si_to_fp(val, Type::DoubleTy)
+ end
+ val
+ end
+
def convert_type_for_2arg_op(b, context, p1, p2)
RubyType.resolve
nop = lambda {|val, type| [val, type]}
@@ -239,13 +248,13 @@ 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
+ elsif rec[0].type then
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
@@ -256,6 +265,7 @@ def gen_loop_proc(para)
end
end
RubyType.resolve
+=end
bcond = context.builder.create_block
bbody = context.builder.create_block
@@ -411,6 +421,7 @@ def gen_method_select(rectype, lexklass, mname)
# Search lexcal class
obj = Object.nested_const_get(lexklass)
end
+
if obj then
obj.ancestors.each do |sup|
minfo = mtab[sup.name.to_sym]
@@ -421,11 +432,13 @@ def gen_method_select(rectype, lexklass, mname)
end
candidatenum = mtab.size
+ candidate = []
if candidatenum > 1 then
candidatenum = 0
mtab.each {|klass, info|
if info[:func] then
candidatenum += 1
+ candidate.push info
end
}
end
@@ -454,6 +467,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
@@ -470,7 +487,7 @@ def get_inline_function(recklass, lexklass, mname)
obj = Object.nested_const_get(lexklass)
end
- if obj then
+ if obj and obj != NilClass then
obj.ancestors.each do |sup|
kls = sup.name.to_sym
if tbl = MethodDefinition::InlineMethod[kls] and
@@ -645,8 +662,8 @@ def gen_arg_eval(args, receiver, ins, local_vars, info, minfo, mname)
nargs = ins[2]
args.each_with_index do |pe, n|
if minfo then
- pe[0].add_same_type(minfo[:argtype][nargs - n - 1])
- minfo[:argtype][nargs - n - 1].add_same_value(pe[0])
+# pe[0].add_same_type(minfo[:argtype][nargs - n - 1])
+# minfo[:argtype][nargs - n - 1].add_same_value(pe[0])
pe[0].add_extent_base minfo[:argtype][nargs - n - 1]
end
para[n] = pe
@@ -661,7 +678,7 @@ def gen_arg_eval(args, receiver, ins, local_vars, info, minfo, mname)
end
if minfo and minfo[:self] then
v[0].add_same_type minfo[:self]
- minfo[:self].add_same_type v[0]
+# minfo[:self].add_same_type v[0]
end
else
v = [local_vars[2][:type],
@@ -670,6 +687,27 @@ def gen_arg_eval(args, receiver, ins, local_vars, info, minfo, mname)
context}]
end
+=begin
+ unless minfo
+ old_tiat = @type_inferece_after_traverse
+ @type_inferece_after_traverse = lambda {
+ old_tiat.call
+ unless minfo
+ minfo, func = gen_method_select(receiver[0], info[0], mname)
+ if minfo and minfo[:self] then
+ args.each_with_index do |pe, n|
+ pe[0].add_same_type(minfo[:argtype][nargs - n - 1])
+ minfo[:argtype][nargs - n - 1].add_same_value(pe[0])
+ pe[0].add_extent_base minfo[:argtype][nargs - n - 1]
+ end
+ v[0].add_same_type minfo[:self]
+ minfo[:self].add_same_type v[0]
+ end
+ end
+ }
+ end
+=end
+
para.push [local_vars[2][:type], lambda {|b, context|
context = v[1].call(b, context)
if v[0].type then
@@ -723,6 +761,32 @@ def gen_arg_eval(args, receiver, ins, local_vars, info, minfo, mname)
yrett = minfoy[:yield_rettype]
brett.add_same_type yrett
yrett.add_same_type brett
+ else
+ old_tiat2 = @type_inferece_after_traverse
+ @type_inferece_after_traverse = lambda {
+ old_tiat2.call
+ recklass = receiver[0].klass
+ minfoy = MethodDefinition::RubyMethod[mname][recklass]
+ minfob = MethodDefinition::RubyMethod[blab][info[0]]
+
+ if minfoy and minfob then
+ yargt = minfoy[:yield_argtype]
+ bargt = minfob[:argtype]
+ if yargt and bargt then
+ yargt.each_with_index do |pe, n|
+# pe.add_same_type bargt[n]
+# bargt[n].add_same_type pe
+ end
+ end
+
+ brett = minfob[:rettype]
+ yrett = minfoy[:yield_rettype]
+ if brett and yrett then
+ brett.add_same_type yrett
+ yrett.add_same_type brett
+ end
+ end
+ }
end
para.push [local_vars[1][:type],
@@ -736,6 +800,7 @@ def gen_arg_eval(args, receiver, ins, local_vars, info, minfo, mname)
end
# receiver of block is parent class
minfo = MethodDefinition::RubyMethod[blab][info[0]]
+
gen_get_block_ptr(info[0], minfo, b, context)
}]
end
@@ -764,6 +829,18 @@ def do_function(receiver, info, ins, local_vars, args, mname, curlevel)
pppp "RubyMethod called #{mname.inspect}"
para = gen_arg_eval(args, receiver, ins, local_vars, info, minfo, mname)
+
+ nargt = minfo[:argtype]
+ nargt.each_with_index do |ele, n|
+ para[n][0].add_same_type ele
+# ele.add_same_type para[n][0]
+ end
+
+ if minfo[:rettype] then
+ rettype.add_same_type minfo[:rettype]
+ minfo[:rettype].add_same_type rettype
+ end
+
if func == nil then
level = @expstack.size
if @array_alloca_size == nil or @array_alloca_size < 1 + level then
View
25 lib/methoddef.rb 100644 → 100755
@@ -90,9 +90,15 @@ module MethodDefinition
idx = para[:args][1]
arr = para[:receiver]
RubyType.resolve
- if arr[0].type.is_a?(ArrayType) then
- val[0].add_same_type(arr[0].type.element_type)
- arr[0].type.element_type.add_same_type(val[0])
+ if arr[0].type.is_a?(ArrayType) then
+ val[0].add_same_type arr[0].type.element_type
+ arr[0].type.element_type.add_same_type val[0]
+ elsif arr[0].type == nil then
+ act = AbstructContainerType.new(nil)
+ arr[0].type = act
+
+ val[0].add_same_type act.element_type
+ act.element_type.add_same_type val[0]
end
val[0].add_extent_base arr[0]
@@ -103,9 +109,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)
@@ -255,7 +261,7 @@ module MethodDefinition
when Type::Int32Ty
context.rc = b.sub(0.llvm, val)
else
- raise "Unsupported type #{val[0].inspect2} in -@"
+ raise "Unsupported type #{recv[0].inspect2} in -@"
end
context}]
},
@@ -520,6 +526,7 @@ module MethodDefinition
context
else
+ p rec[0].conflicted_types.keys
raise "Do not supported #{rec[0].inspect2}"
end
}]
@@ -566,13 +573,13 @@ module MethodDefinition
if minfo[:argtype][i] == nil then
minfo[:argtype][i] = RubyType.new(nil)
end
- minfo[:argtype][i].add_same_type ele[0]
+# minfo[:argtype][i].add_same_type ele[0]
ele[0].add_same_type minfo[:argtype][i]
ele[0].add_extent_base minfo[:argtype][i]
ele[0].slf = rettype
end
# minfo[:argtype][-1].add_same_type rec[0]
- rec[0].add_same_type minfo[:argtype][-1]
+# rec[0].add_same_type minfo[:argtype][-1]
#=end
@expstack.push [rettype,
View
20 lib/type.rb 100644 → 100755
@@ -97,9 +97,11 @@ def content
return @type.content
end
@same_value.reverse.each do |ty|
- cont = ty.type.content
- if !UNDEF.equal?(cont) then
- return cont
+ if ty.type then
+ cont = ty.type.content
+ if !UNDEF.equal?(cont) then
+ return cont
+ end
end
end
UNDEF
@@ -346,7 +348,6 @@ def real_extent
if extmax.extent == :instance then
slf = extmax.slf
if slf.is_arg then
- p "foo"
return :global
else
return slf.real_extent
@@ -459,10 +460,9 @@ def self.from_sym(sym, lno, name)
else
obj = nil
if sym then
- obj = sym.to_s.split(/::/).inject(Object) {|res, sym|
- res.const_get(sym.to_sym, true)
- }
+ obj = Object.nested_const_get(sym)
end
+
unless obj
obj = Object
end
@@ -741,7 +741,7 @@ class AbstructContainerType<ComplexType
include RubyHelpers
def initialize(etype)
- set_klass(Object)
+ set_klass(AbstructContainer)
@element_type = RubyType.new(etype)
@content = UNDEF
@constant = UNDEF
@@ -818,7 +818,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
@@ -885,7 +885,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
Oops, something went wrong.

0 comments on commit 42c6a16

Please sign in to comment.