summaryrefslogtreecommitdiff
path: root/tool/compile_prelude.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-10 09:22:59 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-10 09:22:59 +0000
commit040ffb5d792d932215b7b6fbce9ee9752d76e285 (patch)
tree2d8bfa467abc38cbeccfb504836dfe712784c190 /tool/compile_prelude.rb
parent66c127bc6f95761f967efc5109cd229973fbc50f (diff)
* gem_prelude.rb: new file for gem libraries. currently empty.
* common.mk: generate ext_prelude.c by prelude.rb and gem_prelude.rb. ruby (not miniruby) is linked with ext_prelude.o instead of prelude.o. * inits.c (rb_call_inits): don't call Init_prelude. * ruby.c: support --disable-gems option. (ruby_init_gems): new function to define Gem::Enable and invoke Init_prelude. (process_options): call ruby_init_gems just after ruby_init_loadpath. * tool/compile_prelude.rb: support multiple files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/compile_prelude.rb')
-rw-r--r--tool/compile_prelude.rb64
1 files changed, 55 insertions, 9 deletions
diff --git a/tool/compile_prelude.rb b/tool/compile_prelude.rb
index 1012d1f..1f67d4c 100644
--- a/tool/compile_prelude.rb
+++ b/tool/compile_prelude.rb
@@ -1,33 +1,79 @@
+*preludes, outfile = *ARGV
-prelude, outfile = *ARGV
+C_ESC = {
+ "\\" => "\\\\",
+ '"' => '\"',
+ "\n" => '\n',
+}
+
+0x00.upto(0x1f) {|ch| C_ESC[[ch].pack("C")] ||= "\\x%02x" % ch }
+0x7f.upto(0xff) {|ch| C_ESC[[ch].pack("C")] = "\\x%02x" % ch }
+C_ESC_PAT = Regexp.union(*C_ESC.keys)
+
+def c_esc(str)
+ '"' + str.gsub(C_ESC_PAT) { C_ESC[$&] } + '"'
+end
-lines = File.readlines(prelude).map{|line|
- line.dump
+lines_list = preludes.map {|prelude|
+ lines = []
+ File.readlines(prelude).each {|line|
+ line.gsub!(/RbConfig::CONFIG\["(\w+)"\]/) {
+ require 'rbconfig'
+ if RbConfig::CONFIG.has_key? $1
+ c_esc(RbConfig::CONFIG[$1])
+ else
+ $&
+ end
+ }
+ lines << c_esc(line)
+ }
+ lines
}
open(outfile, 'w'){|f|
- f.puts <<EOS__, <<'EOS__'
+ f.puts <<'EOS__'
#include "ruby/ruby.h"
#include "vm_core.h"
-static const char prelude_name[] = "#{File.basename(prelude)}";
-static const char prelude_code[] =
+EOS__
+
+ preludes.zip(lines_list).each_with_index {|(prelude, lines), i|
+ f.puts <<EOS__
+static const char prelude_name#{i}[] = "#{File.basename(prelude)}";
+static const char prelude_code#{i}[] =
#{lines.join("\n")}
;
EOS__
+ }
+ f.puts <<'EOS__'
void
Init_prelude(void)
{
+EOS__
+ preludes.length.times {|i|
+ f.puts <<EOS__
rb_iseq_eval(rb_iseq_compile(
- rb_str_new(prelude_code, sizeof(prelude_code) - 1),
- rb_str_new(prelude_name, sizeof(prelude_name) - 1),
+ rb_str_new(prelude_code#{i}, sizeof(prelude_code#{i}) - 1),
+ rb_str_new(prelude_name#{i}, sizeof(prelude_name#{i}) - 1),
INT2FIX(1)));
+EOS__
+ }
+ f.puts <<EOS__
#if 0
- printf("%s\n", prelude_code);
+EOS__
+ preludes.length.times {|i|
+ f.puts <<EOS__
+ puts(prelude_code#{i});
+EOS__
+ }
+ f.puts <<EOS__
#endif
+EOS__
+
+ f.puts <<'EOS__'
}
EOS__
}