diff options
Diffstat (limited to 'tool/compile_prelude.rb')
-rwxr-xr-x | tool/compile_prelude.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tool/compile_prelude.rb b/tool/compile_prelude.rb index e0a011ce2..48b9e2e1c 100755 --- a/tool/compile_prelude.rb +++ b/tool/compile_prelude.rb @@ -23,6 +23,10 @@ C_ESC_PAT = Regexp.union(*C_ESC.keys) def c_esc(str) '"' + str.gsub(C_ESC_PAT) { C_ESC[$&] } + '"' end +def prelude_name(*path_nests) + prelude = path_nests.map{|prelude_path| File.basename(prelude_path, ".rb") }.join(":") + "<internal:" + prelude + ">" +end mkconf = nil setup_ruby_prefix = nil @@ -47,6 +51,16 @@ lines_list = preludes.map {|filename| "nil" end } + line.gsub!(/require\s*(\(?)\s*(["'])(.*?)\2\s*\1/) { + orig, path = $&, $3 + srcdir = File.expand_path("../..", __FILE__) + path = File.expand_path(path, srcdir) + if File.exist?(path) + "eval(%s, TOPLEVEL_BINDING, %s, %d)" % [ File.read(path).dump, prelude_name(filename, path).dump, 1] + else + orig + end + } lines << c_esc(line) } setup_lines = [] @@ -60,11 +74,16 @@ lines_list = preludes.map {|filename| require 'erb' tmp = ERB.new(<<'EOS', nil, '%').result(binding) +/* -*-c-*- + THIS FILE WAS AUTOGENERATED BY tool/compile_prelude.rb. DO NOT EDIT. + + soruces: <%= preludes.join(', ') %> +*/ #include "ruby/ruby.h" #include "vm_core.h" % preludes.zip(lines_list).each_with_index {|(prelude, (setup_lines, lines)), i| -static const char prelude_name<%=i%>[] = <%=c_esc("<internal:" + File.basename(prelude, ".rb") + ">")%>; +static const char prelude_name<%=i%>[] = <%=c_esc(prelude_name(prelude))%>; static const char prelude_code<%=i%>[] = % (setup_lines+lines).each {|line| <%=line%> |