cast_off 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/cast_off.gemspec CHANGED
@@ -1,10 +1,12 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "cast_off"
3
- spec.version = "0.3.4"
3
+ spec.version = "0.3.5"
4
4
  spec.platform = Gem::Platform::RUBY
5
5
  spec.summary = "Compiler for Ruby1.9.3"
6
6
  spec.description = <<-EOS
7
- CastOff is a compiler for Ruby1.9.3
7
+ CastOff is a compiler for Ruby1.9.3.
8
+ Command line tool cast_off is available after installation.
9
+ See 'cast_off --help' for more information.
8
10
  EOS
9
11
  spec.files = Dir['{lib/**/*,ext/**/*}'] + %w[
10
12
  cast_off.gemspec
@@ -734,6 +734,12 @@ static VALUE cast_off_class_wrapper_get_cfunc_argc(VALUE self, VALUE mid)
734
734
  }
735
735
  }
736
736
 
737
+ static VALUE cast_off_class_wrapper_method_defined_p(VALUE self, VALUE mid)
738
+ {
739
+ VALUE klass = cast_off_class_wrapper_get_class(self);
740
+ return search_method(klass, SYM2ID(mid)) ? Qtrue : Qfalse;
741
+ }
742
+
737
743
  static VALUE cast_off_class_wrapper_get_method_type(VALUE self, VALUE mid)
738
744
  {
739
745
  VALUE klass = cast_off_class_wrapper_get_class(self);
@@ -948,14 +954,22 @@ static VALUE cast_off_module_wrapper_marshal_dump(VALUE self)
948
954
  VALUE module = cast_off_module_wrapper_get_module(self);
949
955
  VALUE name = rb_mod_name(module);
950
956
 
951
- /* TODO error handling */
957
+ if (TYPE(name) != T_STRING) {
958
+ rb_raise(rb_eTypeError, "failed to get module name");
959
+ }
960
+
952
961
  return name;
953
962
  }
954
963
 
955
964
  static VALUE cast_off_module_wrapper_marshal_load(VALUE self, VALUE name)
956
965
  {
957
- VALUE module = rb_path_to_class(name);
966
+ VALUE module;
967
+
968
+ if (NIL_P(name)) {
969
+ rb_raise(rb_eArgError, "invalid marshal");
970
+ }
958
971
 
972
+ module = rb_path_to_class(name);
959
973
  if (rb_obj_class(module) != rb_cModule) {
960
974
  rb_raise(rb_eCastOffCompileError, "failed to load module");
961
975
  }
@@ -1495,6 +1509,7 @@ void Init_cast_off(void)
1495
1509
  rb_define_method(rb_cCastOffClassWrapper, "singleton?", cast_off_class_wrapper_singleton_p, 0);
1496
1510
  rb_define_method(rb_cCastOffClassWrapper, "get_cfunc_argc", cast_off_class_wrapper_get_cfunc_argc, 1);
1497
1511
  rb_define_method(rb_cCastOffClassWrapper, "get_method_type", cast_off_class_wrapper_get_method_type, 1);
1512
+ rb_define_method(rb_cCastOffClassWrapper, "method_defined?", cast_off_class_wrapper_method_defined_p, 1);
1498
1513
  rb_define_method(rb_cCastOffClassWrapper, "get_attr_id", cast_off_class_wrapper_get_attr_id, 1);
1499
1514
  rb_define_method(rb_cCastOffClassWrapper, "instance_method_exist?", cast_off_class_wrapper_instance_method_exist_p, 1);
1500
1515
  rb_define_method(rb_cCastOffClassWrapper, "contain_class", cast_off_class_wrapper_contain_class, 0);
data/ext/cast_off/depend CHANGED
@@ -3,7 +3,7 @@ $(srcdir)/generated_c_include/unbox_api.h: \
3
3
  $(RUBY) -- $(srcdir)/generated_c_include/unbox_api.h.rb > $@
4
4
 
5
5
 
6
- cast_off.c: \
6
+ $(srcdir)/cast_off.c: \
7
7
  $(srcdir)/ruby_source/1.9.3/debug.h \
8
8
  $(srcdir)/ruby_source/1.9.3/gc.h \
9
9
  $(srcdir)/ruby_source/1.9.3/id.h \
@@ -51,7 +51,7 @@ cast_off.c: \
51
51
  $(RUBY) -- $(srcdir)/cast_off.c.rb $(srcdir)/ruby_source $(srcdir)/generated_c_include > $@
52
52
 
53
53
 
54
- cast_off.o: \
54
+ $(srcdir)/cast_off.o: \
55
55
  $(arch_hdrdir)/ruby/config.h \
56
56
  $(hdrdir)/ruby/defines.h \
57
57
  $(hdrdir)/ruby/intern.h \
@@ -12,8 +12,8 @@ $defs.push '-DCABI_OPERANDS' if enable_config 'cabi-operands', true
12
12
  $defs.push '-DCABI_PASS_CFP' if enable_config 'cabi-pass-cfp', true
13
13
 
14
14
  $INCFLAGS << ' -I$(srcdir)/ruby_source'
15
- $objs = %w'cast_off.o'
16
- $srcs = %w'cast_off.c.rb'
15
+ $objs = %w'$(srcdir)/cast_off.o'
16
+ $srcs = %w'$(srcdir)/cast_off.c.rb'
17
17
  create_header
18
18
  create_makefile 'cast_off'
19
19
 
@@ -1,114 +1,5 @@
1
1
  #define TYPE_ERROR_MESSAGE() "type mismatch"
2
2
 
3
- static inline VALUE
4
- cast_off_inline_fixnum_fixnum_plus(VALUE recv, VALUE obj)
5
- {
6
- #if 0
7
- #ifdef INJECT_GUARD
8
- if (UNLIKELY(!FIXNUM_2_P(recv, obj))) {
9
- rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
10
- }
11
- #endif
12
- #endif
13
-
14
- #ifndef LONG_LONG_VALUE
15
- {
16
- VALUE val = (recv + (obj & (~1)));
17
- #ifdef INJECT_GUARD
18
- if ((~(recv ^ obj) & (recv ^ val)) & ((VALUE)0x01 << ((sizeof(VALUE) * CHAR_BIT) - 1))) {
19
- rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
20
- }
21
- #endif /* INJECT_GUARD */
22
- return val;
23
- }
24
- #else /* LONG_LONG_VALUE */
25
- {
26
- long a, b, c;
27
- a = FIX2LONG(recv);
28
- b = FIX2LONG(obj);
29
- c = a + b;
30
- #ifdef INJECT_GUARD
31
- if (UNLIKELY(!FIXABLE(c))) {
32
- rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
33
- }
34
- #endif /* INJECT_GUARD */
35
- return LONG2FIX(c);
36
- }
37
- #endif /* LONG_LONG_VALUE */
38
- }
39
-
40
- static inline VALUE
41
- cast_off_inline_fixnum_float_plus(VALUE recv, VALUE obj)
42
- {
43
- return DBL2NUM((double)FIX2LONG(recv) + RFLOAT_VALUE(obj));
44
- }
45
-
46
- static inline VALUE
47
- cast_off_inline_fixnum_fixnum_minus(VALUE recv, VALUE obj)
48
- {
49
- long a, b, c;
50
-
51
- #if 0
52
- #ifdef INJECT_GUARD
53
- if (UNLIKELY(!FIXNUM_2_P(recv, obj))) {
54
- rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
55
- }
56
- #endif
57
- #endif
58
-
59
- a = FIX2LONG(recv);
60
- b = FIX2LONG(obj);
61
- c = a - b;
62
- #ifdef INJECT_GUARD
63
- if (LIKELY(FIXABLE(c))) {
64
- #endif
65
- return LONG2FIX(c);
66
- #ifdef INJECT_GUARD
67
- } else {
68
- rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
69
- }
70
- #endif
71
- }
72
-
73
- static inline VALUE
74
- cast_off_inline_fixnum_float_minus(VALUE recv, VALUE obj)
75
- {
76
- return DBL2NUM((double)FIX2LONG(recv) - RFLOAT_VALUE(obj));
77
- }
78
-
79
- static inline VALUE
80
- cast_off_inline_fixnum_fixnum_mult(VALUE recv, VALUE obj)
81
- {
82
- long a, b, c;
83
-
84
- #if 0
85
- #ifdef INJECT_GUARD
86
- if (UNLIKELY(!FIXNUM_2_P(recv, obj))) {
87
- rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
88
- }
89
- #endif
90
- #endif
91
-
92
- a = FIX2LONG(recv);
93
- b = FIX2LONG(obj);
94
- c = a * b;
95
- #ifdef INJECT_GUARD
96
- if (LIKELY(FIXABLE(c))) {
97
- #endif
98
- return LONG2FIX(c);
99
- #ifdef INJECT_GUARD
100
- } else {
101
- rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
102
- }
103
- #endif
104
- }
105
-
106
- static inline VALUE
107
- cast_off_inline_fixnum_float_mult(VALUE recv, VALUE obj)
108
- {
109
- return DBL2NUM((double)FIX2LONG(recv) * RFLOAT_VALUE(obj));
110
- }
111
-
112
3
  static inline VALUE
113
4
  cast_off_inline_fixnum_le(VALUE recv, VALUE obj)
114
5
  {
@@ -9,91 +9,129 @@ ERB.new(DATA.read(), 0, '%-').run();
9
9
  #endif
10
10
  __END__
11
11
  #define CBOOL2RBOOL(b) ((b) ? Qtrue : Qfalse)
12
- #ifdef INJECT_GUARD
13
- #define CFIX2RFIX(b) (FIXABLE?((b)) ? LONG2FIX((b)) : rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE()))
14
- #else
15
- #define CFIX2RFIX(b) LONG2FIX((b))
16
- #endif
17
12
  static inline VALUE CDOUBLE2RINT(double f)
18
13
  {
19
14
  if (f > 0.0) f = floor(f);
20
15
  if (f < 0.0) f = ceil(f);
21
16
  return FIXABLE(f) ? LONG2FIX((double)f) : rb_dbl2big(f);
22
17
  }
18
+ static inline VALUE PLUS(long a, long b)
19
+ {
20
+ long c = a + b;
21
+ if (FIXABLE(c)) {
22
+ return LONG2FIX(c);
23
+ } else {
24
+ return rb_big_plus(rb_int2big(a), rb_int2big(b));
25
+ }
26
+ }
27
+ static inline VALUE MINUS(long a, long b)
28
+ {
29
+ long c = a - b;
30
+ if (FIXABLE(c)) {
31
+ return LONG2FIX(c);
32
+ } else {
33
+ return rb_big_minus(rb_int2big(a), rb_int2big(b));
34
+ }
35
+ }
36
+ static inline VALUE MULT(long a, long b)
37
+ {
38
+ if (a == 0) {
39
+ return LONG2FIX(0);
40
+ } else {
41
+ volatile long c = a * b;
42
+ if (FIXABLE(c) && c / a == b) {
43
+ return LONG2FIX(c);
44
+ } else {
45
+ return rb_big_mul(rb_int2big(a), rb_int2big(b));
46
+ }
47
+ }
48
+ }
23
49
 
24
50
  %# arg size, [type0, type1, ...]
25
51
  %[['float',
26
52
  % {'-' => 'uminus'},
27
53
  % 0,
54
+ % :unary_operator,
28
55
  % {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
29
56
  % {},
30
57
  % {'VALUE' => 'DBL2NUM', 'double' => ''}],
31
58
  % ['float',
32
59
  % {'' => 'to_f'},
33
60
  % 0,
61
+ % :unary_operator,
34
62
  % {'VALUE' => ''},
35
63
  % {},
36
64
  % {'VALUE' => '', 'double' => 'RFLOAT_VALUE'}],
37
65
  % ['float',
38
66
  % {'' => 'to_i'},
39
67
  % 0,
68
+ % :unary_operator,
40
69
  % {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
41
70
  % {},
42
71
  % {'VALUE' => 'CDOUBLE2RINT'}],
43
72
  % ['fixnum',
44
73
  % {'-' => 'uminus'},
45
74
  % 0,
75
+ % :unary_operator,
46
76
  % {'VALUE' => 'FIX2LONG', 'long' => ''},
47
77
  % {},
48
- % {'VALUE' => 'CFIX2RFIX', 'long' => ''}],
78
+ % {'VALUE' => 'LONG2NUM'}],
49
79
  % ['fixnum',
50
80
  % {'(double)' => 'to_f'},
51
81
  % 0,
82
+ % :unary_operator,
52
83
  % {'VALUE' => 'FIX2LONG', 'long' => ''},
53
84
  % {},
54
85
  % {'VALUE' => 'DBL2NUM', 'double' => ''}],
55
86
  % ['float_float',
56
87
  % {'+' => 'plus', '-' => 'minus', '*' => 'mult', '/' => 'div'},
57
88
  % 1,
89
+ % :binary_operator,
58
90
  % {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
59
91
  % {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
60
92
  % {'VALUE' => 'DBL2NUM', 'double' => ''}],
61
93
  % ['float_float',
62
94
  % {'>' => 'gt', '>=' => 'ge', '<' => 'lt', '<=' => 'le', '==' => 'eq', '==' => 'eqq'},
63
95
  % 1,
96
+ % :binary_operator,
64
97
  % {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
65
98
  % {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
66
99
  % {'VALUE' => 'CBOOL2RBOOL'}],
67
100
  % ['fixnum_fixnum',
68
- % {'+' => 'plus', '-' => 'minus', '*' => 'mult', '/' => 'div'},
101
+ % {'PLUS' => 'plus', 'MINUS' => 'minus', 'MULT' => 'mult'},
69
102
  % 1,
103
+ % :function,
70
104
  % {'VALUE' => 'FIX2LONG', 'long' => ''},
71
105
  % {'VALUE' => 'FIX2LONG', 'long' => ''},
72
- % {'VALUE' => 'CFIX2RFIX', 'long' => ''}],
106
+ % {'VALUE' => ''}],
73
107
  % ['fixnum_float',
74
- % {'+' => 'plus', '-' => 'minus', '*' => 'mult', '/' => 'div'},
108
+ % {'+' => 'plus', '-' => 'minus', '*' => 'mult'},
75
109
  % 1,
110
+ % :binary_operator,
76
111
  % {'VALUE' => '(double)FIX2LONG', 'long' => ''},
77
112
  % {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
78
113
  % {'VALUE' => 'DBL2NUM', 'double' => ''}],
79
114
  % ['fixnum_float',
80
115
  % {'>' => 'gt', '>=' => 'ge', '<' => 'lt', '<=' => 'le', '==' => 'eq', '==' => 'eqq'},
81
116
  % 1,
117
+ % :binary_operator,
82
118
  % {'VALUE' => '(double)FIX2LONG', 'long' => ''},
83
119
  % {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
84
120
  % {'VALUE' => 'CBOOL2RBOOL'}],
85
121
  % ['float_fixnum',
86
122
  % {'+' => 'plus', '-' => 'minus', '*' => 'mult', '/' => 'div'},
87
123
  % 1,
124
+ % :binary_operator,
88
125
  % {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
89
126
  % {'VALUE' => '(double)FIX2LONG', 'long' => ''},
90
127
  % {'VALUE' => 'DBL2NUM', 'double' => ''}],
91
128
  % ['float_fixnum',
92
129
  % {'>' => 'gt', '>=' => 'ge', '<' => 'lt', '<=' => 'le', '==' => 'eq', '==' => 'eqq'},
93
130
  % 1,
131
+ % :binary_operator,
94
132
  % {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
95
133
  % {'VALUE' => '(double)FIX2LONG', 'long' => ''},
96
- % {'VALUE' => 'CBOOL2RBOOL'}]].each do |(function_name, h, argc, reciever_converter, arguments_converter, return_value_converter)|
134
+ % {'VALUE' => 'CBOOL2RBOOL'}]].each do |(function_name, h, argc, operation, reciever_converter, arguments_converter, return_value_converter)|
97
135
  % arguments_decls = arguments_converter.keys
98
136
  % reciever_decls = reciever_converter.keys
99
137
  % return_value_decls = return_value_converter.keys
@@ -117,11 +155,17 @@ static inline VALUE CDOUBLE2RINT(double f)
117
155
  static inline <%= return_value %>
118
156
  cast_off_inline_<%= function_name %>_<%= name %>_<%= suffix %>(<%= parameter.join(', ') %>)
119
157
  {
120
- % if argc > 0
158
+ % case operation
159
+ % when :unary_operator
160
+ % raise unless argc == 0 && statement.size == 1
161
+ return <%= return_value_converter[return_value] %>(<%= operator %>(<%= statement.first %>));
162
+ % when :binary_operator
163
+ % raise unless argc == 1 && statement.size == 2
121
164
  return <%= return_value_converter[return_value] %>(<%= statement.join(" #{operator} ") %>);
165
+ % when :function
166
+ return <%= return_value_converter[return_value] %>(<%= operator %>(<%= statement.join(", ") %>));
122
167
  % else
123
- % raise unless statement.size == 1
124
- return <%= return_value_converter[return_value] %>(<%= operator %>(<%= statement.first %>));
168
+ % raise
125
169
  % end
126
170
  }
127
171
  % end
@@ -101,12 +101,12 @@ module CastOff
101
101
  end
102
102
 
103
103
  def version_up()
104
- bug() unless File.exist?(@versionpath)
105
- v = File.read(@versionpath).to_i
104
+ v = File.exist?(@versionpath) ? File.read(@versionpath).to_i : @version
106
105
  bug() if v < 0
107
106
  v = [@version, v].max + 1
108
- vlog("version: #{@version} => #{v}")
107
+ dlog("version: #{@version} => #{v}")
109
108
  File.open(@versionpath, 'w'){|f| f.write(v)}
109
+ set_path()
110
110
  end
111
111
 
112
112
  def fetch_version()
@@ -134,8 +134,13 @@ Max length of signiture is #{FILEPATH_LIMIT} in this environment.
134
134
  def initialize(filepath, line_no)
135
135
  @filepath = filepath
136
136
  @line_no = line_no
137
+ @compilation_target = nil
138
+ set_path()
139
+ end
140
+
141
+ def set_path()
137
142
  base_sign = CodeManager.generate_signiture("#{@filepath}_#{@line_no}")
138
- dir = self.class.program_dir()
143
+ dir = CodeManager.program_dir()
139
144
  @dstdir = "#{dir}/#{base_sign}"
140
145
  @lockpath = "#{@dstdir}/lock"
141
146
  @versionfile = "version"
@@ -154,7 +159,6 @@ Max length of signiture is #{FILEPATH_LIMIT} in this environment.
154
159
  @dstbin = "#{@dstdir}/#{@signiture}.so"
155
160
  @longpath = @base_configuration_path # FIXME
156
161
  check_length()
157
- @compilation_target = nil
158
162
  end
159
163
 
160
164
  class CompilationTarget
@@ -445,7 +445,11 @@ Currently, CastOff doesn't support object, which cannot marshal dump (e.g. STDIN
445
445
  end
446
446
 
447
447
  def self.load(io)
448
- conf = Marshal.load(io)
448
+ begin
449
+ conf = Marshal.load(io)
450
+ rescue NameError
451
+ return nil
452
+ end
449
453
  bug() unless conf.instance_of?(Configuration)
450
454
  return nil unless conf.check_method_information_usage()
451
455
  conf
@@ -1088,7 +1088,7 @@ If you want to use these variables, use CastOff.allow_builtin_variable_incompati
1088
1088
  EOS
1089
1089
  when DEFINED_FUNC
1090
1090
  ret << <<-EOS
1091
- if (rb_method_boundp(rb_class_of(#{val}), #{@id}), 0) {
1091
+ if (rb_method_boundp(rb_class_of(#{val}), #{@id}, 0)) {
1092
1092
  #{@return_value} = #{@needstr ? 'rb_str_new2("method")' : 'Qtrue'};
1093
1093
  } else {
1094
1094
  #{@return_value} = Qnil;
@@ -1714,9 +1714,9 @@ You should not use #{@method_id} method in compilation target of CastOff.
1714
1714
  [MethodWrapper.new(ArrayWrapper, :empty?), 1] => [['empty_p', [], nil, [TrueClass, FalseClass], false, false]],
1715
1715
  [MethodWrapper.new(ArrayWrapper, :last), 1] => [['last', [], nil, nil, false, false]],
1716
1716
  [MethodWrapper.new(ArrayWrapper, :first), 1] => [['first', [], nil, nil, false, false]],
1717
- [MethodWrapper.new(FixnumWrapper, :+), 2] => [['fixnum_plus', [Fixnum], Fixnum, nil, true, true], ['float_plus', [Float], nil, Float, true, true]], # FIXME
1718
- [MethodWrapper.new(FixnumWrapper, :-), 2] => [['fixnum_minus', [Fixnum], Fixnum, nil, true, true], ['float_minus', [Float], nil, Float, true, true]], # FIXME
1719
- [MethodWrapper.new(FixnumWrapper, :*), 2] => [['fixnum_mult', [Fixnum], Fixnum, nil, true, true], ['float_mult', [Float], nil, Float, true, true]], # FIXME
1717
+ [MethodWrapper.new(FixnumWrapper, :+), 2] => [['fixnum_plus', [Fixnum], nil, [Fixnum, Bignum], false, true], ['float_plus', [Float], nil, Float, true, true]], # FIXME
1718
+ [MethodWrapper.new(FixnumWrapper, :-), 2] => [['fixnum_minus', [Fixnum], nil, [Fixnum, Bignum], false, true], ['float_minus', [Float], nil, Float, true, true]], # FIXME
1719
+ [MethodWrapper.new(FixnumWrapper, :*), 2] => [['fixnum_mult', [Fixnum], nil, [Fixnum, Bignum], false, true], ['float_mult', [Float], nil, Float, true, true]], # FIXME
1720
1720
  [MethodWrapper.new(FixnumWrapper, :<=), 2] => [['le', [Fixnum], nil, [TrueClass, FalseClass], false, false]],
1721
1721
  [MethodWrapper.new(FixnumWrapper, :<), 2] => [['lt', [Fixnum], nil, [TrueClass, FalseClass], false, false]],
1722
1722
  [MethodWrapper.new(FixnumWrapper, :>=), 2] => [['ge', [Fixnum], nil, [TrueClass, FalseClass], false, false]],
@@ -1741,7 +1741,7 @@ You should not use #{@method_id} method in compilation target of CastOff.
1741
1741
  ['fixnum_eq', [Fixnum], nil, [TrueClass, FalseClass], false, true]],
1742
1742
  [MethodWrapper.new(FloatWrapper, :===), 2] => [['float_eqq', [Float], nil, [TrueClass, FalseClass], false, true],
1743
1743
  ['fixnum_eqq', [Fixnum], nil, [TrueClass, FalseClass], false, true]],
1744
- [MethodWrapper.new(FixnumWrapper, :-@), 1] => [['uminus', [], Fixnum, nil, true, true]],
1744
+ [MethodWrapper.new(FixnumWrapper, :-@), 1] => [['uminus', [], nil, [Fixnum, Bignum], false, true]],
1745
1745
  [MethodWrapper.new(FloatWrapper, :-@), 1] => [['uminus', [], nil, Float, true, true]],
1746
1746
  [MethodWrapper.new(FixnumWrapper, :to_f), 1] => [['to_f', [], nil, Float, true, true]],
1747
1747
  [MethodWrapper.new(FloatWrapper, :to_f), 1] => [['to_f', [], nil, Float, true, false]],
@@ -2076,7 +2076,7 @@ You should not use #{@method_id} method in compilation target of CastOff.
2076
2076
  id = @translator.allocate_id(@method_id)
2077
2077
  bug() if recv.undefined?
2078
2078
  if @configuration.development? && sampling_return_value?
2079
- ret << " sampling_tmp = #{recv};"
2079
+ ret << " sampling_tmp = #{recv.boxed_form};"
2080
2080
  end
2081
2081
  if blockarg?
2082
2082
  ret << funcall_code(nil, id, recv, param, @argc)
@@ -2117,7 +2117,7 @@ You should not use #{@method_id} method in compilation target of CastOff.
2117
2117
  else_class = types[else_index]
2118
2118
  else_code = not_funcall_code(else_class, @method_id, recv, param, @argc)
2119
2119
  if !else_code
2120
- @dependency.add(else_class, @method_id, false)
2120
+ @dependency.add(else_class, @method_id, false) if else_class.method_defined?
2121
2121
  else_code = funcall_code(else_class, id, recv, param, @argc)
2122
2122
  end
2123
2123
  if nil_code == else_code
@@ -2151,7 +2151,7 @@ You should not use #{@method_id} method in compilation target of CastOff.
2151
2151
  end
2152
2152
  end
2153
2153
  if @configuration.development? && sampling_return_value?
2154
- ret << " sampling_poscall(#{@return_value}, sampling_tmp, ID2SYM(rb_intern(#{@method_id.to_s.inspect})));"
2154
+ ret << " sampling_poscall(#{@return_value.boxed_form}, sampling_tmp, ID2SYM(rb_intern(#{@method_id.to_s.inspect})));"
2155
2155
  end
2156
2156
  ret.join("\n")
2157
2157
  end
@@ -254,12 +254,14 @@ static int <CLASS_CHECK_FUNCTION_NAME>_failed(VALUE obj, VALUE klass)
254
254
  @variables << @guard_value
255
255
  @variables_without_result << @guard_value
256
256
  @result_variable = nil
257
- @dependent_local_variables = get_dependent_local_variables(vars)
258
- @dependent_stack_variables = get_dependent_stack_variables(vars)
259
- @dependent_variables = @dependent_local_variables.values.flatten + @dependent_stack_variables.values.flatten
260
257
  @source = @insn.source
261
258
  @source = @source.empty? ? nil : @source
262
259
  @source_line = @insn.line.to_s
260
+ if @configuration.deoptimize?
261
+ @dependent_local_variables = get_dependent_local_variables(vars)
262
+ @dependent_stack_variables = get_dependent_stack_variables(vars)
263
+ @dependent_variables = @dependent_local_variables.values.flatten + @dependent_stack_variables.values.flatten
264
+ end
263
265
  end
264
266
 
265
267
  ### unboxing begin ###
@@ -277,6 +279,7 @@ static int <CLASS_CHECK_FUNCTION_NAME>_failed(VALUE obj, VALUE klass)
277
279
  if @guard_value.boxed?
278
280
  change |= defs.propergate_boxed_value_backward(@guard_value)
279
281
  if @configuration.deoptimize?
282
+ bug() unless @dependent_variables
280
283
  @dependent_variables.each do |var|
281
284
  if var.is_a?(DynamicVariable)
282
285
  bug() unless var.boxed?
@@ -318,6 +321,7 @@ static int <CLASS_CHECK_FUNCTION_NAME>_failed(VALUE obj, VALUE klass)
318
321
  @alive = true
319
322
  defs.mark(@guard_value)
320
323
  if @configuration.deoptimize?
324
+ bug() unless @dependent_variables
321
325
  @dependent_variables.each{|v| defs.mark(v)}
322
326
  end
323
327
  true
@@ -418,6 +422,7 @@ static int <CLASS_CHECK_FUNCTION_NAME>_failed(VALUE obj, VALUE klass)
418
422
  def reset()
419
423
  super()
420
424
  if @configuration.deoptimize?
425
+ bug() unless @dependent_variables
421
426
  @dependent_variables.map! do |v|
422
427
  bug() unless v.is_a?(Variable)
423
428
  @cfg.find_variable(v)
@@ -616,7 +616,7 @@ Call site is (#{insn}).
616
616
  if @configuration.development?
617
617
  @sampling_variable.each do |var|
618
618
  next if var.is_a?(Literal)
619
- s << " sampling_variable(#{var}, ID2SYM(rb_intern(#{var.source.inspect})));"
619
+ s << " sampling_variable(#{var.boxed_form}, ID2SYM(rb_intern(#{var.source.inspect})));"
620
620
  end
621
621
  end
622
622
  s.empty? ? nil : s.join("\n")
@@ -95,7 +95,11 @@ module CastOff
95
95
  #count = @@compilation_threshold if contain_loop?(klass, mid)
96
96
  bug() unless bind.instance_of?(Binding) || bind.nil?
97
97
  bind_table[[klass, mid]] = bind
98
- location_table[[klass, mid]] = (file =~ /\(/) ? nil : [File.expand_path(file), line]
98
+ begin
99
+ location_table[[klass, mid]] = (file =~ /\(/) ? nil : [File.expand_path(file), line]
100
+ rescue Errno::ENOENT
101
+ location_table[[klass, mid]] = nil
102
+ end
99
103
  end
100
104
  #if cinfo
101
105
  #table = (cinfo_table[[klass, mid]] ||= {})
@@ -153,7 +157,7 @@ module CastOff
153
157
  @@original_instance_method_iseq.delete([t, mid])
154
158
  end
155
159
 
156
- def compile(target, mid, bind_or_typemap = nil, typemap = nil)
160
+ def compile(target, mid, bind_or_typemap = nil, typemap = nil, force_compilation = false)
157
161
  execute_no_hook() do
158
162
  case target
159
163
  when Class, Module
@@ -164,7 +168,7 @@ module CastOff
164
168
  mid, bind, typemap = parse_arguments(mid, bind_or_typemap, typemap)
165
169
  t = override_target(target, mid)
166
170
  iseq = @@original_instance_method_iseq[[t, mid]] || get_iseq(target, mid, false)
167
- manager, configuration, suggestion = compile_iseq(iseq, mid, typemap, false, bind)
171
+ manager, configuration, suggestion = compile_iseq(iseq, mid, typemap, false, bind, force_compilation)
168
172
  manager.compilation_target_is_a(t, mid, false)
169
173
  set_direct_call(target, mid, target.instance_of?(Class) ? :class : :module, manager, configuration)
170
174
  load_binary(manager, configuration, suggestion, iseq)
@@ -182,11 +186,11 @@ module CastOff
182
186
  @@original_singleton_method_iseq.delete([obj, mid])
183
187
  end
184
188
 
185
- def compile_singleton_method(obj, mid, bind_or_typemap = nil, typemap = nil)
189
+ def compile_singleton_method(obj, mid, bind_or_typemap = nil, typemap = nil, force_compilation = false)
186
190
  execute_no_hook() do
187
191
  mid, bind, typemap = parse_arguments(mid, bind_or_typemap, typemap)
188
192
  iseq = @@original_singleton_method_iseq[[obj, mid]] || get_iseq(obj, mid, true)
189
- manager, configuration, suggestion = compile_iseq(iseq, mid, typemap, false, bind)
193
+ manager, configuration, suggestion = compile_iseq(iseq, mid, typemap, false, bind, force_compilation)
190
194
  manager.compilation_target_is_a(obj, mid, true)
191
195
  set_direct_call(obj, mid, :singleton, manager, configuration)
192
196
  load_binary(manager, configuration, suggestion, iseq)
@@ -205,7 +209,7 @@ module CastOff
205
209
  if !@@loaded_binary[key]
206
210
  execute_no_hook() do
207
211
  bind = block.binding
208
- manager, configuration, suggestion = compile_iseq(iseq, nil, typemap, false, bind)
212
+ manager, configuration, suggestion = compile_iseq(iseq, nil, typemap, false, bind, false)
209
213
  load_binary(manager, configuration, suggestion, iseq)
210
214
  @@loaded_binary[key] = manager.signiture
211
215
  end
@@ -257,7 +261,7 @@ module CastOff
257
261
  end
258
262
  end
259
263
 
260
- def compile_iseq(iseq, mid, typemap, is_proc, bind)
264
+ def compile_iseq(iseq, mid, typemap, is_proc, bind, force_compilation)
261
265
  filepath, line_no = *iseq.to_a.slice(7, 2)
262
266
  raise(UnsupportedError.new(<<-EOS)) unless filepath && File.exist?(filepath)
263
267
 
@@ -268,7 +272,7 @@ Currently, CastOff cannot compile method which source file is not exist.
268
272
  suggestion = Suggestion.new(iseq, @@suggestion_io)
269
273
  configuration = nil
270
274
  manager.do_atomically() do
271
- configuration = __compile(iseq, manager, typemap || {}, mid, is_proc, bind, suggestion)
275
+ configuration = __compile(iseq, manager, typemap || {}, mid, is_proc, bind, suggestion, force_compilation)
272
276
  end
273
277
  bug() unless configuration.instance_of?(Configuration)
274
278
  [manager, configuration, suggestion]
@@ -328,9 +332,8 @@ Currently, CastOff cannot compile method which source file is not exist.
328
332
  return false unless update_p
329
333
  ann = manager.load_annotation() || {}
330
334
  bug() unless ann.instance_of?(Hash)
331
- manager.version_up()
332
335
  begin
333
- __send__(singleton ? 'compile_singleton_method' : 'compile', target, mid, ann)
336
+ __send__(singleton ? 'compile_singleton_method' : 'compile', target, mid, ann, nil, true)
334
337
  vlog("re-compilation success: #{target}#{singleton ? '.' : '#'}#{mid}")
335
338
  rescue => e
336
339
  vlog("re-compilation failed: #{target}#{singleton ? '.' : '#'}#{mid} => #{e}")
@@ -340,8 +343,8 @@ Currently, CastOff cannot compile method which source file is not exist.
340
343
 
341
344
  class ReCompilation < StandardError; end
342
345
 
343
- def __compile(iseq, manager, annotation, mid, is_proc, bind, suggestion)
344
- if reuse_compiled_code? && !manager.target_file_updated?
346
+ def __compile(iseq, manager, annotation, mid, is_proc, bind, suggestion, force_compilation)
347
+ if !force_compilation && reuse_compiled_code? && !manager.target_file_updated?
345
348
  # already compiled
346
349
  if CastOff.development? || !CastOff.skip_configuration_check? || manager.last_configuration_enabled_development?
347
350
  conf = Configuration.new(annotation, bind)
@@ -361,6 +364,7 @@ Currently, CastOff cannot compile method which source file is not exist.
361
364
  union_base_configuration(conf, manager)
362
365
  end
363
366
  else
367
+ manager.clear_base_configuration() if manager.target_file_updated?
364
368
  conf = Configuration.new(annotation, bind)
365
369
  union_base_configuration(conf, manager)
366
370
  end
@@ -384,6 +388,7 @@ Currently, CastOff cannot compile method which source file is not exist.
384
388
  require 'cast_off/compile/stack'
385
389
  require 'cast_off/compile/information'
386
390
  conf.validate()
391
+ manager.version_up()
387
392
  bug() unless conf
388
393
  dep = Dependency.new()
389
394
  block_inlining = true
@@ -418,17 +423,17 @@ Currently, CastOff cannot compile method which source file is not exist.
418
423
  end
419
424
  bind = bind.bind if bind
420
425
  skip = false
421
- if singleton
422
- iseq = @@original_singleton_method_iseq[[klass, mid]] || get_iseq(klass, mid, true)
423
- else
424
- begin
426
+ begin
427
+ if singleton
428
+ iseq = @@original_singleton_method_iseq[[klass, mid]] || get_iseq(klass, mid, true)
429
+ else
425
430
  t = override_target(klass, mid)
426
431
  iseq = @@original_instance_method_iseq[[t, mid]] || get_iseq(klass, mid, false)
427
- rescue CompileError, UnsupportedError
428
- @@skipped |= [entry]
429
- dlog("skip: entry = #{entry}")
430
- skip = true
431
432
  end
433
+ rescue CompileError, UnsupportedError
434
+ @@skipped |= [entry]
435
+ dlog("skip: entry = #{entry}")
436
+ skip = true
432
437
  end
433
438
  f, l = *iseq.to_a.slice(7, 2) unless skip
434
439
  if !skip && f == file && l == line
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.3.4
4
+ version: 0.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,13 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-27 00:00:00.000000000 Z
12
+ date: 2011-11-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: ! 'CastOff is a compiler for Ruby1.9.3
14
+ description: ! 'CastOff is a compiler for Ruby1.9.3.
15
+
16
+ Command line tool cast_off is available after installation.
17
+
18
+ See ''cast_off --help'' for more information.
15
19
 
16
20
  '
17
21
  email: shiba@rvm.jp