cast_off 0.3.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +81 -513
- data/README.ja +177 -0
- data/bin/cast_off +12 -37
- data/cast_off.gemspec +6 -3
- data/ext/cast_off/cast_off.c.rb +186 -116
- data/ext/cast_off/generated_c_include/inline_api.h +0 -165
- data/ext/cast_off/generated_c_include/unbox_api.h.rb +1 -1
- data/lib/cast_off.rb +1 -0
- data/lib/cast_off/compile.rb +150 -208
- data/lib/cast_off/compile/code_manager.rb +0 -49
- data/lib/cast_off/compile/configuration.rb +8 -8
- data/lib/cast_off/compile/hook_invocation.rb +1 -0
- data/lib/cast_off/compile/ir/call_ir.rb +21 -13
- data/lib/cast_off/compile/translator.rb +6 -7
- data/lib/cast_off/suggestion.rb +1 -1
- metadata +10 -12
- data/README.en +0 -228
@@ -50,61 +50,12 @@ module CastOff
|
|
50
50
|
dir
|
51
51
|
end
|
52
52
|
|
53
|
-
def self.delete_from_compiled(entry)
|
54
|
-
compiled = load_autocompiled()
|
55
|
-
return false unless compiled
|
56
|
-
return false unless compiled.delete(entry)
|
57
|
-
dump_auto_compiled(compiled)
|
58
|
-
return true
|
59
|
-
end
|
60
|
-
|
61
53
|
def self.compiled_method_exist?(filepath, line_no)
|
62
54
|
return false unless filepath && line_no >= 0
|
63
55
|
base_sign = generate_signiture("#{filepath}_#{line_no}")
|
64
56
|
File.exist?("#{BaseDir}/#{@@program_sign}/#{base_sign}/loadable")
|
65
57
|
end
|
66
58
|
|
67
|
-
@@compiled_methods_fetch_str = nil
|
68
|
-
@@compiled_methods_load_str = nil
|
69
|
-
def self.load_autocompiled()
|
70
|
-
begin
|
71
|
-
dir = program_dir()
|
72
|
-
# fetch classes
|
73
|
-
path = "#{dir}/.compiled_methods"
|
74
|
-
return nil unless File.exist?(path)
|
75
|
-
if !@@compiled_methods_fetch_str
|
76
|
-
@@compiled_methods_fetch_str = File.open(path, 'rb:us-ascii').read()
|
77
|
-
@@compiled_methods_fetch_str.untaint # FIXME
|
78
|
-
end
|
79
|
-
Marshal.load(@@compiled_methods_fetch_str)
|
80
|
-
# load compiled methods information
|
81
|
-
path = "#{dir}/compiled_methods"
|
82
|
-
return nil unless File.exist?(path)
|
83
|
-
if !@@compiled_methods_load_str
|
84
|
-
@@compiled_methods_load_str = File.open(path, 'rb:us-ascii').read()
|
85
|
-
@@compiled_methods_load_str.untaint # FIXME
|
86
|
-
end
|
87
|
-
Marshal.load(@@compiled_methods_load_str)
|
88
|
-
rescue ArgumentError, NameError
|
89
|
-
false
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def self.dump_auto_compiled(compiled)
|
94
|
-
dir = program_dir()
|
95
|
-
path = "#{dir}/.compiled_methods"
|
96
|
-
File.open("#{path}", 'wb:us-ascii') do |f|
|
97
|
-
Marshal.dump(compiled.map{|c| c.first}, f) # dump only classes
|
98
|
-
end
|
99
|
-
@@compiled_methods_fetch_str = nil
|
100
|
-
path = "#{dir}/compiled_methods"
|
101
|
-
File.open("#{path}", 'wb:us-ascii') do |f|
|
102
|
-
Marshal.dump(compiled, f)
|
103
|
-
end
|
104
|
-
@@compiled_methods_load_str = nil
|
105
|
-
load_autocompiled()
|
106
|
-
end
|
107
|
-
|
108
59
|
def create_dstdir()
|
109
60
|
FileUtils.mkdir(@dstdir) unless File.exist?(@dstdir)
|
110
61
|
FileUtils.touch(@lockpath) unless File.exist?(@lockpath)
|
@@ -839,10 +839,10 @@ Currently, CastOff doesn't support object, which cannot marshal dump (e.g. STDIN
|
|
839
839
|
[Kernel, :fail, :singleton],
|
840
840
|
[Kernel, :global_variables, :module],
|
841
841
|
[Kernel, :global_variables, :singleton],
|
842
|
-
[Kernel, :__method__, :module],
|
843
|
-
[Kernel, :__method__, :singleton],
|
844
|
-
[Kernel, :__callee__, :module],
|
845
|
-
[Kernel, :__callee__, :singleton],
|
842
|
+
#[Kernel, :__method__, :module], #rb_frame_caller()
|
843
|
+
#[Kernel, :__method__, :singleton], #rb_frame_caller()
|
844
|
+
#[Kernel, :__callee__, :module], #rb_frame_caller()
|
845
|
+
#[Kernel, :__callee__, :singleton], #rb_frame_caller()
|
846
846
|
[Module, :append_features, :class],
|
847
847
|
[Module, :extend_object, :class],
|
848
848
|
[Module, :include, :class],
|
@@ -850,10 +850,10 @@ Currently, CastOff doesn't support object, which cannot marshal dump (e.g. STDIN
|
|
850
850
|
[Kernel, :eval, :singleton],
|
851
851
|
[Kernel, :local_variables, :module],
|
852
852
|
[Kernel, :local_variables, :singleton],
|
853
|
-
[Kernel, :iterator?, :module],
|
854
|
-
[Kernel, :iterator?, :singleton],
|
855
|
-
[Kernel, :block_given?, :module],
|
856
|
-
[Kernel, :block_given?, :singleton],
|
853
|
+
#[Kernel, :iterator?, :module], #rb_f_block_given_p
|
854
|
+
#[Kernel, :iterator?, :singleton], #rb_f_block_given_p
|
855
|
+
#[Kernel, :block_given?, :module], #rb_f_block_given_p
|
856
|
+
#[Kernel, :block_given?, :singleton], #rb_f_block_given_p
|
857
857
|
[Kernel, :catch, :module],
|
858
858
|
[Kernel, :catch, :singleton],
|
859
859
|
[Kernel, :throw, :module],
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -1486,10 +1486,12 @@ Call site is (#{@insn}).
|
|
1486
1486
|
attr_reader :method_id
|
1487
1487
|
|
1488
1488
|
IncompatMethods = [
|
1489
|
-
:eval,
|
1490
|
-
:binding,
|
1491
|
-
:block_given?,
|
1492
|
-
:iterator?,
|
1489
|
+
:eval, # use vm_get_ruby_level_caller_cfp
|
1490
|
+
:binding, # use vm_get_ruby_level_caller_cfp
|
1491
|
+
:block_given?, # use vm_get_ruby_level_caller_cfp
|
1492
|
+
:iterator?, # use vm_get_ruby_level_caller_cfp
|
1493
|
+
:__method__, # use rb_frame_caller()
|
1494
|
+
:__callee__, # use rb_frame_caller()
|
1493
1495
|
]
|
1494
1496
|
|
1495
1497
|
def initialize(mid, flags, param, argc, return_value, insn, cfg)
|
@@ -1710,34 +1712,40 @@ You should not use #{@method_id} method in compilation target of CastOff.
|
|
1710
1712
|
[MethodWrapper.new(ArrayWrapper, :empty?), 1] => [['empty_p', [], nil, [TrueClass, FalseClass], false, false]],
|
1711
1713
|
[MethodWrapper.new(ArrayWrapper, :last), 1] => [['last', [], nil, nil, false, false]],
|
1712
1714
|
[MethodWrapper.new(ArrayWrapper, :first), 1] => [['first', [], nil, nil, false, false]],
|
1713
|
-
[MethodWrapper.new(FixnumWrapper, :+), 2] => [['fixnum_plus', [Fixnum], nil, [Fixnum, Bignum], false, true], ['float_plus', [Float], nil, Float, true, true]], # FIXME
|
1714
|
-
[MethodWrapper.new(FixnumWrapper, :-), 2] => [['fixnum_minus', [Fixnum], nil, [Fixnum, Bignum], false, true], ['float_minus', [Float], nil, Float, true, true]], # FIXME
|
1715
|
-
[MethodWrapper.new(FixnumWrapper, :*), 2] => [['fixnum_mult', [Fixnum], nil, [Fixnum, Bignum], false, true], ['float_mult', [Float], nil, Float, true, true]], # FIXME
|
1716
|
-
[MethodWrapper.new(FixnumWrapper, :<=), 2] => [['le', [Fixnum], nil, [TrueClass, FalseClass], false, false]],
|
1717
|
-
[MethodWrapper.new(FixnumWrapper, :<), 2] => [['lt', [Fixnum], nil, [TrueClass, FalseClass], false, false]],
|
1718
|
-
[MethodWrapper.new(FixnumWrapper, :>=), 2] => [['ge', [Fixnum], nil, [TrueClass, FalseClass], false, false]],
|
1719
|
-
[MethodWrapper.new(FixnumWrapper, :>), 2] => [['gt', [Fixnum], nil, [TrueClass, FalseClass], false, false]],
|
1720
|
-
[MethodWrapper.new(FixnumWrapper, :==), 2] => [['eq', [Fixnum], nil, [TrueClass, FalseClass], false, false]],
|
1721
|
-
[MethodWrapper.new(FixnumWrapper, :===), 2] => [['eqq', [Fixnum], nil, [TrueClass, FalseClass], false, false]],
|
1722
1715
|
[MethodWrapper.new(FixnumWrapper, :&), 2] => [['and', [Fixnum], Fixnum, nil, false, false]], # FIXME
|
1716
|
+
[MethodWrapper.new(FixnumWrapper, :+), 2] => [['fixnum_plus', [Fixnum], nil, [Fixnum, Bignum], false, true], ['float_plus', [Float], nil, Float, true, true]],
|
1723
1717
|
[MethodWrapper.new(FloatWrapper, :+), 2] => [['float_plus', [Float], nil, Float, true, true], ['fixnum_plus', [Fixnum], nil, Float, true, true]],
|
1718
|
+
[MethodWrapper.new(FixnumWrapper, :-), 2] => [['fixnum_minus', [Fixnum], nil, [Fixnum, Bignum], false, true], ['float_minus', [Float], nil, Float, true, true]],
|
1724
1719
|
[MethodWrapper.new(FloatWrapper, :-), 2] => [['float_minus', [Float], nil, Float, true, true], ['fixnum_minus', [Fixnum], nil, Float, true, true]],
|
1720
|
+
[MethodWrapper.new(FixnumWrapper, :*), 2] => [['fixnum_mult', [Fixnum], nil, [Fixnum, Bignum], false, true], ['float_mult', [Float], nil, Float, true, true]],
|
1725
1721
|
[MethodWrapper.new(FloatWrapper, :*), 2] => [['float_mult', [Float], nil, Float, true, true], ['fixnum_mult', [Fixnum], nil, Float, true, true]],
|
1726
1722
|
[MethodWrapper.new(FloatWrapper, :/), 2] => [['float_div', [Float], nil, Float, true, true], ['fixnum_div', [Fixnum], nil, Float, true, true]],
|
1723
|
+
[MethodWrapper.new(FixnumWrapper, :<=), 2] => [['fixnum_le', [Fixnum], nil, [TrueClass, FalseClass], false, true],
|
1724
|
+
['float_le', [Float], nil, [TrueClass, FalseClass], false, true]],
|
1727
1725
|
[MethodWrapper.new(FloatWrapper, :<=), 2] => [['float_le', [Float], nil, [TrueClass, FalseClass], false, true],
|
1728
1726
|
['fixnum_le', [Fixnum], nil, [TrueClass, FalseClass], false, true]],
|
1727
|
+
[MethodWrapper.new(FixnumWrapper, :<), 2] => [['fixnum_lt', [Fixnum], nil, [TrueClass, FalseClass], false, true],
|
1728
|
+
['float_lt', [Float], nil, [TrueClass, FalseClass], false, true]],
|
1729
1729
|
[MethodWrapper.new(FloatWrapper, :<), 2] => [['float_lt', [Float], nil, [TrueClass, FalseClass], false, true],
|
1730
1730
|
['fixnum_lt', [Fixnum], nil, [TrueClass, FalseClass], false, true]],
|
1731
|
+
[MethodWrapper.new(FixnumWrapper, :>=), 2] => [['fixnum_ge', [Fixnum], nil, [TrueClass, FalseClass], false, true],
|
1732
|
+
['float_ge', [Float], nil, [TrueClass, FalseClass], false, true]],
|
1731
1733
|
[MethodWrapper.new(FloatWrapper, :>=), 2] => [['float_ge', [Float], nil, [TrueClass, FalseClass], false, true],
|
1732
1734
|
['fixnum_ge', [Fixnum], nil, [TrueClass, FalseClass], false, true]],
|
1735
|
+
[MethodWrapper.new(FixnumWrapper, :>), 2] => [['fixnum_gt', [Fixnum], nil, [TrueClass, FalseClass], false, true],
|
1736
|
+
['float_gt', [Float], nil, [TrueClass, FalseClass], false, true]],
|
1733
1737
|
[MethodWrapper.new(FloatWrapper, :>), 2] => [['float_gt', [Float], nil, [TrueClass, FalseClass], false, true],
|
1734
1738
|
['fixnum_gt', [Fixnum], nil, [TrueClass, FalseClass], false, true]],
|
1739
|
+
[MethodWrapper.new(FixnumWrapper, :==), 2] => [['fixnum_eq', [Fixnum], nil, [TrueClass, FalseClass], false, true],
|
1740
|
+
['float_eq', [Float], nil, [TrueClass, FalseClass], false, true]],
|
1735
1741
|
[MethodWrapper.new(FloatWrapper, :==), 2] => [['float_eq', [Float], nil, [TrueClass, FalseClass], false, true],
|
1736
1742
|
['fixnum_eq', [Fixnum], nil, [TrueClass, FalseClass], false, true]],
|
1737
1743
|
[MethodWrapper.new(FixnumWrapper, :!=), 2] => [['fixnum_neq', [Fixnum], nil, [TrueClass, FalseClass], false, true],
|
1738
1744
|
['float_neq', [Float], nil, [TrueClass, FalseClass], false, true]],
|
1739
1745
|
[MethodWrapper.new(FloatWrapper, :!=), 2] => [['float_neq', [Float], nil, [TrueClass, FalseClass], false, true],
|
1740
1746
|
['fixnum_neq', [Fixnum], nil, [TrueClass, FalseClass], false, true]],
|
1747
|
+
[MethodWrapper.new(FixnumWrapper, :===), 2] => [['fixnum_eqq', [Fixnum], nil, [TrueClass, FalseClass], false, true],
|
1748
|
+
['float_eqq', [Float], nil, [TrueClass, FalseClass], false, true]],
|
1741
1749
|
[MethodWrapper.new(FloatWrapper, :===), 2] => [['float_eqq', [Float], nil, [TrueClass, FalseClass], false, true],
|
1742
1750
|
['fixnum_eqq', [Fixnum], nil, [TrueClass, FalseClass], false, true]],
|
1743
1751
|
[MethodWrapper.new(FixnumWrapper, :-@), 1] => [['uminus', [], nil, [Fixnum, Bignum], false, true]],
|
@@ -917,7 +917,7 @@ Source line is #{@root_iseq.source_line}.
|
|
917
917
|
end
|
918
918
|
key = [name, mid, klass.singleton?, convention, argc]
|
919
919
|
entry = @fptr[key] || []
|
920
|
-
fptr.concat("_#{argc}_#{entry.size}")
|
920
|
+
fptr.concat("_#{convention.to_s.gsub(/-/, '_')}_#{argc}_#{entry.size}")
|
921
921
|
entry << fptr
|
922
922
|
@fptr[key] = entry
|
923
923
|
fptr
|
@@ -1048,7 +1048,9 @@ Source line is #{@root_iseq.source_line}.
|
|
1048
1048
|
rescue CompileError
|
1049
1049
|
return nil
|
1050
1050
|
end
|
1051
|
-
|
1051
|
+
unless /^[\w:]+$/.match(path)
|
1052
|
+
return nil
|
1053
|
+
end
|
1052
1054
|
if klass.singleton?
|
1053
1055
|
name = allocate_name("singleton_class_#{path}")
|
1054
1056
|
singleton_p = true
|
@@ -1066,17 +1068,14 @@ Source line is #{@root_iseq.source_line}.
|
|
1066
1068
|
end
|
1067
1069
|
|
1068
1070
|
# for suggestion
|
1069
|
-
MSG_TYPE_NOT_RESOLVED = "
|
1071
|
+
MSG_TYPE_NOT_RESOLVED = "Unresolved receivers"
|
1070
1072
|
COL_TYPE_NOT_RESOLVED = ["<Reciever>", "<Method>", "<Line>", "<Source>"]
|
1071
|
-
MSG_LITERAL_DUPLICATED = "
|
1073
|
+
MSG_LITERAL_DUPLICATED = "Duplicated literals"
|
1072
1074
|
COL_LITERAL_DUPLICATED = ["<Literal>", "<Reason>", "<Line>", "<Source>"]
|
1073
|
-
MSG_INLINEAPI_NOT_USED = "Some inline apis have not used."
|
1074
|
-
COL_INLINEAPI_NOT_USED = ["<Method>", "<Reason>", "<Line>", "<Source>"]
|
1075
1075
|
|
1076
1076
|
SUGGESTION_TABLE = [
|
1077
1077
|
[MSG_TYPE_NOT_RESOLVED, COL_TYPE_NOT_RESOLVED, :@type_suggestion],
|
1078
1078
|
[MSG_LITERAL_DUPLICATED, COL_LITERAL_DUPLICATED, :@literal_suggestion],
|
1079
|
-
[MSG_INLINEAPI_NOT_USED, COL_INLINEAPI_NOT_USED, :@inlineapi_suggestion],
|
1080
1079
|
]
|
1081
1080
|
|
1082
1081
|
SUGGESTION_TABLE.each do |(msg, col, ivar)|
|
data/lib/cast_off/suggestion.rb
CHANGED
@@ -81,7 +81,7 @@ module CastOff
|
|
81
81
|
suggestion << "#{side}#{line.zip(l_titles).map{|c, l| pretty ? c.center(l) : c }.join(" | ")}#{side}"
|
82
82
|
end
|
83
83
|
suggestion << " #{sep} "
|
84
|
-
@suggestion << suggestion.join("\n")
|
84
|
+
@suggestion << suggestion.map{|s| s.force_encoding('ASCII-8BIT')}.join("\n")
|
85
85
|
end
|
86
86
|
|
87
87
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cast_off
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,15 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: !
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
See ''cast_off --help'' for more information.
|
19
|
-
|
20
|
-
'
|
14
|
+
description: ! "CastOff is a compiler for Ruby1.9.3.\nCommand line tool cast_off is
|
15
|
+
available after installation.\nSee 'cast_off --help' for more information.\nCurrently,
|
16
|
+
CastOff supports Ruby1.9.3 only.\nSo, if you attempt to use CastOff, please install
|
17
|
+
CastOff under Ruby1.9.3 runtime. \n\n"
|
21
18
|
email: shiba@rvm.jp
|
22
19
|
executables:
|
23
20
|
- cast_off
|
@@ -45,6 +42,7 @@ files:
|
|
45
42
|
- lib/cast_off/compile/code_manager.rb
|
46
43
|
- lib/cast_off/compile/stack.rb
|
47
44
|
- lib/cast_off/compile/iseq.rb
|
45
|
+
- lib/cast_off/compile/hook_invocation.rb
|
48
46
|
- lib/cast_off/compile/configuration.rb
|
49
47
|
- lib/cast_off/compile/method_information.rb
|
50
48
|
- lib/cast_off/compile/basicblock.rb
|
@@ -97,8 +95,8 @@ files:
|
|
97
95
|
- bin/cast_off
|
98
96
|
- doc/about.pdf
|
99
97
|
- cast_off.gemspec
|
100
|
-
- README.en
|
101
98
|
- README
|
99
|
+
- README.ja
|
102
100
|
homepage: http://github.com/soba1104/CastOff
|
103
101
|
licenses: []
|
104
102
|
post_install_message:
|
@@ -108,9 +106,9 @@ require_paths:
|
|
108
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
107
|
none: false
|
110
108
|
requirements:
|
111
|
-
- -
|
109
|
+
- - =
|
112
110
|
- !ruby/object:Gem::Version
|
113
|
-
version: 1.9.
|
111
|
+
version: 1.9.3
|
114
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
113
|
none: false
|
116
114
|
requirements:
|
data/README.en
DELETED
@@ -1,228 +0,0 @@
|
|
1
|
-
* About CastOff
|
2
|
-
CastOff is a compiler for Ruby1.9.3.
|
3
|
-
CastOff compiles Ruby method (method written in Ruby) into C extension (method written in C)
|
4
|
-
by using given information such as class information of variables.
|
5
|
-
CastOff can reduce Ruby virtual machine overhead, so by use of CastOff,
|
6
|
-
the performance of compilation target method can improve.
|
7
|
-
|
8
|
-
This README document introduce basic functionality of CastOff.
|
9
|
-
If you have any questions, comments, or suggestions please send email to shiba@rvm.jp,
|
10
|
-
or use http://github.com/soba1104/CastOff/issues.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
* License
|
15
|
-
Same as the license of Ruby1.9.3 runtime.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
* Installation
|
20
|
-
$gem install cast_off
|
21
|
-
|
22
|
-
Currently, CastOff supports Ruby1.9.3 only.
|
23
|
-
So, if you attempt to use CastOff, please install CastOff under Ruby1.9.3 runtime.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
* Attention
|
28
|
-
|
29
|
-
** Incompatibility
|
30
|
-
-Continuation
|
31
|
-
CastOff causes problem about capture of continuation (callcc).
|
32
|
-
So, you should not use CastOff to your program which uses Continuation.
|
33
|
-
|
34
|
-
-Constant redefinition
|
35
|
-
<<<Sorry, not yet documented.>>>
|
36
|
-
|
37
|
-
-Built-in functions related with Method and Proc
|
38
|
-
CastOff compiles Ruby method and proc into C extension.
|
39
|
-
So, built-in functions related with Method and Proc (such as Method#arity, Proc#arity)
|
40
|
-
return different values.
|
41
|
-
|
42
|
-
# example
|
43
|
-
class Foo
|
44
|
-
def foo(a, b = :b, *c); end
|
45
|
-
end
|
46
|
-
f = Foo.new
|
47
|
-
puts (f.method(:foo).arity) # => -2
|
48
|
-
CastOff.compile(Foo, :foo)
|
49
|
-
puts (f.method(:foo).arity) # => -1
|
50
|
-
|
51
|
-
|
52
|
-
** Startup time
|
53
|
-
<<<Sorry, not yet documented.>>>
|
54
|
-
|
55
|
-
|
56
|
-
** Compilation time
|
57
|
-
<<<Sorry, not yet documented.>>>
|
58
|
-
|
59
|
-
|
60
|
-
** Load of compiled method
|
61
|
-
CastOff needs definition of compilation target method to load compiled method.
|
62
|
-
If compilation target method is not defined, CastOff cannot load compiled method.
|
63
|
-
|
64
|
-
When you use CastOff from command line, CastOff hooks class definition statement
|
65
|
-
to check method definition. And load compiled method if compilation target method is defined.
|
66
|
-
So, if you want to compile method outer class definition statement (such as following bar method),
|
67
|
-
you need call CastOff.autoload or CastOff.load after method definition explicitly.
|
68
|
-
|
69
|
-
-----------------------------------------------------
|
70
|
-
class Foo # Compiled Foo#foo is loaded after class definition of Foo
|
71
|
-
def foo
|
72
|
-
...
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def bar() # There are no class definition after definition of bar,
|
77
|
-
# so Compiled bar method is not loaded.
|
78
|
-
...
|
79
|
-
end
|
80
|
-
# If you want to load compiled bar method,
|
81
|
-
# you should call CastOff.autoload or CastOff.load after definition of bar method.
|
82
|
-
|
83
|
-
...
|
84
|
-
-----------------------------------------------------
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
* Usage
|
89
|
-
|
90
|
-
** Use CastOff from command line
|
91
|
-
By use of command line tool cast_off, you can improve performance of your Ruby program easily.
|
92
|
-
If you want to improve performance of your Ruby program, you should execute following command repeatedly.
|
93
|
-
|
94
|
-
-----------------------------------------------------
|
95
|
-
$cast_off PathOfTargetProgram ArgumentsOfTargetProgram
|
96
|
-
-----------------------------------------------------
|
97
|
-
|
98
|
-
For example, when you want to improve performance of Ruby program "foo.rb"
|
99
|
-
(in this example, "foo.rb" recieves one argument "bar" or "baz"), you should execute following commands.
|
100
|
-
|
101
|
-
-----------------------------------------------------
|
102
|
-
$cast_off foo.rb bar
|
103
|
-
$cast_off foo.rb baz
|
104
|
-
-----------------------------------------------------
|
105
|
-
|
106
|
-
When you execute these commands, CastOff does followings to compile foo.rb and related libraries.
|
107
|
-
|
108
|
-
1: Executes "foo.rb" with argument "bar" to get profile information.
|
109
|
-
2: Compiles "foo.rb" and related libraries.
|
110
|
-
3: Executes "foo.rb" with argument "baz" to get and update profile information.
|
111
|
-
4: Compiles "foo.rb" and related libraries.
|
112
|
-
|
113
|
-
After CastOff finishes compilation, you can run target program with --run option.
|
114
|
-
In above example, you can run target program with compiled codes by use of following command.
|
115
|
-
|
116
|
-
$cast_off --run foo.rb bar
|
117
|
-
|
118
|
-
|
119
|
-
*** Command line arguments
|
120
|
-
|
121
|
-
cast_off [options] PathOfTargetProgram ArgumentsOfTargetProgram
|
122
|
-
|
123
|
-
|
124
|
-
*** Command line options
|
125
|
-
--run
|
126
|
-
Execute target program with compiled methods.
|
127
|
-
|
128
|
-
--clear
|
129
|
-
Clear profile information and delete compiled methods.
|
130
|
-
If you want to clear profile information and compiled methods of target name "foo",
|
131
|
-
you should execute following command.
|
132
|
-
$cast_off --clear --name=foo
|
133
|
-
|
134
|
-
--threshold=COUNT
|
135
|
-
Compile method which is executed more than COUNT.
|
136
|
-
Default value is 100.
|
137
|
-
|
138
|
-
--name=NAME
|
139
|
-
Name compiled methods NAME.
|
140
|
-
This name is used for search of compiled methods.
|
141
|
-
If you don't use this option, CastOff uses File.basename([programfile]) as name.
|
142
|
-
|
143
|
-
--verbose
|
144
|
-
Show compilation progress and internal information.
|
145
|
-
|
146
|
-
-h, --help
|
147
|
-
Show help.
|
148
|
-
|
149
|
-
--version
|
150
|
-
Show version number of CastOff.
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
** Use CastOff from script
|
155
|
-
<<<Sorry, not yet documented. >>>
|
156
|
-
|
157
|
-
|
158
|
-
*** Specify class information to CastOff
|
159
|
-
You can specify class information to CastOff by followings.
|
160
|
-
|
161
|
-
-Specify class of variables:
|
162
|
-
--local variables, arguments
|
163
|
-
:local_variable_name => class_name
|
164
|
-
:local_variable_name => [class_name1, class_name2, ...]
|
165
|
-
[:local_variable_name1, :local_variable_name2, ...] => class_name
|
166
|
-
[:local_variable_name1, :local_variable_name2, ...] => [class_name1, class_name2, ...]
|
167
|
-
|
168
|
-
--instance variables
|
169
|
-
:@instance_variable_name => class_name
|
170
|
-
:@instance_variable_name => [class_name1, class_name2, ...]
|
171
|
-
[:@instance_variable_name1, :@instance_variable_name2, ...] => class_name
|
172
|
-
[:@instance_variable_name1, :@instance_variable_name2, ...] => [class_name1, class_name2, ...]
|
173
|
-
|
174
|
-
--class variables
|
175
|
-
:@@class_variable_name => class_name
|
176
|
-
:@@class_variable_name => [class_name1, class_name2, ...]
|
177
|
-
[:@@class_variable_name1, :@@class_variable_name2, ...] => class_name
|
178
|
-
[:@@class_variable_name1, :@@class_variable_name2, ...] => [class_name1, class_name2, ...]
|
179
|
-
|
180
|
-
--global variables
|
181
|
-
:$global_variable_name => class_name
|
182
|
-
:$global_variable_name => [class_name1, class_name2, ...]
|
183
|
-
[:$global_variable_name1, :$global_variable_name2, ...] => class_name
|
184
|
-
[:$global_variable_name1, :$global_variable_name2, ...] => [class_name1, class_name2, ...]
|
185
|
-
|
186
|
-
-Specify class of method return values:
|
187
|
-
class_name => {:method_name1 => class_of_return_value, :method_name2 => [class_of_return_value1, class_of_return_value2, ...], ...}
|
188
|
-
|
189
|
-
-Specify class of constants:
|
190
|
-
<<<Sorry, not yet documented. >>>
|
191
|
-
|
192
|
-
|
193
|
-
*** Compilation
|
194
|
-
You can compile Ruby method into C extension by followings.
|
195
|
-
|
196
|
-
-Compile instance method
|
197
|
-
--API
|
198
|
-
CastOff.compile(target(Class or Module), method_name(Symbol))
|
199
|
-
CastOff.compile(target(Class or Module), method_name(Symbol), class_information(Hash))
|
200
|
-
CastOff.compile(target(Class or Module), method_name(Symbol), binding(Binding))
|
201
|
-
CastOff.compile(target(Class or Module), method_name(Symbol), binding(Binding), class_information(Hash))
|
202
|
-
--Notes
|
203
|
-
This API compiles Ruby instance method into C extension and loads compiled method.
|
204
|
-
You should specify method_name(second argument) by Symbol class.
|
205
|
-
CastOff uses binding(third argument) to resolve Ruby constants.
|
206
|
-
|
207
|
-
-Compile singleton method
|
208
|
-
--API
|
209
|
-
CastOff.compile_singleton_method(target(Any Object), method_name(Symbol))
|
210
|
-
CastOff.compile_singleton_method(target(Any Object), method_name(Symbol), class_information(Hash))
|
211
|
-
CastOff.compile_singleton_method(target(Any Object), method_name(Symbol), binding(Binding))
|
212
|
-
CastOff.compile_singleton_method(target(Any Object), method_name(Symbol), binding(Binding), class_information(Hash))
|
213
|
-
--Notes
|
214
|
-
This API compiles Ruby singleton method into C extension and loads compiled method.
|
215
|
-
You should not use CastOff.compile when compile singleton method.
|
216
|
-
You should specify method_name(second argument) by Symbol class.
|
217
|
-
CastOff uses binding(third argument) to resolve Ruby constants.
|
218
|
-
|
219
|
-
-Compile Ruby code and execute
|
220
|
-
--API
|
221
|
-
CastOff.execute(class_information(Hash)) { target code }
|
222
|
-
--Notes
|
223
|
-
This API compiles passed block and executes.
|
224
|
-
|
225
|
-
|
226
|
-
*** Compile options
|
227
|
-
<<<Sorry, not yet documented. >>>
|
228
|
-
|