@@ -15,8 +15,8 @@ def initialize file, option
15
15
@basename = File . basename ( file , '.rcb' )
16
16
@output_dir = option [ :output_dir ]
17
17
@src_rcb = file
18
- @out_rb = File . join ( @output_dir , "#{ @basename } .rb" )
19
- @out_c = File . join ( @output_dir , "#{ @basename } .c" )
18
+ @out_rb = File . join ( @output_dir , "ricsin_ #{ @basename } .rb" )
19
+ @out_c = File . join ( @output_dir , "ricsin_ #{ @basename } .c" )
20
20
@out_so = nil
21
21
@so_basename = "ricsin_#{ @basename } "
22
22
@src = nil
@@ -27,6 +27,7 @@ def initialize file, option
27
27
def run
28
28
raise unless @out_so
29
29
require @out_so
30
+ ::RICSIN_ISEQMAP [ @so_basename ] . eval
30
31
end
31
32
32
33
def generate
@@ -37,6 +38,15 @@ def generate
37
38
38
39
generate_csrc
39
40
generate_dll
41
+ generate_rb
42
+ end
43
+
44
+ def generate_rb
45
+ open ( @out_rb , 'wb' ) { |f |
46
+ f . puts "require '#{ @so_basename } .so'"
47
+ f . puts "$0 = '#{ @basename } .rcb' if $0 == __FILE__"
48
+ f . puts "::RICSIN_ISEQMAP['#{ @so_basename } '].eval"
49
+ }
40
50
end
41
51
42
52
def preprocess file
@@ -75,7 +85,7 @@ def generate_dll
75
85
system ( "#{ ruby } extconf.rb" )
76
86
else
77
87
cmd = "#{ ruby } -r mkmf -e " \
78
- "'$objs=[#{ ( File . basename ( @src_rcb , '.rcb ' ) +'.o' ) . dump } ]; " \
88
+ "'$objs=[#{ ( File . basename ( @out_c , '.c ' ) +'.o' ) . dump } ]; " \
79
89
"create_makefile(#{ @so_basename . dump } )'"
80
90
system ( cmd )
81
91
end or raise "extconf"
@@ -152,6 +162,7 @@ def csrc_init_function
152
162
VALUE file = rb_str_new2("#{ File . basename ( @src_rcb ) } ");
153
163
VALUE line = INT2FIX(1);
154
164
VALUE opt = rb_hash_new();
165
+ VALUE map;
155
166
VALUE iseq;
156
167
157
168
#{
@@ -176,7 +187,14 @@ def csrc_init_function
176
187
rb_io_puts(1, &disasm_str, rb_stdout);
177
188
}
178
189
179
- rb_iseq_eval(iseq);
190
+ if (rb_const_defined(rb_cObject, rb_intern("RICSIN_ISEQMAP"))) {
191
+ map = rb_const_get(rb_cObject, rb_intern("RICSIN_ISEQMAP"));
192
+ }
193
+ else {
194
+ map = rb_hash_new();
195
+ rb_const_set(rb_cObject, rb_intern("RICSIN_ISEQMAP"), map);
196
+ }
197
+ rb_hash_aset(map, rb_str_new2("#{ @so_basename } "), iseq);
180
198
}
181
199
EOS
182
200
end
0 commit comments