BasicObject
AO render benchmark Original program (C) Syoyo Fujita in Javascript (and other languages)
https://code.google.com/p/aobench/
Ruby(yarv2llvm) version by Hideki Miura mruby version by Hideki Miura
# File typeprof-0.12.0/lib/typeprof/type.rb, line 403
def self.any
@any ||= Any.new
end
# File typeprof-0.12.0/lib/typeprof/type.rb, line 411
def self.bool
@bool ||= Union.new(Utils::Set[
Instance.new(Type::Builtin[:true]),
Instance.new(Type::Builtin[:false])
], nil)
end
# File typeprof-0.12.0/lib/typeprof/type.rb, line 407
def self.bot
@bot ||= Union.new(Utils::Set[], nil)
end
# File typeprof-0.12.0/lib/typeprof/type.rb, line 760
def self.builtin_global_variable_type(var)
case var
when :$_, :$/, :$\, :$,, :$;
Type.optional(Type::Instance.new(Type::Builtin[:str]))
when :$0, :$PROGRAM_NAME
Type::Instance.new(Type::Builtin[:str])
when :$~
Type.optional(Type::Instance.new(Type::Builtin[:matchdata]))
when :$., :$$
Type::Instance.new(Type::Builtin[:int])
when :$?
Type.optional(Type::Instance.new(Type::Builtin[:int]))
when :$!
Type.optional(Type::Instance.new(Type::Builtin[:exc]))
when :$@
str = Type::Instance.new(Type::Builtin[:str])
base_ty = Type::Instance.new(Type::Builtin[:ary])
Type.optional(Type::Array.new(Type::Array::Elements.new([], str), base_ty))
when :$*, :$:, :$LOAD_PATH, :$", :$LOADED_FEATURES
str = Type::Instance.new(Type::Builtin[:str])
base_ty = Type::Instance.new(Type::Builtin[:ary])
Type::Array.new(Type::Array::Elements.new([], str), base_ty)
when :$<
:ARGF
when :$>
:STDOUT
when :$DEBUG
Type.bool
when :$FILENAME
Type::Instance.new(Type::Builtin[:str])
when :$stdin
:STDIN
when :$stdout
:STDOUT
when :$stderr
:STDERR
when :$VERBOSE
Type.bool.union(Type.nil)
else
nil
end
end
# File typeprof-0.12.0/lib/typeprof/type.rb, line 701
def self.gen_hash(base_ty = Type::Instance.new(Type::Builtin[:hash]))
hg = HashGenerator.new
yield hg
Type::Hash.new(Type::Hash::Elements.new(hg.map_tys), base_ty)
end
# File typeprof-0.12.0/lib/typeprof/type.rb, line 707
def self.guess_literal_type(obj)
case obj
when ::Symbol
Type::Symbol.new(obj, Type::Instance.new(Type::Builtin[:sym]))
when ::Integer
Type::Literal.new(obj, Type::Instance.new(Type::Builtin[:int]))
when ::Rational
Type::Literal.new(obj, Type::Instance.new(Type::Builtin[:rational]))
when ::Complex
Type::Literal.new(obj, Type::Instance.new(Type::Builtin[:complex]))
when ::Float
Type::Literal.new(obj, Type::Instance.new(Type::Builtin[:float]))
when ::Class
return Type.any if obj < Exception
case obj
when ::Object
Type::Builtin[:obj]
when ::Array
Type::Builtin[:ary]
else
raise "unknown class: #{ obj.inspect }"
end
when ::TrueClass
Type::Instance.new(Type::Builtin[:true])
when ::FalseClass
Type::Instance.new(Type::Builtin[:false])
when ::Array
base_ty = Type::Instance.new(Type::Builtin[:ary])
lead_tys = obj.map {|arg| guess_literal_type(arg) }
Type::Array.new(Type::Array::Elements.new(lead_tys), base_ty)
when ::Hash
Type.gen_hash do |h|
obj.each do |k, v|
k_ty = guess_literal_type(k).globalize(nil, {}, Config.options[:type_depth_limit])
v_ty = guess_literal_type(v)
h[k_ty] = v_ty
end
end
when ::String
Type::Literal.new(obj, Type::Instance.new(Type::Builtin[:str]))
when ::Regexp
Type::Literal.new(obj, Type::Instance.new(Type::Builtin[:regexp]))
when ::NilClass
Type.nil
when ::Range
Type::Literal.new(obj, Type::Instance.new(Type::Builtin[:range]))
when ::Encoding
Type::Literal.new(obj, Type::Instance.new(Type::Builtin[:encoding]))
else
raise "unknown object: #{ obj.inspect }"
end
end
# File typeprof-0.12.0/smoke/array11.rb, line 1
def array(obj)
Array(obj)
end
# File typeprof-0.12.0/smoke/masgn2.rb, line 1
def ary
[1, "str", :sym, 1.0]
end
# File typeprof-0.12.0/testbed/ao.rb, line 142
def clamp(f)
i = f * 255.5
if i > 255.0
i = 255.0
end
if i < 0.0
i = 0.0
end
i.to_i
end
# File typeprof-0.12.0/smoke/flip-flop.rb, line 1
def cond1?
rand < 0.5
end
# File typeprof-0.12.0/smoke/flip-flop.rb, line 5
def cond2?
rand < 0.5
end
# File typeprof-0.12.0/smoke/array-range-aref.rb, line 41
def dispatch(*ary)
f1(*ary)
f2(*ary)
f3(*ary)
f4(*ary)
f5(*ary)
f6(*ary)
f7(*ary)
f8(*ary)
f9(*ary)
f10(*ary)
end
# File typeprof-0.12.0/lib/typeprof/analyzer.rb, line 2105
def do_define_iseq_method(ep, env, mid, iseq, outer_ep)
cref = ep.ctx.cref
if cref.klass.is_a?(Type::Class)
typed_mdef = check_typed_method(cref.klass, mid, ep.ctx.cref.singleton)
recv = cref.klass
recv = Type::Instance.new(recv) unless ep.ctx.cref.singleton
if typed_mdef
mdef = ISeqMethodDef.new(iseq, cref, outer_ep, env.static_env.pub_meth)
typed_mdef.each do |typed_mdef|
typed_mdef.do_match_iseq_mdef(mdef, recv, mid, env, ep, self)
end
else
if ep.ctx.cref.singleton
meth = add_singleton_iseq_method(cref.klass, mid, iseq, cref, outer_ep, true)
else
meth = add_iseq_method(cref.klass, mid, iseq, cref, outer_ep, env.static_env.pub_meth)
if env.static_env.mod_func
add_singleton_iseq_method(cref.klass, mid, iseq, cref, outer_ep, true)
end
end
end
pend_method_execution(iseq, meth, recv, mid, ep.ctx.cref, outer_ep)
else
# XXX: what to do?
end
end
# File typeprof-0.12.0/lib/typeprof/analyzer.rb, line 2094
def do_invoke_block(blk, aargs, ep, env, replace_recv_ty: nil, &ctn)
blk.each_child do |blk|
if blk.is_a?(Type::Proc)
blk.block_body.do_call(aargs, ep, env, self, replace_recv_ty: replace_recv_ty, &ctn)
else
warn(ep, "non-proc is passed as a block")
ctn[Type.any, ep, env]
end
end
end
# File typeprof-0.12.0/lib/typeprof/analyzer.rb, line 2065
def do_send(recv, mid, aargs, ep, env, &ctn)
case recv
when Type::Void
error(ep, "void's method is called: #{ globalize_type(recv, env, ep).screen_name(self) }##{ mid }")
ctn[Type.any, ep, env]
when Type::Any
ctn[Type.any, ep, env]
else
klass, singleton = recv.method_dispatch_info
meths = get_method(klass, singleton, mid) if klass
if meths
meths.each do |meth|
meth.do_send(recv, mid, aargs, ep, env, self, &ctn)
end
else
meths = get_method(klass, singleton, :method_missing) if klass
if meths
aargs = aargs.for_method_missing(Type::Symbol.new(mid, Type::Instance.new(Type::Builtin[:sym])))
meths.each do |meth|
meth.do_send(recv, :method_missing, aargs, ep, env, self, &ctn)
end
else
error(ep, "undefined method: #{ globalize_type(recv, env, ep).screen_name(self) }##{ mid }")
ctn[Type.any, ep, env]
end
end
end
end
# File typeprof-0.12.0/smoke/array14.rb, line 1
def f(a, b, c)
ary = [nil]
foo, bar, ary[0] = a, b, c
ary[0]
end
# File typeprof-0.12.0/smoke/arguments2.rb, line 37
def f10(&blk)
blk.call(1)
end
# File typeprof-0.12.0/smoke/arguments2.rb, line 5
def f2(x, y, z)
end
# File typeprof-0.12.0/smoke/arguments2.rb, line 9
def f3(x = "str", y = "str")
end
# File typeprof-0.12.0/smoke/arguments2.rb, line 17
def f5(x, y = "str", z)
end
# File typeprof-0.12.0/smoke/arguments2.rb, line 25
def f7(k: 42)
end
# File typeprof-0.12.0/smoke/arguments2.rb, line 29
def f8(k: "str")
end
# File typeprof-0.12.0/smoke/arguments2.rb, line 33
def f9(**kw)
end
recursive method
# File typeprof-0.12.0/smoke/demo.rb, line 30
def fib(x)
if x <= 1
x
else
fib(x - 1) + fib(x - 2)
end
end
# File typeprof-0.12.0/smoke/alias.rb, line 1
def foo(x)
x
end
# File typeprof-0.12.0/smoke/enumerator.rb, line 4
def fuga
1.then
end
# File typeprof-0.12.0/smoke/struct2.rb, line 7
def gen_foobar
FooBar.new(1)
end
# File typeprof-0.12.0/lib/typeprof/type.rb, line 152
def generate_substitution
{}
end
# File typeprof-0.12.0/smoke/rbs-interface.rb, line 9
def get_interface
C.new.get_interface
end
# File typeprof-0.12.0/smoke/rbs-interface.rb, line 13
def get_interface_foo
C.new.get_interface.foo
end
# File typeprof-0.12.0/smoke/rbs-interface.rb, line 1
def get_module
C.new.get_module
end
# File typeprof-0.12.0/smoke/rbs-interface.rb, line 5
def get_module_foo
C.new.get_module.foo
end
# File typeprof-0.12.0/smoke/rest3.rb, line 23
def grault(a, o=1, *r, z)
end
# File typeprof-0.12.0/smoke/rbs-vars.rb, line 1
def gvar_test
$gvar
end
# File typeprof-0.12.0/smoke/enumerator.rb, line 1
def hoge
[1, 2, 3].map
end
overrided method
# File typeprof-0.12.0/smoke/demo.rb, line 16
def identity(x)
x
end
# File typeprof-0.12.0/lib/typeprof/type.rb, line 165
def include_untyped?(_scratch)
false
end
# File typeprof-0.12.0/smoke/block-ambiguous.rb, line 4
def log1(x); end
# File typeprof-0.12.0/smoke/block-ambiguous.rb, line 10
def log2(x); end
# File typeprof-0.12.0/smoke/block-ambiguous.rb, line 16
def log3(x); end
# File typeprof-0.12.0/smoke/block-ambiguous.rb, line 22
def log4(x); end
# File typeprof-0.12.0/smoke/block-args1-rest.rb, line 43
def log5(a, o, c); end
# File typeprof-0.12.0/smoke/block-args3-rest.rb, line 52
def log6(a, o, r, c); end
# File typeprof-0.12.0/smoke/array-map3.rb, line 4
def map_bang_test(a)
a.map! {|n| n.to_s }
a
end
# File typeprof-0.12.0/smoke/array-map3.rb, line 8
def map_bang_test_known_bug(a)
a.map! {|n| n.to_s }
end
# File typeprof-0.12.0/smoke/array-map3.rb, line 1
def map_test(a)
a.map {|n| n.to_s }
end
override
# File typeprof-0.12.0/smoke/demo2.rb, line 2
def my_to_s(x)
x.to_s
end
# File typeprof-0.12.0/smoke/function.rb, line 1
def no_argument
"str"
end
# File typeprof-0.12.0/smoke/type_var.rb, line 1
def number?(ty)
%w[integer float].include?(ty).then { puts 1 }
end
# File typeprof-0.12.0/smoke/function.rb, line 5
def one_argument(x)
end
# File typeprof-0.12.0/testbed/ao.rb, line 153
def otherBasis(n)
zero = Vec.new(0.0, 0.0, 0.0)
basis = [zero, zero, zero]
basis[2] = Vec.new(n.x, n.y, n.z)
basis[1] = Vec.new(0.0, 0.0, 0.0)
if n.x < 0.6 and n.x > -0.6
basis[1].x = 1.0
elsif n.y < 0.6 and n.y > -0.6
basis[1].y = 1.0
elsif n.z < 0.6 and n.z > -0.6
basis[1].z = 1.0
else
basis[1].x = 1.0
end
basis[0] = basis[1].vcross(basis[2])
basis[0] = basis[0].vnormalize
basis[1] = basis[2].vcross(basis[0])
basis[1] = basis[1].vnormalize
basis
end
# File typeprof-0.12.0/smoke/rbs-attr.rb, line 1
def read_test_1
Foo.new.reader_example
end
# File typeprof-0.12.0/smoke/rbs-attr.rb, line 5
def read_test_2
Foo.new.accessor_example
end
# File typeprof-0.12.0/lib/typeprof/type.rb, line 161
def remove_type_vars
substitute(DummySubstitution, Config.options[:type_depth_limit])
end
# File typeprof-0.12.0/smoke/manual-rbs.rb, line 12
def ret_int
foo(42)
end
# File typeprof-0.12.0/smoke/manual-rbs.rb, line 16
def ret_str
foo("str")
end
# File typeprof-0.12.0/smoke/array13.rb, line 18
def seq_get
ary = [:a, :b, :c] + []
ary[-1]
end
# File typeprof-0.12.0/smoke/array13.rb, line 12
def seq_set
ary = [:a, :b, :c] + []
ary[-1] = :z
ary
end
# File typeprof-0.12.0/lib/typeprof/analyzer.rb, line 2133
def show_block_signature(blks)
bsig = nil
ret_ty = Type.bot
blks.each do |blk|
blk.each_child_global do |blk|
bsig0 = @block_signatures[blk.block_body]
if bsig0
if bsig
bsig = bsig.merge(bsig0)
else
bsig = bsig0
end
end
@block_to_ctx[blk.block_body]&.each do |blk_ctx|
ret_ty = ret_ty.union(@return_values[blk_ctx]) if @return_values[blk_ctx]
end
end
end
bsig ||= BlockSignature.new([], [], nil, Type.nil)
bsig = bsig.screen_name(nil, self)
ret_ty = ret_ty.screen_name(self)
ret_ty = (ret_ty.include?("|") ? "(#{ ret_ty })" : ret_ty) # XXX?
bsig = bsig + " " if bsig != ""
"{ #{ bsig }-> #{ ret_ty } }"
end
# File typeprof-0.12.0/lib/typeprof/analyzer.rb, line 2191
def show_method_signature(ctx)
farg_tys = @method_signatures[ctx]
ret_ty = @return_values[ctx] || Type.bot
untyped = farg_tys.include_untyped?(self) || ret_ty.include_untyped?(self)
farg_tys = farg_tys.screen_name(ctx.iseq, self)
ret_ty = ret_ty.screen_name(self)
ret_ty = (ret_ty.include?("|") ? "(#{ ret_ty })" : ret_ty) # XXX?
["#{ (farg_tys.empty? ? "" : "#{ farg_tys } ") }-> #{ ret_ty }", untyped]
end
# File typeprof-0.12.0/lib/typeprof/analyzer.rb, line 2164
def show_proc_signature(blks)
farg_tys, ret_ty = nil, Type.bot
blks.each do |blk|
blk.each_child_global do |blk|
next if blk.block_body.is_a?(TypedBlock) # XXX: Support TypedBlock
next unless @block_to_ctx[blk.block_body] # this occurs when screen_name is called before type-profiling finished (e.g., error message)
@block_to_ctx[blk.block_body].each do |blk_ctx|
if farg_tys
farg_tys = farg_tys.merge_as_block_arguments(@method_signatures[blk_ctx])
else
farg_tys = @method_signatures[blk_ctx]
end
ret_ty = ret_ty.union(@return_values[blk_ctx]) if @return_values[blk_ctx]
end
end
end
farg_tys = farg_tys ? farg_tys.screen_name(nil, self) : "(unknown)"
ret_ty = ret_ty.screen_name(self)
ret_ty = (ret_ty.include?("|") ? "(#{ ret_ty })" : ret_ty) # XXX?
farg_tys = farg_tys + " " if farg_tys != ""
"^#{ farg_tys }-> #{ ret_ty }"
end
# File typeprof-0.12.0/lib/typeprof/type.rb, line 148
def substitute(_subst, _depth)
raise "cannot substitute abstract type: #{ self.class }"
end
# File typeprof-0.12.0/smoke/demo11.rb, line 1
def swap(a)
[a[1], a[0]]
end
# File typeprof-0.12.0/smoke/rbs-record.rb, line 6
def test_bar
h = { }
h[:a] = 42
C.new.bar(h)
end
# File typeprof-0.12.0/smoke/rbs-record.rb, line 1
def test_foo
h = C.new.foo
return h[:aaa], h[:bbb]
end
# File typeprof-0.12.0/smoke/array12.rb, line 4
def test_yield
yield
end
# File typeprof-0.12.0/testbed/ao.rb, line 288
def top
Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES)
end
# File typeprof-0.12.0/smoke/array13.rb, line 7
def tuple_get
ary = [:a, :b, :c]
ary[-1]
end