Skip to content

Commit 6e3d697

Browse files
committed
* ricsin/ricsin.rb: fix $0 and fix to output ricsin_#{name}.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ricsin@19568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 48b9605 commit 6e3d697

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

ricsin/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Fri Sep 26 12:49:52 2008 Koichi Sasada <ko1@atdot.net>
2+
3+
* ricsin/ricsin.rb: fix $0 and fix to output ricsin_#{name}.rb.
4+
15
Wed Sep 24 17:42:30 2008 Koichi Sasada <ko1@atdot.net>
26

37
* ricsin/test.rcb: add 2 assersions.

ricsin/ricsin.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def initialize file, option
1515
@basename = File.basename(file, '.rcb')
1616
@output_dir = option[:output_dir]
1717
@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")
2020
@out_so = nil
2121
@so_basename = "ricsin_#{@basename}"
2222
@src = nil
@@ -27,6 +27,7 @@ def initialize file, option
2727
def run
2828
raise unless @out_so
2929
require @out_so
30+
::RICSIN_ISEQMAP[@so_basename].eval
3031
end
3132

3233
def generate
@@ -37,6 +38,15 @@ def generate
3738

3839
generate_csrc
3940
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+
}
4050
end
4151

4252
def preprocess file
@@ -75,7 +85,7 @@ def generate_dll
7585
system("#{ruby} extconf.rb")
7686
else
7787
cmd = "#{ruby} -r mkmf -e "\
78-
"'$objs=[#{(File.basename(@src_rcb, '.rcb')+'.o').dump}]; " \
88+
"'$objs=[#{(File.basename(@out_c, '.c')+'.o').dump}]; " \
7989
"create_makefile(#{@so_basename.dump})'"
8090
system(cmd)
8191
end or raise "extconf"
@@ -152,6 +162,7 @@ def csrc_init_function
152162
VALUE file = rb_str_new2("#{File.basename(@src_rcb)}");
153163
VALUE line = INT2FIX(1);
154164
VALUE opt = rb_hash_new();
165+
VALUE map;
155166
VALUE iseq;
156167
157168
#{
@@ -176,7 +187,14 @@ def csrc_init_function
176187
rb_io_puts(1, &disasm_str, rb_stdout);
177188
}
178189
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);
180198
}
181199
EOS
182200
end

ricsin/t.rcb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
p $0
2+
p $0 == __FILE__
3+
4+
__END__
5+
p $0
6+
p $"
7+
8+
__END__
19

210
$foo = 42
311
p __C__('return $foo; /* $foo */')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy