Skip to content

Commit

Permalink
Some bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
miura1729 committed Sep 10, 2009
1 parent 14f19db commit fbae697
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/llvmutil.rb
Expand Up @@ -470,7 +470,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
Expand Down
5 changes: 2 additions & 3 deletions lib/type.rb
Expand Up @@ -459,10 +459,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
Expand Down
17 changes: 14 additions & 3 deletions lib/vmtraverse.rb
Expand Up @@ -1224,6 +1224,7 @@ def visit_getglobal(code, ins, local_vars, ln, info)
type.extent = :global
end
areap = @global_var_tab[glname][:area]

@expstack.push [type,
lambda {|b, context|
ftype = Type.function(VALUE, [VALUE])
Expand Down Expand Up @@ -1262,14 +1263,15 @@ def visit_setglobal(code, ins, local_vars, ln, info)
srcvalue = src[1]

srctype.add_same_value(dsttype)
dsttype.add_same_value(srctype)
dsttype.add_same_type(srctype)
srctype.extent = :global

oldrescode = @rescode
@rescode = lambda {|b, context|
context = oldrescode.call(b, context)
context = srcvalue.call(b, context)
srcval = context.rc
srcval = implicit_type_conversion(b, context, srcval, srctype)
srcval2 = srctype.type.to_value(srcval, b, context)

dsttype.type = dsttype.type.dup_type
Expand Down Expand Up @@ -2046,6 +2048,7 @@ def visit_leave(code, ins, local_vars, ln, info)
if rett2.type == nil then
retexp[0].add_same_type rett2
RubyType.resolve
# retexp[0].resolve

if rett2.type == nil then
rett2.type = PrimitiveType.new(VALUE, nil)
Expand Down Expand Up @@ -3007,8 +3010,8 @@ def visit_opt_aref(code, ins, local_vars, ln, info)
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.
Expand Down Expand Up @@ -3149,6 +3152,10 @@ def store_to_local(voff, src, local_vars, ln, info)
srctype.add_extent_base dsttype

srctype.add_same_type(areatype)
dsttype.resolve
srctype.resolve
# RubyType.resolve

=begin
RubyType.resolve
if dsttype.dst_type and
Expand Down Expand Up @@ -3223,6 +3230,10 @@ def store_to_parent(voff, slev, src, acode, ln, info)
srctype.add_extent_base dsttype

srctype.add_same_type(areatype)
dsttype.resolve
srctype.resolve
# RubyType.resolve

=begin
RubyType.resolve
if dsttype.dst_type and
Expand Down Expand Up @@ -3366,7 +3377,7 @@ def compcommon(is, opt, preload, bind)
end
iseq = VMLib::InstSeqTree.new(nil, is)
if OPTION[:dump_yarv] then
p iseq.to_a
pp iseq.to_a
end
prelude = 'runtime/prelude.rb'
pcont = File.read(prelude)
Expand Down
10 changes: 6 additions & 4 deletions runtime/prelude.rb
Expand Up @@ -227,8 +227,9 @@ class Array
def collect
res = []
i = 0
self.each do |e|
res[i] = yield e
max = self.size
while i < max
res[i] = yield self[i]
i = i + 1
end
Expand Down Expand Up @@ -256,8 +257,9 @@ def step(st)
def collect
res = []
i = 0
self.each do |e|
res[i] = yield e
max = self.last
while i < max do
res[i] = yield i
i = i + 1
end
Expand Down
10 changes: 6 additions & 4 deletions sample/hello.rb
@@ -1,14 +1,16 @@
m = LLVM::Module.new('hello')
LLVM::ExecutionEngine.get(m)
p_char = LLVM::pointer(Type::Int8Ty)
ftype = LLVM::function(Type::Int32Ty, [p_char])
p_char = Type.pointer(Type::Int8Ty)
#ftype = LLVM::function(Type::Int32Ty, [p_char])
ftype = Type.function(Type::Int32Ty, [p_char])
ftype = ftype.to_raw
printf = m.external_function('printf', ftype)
ftype = LLVM::function(Type::Int32Ty, [])
#ftype = LLVM::function(Type::Int32Ty, [])
ftype = Type.function(Type::Int32Ty, [])
ftype = ftype.to_raw
main = m.get_or_insert_function('main', ftype)
b = main.create_block.builder
strptr = b.create_global_string_ptr("Hello World! \n")
b.call(printf, strptr)
b.return(strptr)
b.return(LLVM::Value.get_constant(Type::Int32Ty, 0))
LLVM::ExecutionEngine.run_function(main)
2 changes: 1 addition & 1 deletion y2llib/llvmruby.rb
@@ -1,5 +1,5 @@
require 'yarv2llvm'
require 'llvmruby'
require 'llvm'

module YARV2LLVM
MethodDefinition::RubyMethod[:get_or_insert_function][:"LLVM::Module"] = {
Expand Down

0 comments on commit fbae697

Please sign in to comment.