typeprof 0.15.2 → 0.20.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +1 -1
- data/Gemfile.lock +4 -4
- data/doc/ide.md +81 -0
- data/doc/typeprof-for-ide-log.png +0 -0
- data/doc/typeprof-for-ide.png +0 -0
- data/exe/typeprof +5 -1
- data/lib/typeprof/analyzer.rb +235 -56
- data/lib/typeprof/arguments.rb +1 -0
- data/lib/typeprof/builtin.rb +23 -23
- data/lib/typeprof/cli.rb +23 -5
- data/lib/typeprof/code-range.rb +177 -0
- data/lib/typeprof/config.rb +41 -20
- data/lib/typeprof/container-type.rb +10 -1
- data/lib/typeprof/export.rb +191 -15
- data/lib/typeprof/import.rb +38 -9
- data/lib/typeprof/insns-def.rb +1 -0
- data/lib/typeprof/iseq.rb +224 -17
- data/lib/typeprof/lsp.rb +884 -0
- data/lib/typeprof/method.rb +15 -11
- data/lib/typeprof/type.rb +46 -38
- data/lib/typeprof/utils.rb +18 -1
- data/lib/typeprof/version.rb +1 -1
- data/lib/typeprof.rb +3 -5
- data/typeprof-lsp +3 -0
- data/typeprof.gemspec +2 -2
- data/vscode/.gitignore +5 -0
- data/vscode/.vscode/launch.json +16 -0
- data/vscode/.vscodeignore +7 -0
- data/vscode/README.md +22 -0
- data/vscode/development.md +31 -0
- data/vscode/package-lock.json +2211 -0
- data/vscode/package.json +71 -0
- data/vscode/sandbox/test.rb +24 -0
- data/vscode/src/extension.ts +285 -0
- data/vscode/tsconfig.json +15 -0
- metadata +20 -333
- data/smoke/alias.rb +0 -31
- data/smoke/alias2.rb +0 -21
- data/smoke/any-cbase.rb +0 -5
- data/smoke/any1.rb +0 -16
- data/smoke/any2.rb +0 -18
- data/smoke/arguments.rb +0 -17
- data/smoke/arguments2.rb +0 -56
- data/smoke/array-each.rb +0 -15
- data/smoke/array-each2.rb +0 -16
- data/smoke/array-each3.rb +0 -13
- data/smoke/array-ltlt.rb +0 -14
- data/smoke/array-ltlt2.rb +0 -17
- data/smoke/array-map.rb +0 -12
- data/smoke/array-map2.rb +0 -11
- data/smoke/array-map3.rb +0 -23
- data/smoke/array-mul.rb +0 -18
- data/smoke/array-plus1.rb +0 -11
- data/smoke/array-plus2.rb +0 -16
- data/smoke/array-pop.rb +0 -12
- data/smoke/array-range-aref.rb +0 -71
- data/smoke/array-replace.rb +0 -13
- data/smoke/array-s-aref.rb +0 -12
- data/smoke/array1.rb +0 -27
- data/smoke/array10.rb +0 -15
- data/smoke/array11.rb +0 -14
- data/smoke/array12.rb +0 -25
- data/smoke/array13.rb +0 -31
- data/smoke/array14.rb +0 -14
- data/smoke/array15.rb +0 -16
- data/smoke/array2.rb +0 -28
- data/smoke/array3.rb +0 -26
- data/smoke/array4.rb +0 -15
- data/smoke/array5.rb +0 -14
- data/smoke/array6.rb +0 -17
- data/smoke/array7.rb +0 -14
- data/smoke/array8.rb +0 -13
- data/smoke/array9.rb +0 -13
- data/smoke/attr-module.rb +0 -24
- data/smoke/attr-vis.rb +0 -43
- data/smoke/attr-vis.rbs +0 -4
- data/smoke/attr.rb +0 -28
- data/smoke/autoload.rb +0 -14
- data/smoke/backtrace.rb +0 -33
- data/smoke/block-ambiguous.rb +0 -37
- data/smoke/block-args1-rest.rb +0 -64
- data/smoke/block-args1.rb +0 -60
- data/smoke/block-args2-rest.rb +0 -64
- data/smoke/block-args2.rb +0 -60
- data/smoke/block-args3-rest.rb +0 -75
- data/smoke/block-args3.rb +0 -71
- data/smoke/block-blockarg.rb +0 -28
- data/smoke/block-kwarg.rb +0 -53
- data/smoke/block1.rb +0 -23
- data/smoke/block10.rb +0 -15
- data/smoke/block11.rb +0 -40
- data/smoke/block12.rb +0 -23
- data/smoke/block13.rb +0 -9
- data/smoke/block13.rbs +0 -3
- data/smoke/block14.rb +0 -18
- data/smoke/block2.rb +0 -15
- data/smoke/block3.rb +0 -38
- data/smoke/block4.rb +0 -19
- data/smoke/block5.rb +0 -21
- data/smoke/block6.rb +0 -21
- data/smoke/block7.rb +0 -19
- data/smoke/block8.rb +0 -28
- data/smoke/block9.rb +0 -13
- data/smoke/block_given.rb +0 -37
- data/smoke/blown.rb +0 -13
- data/smoke/break1.rb +0 -19
- data/smoke/break2.rb +0 -16
- data/smoke/break3.rb +0 -13
- data/smoke/break4.rb +0 -17
- data/smoke/case.rb +0 -17
- data/smoke/case2.rb +0 -18
- data/smoke/case3.rb +0 -17
- data/smoke/class-hierarchy.rb +0 -54
- data/smoke/class-hierarchy2.rb +0 -27
- data/smoke/class-new.rb +0 -15
- data/smoke/class.rb +0 -7
- data/smoke/class_eval.rb +0 -22
- data/smoke/class_instance_var.rb +0 -9
- data/smoke/class_method.rb +0 -25
- data/smoke/class_method2.rb +0 -21
- data/smoke/class_method3.rb +0 -29
- data/smoke/constant1.rb +0 -46
- data/smoke/constant2.rb +0 -36
- data/smoke/constant3.rb +0 -10
- data/smoke/constant4.rb +0 -12
- data/smoke/context-sensitive1.rb +0 -13
- data/smoke/cvar.rb +0 -31
- data/smoke/cvar2.rb +0 -17
- data/smoke/define_method.rb +0 -16
- data/smoke/define_method2.rb +0 -18
- data/smoke/define_method3.rb +0 -14
- data/smoke/define_method3.rbs +0 -3
- data/smoke/define_method4.rb +0 -15
- data/smoke/define_method4.rbs +0 -3
- data/smoke/define_method5.rb +0 -12
- data/smoke/define_method6.rb +0 -19
- data/smoke/define_method7.rb +0 -18
- data/smoke/demo.rb +0 -81
- data/smoke/demo1.rb +0 -17
- data/smoke/demo10.rb +0 -21
- data/smoke/demo11.rb +0 -12
- data/smoke/demo2.rb +0 -15
- data/smoke/demo3.rb +0 -17
- data/smoke/demo4.rb +0 -27
- data/smoke/demo5.rb +0 -16
- data/smoke/demo6.rb +0 -22
- data/smoke/demo7.rb +0 -15
- data/smoke/demo8.rb +0 -19
- data/smoke/demo9.rb +0 -18
- data/smoke/dummy-execution1.rb +0 -15
- data/smoke/dummy-execution2.rb +0 -16
- data/smoke/dummy_element.rb +0 -14
- data/smoke/ensure1.rb +0 -21
- data/smoke/enum_for.rb +0 -15
- data/smoke/enum_for2.rb +0 -17
- data/smoke/enumerator.rb +0 -16
- data/smoke/expandarray1.rb +0 -23
- data/smoke/expandarray2.rb +0 -24
- data/smoke/extended.rb +0 -38
- data/smoke/fib.rb +0 -28
- data/smoke/flip-flop.rb +0 -28
- data/smoke/flow1.rb +0 -17
- data/smoke/flow10.rb +0 -17
- data/smoke/flow11.rb +0 -17
- data/smoke/flow2.rb +0 -15
- data/smoke/flow3.rb +0 -15
- data/smoke/flow4.rb +0 -5
- data/smoke/flow5.rb +0 -20
- data/smoke/flow6.rb +0 -20
- data/smoke/flow7.rb +0 -21
- data/smoke/flow8.rb +0 -14
- data/smoke/flow9.rb +0 -12
- data/smoke/for.rb +0 -9
- data/smoke/freeze.rb +0 -12
- data/smoke/function.rb +0 -17
- data/smoke/gvar.rb +0 -14
- data/smoke/gvar2.rb +0 -15
- data/smoke/gvar2.rbs +0 -1
- data/smoke/hash-bot.rb +0 -12
- data/smoke/hash-fetch.rb +0 -28
- data/smoke/hash-merge-bang.rb +0 -12
- data/smoke/hash1.rb +0 -20
- data/smoke/hash2.rb +0 -13
- data/smoke/hash3.rb +0 -14
- data/smoke/hash4.rb +0 -11
- data/smoke/hash5.rb +0 -14
- data/smoke/huge_union.rb +0 -86
- data/smoke/identifier_keywords.rb +0 -17
- data/smoke/included.rb +0 -38
- data/smoke/inheritance.rb +0 -34
- data/smoke/inheritance2.rb +0 -35
- data/smoke/inherited.rb +0 -26
- data/smoke/initialize.rb +0 -28
- data/smoke/instance_eval.rb +0 -18
- data/smoke/instance_eval2.rb +0 -10
- data/smoke/instance_eval3.rb +0 -25
- data/smoke/instance_eval4.rb +0 -12
- data/smoke/int_times.rb +0 -15
- data/smoke/integer.rb +0 -11
- data/smoke/ivar.rb +0 -31
- data/smoke/ivar2.rb +0 -30
- data/smoke/ivar3.rb +0 -17
- data/smoke/ivar3.rbs +0 -3
- data/smoke/ivar4.rb +0 -21
- data/smoke/kernel-class.rb +0 -13
- data/smoke/keyword1.rb +0 -12
- data/smoke/keyword2.rb +0 -12
- data/smoke/keyword3.rb +0 -12
- data/smoke/keyword4.rb +0 -12
- data/smoke/keyword5.rb +0 -16
- data/smoke/kwrest.rb +0 -13
- data/smoke/kwrest.rbs +0 -3
- data/smoke/kwsplat1.rb +0 -43
- data/smoke/kwsplat2.rb +0 -13
- data/smoke/lit-complex.rb +0 -10
- data/smoke/lit-encoding.rb +0 -10
- data/smoke/manual-rbs.rb +0 -29
- data/smoke/manual-rbs.rbs +0 -3
- data/smoke/manual-rbs2.rb +0 -21
- data/smoke/manual-rbs2.rbs +0 -8
- data/smoke/manual-rbs3.rb +0 -13
- data/smoke/manual-rbs3.rbs +0 -3
- data/smoke/masgn1.rb +0 -14
- data/smoke/masgn2.rb +0 -18
- data/smoke/masgn3.rb +0 -13
- data/smoke/method_in_branch.rb +0 -23
- data/smoke/method_missing.rb +0 -29
- data/smoke/module1.rb +0 -29
- data/smoke/module2.rb +0 -28
- data/smoke/module3.rb +0 -33
- data/smoke/module4.rb +0 -35
- data/smoke/module5.rb +0 -17
- data/smoke/module6.rb +0 -40
- data/smoke/module_function1.rb +0 -29
- data/smoke/module_function2.rb +0 -29
- data/smoke/multiple-include.rb +0 -15
- data/smoke/multiple-superclass.rb +0 -28
- data/smoke/next1.rb +0 -21
- data/smoke/next2.rb +0 -17
- data/smoke/noname.rb +0 -9
- data/smoke/object-send1.rb +0 -23
- data/smoke/object-send2.rb +0 -10
- data/smoke/object-send3.rb +0 -18
- data/smoke/once.rb +0 -13
- data/smoke/optional1.rb +0 -14
- data/smoke/optional2.rb +0 -16
- data/smoke/optional3.rb +0 -11
- data/smoke/or_raise.rb +0 -18
- data/smoke/parameterizedd-self.rb +0 -20
- data/smoke/parameterizedd-self2.rb +0 -15
- data/smoke/pathname1.rb +0 -14
- data/smoke/pathname2.rb +0 -14
- data/smoke/pattern-match1.rb +0 -19
- data/smoke/pattern-match2.rb +0 -16
- data/smoke/prepend1.rb +0 -33
- data/smoke/prepend2.rb +0 -10
- data/smoke/prepend2.rbs +0 -9
- data/smoke/primitive_method.rb +0 -19
- data/smoke/printf.rb +0 -20
- data/smoke/proc.rb +0 -20
- data/smoke/proc2.rb +0 -17
- data/smoke/proc3.rb +0 -15
- data/smoke/proc4.rb +0 -12
- data/smoke/proc5.rb +0 -19
- data/smoke/proc6.rb +0 -13
- data/smoke/proc7.rb +0 -32
- data/smoke/public.rb +0 -38
- data/smoke/range.rb +0 -14
- data/smoke/rbs-alias.rb +0 -10
- data/smoke/rbs-alias.rbs +0 -4
- data/smoke/rbs-attr.rb +0 -27
- data/smoke/rbs-attr.rbs +0 -5
- data/smoke/rbs-attr2.rb +0 -11
- data/smoke/rbs-attr2.rbs +0 -3
- data/smoke/rbs-extend.rb +0 -10
- data/smoke/rbs-extend.rbs +0 -7
- data/smoke/rbs-interface.rb +0 -25
- data/smoke/rbs-interface.rbs +0 -12
- data/smoke/rbs-module.rb +0 -26
- data/smoke/rbs-module.rbs +0 -4
- data/smoke/rbs-opt-and-rest.rb +0 -10
- data/smoke/rbs-opt-and-rest.rbs +0 -3
- data/smoke/rbs-proc1.rb +0 -10
- data/smoke/rbs-proc1.rbs +0 -3
- data/smoke/rbs-proc2.rb +0 -21
- data/smoke/rbs-proc2.rbs +0 -3
- data/smoke/rbs-proc3.rb +0 -14
- data/smoke/rbs-proc3.rbs +0 -4
- data/smoke/rbs-record.rb +0 -18
- data/smoke/rbs-record.rbs +0 -4
- data/smoke/rbs-tyvar.rb +0 -19
- data/smoke/rbs-tyvar.rbs +0 -5
- data/smoke/rbs-tyvar2.rb +0 -21
- data/smoke/rbs-tyvar2.rbs +0 -9
- data/smoke/rbs-tyvar3.rb +0 -18
- data/smoke/rbs-tyvar3.rbs +0 -5
- data/smoke/rbs-tyvar4.rb +0 -37
- data/smoke/rbs-tyvar5.rb +0 -13
- data/smoke/rbs-tyvar5.rbs +0 -8
- data/smoke/rbs-tyvar6.rb +0 -18
- data/smoke/rbs-tyvar6.rbs +0 -12
- data/smoke/rbs-tyvar7.rb +0 -12
- data/smoke/rbs-tyvar7.rbs +0 -7
- data/smoke/rbs-vars.rb +0 -35
- data/smoke/rbs-vars.rbs +0 -7
- data/smoke/redo1.rb +0 -22
- data/smoke/redo2.rb +0 -23
- data/smoke/req-keyword.rb +0 -13
- data/smoke/require1.rb +0 -13
- data/smoke/require2.rb +0 -13
- data/smoke/rescue1.rb +0 -21
- data/smoke/rescue2.rb +0 -23
- data/smoke/rescue3.rb +0 -20
- data/smoke/rescue4.rb +0 -17
- data/smoke/respond_to.rb +0 -23
- data/smoke/rest-farg.rb +0 -11
- data/smoke/rest1.rb +0 -26
- data/smoke/rest2.rb +0 -31
- data/smoke/rest3.rb +0 -37
- data/smoke/rest4.rb +0 -19
- data/smoke/rest5.rb +0 -11
- data/smoke/rest6.rb +0 -12
- data/smoke/retry1.rb +0 -21
- data/smoke/return.rb +0 -14
- data/smoke/reveal.rb +0 -13
- data/smoke/simple.rb +0 -12
- data/smoke/singleton_class.rb +0 -8
- data/smoke/singleton_method.rb +0 -12
- data/smoke/step.rb +0 -18
- data/smoke/string-split.rb +0 -12
- data/smoke/struct-keyword_init.rb +0 -10
- data/smoke/struct.rb +0 -13
- data/smoke/struct2.rb +0 -25
- data/smoke/struct3.rb +0 -14
- data/smoke/struct4.rb +0 -7
- data/smoke/struct5.rb +0 -16
- data/smoke/struct6.rb +0 -15
- data/smoke/struct7.rb +0 -17
- data/smoke/stub-keyword.rb +0 -10
- data/smoke/super1.rb +0 -69
- data/smoke/super2.rb +0 -16
- data/smoke/super3.rb +0 -20
- data/smoke/super4.rb +0 -45
- data/smoke/super5.rb +0 -38
- data/smoke/svar1.rb +0 -13
- data/smoke/symbol-proc-attr.rb +0 -22
- data/smoke/symbol-proc-attr2.rb +0 -15
- data/smoke/symbol-proc-bot.rb +0 -13
- data/smoke/symbol-proc.rb +0 -25
- data/smoke/tap1.rb +0 -18
- data/smoke/toplevel.rb +0 -13
- data/smoke/two-map.rb +0 -18
- data/smoke/type_var.rb +0 -11
- data/smoke/typed_method.rb +0 -16
- data/smoke/uninitialize-var.rb +0 -13
- data/smoke/union-recv.rb +0 -35
- data/smoke/user-demo.rb +0 -15
- data/smoke/wrong-extend.rb +0 -27
- data/smoke/wrong-include.rb +0 -27
- data/smoke/wrong-include2.rb +0 -17
- data/smoke/wrong-rbs.rb +0 -15
- data/smoke/wrong-rbs.rbs +0 -7
- data/testbed/ao.rb +0 -297
- data/testbed/diff-lcs-entrypoint.rb +0 -4
- data/testbed/goodcheck-Gemfile.lock +0 -51
data/smoke/svar1.rb
DELETED
data/smoke/symbol-proc-attr.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
class Foo
|
2
|
-
attr_reader :foo
|
3
|
-
def initialize(foo)
|
4
|
-
@foo = foo
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
def log
|
9
|
-
[Foo.new(42)].map(&:foo)
|
10
|
-
end
|
11
|
-
|
12
|
-
__END__
|
13
|
-
# Classes
|
14
|
-
class Object
|
15
|
-
private
|
16
|
-
def log: -> (Array[Integer | untyped])
|
17
|
-
end
|
18
|
-
|
19
|
-
class Foo
|
20
|
-
attr_reader foo: Integer | untyped
|
21
|
-
def initialize: (Integer | untyped foo) -> void
|
22
|
-
end
|
data/smoke/symbol-proc-attr2.rb
DELETED
data/smoke/symbol-proc-bot.rb
DELETED
data/smoke/symbol-proc.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
def foo
|
2
|
-
[1, :sym, "str"].map(&:to_s)
|
3
|
-
end
|
4
|
-
|
5
|
-
class Foo
|
6
|
-
def foo
|
7
|
-
:foo
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def bar
|
12
|
-
[Foo.new].map(&:foo)
|
13
|
-
end
|
14
|
-
|
15
|
-
__END__
|
16
|
-
# Classes
|
17
|
-
class Object
|
18
|
-
private
|
19
|
-
def foo: -> Array[String]
|
20
|
-
def bar: -> Array[:foo]
|
21
|
-
end
|
22
|
-
|
23
|
-
class Foo
|
24
|
-
def foo: -> :foo
|
25
|
-
end
|
data/smoke/tap1.rb
DELETED
data/smoke/toplevel.rb
DELETED
data/smoke/two-map.rb
DELETED
data/smoke/type_var.rb
DELETED
data/smoke/typed_method.rb
DELETED
data/smoke/uninitialize-var.rb
DELETED
data/smoke/union-recv.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
class SuperBase
|
2
|
-
def self.foo
|
3
|
-
self
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
class Base < SuperBase
|
8
|
-
def self.foo
|
9
|
-
super
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class A < Base
|
14
|
-
foo
|
15
|
-
end
|
16
|
-
|
17
|
-
class B < Base
|
18
|
-
foo
|
19
|
-
end
|
20
|
-
|
21
|
-
__END__
|
22
|
-
# Classes
|
23
|
-
class SuperBase
|
24
|
-
def self.foo: -> (singleton(A) | singleton(B))
|
25
|
-
end
|
26
|
-
|
27
|
-
class Base < SuperBase
|
28
|
-
def self.foo: -> (singleton(A) | singleton(B))
|
29
|
-
end
|
30
|
-
|
31
|
-
class A < Base
|
32
|
-
end
|
33
|
-
|
34
|
-
class B < Base
|
35
|
-
end
|
data/smoke/user-demo.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
class User
|
2
|
-
def foo(name: "str", age: 0)
|
3
|
-
@name, @age = name, age
|
4
|
-
end
|
5
|
-
|
6
|
-
attr_reader :name, :age
|
7
|
-
end
|
8
|
-
|
9
|
-
__END__
|
10
|
-
# Classes
|
11
|
-
class User
|
12
|
-
def foo: (?name: String | untyped, ?age: Integer | untyped) -> ([String | untyped, Integer | untyped])
|
13
|
-
attr_reader name: String | untyped
|
14
|
-
attr_reader age: Integer | untyped
|
15
|
-
end
|
data/smoke/wrong-extend.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Bar
|
2
|
-
def bar
|
3
|
-
:bar
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
module Foo
|
8
|
-
mod = rand < 0.5 ? Bar : "Not module"
|
9
|
-
|
10
|
-
extend mod
|
11
|
-
|
12
|
-
def foo
|
13
|
-
:foo
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
__END__
|
18
|
-
# Classes
|
19
|
-
module Bar
|
20
|
-
def bar: -> :bar
|
21
|
-
end
|
22
|
-
|
23
|
-
module Foo
|
24
|
-
extend Bar
|
25
|
-
|
26
|
-
def foo: -> :foo
|
27
|
-
end
|
data/smoke/wrong-include.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Bar
|
2
|
-
def bar
|
3
|
-
:bar
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
module Foo
|
8
|
-
mod = rand < 0.5 ? Bar : "Not module"
|
9
|
-
|
10
|
-
include mod
|
11
|
-
|
12
|
-
def foo
|
13
|
-
:foo
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
__END__
|
18
|
-
# Classes
|
19
|
-
module Bar
|
20
|
-
def bar: -> :bar
|
21
|
-
end
|
22
|
-
|
23
|
-
module Foo
|
24
|
-
include Bar
|
25
|
-
|
26
|
-
def foo: -> :foo
|
27
|
-
end
|
data/smoke/wrong-include2.rb
DELETED
data/smoke/wrong-rbs.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
def foo
|
2
|
-
end
|
3
|
-
def bar(n)
|
4
|
-
end
|
5
|
-
def baz(n=1)
|
6
|
-
end
|
7
|
-
def qux(a,n=1)
|
8
|
-
end
|
9
|
-
|
10
|
-
__END__
|
11
|
-
# Errors
|
12
|
-
smoke/wrong-rbs.rb:1: [error] RBS says that the arity may be 1, but the method definition requires at most 0 arguments
|
13
|
-
smoke/wrong-rbs.rb:3: [error] RBS says that the arity may be 0, but the method definition requires at least 1 arguments
|
14
|
-
|
15
|
-
# Classes
|
data/smoke/wrong-rbs.rbs
DELETED
data/testbed/ao.rb
DELETED
@@ -1,297 +0,0 @@
|
|
1
|
-
# AO render benchmark
|
2
|
-
# Original program (C) Syoyo Fujita in Javascript (and other languages)
|
3
|
-
# https://code.google.com/p/aobench/
|
4
|
-
# Ruby(yarv2llvm) version by Hideki Miura
|
5
|
-
# mruby version by Hideki Miura
|
6
|
-
#
|
7
|
-
|
8
|
-
IMAGE_WIDTH = 64
|
9
|
-
IMAGE_HEIGHT = 64
|
10
|
-
NSUBSAMPLES = 2
|
11
|
-
NAO_SAMPLES = 8
|
12
|
-
|
13
|
-
class Vec
|
14
|
-
# include Inline
|
15
|
-
def initialize(x, y, z)
|
16
|
-
@x = x
|
17
|
-
@y = y
|
18
|
-
@z = z
|
19
|
-
end
|
20
|
-
|
21
|
-
attr_accessor :x, :y, :z
|
22
|
-
|
23
|
-
def vadd(b)
|
24
|
-
Vec.new(@x + b.x, @y + b.y, @z + b.z)
|
25
|
-
end
|
26
|
-
|
27
|
-
def vsub(b)
|
28
|
-
Vec.new(@x - b.x, @y - b.y, @z - b.z)
|
29
|
-
end
|
30
|
-
# make_inline_method :vsub
|
31
|
-
|
32
|
-
def vcross(b)
|
33
|
-
Vec.new(@y * b.z - @z * b.y,
|
34
|
-
@z * b.x - @x * b.z,
|
35
|
-
@x * b.y - @y * b.x)
|
36
|
-
end
|
37
|
-
# make_inline_method :vcross
|
38
|
-
|
39
|
-
def vdot(b)
|
40
|
-
r = @x * b.x + @y * b.y + @z * b.z
|
41
|
-
r
|
42
|
-
end
|
43
|
-
# make_inline_method :vdot
|
44
|
-
|
45
|
-
def vlength
|
46
|
-
Math.sqrt(@x * @x + @y * @y + @z * @z)
|
47
|
-
end
|
48
|
-
# make_inline_method :vlength
|
49
|
-
|
50
|
-
def vnormalize
|
51
|
-
len = vlength
|
52
|
-
v = Vec.new(@x, @y, @z)
|
53
|
-
if len > 1.0e-17
|
54
|
-
v.x = v.x / len
|
55
|
-
v.y = v.y / len
|
56
|
-
v.z = v.z / len
|
57
|
-
end
|
58
|
-
v
|
59
|
-
end
|
60
|
-
# make_inline_method :vnormalize
|
61
|
-
end
|
62
|
-
|
63
|
-
class Sphere
|
64
|
-
def initialize(center, radius)
|
65
|
-
@center = center
|
66
|
-
@radius = radius
|
67
|
-
end
|
68
|
-
|
69
|
-
attr_reader :center, :radius
|
70
|
-
|
71
|
-
def intersect(ray, isect)
|
72
|
-
rs = ray.org.vsub(@center)
|
73
|
-
b = rs.vdot(ray.dir)
|
74
|
-
c = rs.vdot(rs) - (@radius * @radius)
|
75
|
-
d = b * b - c
|
76
|
-
if d > 0.0
|
77
|
-
t = - b - Math.sqrt(d)
|
78
|
-
|
79
|
-
if t > 0.0 and t < isect.t
|
80
|
-
isect.t = t
|
81
|
-
isect.hit = true
|
82
|
-
isect.pl = Vec.new(ray.org.x + ray.dir.x * t,
|
83
|
-
ray.org.y + ray.dir.y * t,
|
84
|
-
ray.org.z + ray.dir.z * t)
|
85
|
-
n = isect.pl.vsub(@center)
|
86
|
-
isect.n = n.vnormalize
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class Plane
|
93
|
-
def initialize(p, n)
|
94
|
-
@p = p
|
95
|
-
@n = n
|
96
|
-
end
|
97
|
-
|
98
|
-
def intersect(ray, isect)
|
99
|
-
d = -@p.vdot(@n)
|
100
|
-
v = ray.dir.vdot(@n)
|
101
|
-
v0 = v
|
102
|
-
if v < 0.0
|
103
|
-
v0 = -v
|
104
|
-
end
|
105
|
-
if v0 < 1.0e-17
|
106
|
-
return
|
107
|
-
end
|
108
|
-
|
109
|
-
t = -(ray.org.vdot(@n) + d) / v
|
110
|
-
|
111
|
-
if t > 0.0 and t < isect.t
|
112
|
-
isect.hit = true
|
113
|
-
isect.t = t
|
114
|
-
isect.n = @n
|
115
|
-
isect.pl = Vec.new(ray.org.x + t * ray.dir.x,
|
116
|
-
ray.org.y + t * ray.dir.y,
|
117
|
-
ray.org.z + t * ray.dir.z)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
class Ray
|
123
|
-
def initialize(org, dir)
|
124
|
-
@org = org
|
125
|
-
@dir = dir
|
126
|
-
end
|
127
|
-
|
128
|
-
attr_accessor :org, :dir
|
129
|
-
end
|
130
|
-
|
131
|
-
class Isect
|
132
|
-
def initialize
|
133
|
-
@t = 10000000.0
|
134
|
-
@hit = false
|
135
|
-
@pl = Vec.new(0.0, 0.0, 0.0)
|
136
|
-
@n = Vec.new(0.0, 0.0, 0.0)
|
137
|
-
end
|
138
|
-
|
139
|
-
attr_accessor :t, :hit, :pl, :n
|
140
|
-
end
|
141
|
-
|
142
|
-
def clamp(f)
|
143
|
-
i = f * 255.5
|
144
|
-
if i > 255.0
|
145
|
-
i = 255.0
|
146
|
-
end
|
147
|
-
if i < 0.0
|
148
|
-
i = 0.0
|
149
|
-
end
|
150
|
-
i.to_i
|
151
|
-
end
|
152
|
-
|
153
|
-
def otherBasis(n)
|
154
|
-
zero = Vec.new(0.0, 0.0, 0.0)
|
155
|
-
basis = [zero, zero, zero]
|
156
|
-
basis[2] = Vec.new(n.x, n.y, n.z)
|
157
|
-
basis[1] = Vec.new(0.0, 0.0, 0.0)
|
158
|
-
|
159
|
-
if n.x < 0.6 and n.x > -0.6
|
160
|
-
basis[1].x = 1.0
|
161
|
-
elsif n.y < 0.6 and n.y > -0.6
|
162
|
-
basis[1].y = 1.0
|
163
|
-
elsif n.z < 0.6 and n.z > -0.6
|
164
|
-
basis[1].z = 1.0
|
165
|
-
else
|
166
|
-
basis[1].x = 1.0
|
167
|
-
end
|
168
|
-
|
169
|
-
basis[0] = basis[1].vcross(basis[2])
|
170
|
-
basis[0] = basis[0].vnormalize
|
171
|
-
|
172
|
-
basis[1] = basis[2].vcross(basis[0])
|
173
|
-
basis[1] = basis[1].vnormalize
|
174
|
-
|
175
|
-
basis
|
176
|
-
end
|
177
|
-
|
178
|
-
class Scene
|
179
|
-
def initialize
|
180
|
-
@spheres = [
|
181
|
-
Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5),
|
182
|
-
Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5),
|
183
|
-
Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5),
|
184
|
-
]
|
185
|
-
@plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0))
|
186
|
-
end
|
187
|
-
|
188
|
-
def ambient_occlusion(isect)
|
189
|
-
basis = otherBasis(isect.n)
|
190
|
-
|
191
|
-
ntheta = NAO_SAMPLES
|
192
|
-
nphi = NAO_SAMPLES
|
193
|
-
eps = 0.0001
|
194
|
-
occlusion = 0.0
|
195
|
-
|
196
|
-
p0 = Vec.new(isect.pl.x + eps * isect.n.x,
|
197
|
-
isect.pl.y + eps * isect.n.y,
|
198
|
-
isect.pl.z + eps * isect.n.z)
|
199
|
-
nphi.times do |j|
|
200
|
-
ntheta.times do |i|
|
201
|
-
r = rand
|
202
|
-
# r = $rand.rand
|
203
|
-
phi = 2.0 * 3.14159265 * rand
|
204
|
-
# phi = 2.0 * 3.14159265 * $rand.rand
|
205
|
-
x = Math.cos(phi) * Math.sqrt(1.0 - r)
|
206
|
-
y = Math.sin(phi) * Math.sqrt(1.0 - r)
|
207
|
-
z = Math.sqrt(r)
|
208
|
-
|
209
|
-
rx = x * basis[0].x + y * basis[1].x + z * basis[2].x
|
210
|
-
ry = x * basis[0].y + y * basis[1].y + z * basis[2].y
|
211
|
-
rz = x * basis[0].z + y * basis[1].z + z * basis[2].z
|
212
|
-
|
213
|
-
raydir = Vec.new(rx, ry, rz)
|
214
|
-
ray = Ray.new(p0, raydir)
|
215
|
-
|
216
|
-
occisect = Isect.new
|
217
|
-
@spheres[0].intersect(ray, occisect)
|
218
|
-
@spheres[1].intersect(ray, occisect)
|
219
|
-
@spheres[2].intersect(ray, occisect)
|
220
|
-
@plane.intersect(ray, occisect)
|
221
|
-
if occisect.hit
|
222
|
-
occlusion = occlusion + 1.0
|
223
|
-
else
|
224
|
-
0.0
|
225
|
-
end
|
226
|
-
1.0
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f)
|
231
|
-
Vec.new(occlusion, occlusion, occlusion)
|
232
|
-
end
|
233
|
-
|
234
|
-
def render(w, h, nsubsamples)
|
235
|
-
cnt = 0
|
236
|
-
nsf = nsubsamples.to_f
|
237
|
-
h.times do |y|
|
238
|
-
w.times do |x|
|
239
|
-
rad = Vec.new(0.0, 0.0, 0.0)
|
240
|
-
|
241
|
-
# Subsmpling
|
242
|
-
nsubsamples.times do |v|
|
243
|
-
nsubsamples.times do |u|
|
244
|
-
cnt = cnt + 1
|
245
|
-
wf = w.to_f
|
246
|
-
hf = h.to_f
|
247
|
-
xf = x.to_f
|
248
|
-
yf = y.to_f
|
249
|
-
uf = u.to_f
|
250
|
-
vf = v.to_f
|
251
|
-
|
252
|
-
px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0)
|
253
|
-
py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0)
|
254
|
-
|
255
|
-
eye = Vec.new(px, py, -1.0).vnormalize
|
256
|
-
|
257
|
-
ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye)
|
258
|
-
|
259
|
-
isect = Isect.new
|
260
|
-
@spheres[0].intersect(ray, isect)
|
261
|
-
@spheres[1].intersect(ray, isect)
|
262
|
-
@spheres[2].intersect(ray, isect)
|
263
|
-
@plane.intersect(ray, isect)
|
264
|
-
if isect.hit
|
265
|
-
col = ambient_occlusion(isect)
|
266
|
-
rad.x = rad.x + col.x
|
267
|
-
rad.y = rad.y + col.y
|
268
|
-
rad.z = rad.z + col.z
|
269
|
-
else
|
270
|
-
0.0
|
271
|
-
end
|
272
|
-
1
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
r = rad.x / (nsf * nsf)
|
277
|
-
g = rad.y / (nsf * nsf)
|
278
|
-
b = rad.z / (nsf * nsf)
|
279
|
-
printf("%c", clamp(r))
|
280
|
-
printf("%c", clamp(g))
|
281
|
-
printf("%c", clamp(b))
|
282
|
-
1
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
def top
|
289
|
-
Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES)
|
290
|
-
end
|
291
|
-
|
292
|
-
top
|
293
|
-
|
294
|
-
if $0 == __FILE__
|
295
|
-
v = Vec.new(0.0, 0.0, 0.0)
|
296
|
-
v.vadd(v)
|
297
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
goodcheck (2.5.2)
|
5
|
-
activesupport (>= 4.0, < 7.0)
|
6
|
-
psych (>= 3.1, < 4.0)
|
7
|
-
rainbow (~> 3.0.0)
|
8
|
-
strong_json (>= 1.1, < 2.2)
|
9
|
-
|
10
|
-
GEM
|
11
|
-
remote: https://rubygems.org/
|
12
|
-
specs:
|
13
|
-
activesupport (6.0.3.3)
|
14
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
-
i18n (>= 0.7, < 2)
|
16
|
-
minitest (~> 5.1)
|
17
|
-
tzinfo (~> 1.1)
|
18
|
-
zeitwerk (~> 2.2, >= 2.2.2)
|
19
|
-
ansi (1.5.0)
|
20
|
-
builder (3.2.4)
|
21
|
-
concurrent-ruby (1.1.7)
|
22
|
-
i18n (1.8.5)
|
23
|
-
concurrent-ruby (~> 1.0)
|
24
|
-
minitest (5.14.3)
|
25
|
-
minitest-reporters (1.4.2)
|
26
|
-
ansi
|
27
|
-
builder
|
28
|
-
minitest (>= 5.0)
|
29
|
-
ruby-progressbar
|
30
|
-
psych (3.2.0)
|
31
|
-
rainbow (3.0.0)
|
32
|
-
rake (13.0.1)
|
33
|
-
ruby-progressbar (1.10.1)
|
34
|
-
strong_json (1.1.0)
|
35
|
-
thread_safe (0.3.6)
|
36
|
-
tzinfo (1.2.7)
|
37
|
-
thread_safe (~> 0.1)
|
38
|
-
zeitwerk (2.4.0)
|
39
|
-
|
40
|
-
PLATFORMS
|
41
|
-
ruby
|
42
|
-
|
43
|
-
DEPENDENCIES
|
44
|
-
bundler (>= 1.16)
|
45
|
-
goodcheck!
|
46
|
-
minitest (~> 5.0)
|
47
|
-
minitest-reporters (~> 1.4.2)
|
48
|
-
rake (~> 13.0)
|
49
|
-
|
50
|
-
BUNDLED WITH
|
51
|
-
2.1.2
|