From 3b37c7456406b7b9423c5fe0399f792be37e7d27 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 15 Nov 2007 03:26:20 +0000 Subject: * tool/compile_prelude.rb: use simple template system for source code generation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/compile_prelude.rb | 70 +++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'tool/compile_prelude.rb') diff --git a/tool/compile_prelude.rb b/tool/compile_prelude.rb index 4d3707a8c9..1884cd08a2 100644 --- a/tool/compile_prelude.rb +++ b/tool/compile_prelude.rb @@ -51,51 +51,57 @@ lines_list = preludes.map {|filename| [setup_lines, lines] } -open(outfile, 'w'){|f| - f.puts <<'EOS__' +def serb(str, var) + result = '' + str.each_line {|line| + if /\A!/ =~ line + result << $' + else + line.split(/(<%.*?%>)/).each {|x| + if /\A<%(.*)%>\z/ =~ x + result << "#{var} << (#{$1}).to_s\n" + else + result << "#{var} << #{x.dump}\n" + end + } + end + } + result +end +tmp = '' +eval(serb(<<'EOS', 'tmp')) #include "ruby/ruby.h" #include "vm_core.h" -EOS__ - - preludes.zip(lines_list).each_with_index {|(prelude, (setup_lines, lines)), i| - f.puts <[] = <%c_esc(File.basename(prelude))%>; +static const char prelude_code<%i%>[] = +! (setup_lines+lines).each {|line| +<%line%> +! } ; -EOS__ - } - f.puts <<'EOS__' +! } void Init_prelude(void) { -EOS__ - lines_list.each_with_index {|(setup_lines, lines), i| - f.puts <, sizeof(prelude_code<%i%>) - 1), + rb_str_new(prelude_name<%i%>, sizeof(prelude_name<%i%>) - 1), + INT2FIX(<%1-setup_lines.length%>))); -EOS__ - } - f.puts <); +! } #endif -EOS__ - - f.puts <<'EOS__' } -EOS__ +EOS + +open(outfile, 'w'){|f| + f << tmp } -- cgit v1.2.3