summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-15 03:26:20 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-15 03:26:20 +0000
commit3b37c7456406b7b9423c5fe0399f792be37e7d27 (patch)
tree6b7acccab591189baa9fbbef72113bd689342795 /tool
parentaf2ab37334cdd70ad4d0a7e859ded4653dcc391c (diff)
downloadruby-3b37c7456406b7b9423c5fe0399f792be37e7d27.tar.gz
* 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
Diffstat (limited to 'tool')
-rw-r--r--tool/compile_prelude.rb70
1 files changed, 38 insertions, 32 deletions
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 <<EOS__
-static const char prelude_name#{i}[] = "#{File.basename(prelude)}";
-static const char prelude_code#{i}[] =
-#{(setup_lines+lines).join("\n")}
+! preludes.zip(lines_list).each_with_index {|(prelude, (setup_lines, lines)), i|
+static const char prelude_name<%i%>[] = <%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 <<EOS__
+! lines_list.each_with_index {|(setup_lines, lines), i|
rb_iseq_eval(rb_iseq_compile(
- rb_str_new(prelude_code#{i}, sizeof(prelude_code#{i}) - 1),
- rb_str_new(prelude_name#{i}, sizeof(prelude_name#{i}) - 1),
- INT2FIX(#{1-setup_lines.length})));
+ rb_str_new(prelude_code<%i%>, sizeof(prelude_code<%i%>) - 1),
+ rb_str_new(prelude_name<%i%>, sizeof(prelude_name<%i%>) - 1),
+ INT2FIX(<%1-setup_lines.length%>)));
-EOS__
- }
- f.puts <<EOS__
+! }
#if 0
-EOS__
- preludes.length.times {|i|
- f.puts <<EOS__
- puts(prelude_code#{i});
-EOS__
- }
- f.puts <<EOS__
+! preludes.length.times {|i|
+ puts(prelude_code<%i%>);
+! }
#endif
-EOS__
-
- f.puts <<'EOS__'
}
-EOS__
+EOS
+
+open(outfile, 'w'){|f|
+ f << tmp
}